summaryrefslogtreecommitdiffhomepage
path: root/entity
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-23 07:25:55 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-23 07:26:22 +0100
commit06ccfd8b34c702da9ad695982e8210823d7b501c (patch)
treeeb2986f39294b4c8902b68c0337e004eebb09f37 /entity
parent384d5c20d85a8ed9a4ccd0ede4457381c7458549 (diff)
wip
Diffstat (limited to 'entity')
-rw-r--r--entity/erased-constraints.cpp71
-rw-r--r--entity/erased-constraints.hpp58
2 files changed, 74 insertions, 55 deletions
diff --git a/entity/erased-constraints.cpp b/entity/erased-constraints.cpp
new file mode 100644
index 00000000..599b4164
--- /dev/null
+++ b/entity/erased-constraints.cpp
@@ -0,0 +1,71 @@
+#include "erased-constraints.hpp"
+#include "compat/assert.hpp"
+#include <cstdint>
+#include <cmath>
+#include <limits>
+
+static_assert(sizeof(std::size_t) == sizeof(std::uintptr_t));
+static_assert(sizeof(std::size_t) == sizeof(std::ptrdiff_t));
+
+namespace floormat::entities::erased_constraints {
+
+template<typename T> std::pair<T, T> range::convert() const
+{
+ static_assert(sizeof(T) <= sizeof(std::size_t));
+ using limits = std::numeric_limits<T>;
+
+ if (type == type_none)
+ return { limits::min(), limits::max() };
+ else
+ {
+ if constexpr (std::is_integral_v<T>)
+ {
+ if (std::is_signed_v<T>)
+ {
+ fm_assert(type == type_int);
+ return { T(min.i), T(max.i) };
+ }
+ else
+ {
+ fm_assert(type == type_uint);
+ return { T(min.u), T(max.u) };
+ }
+ }
+ else
+ {
+ static_assert(std::is_floating_point_v<T>);
+ fm_assert(type == type_float);
+ return { T(min.f), T(max.f) };
+ }
+ }
+}
+
+template std::pair<std::uint8_t, std::uint8_t> range::convert() const;
+template std::pair<std::uint16_t, std::uint16_t> range::convert() const;
+template std::pair<std::uint32_t, std::uint32_t> range::convert() const;
+template std::pair<std::uint64_t, std::uint64_t> range::convert() const;
+template std::pair<std::int8_t, std::int8_t> range::convert() const;
+template std::pair<std::int16_t, std::int16_t> range::convert() const;
+template std::pair<std::int32_t, std::int32_t> range::convert() const;
+template std::pair<std::int64_t, std::int64_t> range::convert() const;
+template std::pair<float, float> range::convert() const;
+template std::pair<double, double> range::convert() const;
+
+bool operator==(const range& a, const range& b)
+{
+ if (a.type != b.type)
+ return false;
+
+ constexpr float eps = 1e-6f;
+
+ switch (a.type)
+ {
+ default: return false;
+ case range::type_none: return true;
+ case range::type_float: return std::fabs(a.min.f - b.min.f) < eps && std::fabs(a.max.f - b.max.f) < eps;
+ case range::type_uint: return a.min.u == b.min.u && a.max.u == b.max.u;
+ case range::type_int: return a.min.i == b.min.i && a.max.i == b.max.i;
+ }
+}
+
+} // namespace floormat::entities::erased_constraints
diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp
index 4fe5c853..5a6cb939 100644
--- a/entity/erased-constraints.hpp
+++ b/entity/erased-constraints.hpp
@@ -1,15 +1,8 @@
#pragma once
-#include <cstddef>
-#include <cmath>
-#include <limits>
-#include <cstdint>
#include <Corrade/Containers/StringView.h>
namespace floormat::entities::erased_constraints {
-static_assert(sizeof(std::size_t) == sizeof(std::uintptr_t));
-static_assert(sizeof(std::size_t) == sizeof(std::ptrdiff_t));
-
struct range final
{
using U = std::size_t;
@@ -24,57 +17,13 @@ struct range final
element min {.i = 0}, max {.i = 0};
type_ type = type_none;
- template<typename T> constexpr std::pair<T, T> convert() const;
+ template<typename T> std::pair<T, T> convert() const;
+ friend bool operator==(const range& a, const range& b);
};
-template<typename T> constexpr std::pair<T, T> range::convert() const
-{
- static_assert(sizeof(T) <= sizeof(std::size_t));
- using limits = std::numeric_limits<T>;
-
- if (type == type_none)
- return { limits::min(), limits::max() };
- else
- {
- if constexpr (std::is_integral_v<T> && std::is_signed_v<T>)
- {
- fm_assert(type == type_int);
- return { T(min.i), T(max.i) };
- }
- else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>)
- {
- fm_assert(type == type_uint);
- return { T(min.u), T(max.u) };
- }
- else
- {
- fm_assert(type == type_float);
- return { T(min.i), T(max.i) };
- }
- }
-}
-
-constexpr bool operator==(const range& a, const range& b)
-{
- if (a.type != b.type)
- return false;
-
- constexpr float eps = 1e-6f;
-
- switch (a.type)
- {
- default: return false;
- case range::type_none: return true;
- case range::type_float: return std::fabs(a.min.f - b.min.f) < eps && std::fabs(a.max.f - b.max.f) < eps;
- case range::type_uint: return a.min.u == b.min.u && a.max.u == b.max.u;
- case range::type_int: return a.min.i == b.min.i && a.max.i == b.max.i;
- }
-}
-
struct max_length final {
- std::size_t value = std::numeric_limits<std::size_t>::max();
+ std::size_t value = std::size_t(-1);
constexpr operator std::size_t() const { return value; }
- //constexpr bool operator==(const max_length&) const noexcept = default;
};
struct group final {
@@ -82,7 +31,6 @@ struct group final {
constexpr operator StringView() const { return group_name; }
constexpr group() = default;
constexpr group(StringView name) : group_name{name} {}
- //constexpr bool operator==(const group&) const noexcept = default;
};
} // namespace floormat::entities::erased_constraints