Traits work for handles to permit sharing functionality and operators. NFC.
parent
346f004e51
commit
7bd4b149f7
29
src/dsc.h
29
src/dsc.h
|
@ -9,6 +9,34 @@
|
|||
|
||||
#include "solvespace.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
/// 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<typename T>
|
||||
struct IsHandleOracle : std::false_type {};
|
||||
|
||||
// Equality-compare any two instances of a handle type.
|
||||
template<typename T>
|
||||
static inline typename std::enable_if<IsHandleOracle<T>::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<typename T>
|
||||
static inline typename std::enable_if<IsHandleOracle<T>::value, bool>::type
|
||||
operator!=(T const &lhs, T const &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
// Less-than-compare any two instances of a handle type.
|
||||
template<typename T>
|
||||
static inline typename std::enable_if<IsHandleOracle<T>::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.
|
||||
|
|
|
@ -172,6 +172,13 @@ public:
|
|||
virtual std::shared_ptr<BatchCanvas> CreateBatch();
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<Canvas::hStroke> : std::true_type {};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<Canvas::hFill> : std::true_type {};
|
||||
|
||||
|
||||
// An interface for view-dependent visualization.
|
||||
class ViewportCanvas : public Canvas {
|
||||
public:
|
||||
|
|
28
src/sketch.h
28
src/sketch.h
|
@ -59,6 +59,10 @@ public:
|
|||
inline hParam param(int i) const;
|
||||
inline hEquation equation(int i) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hGroup> : std::true_type {};
|
||||
|
||||
class hRequest {
|
||||
public:
|
||||
// bits 15: 0 -- request index
|
||||
|
@ -69,6 +73,10 @@ public:
|
|||
|
||||
inline bool IsFromReferences() const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hRequest> : 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<hEntity> : std::true_type {};
|
||||
|
||||
class hParam {
|
||||
public:
|
||||
// bits 15: 0 -- param index
|
||||
|
@ -89,14 +101,24 @@ public:
|
|||
inline hRequest request() const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hParam> : std::true_type {};
|
||||
|
||||
class hStyle {
|
||||
public:
|
||||
uint32_t v;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hStyle> : std::true_type {};
|
||||
|
||||
struct EntityId {
|
||||
uint32_t v; // entity ID, starting from 0
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<EntityId> : std::true_type {};
|
||||
|
||||
struct EntityKey {
|
||||
hEntity input;
|
||||
int copyNumber;
|
||||
|
@ -595,6 +617,9 @@ public:
|
|||
inline hParam param(int i) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hConstraint> : std::true_type {};
|
||||
|
||||
class ConstraintBase {
|
||||
public:
|
||||
int tag;
|
||||
|
@ -763,6 +788,9 @@ public:
|
|||
inline hConstraint constraint() const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hEquation> : std::true_type {};
|
||||
|
||||
class Equation {
|
||||
public:
|
||||
int tag;
|
||||
|
|
|
@ -63,11 +63,17 @@ public:
|
|||
uint32_t v;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hSSurface> : std::true_type {};
|
||||
|
||||
class hSCurve {
|
||||
public:
|
||||
uint32_t v;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct IsHandleOracle<hSCurve> : 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.
|
||||
|
|
Loading…
Reference in New Issue