From: Markus R. <rol...@us...> - 2007-05-01 08:28:45
|
Update of /cvsroot/simspark/simspark/spark/zeitgeist In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv6247 Modified Files: Tag: RSGEDIT_FILEREF leaf.cpp leaf.h node.cpp node.h Log Message: - added member GetNumberOfChildren() to node that returns the total number of children - modified SetParent() to care for a uniqe name among sibling nodes. If another sibling with the same name exists the current number of children is appended to the node name. If mporter classes create nodes in a stable order this also assures consistent node names through simulation restarts Index: node.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/node.h,v retrieving revision 1.1 retrieving revision 1.1.6.1 diff -C2 -d -r1.1 -r1.1.6.1 *** node.h 5 Dec 2005 20:59:18 -0000 1.1 --- node.h 1 May 2007 08:28:39 -0000 1.1.6.1 *************** *** 83,86 **** --- 83,89 ---- virtual bool IsLeaf() const; + /** returns the total number of children */ + virtual int GetNumberOfChildren() const; + /** update variables from a script */ virtual void UpdateCached(); *************** *** 131,150 **** boost::shared_ptr<Node> node = boost::shared_static_cast<Node>(make_shared(GetParent())); ! while (node.get() != 0) { boost::shared_ptr<CLASS> test = boost::shared_dynamic_cast<CLASS>(node); ! if (test.get() != 0) { return test; } ! //node = boost::shared_static_cast<Node>(make_shared(node->GetParent())); node = boost::shared_static_cast<Node>(node->GetParent().lock()); ! } ! return boost::shared_ptr<CLASS>(); } --- 134,153 ---- boost::shared_ptr<Node> node = boost::shared_static_cast<Node>(make_shared(GetParent())); ! while (node.get() != 0) { boost::shared_ptr<CLASS> test = boost::shared_dynamic_cast<CLASS>(node); ! if (test.get() != 0) { return test; } ! //node = boost::shared_static_cast<Node>(make_shared(node->GetParent())); node = boost::shared_static_cast<Node>(node->GetParent().lock()); ! } ! return boost::shared_ptr<CLASS>(); } Index: leaf.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/leaf.cpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** leaf.cpp 15 Mar 2007 07:26:31 -0000 1.2 --- leaf.cpp 1 May 2007 08:28:39 -0000 1.2.2.1 *************** *** 23,26 **** --- 23,27 ---- #include "node.h" #include <iostream> + #include <sstream> using namespace boost; *************** *** 112,115 **** --- 113,122 ---- } + int + Leaf::GetNumberOfChildren() const + { + return 0; + } + bool Leaf::IsLeaf() const { *************** *** 199,209 **** void Leaf::SetParent(const boost::shared_ptr<Node> &newParent) { ! shared_ptr<Node> oldParent = make_shared(GetParent()); if (oldParent.get() != 0) { // we have a parent, so update our state - shared_ptr<Leaf> self - = shared_static_cast<Leaf>(make_shared(GetSelf())); - // here reference count should be > 1 (at least one in the // parent, and one in this routine) --- 206,215 ---- void Leaf::SetParent(const boost::shared_ptr<Node> &newParent) { ! shared_ptr<Node> oldParent = GetParent().lock(); ! shared_ptr<Leaf> self = shared_static_cast<Leaf>(GetSelf().lock()); ! if (oldParent.get() != 0) { // we have a parent, so update our state // here reference count should be > 1 (at least one in the // parent, and one in this routine) *************** *** 229,237 **** mParent = newParent; ! if (! mParent.expired()) { ! // we have been linked, so now we can do something :) ! OnLink(); } } --- 235,255 ---- mParent = newParent; ! if (newParent.get() == 0) { ! return; ! } ! ! // assure a unique name among our siblings ! shared_ptr<Leaf> sibling = newParent->GetChild(mName); ! ! if (sibling != self) ! { ! stringstream ss; ! ss << mName << "_" << newParent->GetNumberOfChildren() << ">"; ! mName = ss.str().c_str(); } + + // we have been linked, so now we can do something :) + OnLink(); } Index: leaf.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/leaf.h,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** leaf.h 15 Mar 2007 07:26:31 -0000 1.2 --- leaf.h 1 May 2007 08:28:39 -0000 1.2.2.1 *************** *** 220,223 **** --- 220,226 ---- virtual bool IsLeaf() const; + /** returns the total number of children */ + virtual int GetNumberOfChildren() const; + /** removes base from the set of children. */ virtual void RemoveChildReference(const boost::shared_ptr<Leaf> &base); Index: node.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/zeitgeist/node.cpp,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** node.cpp 15 Mar 2007 07:26:31 -0000 1.2 --- node.cpp 1 May 2007 08:28:39 -0000 1.2.2.1 *************** *** 184,187 **** --- 184,193 ---- } + int + Node::GetNumberOfChildren() const + { + return static_cast<int>(mChildren.size()); + } + bool Node::IsLeaf() const |