Traits work for handles to permit sharing functionality and operators. NFC.
This commit is contained in:
parent
346f004e51
commit
7bd4b149f7
29
src/dsc.h
29
src/dsc.h
@ -9,6 +9,34 @@
|
|||||||
|
|
||||||
#include "solvespace.h"
|
#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 Vector;
|
||||||
class Vector4;
|
class Vector4;
|
||||||
class Point2d;
|
class Point2d;
|
||||||
@ -285,6 +313,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// A list, where each element has an integer identifier. The list is kept
|
// 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
|
// sorted by that identifier, and items can be looked up in log n time by
|
||||||
// id.
|
// id.
|
||||||
|
@ -172,6 +172,13 @@ public:
|
|||||||
virtual std::shared_ptr<BatchCanvas> CreateBatch();
|
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.
|
// An interface for view-dependent visualization.
|
||||||
class ViewportCanvas : public Canvas {
|
class ViewportCanvas : public Canvas {
|
||||||
public:
|
public:
|
||||||
|
28
src/sketch.h
28
src/sketch.h
@ -59,6 +59,10 @@ public:
|
|||||||
inline hParam param(int i) const;
|
inline hParam param(int i) const;
|
||||||
inline hEquation equation(int i) const;
|
inline hEquation equation(int i) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hGroup> : std::true_type {};
|
||||||
|
|
||||||
class hRequest {
|
class hRequest {
|
||||||
public:
|
public:
|
||||||
// bits 15: 0 -- request index
|
// bits 15: 0 -- request index
|
||||||
@ -69,6 +73,10 @@ public:
|
|||||||
|
|
||||||
inline bool IsFromReferences() const;
|
inline bool IsFromReferences() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hRequest> : std::true_type {};
|
||||||
|
|
||||||
class hEntity {
|
class hEntity {
|
||||||
public:
|
public:
|
||||||
// bits 15: 0 -- entity index
|
// bits 15: 0 -- entity index
|
||||||
@ -80,6 +88,10 @@ public:
|
|||||||
inline hGroup group() const;
|
inline hGroup group() const;
|
||||||
inline hEquation equation(int i) const;
|
inline hEquation equation(int i) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hEntity> : std::true_type {};
|
||||||
|
|
||||||
class hParam {
|
class hParam {
|
||||||
public:
|
public:
|
||||||
// bits 15: 0 -- param index
|
// bits 15: 0 -- param index
|
||||||
@ -89,14 +101,24 @@ public:
|
|||||||
inline hRequest request() const;
|
inline hRequest request() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hParam> : std::true_type {};
|
||||||
|
|
||||||
class hStyle {
|
class hStyle {
|
||||||
public:
|
public:
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hStyle> : std::true_type {};
|
||||||
|
|
||||||
struct EntityId {
|
struct EntityId {
|
||||||
uint32_t v; // entity ID, starting from 0
|
uint32_t v; // entity ID, starting from 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<EntityId> : std::true_type {};
|
||||||
|
|
||||||
struct EntityKey {
|
struct EntityKey {
|
||||||
hEntity input;
|
hEntity input;
|
||||||
int copyNumber;
|
int copyNumber;
|
||||||
@ -595,6 +617,9 @@ public:
|
|||||||
inline hParam param(int i) const;
|
inline hParam param(int i) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hConstraint> : std::true_type {};
|
||||||
|
|
||||||
class ConstraintBase {
|
class ConstraintBase {
|
||||||
public:
|
public:
|
||||||
int tag;
|
int tag;
|
||||||
@ -763,6 +788,9 @@ public:
|
|||||||
inline hConstraint constraint() const;
|
inline hConstraint constraint() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hEquation> : std::true_type {};
|
||||||
|
|
||||||
class Equation {
|
class Equation {
|
||||||
public:
|
public:
|
||||||
int tag;
|
int tag;
|
||||||
|
@ -63,11 +63,17 @@ public:
|
|||||||
uint32_t v;
|
uint32_t v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hSSurface> : std::true_type {};
|
||||||
|
|
||||||
class hSCurve {
|
class hSCurve {
|
||||||
public:
|
public:
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IsHandleOracle<hSCurve> : std::true_type {};
|
||||||
|
|
||||||
// Stuff for rational polynomial curves, of degree one to three. These are
|
// Stuff for rational polynomial curves, of degree one to three. These are
|
||||||
// our inputs, and are also calculated for certain exact surface-surface
|
// our inputs, and are also calculated for certain exact surface-surface
|
||||||
// intersections.
|
// intersections.
|
||||||
|
Loading…
Reference in New Issue
Block a user