[Mobies-commit] [commit] r3773 - in UDM/trunk: include src/Udm src/UdmBase src/UdmDom src/UdmGme src/Uml

endre at redhat1.isis.vanderbilt.edu endre at redhat1.isis.vanderbilt.edu
Mon Jul 4 13:18:22 CDT 2011


Author: endre
Date: Mon Jul  4 13:18:21 2011
New Revision: 3773

Log:
Make ObjectImpl::__getdn() a const method.

mydn data member of static objects is updated when the object is attached
to a network by setting its parent.

Modified:
   UDM/trunk/include/UdmBase.h
   UDM/trunk/include/UdmStatic.h
   UDM/trunk/src/Udm/DiagramGen.cpp
   UDM/trunk/src/UdmBase/UdmStatic.cpp
   UDM/trunk/src/UdmDom/UdmDom.cpp
   UDM/trunk/src/UdmGme/GmeObject.h
   UDM/trunk/src/UdmGme/UdmGme.cpp
   UDM/trunk/src/Uml/Uml.cpp

Modified: UDM/trunk/include/UdmBase.h
==============================================================================
--- UDM/trunk/include/UdmBase.h	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/include/UdmBase.h	Mon Jul  4 13:18:21 2011	(r3773)
@@ -296,7 +296,7 @@
 	public:
 		virtual ObjectImpl *clone() = 0;
 		virtual void release() = 0;
-		virtual DataNetwork *__getdn() = 0;
+		virtual DataNetwork *__getdn() const = 0;
 
 	// --- type
 
@@ -593,7 +593,7 @@
 		// in Object::Object(...) we assume this refererence counting behaviour
 		virtual ObjectImpl *clone() { return this; }
 		virtual void release() { } 
-		virtual DataNetwork *__getdn() { throw e; }
+		virtual DataNetwork *__getdn() const { throw e; }
 
 		virtual const ::Uml::Class &type() const { throw e; }
 
@@ -4071,6 +4071,6 @@
 
 //versioning
 #define UDM_VERSION_MAJOR 3
-#define UDM_VERSION_MINOR 28
+#define UDM_VERSION_MINOR 27
 #define UDM_VERSION UDM_VERSION_MAJOR * 100 + UDM_VERSION_MINOR
 #endif//MOBIES_UDMBASE_H

Modified: UDM/trunk/include/UdmStatic.h
==============================================================================
--- UDM/trunk/include/UdmStatic.h	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/include/UdmStatic.h	Mon Jul  4 13:18:21 2011	(r3773)
@@ -174,6 +174,8 @@
 		static void Cleanup();
 		friend class Udm::UdmStaticData; // needs to alter the id_map_so_set_deleted flag
 		friend unsigned long StaticDataNetwork::DeSerialize(FILE*, map<unsigned long, const StaticObject*>&, Object&);
+		friend void CreateComposition(const Object &, const ::Uml::CompositionChildRole &, const Object &, const ::Uml::CompositionParentRole &);
+		friend void Uml::Initialize();
 	private:
 		StaticDataNetwork * mydn;
 
@@ -205,6 +207,9 @@
 		bool lib_object;
 		bool lib_root;
 
+		// initialization needed from constructors
+		void init();
+
 	public:
 
 		StaticObject(const ::Uml::Class &meta, 
@@ -212,6 +217,9 @@
 					StaticObject * archetype = NULL, 
 					const bool subtype = false,
 					const bool real_archetype = true);
+		StaticObject(const ::Uml::Class &meta,
+					StaticDataNetwork *dn,
+					int ref);
 		void Destroy(bool root);		//destroy the object network
 										// this deletes all the objects explicitly,
 										// to be used only when the data network is going away ..
@@ -230,7 +238,7 @@
 
 		ObjectImpl *clone();
 		void release();
-		Udm::DataNetwork *__getdn();
+		Udm::DataNetwork *__getdn() const;
 		const ::Uml::Class &m_type;
 		bool m_type_is_safetype;
 	

Modified: UDM/trunk/src/Udm/DiagramGen.cpp
==============================================================================
--- UDM/trunk/src/Udm/DiagramGen.cpp	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/Udm/DiagramGen.cpp	Mon Jul  4 13:18:21 2011	(r3773)
@@ -134,6 +134,18 @@
 ")
 					);
 
+	// create a static DN for Uml meta
+	if (gen.opts.meta_init == UdmOpts::STATIC_INIT && dgr_name == "Uml")
+		meth_defs.push_back( boost::format("\tUdmStatic::StaticDataNetwork* dn = new UdmStatic::StaticDataNetwork(diagram);\n\
+\t\tdn->rootobject = meta;\n\
+\t\tstatic_cast<UdmStatic::StaticObject*>(dn->rootobject.__impl())->mydn = dn;\n\
+\t\tdn->systemname = \"%1%\";\n\
+\t\tdn->sem = Udm::CHANGES_LOST_DEFAULT;\n\
+\n\
+")
+					% dgr_name
+					);
+
 	meth_defs.push_back( boost::format("\tCreateMeta();\n\
 \t\tInitMeta();\n\
 \t\tInitMetaLinks();\n\
@@ -141,7 +153,6 @@
 				);
 
 	if (gen.opts.meta_init == UdmOpts::STATIC_INIT)
-	{
 		meth_defs.push_back( boost::format("\t::Uml::InitDiagram(meta, \"%1%\", \"%2%\");\n\
 \n\
 ")
@@ -149,17 +160,6 @@
 					% (string) c.version()
 					);
 
-		// create a static DN for Uml meta
-		if (dgr_name == "Uml") 
-			meth_defs.push_back( boost::format("\tUdmStatic::StaticDataNetwork* dn = new UdmStatic::StaticDataNetwork(diagram);\n\
-\t\tdn->rootobject = meta;\n\
-\t\tdn->systemname = \"%1%\";\n\
-\t\tdn->sem = Udm::CHANGES_LOST_DEFAULT;\n\
-\n\
-")
-						% dgr_name
-						);
-	}
 	else if (gen.opts.meta_init == UdmOpts::CORBA_INIT)
 		meth_defs.push_back( boost::format("\t::Uml::InitCORBADiagram(meta, \"%1%\", \"%2%\");\n\
 \n\

Modified: UDM/trunk/src/UdmBase/UdmStatic.cpp
==============================================================================
--- UDM/trunk/src/UdmBase/UdmStatic.cpp	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/UdmBase/UdmStatic.cpp	Mon Jul  4 13:18:21 2011	(r3773)
@@ -290,21 +290,40 @@
 	m_type(meta), 
 	id_map_so_set_deleted(false),
 	m_parent(NULL),
+	mydn(NULL),
 	lib_object(false),
 	lib_root(false),
 	lib_name("")
 	{ 
-	//	GetIdForObject((StaticObject*)this);
-	//	InsertObject((StaticObject*)this);
+		init();
+	}
+
+	StaticObject::StaticObject(const ::Uml::Class &meta, StaticDataNetwork *dn, int ref) :
+	deleted(false), 
+	archetype(NULL), 
+	subtype(false),  
+	real_archetype(true), 
+	refCount(ref),
+	m_type(meta), 
+	id_map_so_set_deleted(false),
+	m_parent(NULL),
+	mydn(dn),
+	lib_object(false),
+	lib_root(false),
+	lib_name("")
+	{
+		init();
+	}
 
+	void StaticObject::init()
+	{
 		pair<set<StaticObject*>::iterator, bool> ins_res  = Udm::_UdmStaticData.so_set.insert(this);
 		if (!ins_res.second)
 			throw udm_exception(" Corrupt set, pointer already exists in the map ?");
 
-		mydn = NULL;
 		m_type_is_safetype = Uml::SafeTypeContainer::IsSafeType(m_type);
 	}
-	
+
 	StaticObject::~StaticObject()
 	{
 
@@ -375,25 +394,29 @@
 	}
 
 
-	Udm::DataNetwork * StaticObject::__getdn() 
+	Udm::DataNetwork * StaticObject::__getdn() const
 	{ 
-
+#ifdef _DEBUG
 		if (!mydn)
 		{
-			StaticObject * p = this;
+			// Check if the object belongs to a DN but its mydn member is not set
+			const StaticObject * p = this;
 			while (p->m_parent) p = p->m_parent;				
 			for(SDNList::iterator ff = Udm::_UdmStaticData.SDNs.begin(); ff != Udm::_UdmStaticData.SDNs.end(); ff++) 
 			{
 				Object root = (*ff)->GetRootObject();
-				if(root && static_cast<StaticObject *>(root.__impl())  == p) 
-				{
-					mydn = *ff;			//*ff is a StaticDataNetwork
-					return *ff;			//*ff is casted to Udm::DataNetwork
+				if ( static_cast<StaticObject *>(root.__impl()) == p ) {
+					const StaticObject *p = this;
+					while (p->m_parent) {
+						StaticObject *p2 = p->m_parent;
+						p = p->m_parent;
+					}
 				}
+				UDM_ASSERT( static_cast<StaticObject *>(root.__impl()) != p );
 			}
-			return NULL;
-				
-		} else return mydn;
+		}
+#endif
+		return mydn;
 
 	}
 
@@ -1069,6 +1092,7 @@
 								children_type::iterator j = ii++;
 								st_and_i_o->m_parent->m_children.erase(j);
 								st_and_i_o->refCount--;//we don't release it, it might be reused. if not, it will be deleted
+								st_and_i_o->mydn = NULL;
 								cntt++;
 								
 							} else ii++;
@@ -1113,11 +1137,13 @@
 							pair<uniqueId_type const, StaticObject *> child(ccr.uniqueId(), (StaticObject*)(st_and_i_o->clone()));
 							/*children_type::iterator ins_res = */cp_impl->m_children.insert(child);
 							st_and_i_o->m_parent = cp_impl;
+							st_and_i_o->mydn = static_cast<StaticDataNetwork*>(cp_impl->__getdn());
 							moved_to_parents_ok.insert(cp_impl);
 						}
 						else
 						{
 							st_and_i_o->m_parent = NULL; //refcount is already decremented because of this
+							st_and_i_o->mydn = NULL;
 							st_and_i_o->setParent(NULL, NULL, false);
 						}
 						
@@ -1126,6 +1152,7 @@
 				}
 			}
 			m_parent = NULL;
+			mydn = NULL;
 		};
 
 		//end of removal from children of my parent
@@ -1142,6 +1169,9 @@
 			/*children_type::iterator ins_res = */aa.m_children.insert(child);
 			m_parent =(UdmStatic::StaticObject*)a;
 
+			// set our dn
+			mydn = static_cast<StaticDataNetwork*>(a->__getdn());
+
 			//in the situation which the new parent has derived/instantiated objects
 			//and the new child is not coming from the archetype block
 			if (direct)
@@ -2640,11 +2670,13 @@
 			
 			//create the `so` object with the meta information
 			StaticObject * so = new StaticObject(safe_type, 1, reinterpret_cast<StaticObject *>(archetype_id), subtype_val, real_archetype_val );
+			so->mydn = this;
 			read_list.push_front(so);		//add to the list of read objects
 
 			//if this is the first call, then assign the first StaticObject to rootobject
 			if(is_first)
 			{
+				so->mydn = this;
 				root_o = so;
 				is_first = false;
 			}
@@ -4012,6 +4044,7 @@
 			
 			//now it's a real object, set it's parent to so
 			((*so_ch_i).second)->m_parent = this;
+			((*so_ch_i).second)->mydn = static_cast<StaticDataNetwork *>(__getdn());
 			((*so_ch_i).second)->clone();		//because it's in my children map
 			
 		}
@@ -4107,6 +4140,7 @@
 		pair<uniqueId_type const, StaticObject *> child(0, (StaticObject *) (dep->clone()));
 		m_children.insert(child);
 		dep->m_parent = this;
+		dep->mydn = mydn;
 
 		dep->setDefaultAttributes(false);
 
@@ -4166,14 +4200,14 @@
 
 		root_o->Destroy(true);
 	
-		rootobject =&Udm::_null;
+		rootobject = Udm::null;
 	};
 
 	
 	UDM_DLL StaticDataNetwork::StaticDataNetwork(const Udm::UdmDiagram &metainfo, Udm::UdmProject* project) :	Udm::DataNetwork(metainfo, project)   
 	{
 		Udm::_UdmStaticData.SDNs.push_front(this);
-		rootobject = NULL;
+		rootobject = Udm::null;
 		
 		/*
 			a meta-data network is needed for getting the meta-objects(attributes, childroles, associationroles) by their IDs.
@@ -4182,7 +4216,8 @@
 			line above would be NULL. In this cases, knowning that StaticDataNetwork::ObjectById() will work fine for _all_ StaticObjects, we
 			use our Datanetwork's StaticDataNetwork to map back ids to objects.
 		*/
-		meta_dn = metainfo.dgr->__impl()->__getdn();
+		if (metainfo.dgr->__impl() != &Udm::_null)
+			meta_dn = metainfo.dgr->__impl()->__getdn();
 		if (!meta_dn) meta_dn = this;
 
 	};
@@ -4197,7 +4232,7 @@
 	UDM_DLL void StaticDataNetwork::CreateNew(const string &systemname, const string &metalocator, 
 		const ::Uml::Class &rootclass, enum Udm::BackendSemantics sem) 
 	{
-		rootobject = new StaticObject(rootclass, 1);
+		rootobject = new StaticObject(rootclass, this, 1);
 	//	rootobject.__impl()->setDefaultAttributes();
 		this->systemname = systemname;
 		this->sem = sem;
@@ -4331,6 +4366,7 @@
 
 		child->refCount += 2;
 		child->m_parent = parent;
+		child->mydn = static_cast<StaticDataNetwork *>(parent->__getdn());
 		parent->m_children.insert(StaticObject::children_type::value_type(
 			childRole.uniqueId(), child));
 	}

Modified: UDM/trunk/src/UdmDom/UdmDom.cpp
==============================================================================
--- UDM/trunk/src/UdmDom/UdmDom.cpp	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/UdmDom/UdmDom.cpp	Mon Jul  4 13:18:21 2011	(r3773)
@@ -691,7 +691,7 @@
 			return !isSubtype();
 		}
 
-		Udm::DataNetwork *__getdn() 
+		Udm::DataNetwork *__getdn() const
 		{
 			return const_cast<Udm::DataNetwork*>(mydn);
 		}//eo __getdn();

Modified: UDM/trunk/src/UdmGme/GmeObject.h
==============================================================================
--- UDM/trunk/src/UdmGme/GmeObject.h	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/UdmGme/GmeObject.h	Mon Jul  4 13:18:21 2011	(r3773)
@@ -79,7 +79,7 @@
 
 		virtual ObjectImpl *clone();
 		virtual void release();
-		virtual Udm::DataNetwork *__getdn();
+		virtual Udm::DataNetwork *__getdn() const;
 
 	// --- lookup
 

Modified: UDM/trunk/src/UdmGme/UdmGme.cpp
==============================================================================
--- UDM/trunk/src/UdmGme/UdmGme.cpp	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/UdmGme/UdmGme.cpp	Mon Jul  4 13:18:21 2011	(r3773)
@@ -2804,7 +2804,7 @@
 	
 
 
-	Udm::DataNetwork * GmeObject::__getdn()
+	Udm::DataNetwork * GmeObject::__getdn() const
 	{ 
 		if (mydn) return const_cast<Udm::DataNetwork*>(mydn);
 		throw udm_exception("Data Network is NULL in constructor! GmeObject without a data network ?!");

Modified: UDM/trunk/src/Uml/Uml.cpp
==============================================================================
--- UDM/trunk/src/Uml/Uml.cpp	Wed Jun 29 14:34:34 2011	(r3772)
+++ UDM/trunk/src/Uml/Uml.cpp	Mon Jul  4 13:18:21 2011	(r3773)
@@ -501,6 +501,11 @@
 
 		meta = ::Uml::CreateDiagram();
 
+		UdmStatic::StaticDataNetwork* dn = new UdmStatic::StaticDataNetwork(diagram);
+		dn->rootobject = meta;
+		static_cast<UdmStatic::StaticObject*>(dn->rootobject.__impl())->mydn = dn;
+		dn->systemname = "Uml";
+		dn->sem = Udm::CHANGES_LOST_DEFAULT;
 
 		CreateMeta();
 		InitMeta();
@@ -509,12 +514,6 @@
 		::Uml::InitDiagram(meta, "Uml", "2.04");
 
 
-		UdmStatic::StaticDataNetwork* dn = new UdmStatic::StaticDataNetwork(diagram);
-		dn->rootobject = meta;
-		dn->systemname = "Uml";
-		dn->sem = Udm::CHANGES_LOST_DEFAULT;
-
-
 		_SetXsdStorage();
 
 	}


More information about the Mobies-commit mailing list