certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] certi/libCERTI Interaction.cc Interaction.hh Ro...


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI Interaction.cc Interaction.hh Ro...
Date: Sat, 21 Nov 2009 15:13:08 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      09/11/21 15:13:08

Modified files:
        libCERTI       : Interaction.cc Interaction.hh RootObject.cc 

Log message:
        Check-in [improvement] patch from Mathias
        patch #6987: Use a std::map to store the interaction parameter indexed 
by handle
        (second patch)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Interaction.cc?cvsroot=certi&r1=3.56&r2=3.57
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Interaction.hh?cvsroot=certi&r1=3.38&r2=3.39
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/RootObject.cc?cvsroot=certi&r1=3.45&r2=3.46

Patches:
Index: Interaction.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Interaction.cc,v
retrieving revision 3.56
retrieving revision 3.57
diff -u -b -r3.56 -r3.57
--- Interaction.cc      19 Nov 2009 18:15:30 -0000      3.56
+++ Interaction.cc      21 Nov 2009 15:13:08 -0000      3.57
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: Interaction.cc,v 3.56 2009/11/19 18:15:30 erk Exp $
+// $Id: Interaction.cc,v 3.57 2009/11/21 15:13:08 erk Exp $
 // ----------------------------------------------------------------------------
 
 
@@ -56,9 +56,8 @@
 
 Interaction::~Interaction()
 {
-       while (!parameterSet.empty()) {
-               delete parameterSet.front();
-               parameterSet.pop_front();
+        for (HandleParameterMap::iterator i = _handleParameterMap.begin(); i 
!= _handleParameterMap.end(); ++i) {
+                delete i->second;
        }
 
        if (!publishers.empty())
@@ -100,7 +99,7 @@
        if (!is_inherited)
                the_parameter->LevelID = id ;
 
-       parameterSet.push_front(the_parameter);
+        _handleParameterMap[the_parameter->getHandle()] = the_parameter;
 
        Debug(D, pdRegister) << "Interaction " << handle << "[" << name
        << "] has a new parameter "
@@ -113,24 +112,20 @@
 void
 Interaction::addInheritedClassParameter(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)
-       Parameter *child = NULL ;
-       list<Parameter *>::reverse_iterator it ;
-       for (it = parameterSet.rbegin(); it != parameterSet.rend(); it++) {
-               assert((*it) != NULL);
+        for (HandleParameterMap::iterator i = _handleParameterMap.begin(); i 
!= _handleParameterMap.end(); ++i) {
+               assert(i->second != NULL);
 
-               child = new Parameter(**it);
+                Parameter *child = new Parameter(*(i->second));
                assert(child != NULL);
 
                D.Out(pdProtocol,
                                "ObjectClass %u adding new parameter %d to 
child class %u.",
-                               handle, (*it)->getHandle(), the_child->handle);
+                               handle, i->second->getHandle(), 
the_child->handle);
 
                the_child->addParameter(child, true);
 
                /* FIXME EN: what is the purpose of the check ?? */
-               if (child->getHandle() != (*it)->getHandle()) {
+               if (child->getHandle() != i->second->getHandle()) {
                        throw RTIinternalError("Error while copying child's 
attributes.");
                } else {
                        ;
@@ -157,11 +152,9 @@
        // 2. Update message Parameters list by removing child's Parameters.
        for (int i = 0 ; i < ibList->message->handleArraySize ;) {
                // If the Parameter is not in that class, remove it from the 
message.
-               try {
-                       getParameterByHandle(ibList->message->handleArray[i]);
-                       i++ ;
-               }
-               catch (InteractionParameterNotDefined) {
+                if (hasParameter(ibList->message->handleArray[i])) {
+                       ++i;
+                } else {
                        ibList->message->removeParameter(i);
                }
        }
@@ -267,11 +260,10 @@
 
        // Display parameters
 
-       cout << " " << parameterSet.size() << " Parameters:" << endl ;
+       cout << " " << _handleParameterMap.size() << " Parameters:" << endl ;
 
-       list<Parameter *>::const_iterator p = parameterSet.begin();
-       for (; p != parameterSet.end(); p++) {
-               (*p)->display();
+        for (HandleParameterMap::const_iterator i = 
_handleParameterMap.begin(); i != _handleParameterMap.end(); ++i) {
+               i->second->display();
        }
 }
 
@@ -281,10 +273,9 @@
 Interaction::getParameterByHandle(ParameterHandle the_handle) const
 throw (InteractionParameterNotDefined, RTIinternalError)
 {
-       list<Parameter *>::const_iterator p ;
-       for (p = parameterSet.begin(); p != parameterSet.end(); p++) {
-               if ((*p)->getHandle() == the_handle)
-                       return (*p);
+        HandleParameterMap::const_iterator i = 
_handleParameterMap.find(the_handle);
+        if (i != _handleParameterMap.end()) {
+                return i->second;
        }
 
        throw InteractionParameterNotDefined("");
@@ -296,13 +287,13 @@
 Interaction::getParameterHandle(const std::string& the_name) const
 throw (NameNotFound, RTIinternalError)
 {
-       list<Parameter *>::const_iterator p ;
-       for (p = parameterSet.begin(); p != parameterSet.end(); p++) {
-               if ((*p)->getName() == the_name)
-                       return (*p)->getHandle();
+        for (HandleParameterMap::const_iterator i = 
_handleParameterMap.begin(); i != _handleParameterMap.end(); ++i) {
+                if (i->second->getName() == the_name) {
+                       return i->second->getHandle();
+                }
        }
 
-       throw NameNotFound("");
+       throw NameNotFound(the_name);
 }
 
 // ----------------------------------------------------------------------------
@@ -315,6 +306,16 @@
        return getParameterByHandle(the_handle)->getName();
                }
 
+
+// ----------------------------------------------------------------------------
+//! Return true if the interaction contains the given parameter
+bool
+Interaction::hasParameter(ParameterHandle parameterHandle) const
+{
+        return _handleParameterMap.find(parameterHandle) != 
_handleParameterMap.end();
+}
+
+
 // ----------------------------------------------------------------------------
 //! Return true if federate is publishing the attribute.
 bool
@@ -547,4 +548,4 @@
 
 } // namespace certi
 
-// $Id: Interaction.cc,v 3.56 2009/11/19 18:15:30 erk Exp $
+// $Id: Interaction.cc,v 3.57 2009/11/21 15:13:08 erk Exp $

Index: Interaction.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Interaction.hh,v
retrieving revision 3.38
retrieving revision 3.39
diff -u -b -r3.38 -r3.39
--- Interaction.hh      19 Nov 2009 18:15:30 -0000      3.38
+++ Interaction.hh      21 Nov 2009 15:13:08 -0000      3.39
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: Interaction.hh,v 3.38 2009/11/19 18:15:30 erk Exp $
+// $Id: Interaction.hh,v 3.39 2009/11/21 15:13:08 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef _CERTI_INTERACTION_HH
@@ -37,7 +37,7 @@
 #include "Parameter.hh"
 #include "Subscribable.hh"
 
-#include <list>
+#include <map>
 #include <set>
 #include <string>
 
@@ -74,7 +74,7 @@
        /**
         * The type for the parameter list.
         */
-       typedef std::list<Parameter*> ParameterList_t;
+       typedef std::map<ParameterHandle, Parameter*> HandleParameterMap;
 
     Interaction(const std::string& theName, InteractionClassHandle theHandle, 
TransportType theTransport, OrderType theOrder);
     /**
@@ -144,6 +144,13 @@
     const std::string& getParameterName(ParameterHandle the_handle) const
         throw (InteractionParameterNotDefined, RTIinternalError);
 
+    /**
+     * Returns true if the Interaction has the parameter with the given handle.
+     * @param[in] parameterHandle the parameter handle
+     * @return if the Interaction has the parameter
+     */
+    bool hasParameter(ParameterHandle parameterHandle) const;
+
     void killFederate(FederateHandle theFederate)
         throw ();
 
@@ -192,9 +199,9 @@
 
     /**
      * Getter for the parameter list of the interaction class.
-     * param[out] ParameterList_t @see Interaction::ParameterList_t
+     * param[out] ParameterList_t @see Interaction::HandleParameterMap
      */
-    const ParameterList_t& getParameterList(void) const { return parameterSet; 
}
+    const HandleParameterMap& getHandleParameterMap(void) const { return 
_handleParameterMap; }
 
     //! This Object helps to find a TCPLink given a Federate Handle.
     SecurityServer *server ;
@@ -248,7 +255,7 @@
     SpaceHandle space ;
 
     //! List of this Interaction Class' Parameters.
-    ParameterList_t parameterSet ;
+    HandleParameterMap _handleParameterMap;
 
     typedef std::set<FederateHandle> PublishersList ;
     PublishersList publishers ;
@@ -258,4 +265,4 @@
 
 #endif // _CERTI_INTERACTION.HH
 
-// $Id: Interaction.hh,v 3.38 2009/11/19 18:15:30 erk Exp $
+// $Id: Interaction.hh,v 3.39 2009/11/21 15:13:08 erk Exp $

Index: RootObject.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/RootObject.cc,v
retrieving revision 3.45
retrieving revision 3.46
diff -u -b -r3.45 -r3.46
--- RootObject.cc       21 Nov 2009 14:46:17 -0000      3.45
+++ RootObject.cc       21 Nov 2009 15:13:08 -0000      3.46
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: RootObject.cc,v 3.45 2009/11/21 14:46:17 erk Exp $
+// $Id: RootObject.cc,v 3.46 2009/11/21 15:13:08 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include "Object.hh"
@@ -446,38 +446,30 @@
                 mic.setTransport(interactionClass->transport);
 
                 // Dump only those attributes from the list that are not 
alreay in the parent
-                Interaction::ParameterList_t parameterList = 
i->second->getParameterList();
+                Interaction* parent = 0;
                 if (0 < superclassHandle) {
-                        Interaction* parent = 
getInteractionClass(superclassHandle);
+                        parent = getInteractionClass(superclassHandle);
 
                         // strip the common substring from the parents name.
                         if (name.find(parent->getName() + ".") == 0)
                                 name = name.substr(parent->getName().size() + 
1);
-
-                        // remove the parents attributes from the transfered 
list
-                        Interaction::ParameterList_t parentParameterList = 
parent->getParameterList();
-                        Interaction::ParameterList_t::const_iterator j = 
parentParameterList.begin();
-                        for (; j != parentParameterList.end(); ++j) {
-                                Interaction::ParameterList_t::iterator k = 
parameterList.begin();
-                                for (; k != parameterList.end(); ++k) {
-                                        if ((*k)->getHandle() != 
(*j)->getHandle())
-                                                continue;
-                                        parameterList.erase(k);
-                                        break;
-                                }
-                        }
                 }
 
                 // Transfer the simple name
                 mic.setName(name);
 
                 // Transfer the new parameters
-                mic.setNumParameters(parameterList.size());
-                Interaction::ParameterList_t::const_reverse_iterator j = 
parameterList.rbegin();
                 uint32_t jdx = 0;
-                for (; j != parameterList.rend(); ++j, ++jdx) {
-                        const Parameter* parameter = *j;
-                        NM_FOM_Parameter& mp = mic.getParameter(jdx);
+                const Interaction::HandleParameterMap& parameterMap = 
i->second->getHandleParameterMap();
+                Interaction::HandleParameterMap::const_iterator j = 
parameterMap.begin();
+                for (; j != parameterMap.end(); ++j) {
+                        // Dump only those attributes from the list that are 
not alreay in the parent
+                        const Parameter* parameter = j->second;
+                        if (parent && 
parent->hasParameter(parameter->getHandle()))
+                                continue;
+
+                        mic.setNumParameters(++jdx);
+                        NM_FOM_Parameter& mp = mic.getParameter(jdx - 1);
 
                         mp.setHandle(parameter->getHandle());
                         mp.setName(parameter->getName());
@@ -551,14 +543,6 @@
 
                 addInteractionClass(current, parent);
 
-                if (parent) {
-                        const Interaction::ParameterList_t& parameterList = 
parent->getParameterList();
-                        for (Interaction::ParameterList_t::const_iterator j = 
parameterList.begin();
-                             j != parameterList.end(); ++j) {
-                                  current->addParameter(new Parameter(**j));
-                        }
-                }
- 
                 uint32_t parameterCount = mic.getNumParameters();
                 for (uint32_t j = 0; j < parameterCount; ++j) {
                         const NM_FOM_Parameter& mp = mic.getParameter(j);
@@ -573,4 +557,4 @@
 
 } // namespace certi
 
-// $Id: RootObject.cc,v 3.45 2009/11/21 14:46:17 erk Exp $
+// $Id: RootObject.cc,v 3.46 2009/11/21 15:13:08 erk Exp $




reply via email to

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