23 #include "glShared.h" |
23 #include "glShared.h" |
24 #include "colors.h" |
24 #include "colors.h" |
25 |
25 |
26 #define LDOBJ(T) \ |
26 #define LDOBJ(T) \ |
27 public: \ |
27 public: \ |
|
28 static constexpr LDObjectType SubclassType = OBJ_##T; \ |
|
29 LD##T (LDObjectPtr* selfptr); \ |
|
30 \ |
28 virtual LDObjectType type() const override \ |
31 virtual LDObjectType type() const override \ |
29 { \ |
32 { \ |
30 return OBJ_##T; \ |
33 return OBJ_##T; \ |
31 } \ |
34 } \ |
|
35 \ |
32 virtual QString asText() const override; \ |
36 virtual QString asText() const override; \ |
33 virtual void invert() override; \ |
37 virtual void invert() override; \ |
34 \ |
|
35 LD##T (LDObjectPtr* selfptr); \ |
|
36 |
38 |
37 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
39 #define LDOBJ_NAME(N) public: virtual QString typeName() const override { return #N; } |
38 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
40 #define LDOBJ_VERTICES(V) public: virtual int numVertices() const override { return V; } |
39 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
41 #define LDOBJ_SETCOLORED(V) public: virtual bool isColored() const override { return V; } |
40 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
42 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) |
592 "see CAreadme.txt"); |
594 "see CAreadme.txt"); |
593 static const int LowResolution = 16; |
595 static const int LowResolution = 16; |
594 static const int HighResolution = 48; |
596 static const int HighResolution = 48; |
595 |
597 |
596 QString PreferredLicenseText(); |
598 QString PreferredLicenseText(); |
|
599 |
|
600 template<typename T> |
|
601 inline void DynamicExecute (LDObjectPtr obj, std::function<void (QSharedPointer<T> const&)> func) |
|
602 { |
|
603 static_assert (std::is_base_of<LDObject, T>::value, |
|
604 "DynamicExecute may only be used with LDObject-derivatives"); |
|
605 |
|
606 if (obj->type() == T::SubclassType) |
|
607 func (obj.staticCast<T>()); |
|
608 } |
|
609 |
|
610 struct LDIterationBreakage {}; |
|
611 |
|
612 template<typename T> |
|
613 inline void LDIterate (LDObjectList const& objs, |
|
614 std::function<void (QSharedPointer<T> const&)> func) |
|
615 { |
|
616 static_assert (std::is_base_of<LDObject, T>::value, |
|
617 "LDIterate may only be used with LDObject-derivatives"); |
|
618 |
|
619 try |
|
620 { |
|
621 for (LDObjectPtr const& obj : objs) |
|
622 DynamicExecute<T> (obj, func); |
|
623 } |
|
624 catch (LDIterationBreakage) {} |
|
625 } |
|
626 |
|
627 inline void Break() |
|
628 { |
|
629 throw LDIterationBreakage(); |
|
630 } |