[Mobies-commit] [commit] r4033 - in UDM/trunk: include src/UdmBase src/UdmDom src/UdmGme tests/test_generic
endre at redhat1.isis.vanderbilt.edu
endre at redhat1.isis.vanderbilt.edu
Mon Mar 26 13:22:59 CDT 2012
Author: endre
Date: Mon Mar 26 13:22:59 2012
New Revision: 4033
Log:
Add methods to get the composition child role a child has in a parent, task #5
The methods are:
- ObjectImpl::getChildRole
- Object::GetChildRole
Modified:
UDM/trunk/include/UdmBase.h
UDM/trunk/include/UdmStatic.h
UDM/trunk/src/UdmBase/UdmStatic.cpp
UDM/trunk/src/UdmBase/UdmTomi.cpp
UDM/trunk/src/UdmDom/UdmDom.cpp
UDM/trunk/src/UdmGme/GmeObject.h
UDM/trunk/src/UdmGme/UdmGme.cpp
UDM/trunk/tests/test_generic/genericTest.cpp
Modified: UDM/trunk/include/UdmBase.h
==============================================================================
--- UDM/trunk/include/UdmBase.h Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/include/UdmBase.h Mon Mar 26 13:22:59 2012 (r4033)
@@ -413,6 +413,11 @@
const bool real_archetype = true,
const bool need_safetype = false) = 0;
+ /*
+ If c is a child of this object, then set ret to be the role taken by the child,
+ otherwise set ret to null.
+ */
+ virtual void getChildRole(ObjectImpl *c, ::Uml::CompositionChildRole &ret) const = 0;
/*
should be invoked when an object has an archetype
@@ -656,6 +661,8 @@
const bool real_archetype = true,
const bool need_safetype = false) { throw e; }
+ virtual void getChildRole(ObjectImpl *c, ::Uml::CompositionChildRole &ret) const { throw e; }
+
virtual vector<ObjectImpl*> getAssociation(const ::Uml::AssociationRole &meta, int mode = TARGETFROMPEER) const { throw e; }
virtual void setAssociation(
const ::Uml::AssociationRole &meta,
@@ -3010,6 +3017,9 @@
// To ignore child types set clsChildType to ClassType(NULL).
set<Object> GetChildObjects(const CompositionInfo& cmpType, const ::Uml::Class & clsChildType) const;
// UDM TOMI Paradigm Independent Interface
+ // Get the composition child role the given child has in this parent. Sets the ret parameter to NULL if the given child is not actually a child.
+ void GetChildRole(const Object &child, ::Uml::CompositionChildRole &ret) const;
+ // UDM TOMI Paradigm Independent Interface
// Test if the object is in the tree rooted at where
bool IsNodeOfTree(const Object &where);
Modified: UDM/trunk/include/UdmStatic.h
==============================================================================
--- UDM/trunk/include/UdmStatic.h Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/include/UdmStatic.h Mon Mar 26 13:22:59 2012 (r4033)
@@ -335,6 +335,7 @@
vector<ObjectImpl*> getChildren(const ::Uml::CompositionChildRole &meta, const ::Uml::Class &cls) const;
void setChildren(const ::Uml::CompositionChildRole &meta, const vector<ObjectImpl*> &a, const bool direct = true);
ObjectImpl *createChild(const ::Uml::CompositionChildRole &childrole, const ::Uml::Class &meta, const Udm::ObjectImpl* archetype = NULL, const bool subtype = false, const bool real_archetype = true, const bool need_safetype = false);
+ void getChildRole(ObjectImpl *c, ::Uml::CompositionChildRole &ret) const;
// --- associations
typedef udm_multimap<uniqueId_type, StaticObject*> assoc_type;
Modified: UDM/trunk/src/UdmBase/UdmStatic.cpp
==============================================================================
--- UDM/trunk/src/UdmBase/UdmStatic.cpp Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/src/UdmBase/UdmStatic.cpp Mon Mar 26 13:22:59 2012 (r4033)
@@ -1770,6 +1770,20 @@
// the final refCount is 3 after leaving this function !
}
+ void StaticObject::getChildRole(ObjectImpl *c, ::Uml::CompositionChildRole &ret) const
+ {
+ ret = NULL;
+ if (c == NULL || c == &Udm::_null) return;
+
+ for (children_type::const_iterator i = m_children.begin(); i != m_children.end(); i++)
+ if (i->second == c)
+ {
+ Udm::DataNetwork * meta_dn = ((StaticDataNetwork*)c->__getdn())->GetMetaDn();
+ ret = ::Uml::CompositionChildRole::Cast(meta_dn->ObjectById(i->first));
+ return;
+ }
+ }
+
vector<ObjectImpl*> StaticObject::getAssociation(const ::Uml::AssociationRole &meta, int mode ) const
{
Modified: UDM/trunk/src/UdmBase/UdmTomi.cpp
==============================================================================
--- UDM/trunk/src/UdmBase/UdmTomi.cpp Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/src/UdmBase/UdmTomi.cpp Mon Mar 26 13:22:59 2012 (r4033)
@@ -1075,6 +1075,14 @@
// UDM TOMI Paradigm Independent Interface
+// Get the composition child role the given child has in this parent. Sets the ret parameter to NULL if the given child is not actually a child.
+UDM_DLL void Object::GetChildRole(const Object &child, ::Uml::CompositionChildRole &ret) const
+{
+ impl->getChildRole(child.__impl(), ret);
+}
+
+
+// UDM TOMI Paradigm Independent Interface
// Test if the object is in the tree rooted at where
UDM_DLL bool Object::IsNodeOfTree(const Object &where)
{
Modified: UDM/trunk/src/UdmDom/UdmDom.cpp
==============================================================================
--- UDM/trunk/src/UdmDom/UdmDom.cpp Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/src/UdmDom/UdmDom.cpp Mon Mar 26 13:22:59 2012 (r4033)
@@ -2381,6 +2381,47 @@
return dep;
}
+ void getChildRole(ObjectImpl *c, ::Uml::CompositionChildRole &ret) const
+ {
+ ret = NULL;
+ if (c == NULL || c == &Udm::_null) return;
+
+ DomObject &cc = *static_cast<DomObject *>(c);
+
+ // check that c is our child
+ bool is_child = false;
+ for (DOMNode *n = dom_element->getFirstChild(); n != NULL; n = n->getNextSibling())
+ if (n->getNodeType() == DOMNode::ELEMENT_NODE && n->isEqualNode(cc.dom_element))
+ {
+ is_child = true;
+ break;
+ }
+
+ if (!is_child) return;
+
+ ::Uml::Composition comp = ::Uml::matchChildToParent(cc.m_type, m_type);
+ if (comp)
+ {
+ ret = comp.childRole();
+ return;
+ }
+
+ XMLCh *chas = (XMLCh*) cc.dom_element->getAttribute(gXML___child_as);
+
+ set< ::Uml::Class> pancs = ::Uml::AncestorClasses(m_type);
+ set< ::Uml::Class> cancs = ::Uml::AncestorClasses(cc.m_type);
+ for (set< ::Uml::Class>::const_iterator j = cancs.begin(); j != cancs.end(); j++) {
+ set< ::Uml::CompositionChildRole> cr = j->childRoles();
+ for (set< ::Uml::CompositionChildRole>::const_iterator i = cr.begin(); i != cr.end(); i++)
+ if (pancs.find(::Uml::theOther(*i).target()) != pancs.end())
+ if (DSFind(chas, GetANameFor(i->parent())) >= 0) {
+ ret = *i;
+ return;
+ }
+ }
+ }
+
+
// --- associations
public:
Modified: UDM/trunk/src/UdmGme/GmeObject.h
==============================================================================
--- UDM/trunk/src/UdmGme/GmeObject.h Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/src/UdmGme/GmeObject.h Mon Mar 26 13:22:59 2012 (r4033)
@@ -145,6 +145,7 @@
//does not recurse when a a derived/instace
//object is created with an archetype that has children
//(this is done by the underlaying MGA layer
+ virtual void getChildRole(Udm::ObjectImpl *c, ::Uml::CompositionChildRole &ret) const;
// --- associations
Modified: UDM/trunk/src/UdmGme/UdmGme.cpp
==============================================================================
--- UDM/trunk/src/UdmGme/UdmGme.cpp Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/src/UdmGme/UdmGme.cpp Mon Mar 26 13:22:59 2012 (r4033)
@@ -2301,6 +2301,100 @@
};
*/
+ void GmeObject::getChildRole(Udm::ObjectImpl *c, ::Uml::CompositionChildRole &ret) const
+ {
+ ret = NULL;
+ if (c == NULL || c == &Udm::_null) return;
+
+ GmeObject *cc = static_cast<GmeObject *>(c);
+
+ // check that c is our child
+ IMgaMetaRolePtr rr;
+ bool is_child = false;
+ if (folderself)
+ {
+ if (cc->folderself)
+ {
+ IMgaFoldersPtr fchds = folderself->ChildFolders;
+ MGACOLL_ITERATE(IMgaFolder, fchds)
+ {
+ if (MGACOLL_ITER == cc->folderself)
+ {
+ is_child = true;
+ break;
+ }
+ }
+ MGACOLL_ITERATE_END;
+ }
+ else
+ {
+ IMgaFCOsPtr chds = folderself->ChildFCOs;
+ MGACOLL_ITERATE(IMgaFCO, chds)
+ {
+ if (MGACOLL_ITER == cc->self)
+ {
+ is_child = true;
+ rr = MGACOLL_ITER->MetaRole;
+ break;
+ }
+ }
+ MGACOLL_ITERATE_END;
+ }
+ }
+ else
+ {
+ IMgaModelPtr model = self;
+ if (model == NULL) return;
+
+ IMgaFCOsPtr chds = model->ChildFCOs;
+ MGACOLL_ITERATE(IMgaFCO, chds)
+ {
+ if (MGACOLL_ITER == cc->self)
+ {
+ is_child = true;
+ rr = MGACOLL_ITER->MetaRole;
+ break;
+ }
+ }
+ MGACOLL_ITERATE_END;
+ }
+
+ if (!is_child) return;
+
+ // if only one composition role permitted, then return it
+ ::Uml::Composition comp = ::Uml::matchChildToParent(cc->m_type, m_type);
+ if (comp)
+ {
+ ret = comp.childRole();
+ return;
+ }
+
+ ASSERT(rr != NULL);
+ string MetaRole((const char *) rr->Name);
+
+ set< ::Uml::Class> pancs = ::Uml::AncestorClasses(m_type);
+ set< ::Uml::Class> cancs = ::Uml::AncestorClasses(cc->m_type);
+ for (set< ::Uml::Class>::const_iterator j = cancs.begin(); j != cancs.end(); j++) {
+ set< ::Uml::CompositionChildRole> cr = j->childRoles();
+ for (set< ::Uml::CompositionChildRole>::const_iterator i = cr.begin(); i != cr.end(); i++)
+ if (pancs.find(::Uml::theOther(*i).target()) != pancs.end())
+ {
+ if (MetaRole == (string)i->name())
+ {
+ ret = *i;
+ return;
+ }
+ set<string> MetaRoleFilter = ((GmeDataNetwork*) mydn)->GetMetaRoleFilter(*i);
+ if (MetaRoleFilter.find(MetaRole) != MetaRoleFilter.end())
+ {
+ ret = *i;
+ return;
+ }
+ }
+ }
+ }
+
+
IMgaAttributePtr GmeObject::getAttribute(BSTR name)
{
IMgaMetaAttributePtr attr_meta;
Modified: UDM/trunk/tests/test_generic/genericTest.cpp
==============================================================================
--- UDM/trunk/tests/test_generic/genericTest.cpp Thu Mar 22 17:13:27 2012 (r4032)
+++ UDM/trunk/tests/test_generic/genericTest.cpp Mon Mar 26 13:22:59 2012 (r4033)
@@ -265,7 +265,7 @@
s3t2.position() = "(220,100)";
-
+
// Create bulbs with terminals
Bulb bulb1 = Bulb::Create(doubleBulbLamp);
@@ -304,11 +304,35 @@
b3t1.position() = "(320,100)";
ElectricTerminal b3t2 = ElectricTerminal::Create(bulb3);
b3t2.position() = "(320,200)";
-
+ // Check child roles
+ {
+ ::Uml::CompositionChildRole ccr;
+
+ // child can have only one possible role
+ doubleBulbLamp.GetChildRole(thePlug, ccr);
+ CPPUNIT_ASSERT(ccr = Lamp::meta_Plug_child);
+
+ // child can have multiple roles
+ doubleBulbLamp.GetChildRole(mainSwitch, ccr);
+ CPPUNIT_ASSERT(ccr == Lamp::meta_MainSwitch);
+ doubleBulbLamp.GetChildRole(switch1, ccr);
+ CPPUNIT_ASSERT(ccr == Lamp::meta_FunctionSwitch);
+ doubleBulbLamp.GetChildRole(bulb3, ccr);
+ CPPUNIT_ASSERT(ccr = Lamp::meta_Bulb_children);
+
+ // first parameter is not actually a child
+ doubleBulbLamp.GetChildRole(mst1, ccr);
+ CPPUNIT_ASSERT(!ccr);
+
+ doubleBulbLamp.GetChildRole(Udm::null, ccr);
+ CPPUNIT_ASSERT(!ccr);
+ }
+
+
More information about the Mobies-commit
mailing list