diff --git a/src/dsc.h b/src/dsc.h index 56c61674..9b1183ba 100644 --- a/src/dsc.h +++ b/src/dsc.h @@ -9,6 +9,34 @@ #include "solvespace.h" +#include + +/// Trait indicating which types are handle types and should get the associated operators. +/// Specialize for each handle type and inherit from std::true_type. +template +struct IsHandleOracle : std::false_type {}; + +// Equality-compare any two instances of a handle type. +template +static inline typename std::enable_if::value, bool>::type +operator==(T const &lhs, T const &rhs) { + return lhs.v == rhs.v; +} + +// Inequality-compare any two instances of a handle type. +template +static inline typename std::enable_if::value, bool>::type +operator!=(T const &lhs, T const &rhs) { + return !(lhs == rhs); +} + +// Less-than-compare any two instances of a handle type. +template +static inline typename std::enable_if::value, bool>::type +operator<(T const &lhs, T const &rhs) { + return lhs.v < rhs.v; +} + class Vector; class Vector4; class Point2d; @@ -285,6 +313,7 @@ public: } }; + // A list, where each element has an integer identifier. The list is kept // sorted by that identifier, and items can be looked up in log n time by // id. diff --git a/src/render/render.h b/src/render/render.h index 714180d2..c179d878 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -172,6 +172,13 @@ public: virtual std::shared_ptr CreateBatch(); }; +template<> +struct IsHandleOracle : std::true_type {}; + +template<> +struct IsHandleOracle : std::true_type {}; + + // An interface for view-dependent visualization. class ViewportCanvas : public Canvas { public: diff --git a/src/sketch.h b/src/sketch.h index 2f568386..e1c442bd 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -59,6 +59,10 @@ public: inline hParam param(int i) const; inline hEquation equation(int i) const; }; + +template<> +struct IsHandleOracle
: std::true_type {}; + class hRequest { public: // bits 15: 0 -- request index @@ -69,6 +73,10 @@ public: inline bool IsFromReferences() const; }; + +template<> +struct IsHandleOracle : std::true_type {}; + class hEntity { public: // bits 15: 0 -- entity index @@ -80,6 +88,10 @@ public: inline hGroup group() const; inline hEquation equation(int i) const; }; + +template<> +struct IsHandleOracle : std::true_type {}; + class hParam { public: // bits 15: 0 -- param index @@ -89,14 +101,24 @@ public: inline hRequest request() const; }; +template<> +struct IsHandleOracle : std::true_type {}; + class hStyle { public: uint32_t v; }; +template<> +struct IsHandleOracle : std::true_type {}; + struct EntityId { uint32_t v; // entity ID, starting from 0 }; + +template<> +struct IsHandleOracle : std::true_type {}; + struct EntityKey { hEntity input; int copyNumber; @@ -595,6 +617,9 @@ public: inline hParam param(int i) const; }; +template<> +struct IsHandleOracle : std::true_type {}; + class ConstraintBase { public: int tag; @@ -763,6 +788,9 @@ public: inline hConstraint constraint() const; }; +template<> +struct IsHandleOracle : std::true_type {}; + class Equation { public: int tag; diff --git a/src/srf/surface.h b/src/srf/surface.h index 4bca7e7d..f61b87c1 100644 --- a/src/srf/surface.h +++ b/src/srf/surface.h @@ -63,11 +63,17 @@ public: uint32_t v; }; +template<> +struct IsHandleOracle : std::true_type {}; + class hSCurve { public: uint32_t v; }; +template<> +struct IsHandleOracle : std::true_type {}; + // Stuff for rational polynomial curves, of degree one to three. These are // our inputs, and are also calculated for certain exact surface-surface // intersections.