src/ldObject.h

changeset 956
2af18ba2665f
parent 946
9cbd658b63f9
child 959
737245eee433
equal deleted inserted replaced
955:39d789d675fc 956:2af18ba2665f
98 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE) 98 PROPERTY (public, LDColor, color, setColor, CUSTOM_WRITE)
99 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE) 99 PROPERTY (private, QColor, randomColor, setRandomColor, STOCK_WRITE)
100 100
101 public: 101 public:
102 LDObject (LDDocument* document = nullptr); 102 LDObject (LDDocument* document = nullptr);
103 virtual ~LDObject();
104 103
105 // This object as LDraw code 104 // This object as LDraw code
106 virtual QString asText() const = 0; 105 virtual QString asText() const = 0;
107 106
108 // Makes a copy of this object 107 // Makes a copy of this object
187 186
188 // Get a description of a list of LDObjects 187 // Get a description of a list of LDObjects
189 static QString describeObjects (const LDObjectList& objs); 188 static QString describeObjects (const LDObjectList& objs);
190 static LDObject* fromID (int id); 189 static LDObject* fromID (int id);
191 LDPolygon* getPolygon(); 190 LDPolygon* getPolygon();
191 bool isDestroyed() const { return m_isDestroyed; }
192 192
193 // TODO: make this private! 193 // TODO: make this private!
194 QListWidgetItem* qObjListEntry; 194 QListWidgetItem* qObjListEntry;
195 195
196 protected:
197 virtual ~LDObject();
198
196 private: 199 private:
197 Vertex m_coords[4]; 200 Vertex m_coords[4];
198 201 bool m_isDestroyed;
202
199 void chooseID(); 203 void chooseID();
200 }; 204 };
201 205
202 // 206 //
203 // Makes a new LDObject. This makes the shared pointer always use the custom 207 // Makes a new LDObject. This makes the shared pointer always use the custom
537 LowResolution = 16, 541 LowResolution = 16,
538 HighResolution = 48 542 HighResolution = 48
539 }; 543 };
540 544
541 QString PreferredLicenseText(); 545 QString PreferredLicenseText();
542
543 template<typename T>
544 inline void DynamicExecute (LDObject* obj, std::function<void (T*)> func)
545 {
546 static_assert (std::is_base_of<LDObject, T>::value,
547 "DynamicExecute may only be used with LDObject-derivatives");
548
549 if (obj->type() == T::SubclassType)
550 func (static_cast<T*> (obj));
551 }
552
553 struct LDIterationBreakage {};
554
555 template<typename T>
556 inline void LDIterate (LDObjectList const& objs,
557 std::function<void (T*)> func)
558 {
559 static_assert (std::is_base_of<LDObject, T>::value,
560 "LDIterate may only be used with LDObject-derivatives");
561
562 try
563 {
564 for (LDObject* const& obj : objs)
565 DynamicExecute<T> (obj, func);
566 }
567 catch (LDIterationBreakage) {}
568 }
569
570 inline void Break()
571 {
572 throw LDIterationBreakage();
573 }

mercurial