src/ldObject.cc

changeset 770
b04c1e6ca1fb
parent 769
8bb3bed44570
child 771
0f04e34bec54
--- a/src/ldObject.cc	Fri May 16 01:22:24 2014 +0300
+++ b/src/ldObject.cc	Fri May 16 21:31:20 2014 +0300
@@ -34,31 +34,45 @@
 // List of all LDObjects
 static QMap<long, LDObjectWeakPtr> g_allObjects;
 
-// Temporary resource
-LDObjectPtr g_temporaryLDObject;
+#define LDOBJ_DEFAULT_CTOR(T,BASE) \
+	T :: T (LDObjectPtr* selfptr) : \
+		BASE (selfptr) {}
 
 // =============================================================================
 // LDObject constructors
 //
-LDObject::LDObject() :
+LDObject::LDObject (LDObjectPtr* selfptr) :
 	m_isHidden (false),
 	m_isSelected (false),
 	m_isDestructed (false),
 	m_document (null),
 	qObjListEntry (null)
 {
-	LDObjectPtr selfptr (this, [](LDObject* obj){ obj->finalDelete(); });
+	*selfptr = LDObjectPtr (this, [](LDObject* obj){ obj->finalDelete(); });
 	memset (m_coords, 0, sizeof m_coords);
-	m_self = selfptr;
+	m_self = selfptr->toWeakRef();
 	chooseID();
 	g_allObjects[id()] = self();
 	setRandomColor (QColor::fromHsv (rand() % 360, rand() % 256, rand() % 96 + 128));
+}
 
-	// This prevents the object from being prematurely deleted just because
-	// selfptr falls out of scope before it's caught by spawn()
-	g_temporaryLDObject = selfptr;
+LDSubfile::LDSubfile (LDObjectPtr* selfptr) :
+	LDObject (selfptr)
+{
+	setLinkPointer (self());
 }
 
+LDOBJ_DEFAULT_CTOR (LDEmpty, LDObject)
+LDOBJ_DEFAULT_CTOR (LDError, LDObject)
+LDOBJ_DEFAULT_CTOR (LDLine, LDObject)
+LDOBJ_DEFAULT_CTOR (LDTriangle, LDObject)
+LDOBJ_DEFAULT_CTOR (LDCondLine, LDLine)
+LDOBJ_DEFAULT_CTOR (LDQuad, LDObject)
+LDOBJ_DEFAULT_CTOR (LDVertex, LDObject)
+LDOBJ_DEFAULT_CTOR (LDOverlay, LDObject)
+LDOBJ_DEFAULT_CTOR (LDBFC, LDObject)
+LDOBJ_DEFAULT_CTOR (LDComment, LDObject)
+
 // =============================================================================
 //
 void LDObject::chooseID()
@@ -69,9 +83,6 @@
 	{
 		LDObjectPtr obj = it->toStrongRef();
 
-		if (not obj)
-			fprint (stdout, "obj #%1 wasn't removed properly\n", it.key());
-
 		assert (obj != this);
 		assert (obj != null);
 
@@ -91,8 +102,6 @@
 	setVertex (i, v);
 }
 
-LDError::LDError() {}
-
 // =============================================================================
 //
 String LDComment::asText() const
@@ -246,7 +255,8 @@
 
 // =============================================================================
 //
-LDLine::LDLine (Vertex v1, Vertex v2)
+LDLine::LDLine (LDObjectPtr* selfptr, Vertex v1, Vertex v2) :
+	LDObject (selfptr)
 {
 	setVertex (0, v1);
 	setVertex (1, v2);
@@ -254,7 +264,9 @@
 
 // =============================================================================
 //
-LDQuad::LDQuad (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3)
+LDQuad::LDQuad (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1,
+				const Vertex& v2, const Vertex& v3) :
+	LDObject (selfptr)
 {
 	setVertex (0, v0);
 	setVertex (1, v1);
@@ -264,7 +276,9 @@
 
 // =============================================================================
 //
-LDCondLine::LDCondLine (const Vertex& v0, const Vertex& v1, const Vertex& v2, const Vertex& v3)
+LDCondLine::LDCondLine (LDObjectPtr* selfptr, const Vertex& v0, const Vertex& v1,
+						const Vertex& v2, const Vertex& v3) :
+	LDLine (selfptr)
 {
 	setVertex (0, v0);
 	setVertex (1, v1);

mercurial