certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libCERTI fed.cc InteractionSet.hh ObjectC...


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI fed.cc InteractionSet.hh ObjectC...
Date: Sun, 02 Nov 2008 00:26:41 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      08/11/02 00:26:41

Modified files:
        libCERTI       : fed.cc InteractionSet.hh ObjectClass.hh 
                         Interaction.cc Interaction.hh 
                         TreeNamedAndHandledSet.hh InteractionSet.cc 
                         ObjectClass.cc 

Log message:
        Now both Object Class set and  Interaction Class set
        inherit from same templated base class.
        So much duplicated code gained :=)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/fed.cc?cvsroot=certi&r1=3.19&r2=3.20
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/InteractionSet.hh?cvsroot=certi&r1=3.20&r2=3.21
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectClass.hh?cvsroot=certi&r1=3.41&r2=3.42
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Interaction.cc?cvsroot=certi&r1=3.47&r2=3.48
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Interaction.hh?cvsroot=certi&r1=3.33&r2=3.34
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/TreeNamedAndHandledSet.hh?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/InteractionSet.cc?cvsroot=certi&r1=3.25&r2=3.26
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectClass.cc?cvsroot=certi&r1=3.58&r2=3.59

Patches:
Index: fed.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/fed.cc,v
retrieving revision 3.19
retrieving revision 3.20
diff -u -b -r3.19 -r3.20
--- fed.cc      31 Oct 2008 13:50:24 -0000      3.19
+++ fed.cc      2 Nov 2008 00:26:40 -0000       3.20
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: fed.cc,v 3.19 2008/10/31 13:50:24 erk Exp $
+// $Id: fed.cc,v 3.20 2008/11/02 00:26:40 erk Exp $
 // ----------------------------------------------------------------------------
 
 // CERTI header
@@ -336,7 +336,7 @@
 addInteractionSecurityLevel()
 {
        SecurityLevelID level = root_object->getSecurityLevelID(arg);
-       interactions.back()->setLevelId(level);
+       interactions.back()->setSecurityLevelId(level);
        indent();
        if(verbose)
                cout << "(sec_level \"" << arg << "\")" ;
@@ -452,4 +452,4 @@
 
 }} // namespaces
 
-// $Id: fed.cc,v 3.19 2008/10/31 13:50:24 erk Exp $
+// $Id: fed.cc,v 3.20 2008/11/02 00:26:40 erk Exp $

Index: InteractionSet.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/InteractionSet.hh,v
retrieving revision 3.20
retrieving revision 3.21
diff -u -b -r3.20 -r3.21
--- InteractionSet.hh   1 Nov 2008 19:19:34 -0000       3.20
+++ InteractionSet.hh   2 Nov 2008 00:26:40 -0000       3.21
@@ -19,27 +19,25 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: InteractionSet.hh,v 3.20 2008/11/01 19:19:34 erk Exp $
+// $Id: InteractionSet.hh,v 3.21 2008/11/02 00:26:40 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_INTERACTION_SET_HH
 #define _CERTI_INTERACTION_SET_HH
 
-// forward declaration
-namespace certi {
-       class Interaction;
-}  // namespace certi
-
 // CERTI headers
 #include "certi.hh"
 #include "SecurityServer.hh"
+#include "Interaction.hh"
+#include "TreeNamedAndHandledSet.hh"
 
+// System headers
 #include <string>
 #include <map>
 
 namespace certi {
 
-class CERTI_EXPORT InteractionSet
+class CERTI_EXPORT InteractionSet : public TreeNamedAndHandledSet<Interaction>
 {
 
 public:
@@ -53,17 +51,6 @@
         */
        void addClass(Interaction *theClass);
 
-       /**
-        * Build inheritance relation between two objects class.
-        * Build a Parent-Child relation between two classe, by setting the
-     * Child's Parent handle, and registering the Child in the Parent's SonSet.
-     * Also copy all Parent's Attributes/Parameter in the Child Class.
-        * @param[in,out] child the future child object class
-        * @param[in,out] parent the parent object class
-        * @post the child and parent object classes are linked
-        *       with inheritance relationship.
-        */
-       void buildParentRelation(Interaction *child, Interaction *parent);
 
        /**
         *  Print the Interactions tree to the standard output.
@@ -171,26 +158,8 @@
                        InteractionParameterNotDefined,
                        RTIinternalError);
 
-       typedef 
std::map<InteractionClassHandle,Interaction*,std::less<InteractionClassHandle> 
> Handle2InteractionClassMap_t;
-       typedef std::map<std::string,Interaction*,std::less<std::string> > 
Name2InteractionClassMap_t;
-       typedef Handle2InteractionClassMap_t::const_iterator 
handledIC_const_iterator;
-       typedef Name2InteractionClassMap_t::const_iterator 
namedIC_const_iterator;
-
-       namedIC_const_iterator NamedBegin() const {
-               return ICFromName.begin();
-       }
-
-       namedIC_const_iterator NamedEnd() const {
-               return ICFromName.end();
-       }
-
-       const size_t size() {return ICFromName.size();}
-
 private:
 
-       Handle2InteractionClassMap_t ICFromHandle;
-       Name2InteractionClassMap_t   ICFromName;
-       bool                         isRootClassSet;
        SecurityServer *server ;
 };
 
@@ -198,4 +167,4 @@
 
 #endif // _CERTI_INTERACTION_SET_HH
 
-// $Id: InteractionSet.hh,v 3.20 2008/11/01 19:19:34 erk Exp $
+// $Id: InteractionSet.hh,v 3.21 2008/11/02 00:26:40 erk Exp $

Index: ObjectClass.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectClass.hh,v
retrieving revision 3.41
retrieving revision 3.42
diff -u -b -r3.41 -r3.42
--- ObjectClass.hh      2 Nov 2008 00:02:45 -0000       3.41
+++ ObjectClass.hh      2 Nov 2008 00:26:40 -0000       3.42
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectClass.hh,v 3.41 2008/11/02 00:02:45 erk Exp $
+// $Id: ObjectClass.hh,v 3.42 2008/11/02 00:26:40 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_OBJECT_CLASS_HH
@@ -134,7 +134,7 @@
        AttributeHandle addAttribute(ObjectClassAttribute *the_attribute,
                        bool is_inherited = false);
 
-       void addAttributesToChild(ObjectClass *child);
+       void addToChild(ObjectClass *child);
 
        // Publication and Subscription
        void publish(FederateHandle theFederateHandle,
@@ -318,4 +318,4 @@
 
 #endif // _CERTI_OBJECT_CLASS_HH
 
-// $Id: ObjectClass.hh,v 3.41 2008/11/02 00:02:45 erk Exp $
+// $Id: ObjectClass.hh,v 3.42 2008/11/02 00:26:40 erk Exp $

Index: Interaction.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Interaction.cc,v
retrieving revision 3.47
retrieving revision 3.48
diff -u -b -r3.47 -r3.48
--- Interaction.cc      1 Nov 2008 19:19:34 -0000       3.47
+++ Interaction.cc      2 Nov 2008 00:26:40 -0000       3.48
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: Interaction.cc,v 3.47 2008/11/01 19:19:34 erk Exp $
+// $Id: Interaction.cc,v 3.48 2008/11/02 00:26:40 erk Exp $
 // ----------------------------------------------------------------------------
 
 
@@ -102,7 +102,7 @@
 // ----------------------------------------------------------------------------
 //! Add the class' attributes to the 'Child' Class.
 void
-Interaction::addParametersToChild(Interaction *the_child)
+Interaction::addToChild(Interaction *the_child)
 {
        // The Parameter List is read backward to respect the same attribute 
order
        // for the child (Parameters are inserted at the beginning of the list)
@@ -512,7 +512,7 @@
 /*! A class' LevelID can only be increased.
  */
 void
-Interaction::setLevelId(SecurityLevelID new_levelID)
+Interaction::setSecurityLevelId(SecurityLevelID new_levelID)
 {
        if (!server->dominates(new_levelID, id))
                throw SecurityError("Attempt to lower interaction class 
level.");
@@ -538,4 +538,4 @@
 
 } // namespace certi
 
-// $Id: Interaction.cc,v 3.47 2008/11/01 19:19:34 erk Exp $
+// $Id: Interaction.cc,v 3.48 2008/11/02 00:26:40 erk Exp $

Index: Interaction.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Interaction.hh,v
retrieving revision 3.33
retrieving revision 3.34
diff -u -b -r3.33 -r3.34
--- Interaction.hh      1 Nov 2008 19:19:35 -0000       3.33
+++ Interaction.hh      2 Nov 2008 00:26:41 -0000       3.34
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: Interaction.hh,v 3.33 2008/11/01 19:19:35 erk Exp $
+// $Id: Interaction.hh,v 3.34 2008/11/02 00:26:41 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_INTERACTION_HH
@@ -46,6 +46,15 @@
 class CERTI_EXPORT Interaction : public Subscribable
 {
 public:
+
+       /**
+        * The type of the handle of this class.
+        */
+       typedef InteractionClassHandle handle_t;
+       /**
+        * The type of the exception to when such object is not found
+        */
+       typedef InteractionClassNotDefined ObjectNotDefinedException;
        /**
         * Build an interaction class object.
         * @param[in] name the name of the interaction class
@@ -94,7 +103,7 @@
     ParameterHandle addParameter(Parameter *the_parameter,
                                  bool is_inherited = false);
 
-    void addParametersToChild(Interaction *new_child);
+    void addToChild(Interaction *new_child);
     void display() const ;
 
     // -- Security Methods --
@@ -102,8 +111,8 @@
                              const char *reason) const
         throw (SecurityError);
 
-    SecurityLevelID getLevelId() const { return id ; };
-    void setLevelId(SecurityLevelID NewLevelID);
+    SecurityLevelID getSecurityLevelId() const { return id ; };
+    void setSecurityLevelId(SecurityLevelID NewLevelID);
 
     // -- Publication and Subscription --
     void publish(FederateHandle)
@@ -230,4 +239,4 @@
 
 #endif // _CERTI_INTERACTION.HH
 
-// $Id: Interaction.hh,v 3.33 2008/11/01 19:19:35 erk Exp $
+// $Id: Interaction.hh,v 3.34 2008/11/02 00:26:41 erk Exp $

Index: TreeNamedAndHandledSet.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/TreeNamedAndHandledSet.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- TreeNamedAndHandledSet.hh   1 Nov 2008 23:58:59 -0000       1.1
+++ TreeNamedAndHandledSet.hh   2 Nov 2008 00:26:41 -0000       1.2
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: TreeNamedAndHandledSet.hh,v 1.1 2008/11/01 23:58:59 erk Exp $
+// $Id: TreeNamedAndHandledSet.hh,v 1.2 2008/11/02 00:26:41 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _TreeNamedAndHandledSet_HH
@@ -128,6 +128,13 @@
        typedef typename Handle2ObjectMap_t::const_iterator 
handled_const_iterator;
        typedef typename Handle2ObjectMap_t::iterator       handled_iterator;
 
+       handled_const_iterator handled_begin() const {
+               return fromHandle.begin();
+       }
+
+       handled_const_iterator handled_end() const {
+               return fromHandle.end();
+       }
        /**
         * Map from name to ObjectType::handle_t.
         */
@@ -229,7 +236,7 @@
     child->setSuperclass(parent->getHandle());
     child->setSecurityLevelId(parent->getSecurityLevelId());
     parent->addSubclass(child);
-    parent->addAttributesToChild(child);
+    parent->addToChild(child);
 }
 
 template <typename ObjectType>

Index: InteractionSet.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/InteractionSet.cc,v
retrieving revision 3.25
retrieving revision 3.26
diff -u -b -r3.25 -r3.26
--- InteractionSet.cc   1 Nov 2008 19:19:35 -0000       3.25
+++ InteractionSet.cc   2 Nov 2008 00:26:41 -0000       3.26
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: InteractionSet.cc,v 3.25 2008/11/01 19:19:35 erk Exp $
+// $Id: InteractionSet.cc,v 3.26 2008/11/02 00:26:41 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include "Interaction.hh"
@@ -40,67 +40,22 @@
 
 
 InteractionSet::InteractionSet(SecurityServer *security_server, bool 
isRootClassSet)
-: isRootClassSet(isRootClassSet), server(security_server) {
+: TreeNamedAndHandledSet<Interaction>(isRootClassSet) {
+    // It can be NULL on the RTIA.
+    server = security_server ;
 }
 
 InteractionSet::~InteractionSet() {
-       /* clear name map */
-       ICFromName.clear();
-       /*
-        * If we are Root ClassSet (the class set owned by RootObject)
-        *    we delete the content
-        * If not we only clear the map in order to avoid double deletion.
-        *
-        * FIXME EN: this is a trick in order because we do not
-        *           really maintain a tree of ObjectClass in order
-        *           to support flat interaction class name
-        *           ("Boule" instead of "Bille.Boule")
-        *           We may get rid of this as soon as we want to support
-        *           same name for interaction class in different branch of the 
tree.
-        */
-       if (isRootClassSet) {
-               while (!ICFromHandle.empty()) {
-                       delete (ICFromHandle.begin()->second);
-                       ICFromHandle.erase(ICFromHandle.begin());
-               }
-       }
-       else {
-               ICFromHandle.clear();
-       }
+
 } /* end of ~InteractionSet */
 
 void
 InteractionSet::addClass(Interaction *newClass) {
 
-       Name2InteractionClassMap_t::iterator findit;
-       std::stringstream                       msg;
-
        D.Out(pdInit, "Adding new interaction class %d, ", 
newClass->getHandle());
-
        /* link to server */
        newClass->server = server ;
-
-       /*
-        * Check whether addition of this interaction class
-        * will generate a name collision or not.
-        * i.e. we may not add an object class of the SAME
-        * name to the interaction class set
-        */
-       findit = ICFromName.find(newClass->getName());
-       if (findit != ICFromName.end()) {
-               msg << "Name collision another interaction class named <"
-               << newClass->getName()
-               << "> with handle <"
-               << findit->second->getHandle()
-               << "> was found when trying to add identically named object 
class with handle <"
-               << newClass->getHandle();
-               throw RTIinternalError(msg.str().c_str());
-       }
-       /* store ref to new class in ObjectClass from Handle Map */
-       ICFromHandle[newClass->getHandle()] = newClass;
-       /* store ref to new class in ObjectClass from Name Map */
-       ICFromName[newClass->getName()] = newClass;
-
+       add(newClass);
 } /* end of addClass */
 
 // ----------------------------------------------------------------------------
@@ -199,27 +154,11 @@
 } /* end of broadcastInteraction (WITHOUT time) */
 
 void
-InteractionSet::buildParentRelation(Interaction *child, Interaction *parent)
-{
-       // Register parent to son.
-       child->setSuperclass(parent->getHandle());
-
-       // Transfert security level.
-       child->setLevelId(parent->getLevelId());
-
-       // Register son to parent.
-       parent->addSubclass(child);
-
-       // Copy parent Attribute into child class.
-       parent->addParametersToChild(child);
-} /* end of buildParentRelation */
-
-void
 InteractionSet::display() const
 {
        cout << " Interactions :" << endl ;
-       handledIC_const_iterator i;
-       for (i = ICFromHandle.begin(); i != ICFromHandle.end(); ++i) {
+       handled_const_iterator i;
+       for (i = handled_begin(); i != handled_end(); ++i) {
                i->second->display();
        }
 } /* end of display */
@@ -230,11 +169,11 @@
 {
        std::stringstream msg;
 
-       handledIC_const_iterator iter;
+       handled_const_iterator iter;
 
-       iter = ICFromHandle.find(the_handle);
+       iter = fromHandle.find(the_handle);
 
-       if (iter != ICFromHandle.end()) {
+       if (iter != fromHandle.end()) {
                return iter->second;
        } else {
                msg << "Unknown Object Class Handle <" << the_handle << ">";
@@ -249,56 +188,7 @@
 InteractionSet::getInteractionClassHandle(const std::string& class_name) const
 throw (NameNotFound)  {
 
-       std::string                 currentName;
-       std::string                 remainingName;
-       InteractionClassHandle      currentHandle;
-       Interaction*                currentClass;
-       InteractionSet const*       currentClassSet;
-       namedIC_const_iterator      iter;
-
-       currentClassSet = this;
-       remainingName = class_name;
-       D.Out(pdDebug,"Looking for interaction class <%s>",class_name.c_str());
-       /*
-        * If the name is qualified (a.k.a. hierarchical name)
-        * like "Bille.Boule"
-        * then iterate through subClass in order to reach the leaf
-        * "unqualified name"
-        */
-       while (Named::isQualifiedClassName(remainingName)) {
-               /*
-                * The first current should be the name of
-                * of a subclass of the current ClassSet
-                */
-               currentName = Named::getNextClassName(remainingName);
-               D.Out(pdDebug,"Now Looking for interaction class 
<%s>",currentName.c_str());
-               /*
-                * Get the handle of the subclass
-                * NOTE that we won't recurse more than once here
-                * since the provided 'currentName' is not qualified
-                * 'by design'
-                * The recursive deepness is at most 2.
-                */
-               currentHandle = 
currentClassSet->getInteractionClassHandle(currentName);
-               /* Get the corresponding class object */
-               currentClass = currentClassSet->getByHandle(currentHandle);
-               /* now update currentClassSet */
-               currentClassSet = currentClass->getSubClasses();
-       }
-
-       /*
-        * Now the current classClassSet should be a leaf
-        * so that we can search in the
-        */
-       iter = currentClassSet->ICFromName.find(remainingName);
-
-       if (iter != currentClassSet->ICFromName.end()) {
-               G.Out(pdGendoc,"exit ObjectClassSet::getObjectClassHandle");
-               return iter->second->getHandle();
-       } else {
-               G.Out(pdGendoc,"exit ObjectClassSet::getObjectClassHandle on 
NameNotFound");
-               throw NameNotFound(class_name.c_str());
-       }
+       return getHandleFromName(class_name);
 
 } /* end of getInteractionClassHandle */
 
@@ -308,7 +198,7 @@
 InteractionSet::getInteractionClassName(InteractionClassHandle the_handle) 
const
 throw (InteractionClassNotDefined)
 {
-       return getByHandle(the_handle)->getName();
+       return getNameFromHandle(the_handle);
 } /* end of getInteractionClassName */
 
 // ----------------------------------------------------------------------------
@@ -366,9 +256,9 @@
 void
 InteractionSet::killFederate(FederateHandle the_federate)
 throw () {
-    Handle2InteractionClassMap_t::iterator i;
+    handled_const_iterator i;
 
-    for (i = ICFromHandle.begin(); i != ICFromHandle.end(); ++i) {
+    for (i = handled_begin(); i != handled_end(); ++i) {
         // Call KillFederate on that class until it returns NULL.
         i->second->killFederate(the_federate);
     }
@@ -416,4 +306,4 @@
 
 } // namespace certi
 
-// $Id: InteractionSet.cc,v 3.25 2008/11/01 19:19:35 erk Exp $
+// $Id: InteractionSet.cc,v 3.26 2008/11/02 00:26:41 erk Exp $

Index: ObjectClass.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectClass.cc,v
retrieving revision 3.58
retrieving revision 3.59
diff -u -b -r3.58 -r3.59
--- ObjectClass.cc      2 Nov 2008 00:02:45 -0000       3.58
+++ ObjectClass.cc      2 Nov 2008 00:26:41 -0000       3.59
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectClass.cc,v 3.58 2008/11/02 00:02:45 erk Exp $
+// $Id: ObjectClass.cc,v 3.59 2008/11/02 00:26:41 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include  "Object.hh"
@@ -84,7 +84,7 @@
 // ----------------------------------------------------------------------------
 //! Add the class' attributes to the 'Child' Class.
 void
-ObjectClass::addAttributesToChild(ObjectClass *the_child)
+ObjectClass::addToChild(ObjectClass *the_child)
 {
     // The Attribute List is read backwards to respect the same attribute order
     // for the child(Attributes are inserted at the beginning of the list).
@@ -1818,4 +1818,4 @@
 
 } // namespace certi
 
-// $Id: ObjectClass.cc,v 3.58 2008/11/02 00:02:45 erk Exp $
+// $Id: ObjectClass.cc,v 3.59 2008/11/02 00:26:41 erk Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]