certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] certi/libCERTI ObjectAttribute.cc ObjectAttribu...


From: certi-cvs
Subject: [certi-cvs] certi/libCERTI ObjectAttribute.cc ObjectAttribu...
Date: Fri, 20 Nov 2009 17:33:57 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      09/11/20 17:33:57

Modified files:
        libCERTI       : ObjectAttribute.cc ObjectAttribute.hh 
                         ObjectClass.cc 

Log message:
        Check-in clean-up patch from Mathias
        patch #6985: Use std::set for ObjectAttribute::ownerCandidates

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectAttribute.cc?cvsroot=certi&r1=3.18&r2=3.19
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectAttribute.hh?cvsroot=certi&r1=3.18&r2=3.19
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/ObjectClass.cc?cvsroot=certi&r1=3.70&r2=3.71

Patches:
Index: ObjectAttribute.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectAttribute.cc,v
retrieving revision 3.18
retrieving revision 3.19
diff -u -b -r3.18 -r3.19
--- ObjectAttribute.cc  21 Oct 2009 18:56:28 -0000      3.18
+++ ObjectAttribute.cc  20 Nov 2009 17:33:57 -0000      3.19
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectAttribute.cc,v 3.18 2009/10/21 18:56:28 erk Exp $
+// $Id: ObjectAttribute.cc,v 3.19 2009/11/20 17:33:57 erk Exp $
 // ----------------------------------------------------------------------------
 
 
@@ -32,7 +32,6 @@
 
 using std::cout ;
 using std::endl ;
-using std::list ;
 
 namespace certi {
 
@@ -97,16 +96,10 @@
 
 // ----------------------------------------------------------------------------
 //! Return the candidate position in list, null otherwise.
-int
+bool
 ObjectAttribute::isCandidate(FederateHandle candidate) const
 {
-    list<FederateHandle>::const_iterator i = ownerCandidates.begin();
-    for (int j = 1 ; i != ownerCandidates.end(); i++, j++) {
-        if ((*i) == candidate)
-            return j ;
-    }
-
-    return 0 ;
+    return ownerCandidates.find(candidate) != ownerCandidates.end();
 }
 
 // ----------------------------------------------------------------------------
@@ -114,7 +107,7 @@
 void
 ObjectAttribute::addCandidate(FederateHandle candidate)
 {
-    ownerCandidates.push_front(candidate);
+    ownerCandidates.insert(candidate);
 }
 
 // ----------------------------------------------------------------------------
@@ -122,31 +115,26 @@
 void
 ObjectAttribute::removeCandidate(FederateHandle candidate)
 {
-    ownerCandidates.remove(candidate);
+    ownerCandidates.erase(candidate);
 }
 
 // ----------------------------------------------------------------------------
 // Returns the federate candidate at position in list.
 FederateHandle
-ObjectAttribute::getCandidate(unsigned int indice) const
+ObjectAttribute::getFirstCandidate() const
     throw (RTIinternalError)
 {
-    if ((indice <= 0) || (indice > ownerCandidates.size()))
+    if (ownerCandidates.empty())
         throw RTIinternalError("");
 
-    list<FederateHandle>::const_iterator i = ownerCandidates.begin();
-    for (unsigned int j = 1 ; i != ownerCandidates.end(); i++, j++) {
-        if (j == indice)
-            return (*i);
-    }
-    throw RTIinternalError("");
+    return *ownerCandidates.begin();
 }
 
 // ----------------------------------------------------------------------------
 bool
 ObjectAttribute::hasCandidates() const
 {
-    return (!ownerCandidates.empty());
+    return !ownerCandidates.empty();
 }
 
 // ----------------------------------------------------------------------------
@@ -199,4 +187,4 @@
 
 } //namespace certi
 
-// $Id: ObjectAttribute.cc,v 3.18 2009/10/21 18:56:28 erk Exp $
+// $Id: ObjectAttribute.cc,v 3.19 2009/11/20 17:33:57 erk Exp $

Index: ObjectAttribute.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectAttribute.hh,v
retrieving revision 3.18
retrieving revision 3.19
diff -u -b -r3.18 -r3.19
--- ObjectAttribute.hh  19 Nov 2009 18:15:30 -0000      3.18
+++ ObjectAttribute.hh  20 Nov 2009 17:33:57 -0000      3.19
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectAttribute.hh,v 3.18 2009/11/19 18:15:30 erk Exp $
+// $Id: ObjectAttribute.hh,v 3.19 2009/11/20 17:33:57 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef CERTI_OBJECT_ATTRIBUTE_HH
@@ -28,7 +28,7 @@
 #include "certi.hh"
 #include "Exception.hh"
 
-#include <list>
+#include <set>
 
 namespace certi {
 
@@ -60,10 +60,10 @@
     void setDivesting(bool divesting_state);
     bool beingDivested() const ;
 
-    int isCandidate(FederateHandle candidate) const ;
+    bool isCandidate(FederateHandle candidate) const ;
     void addCandidate(FederateHandle candidate);
     void removeCandidate(FederateHandle candidate);
-    FederateHandle getCandidate(unsigned int) const throw (RTIinternalError);
+    FederateHandle getFirstCandidate() const throw (RTIinternalError);
     bool hasCandidates() const ;
 
     AttributeHandle getHandle() const ;
@@ -86,7 +86,7 @@
     AttributeHandle handle ; //!< The object attribute handle.
     FederateHandle owner ; //!< Federate who owns the attribute.
     bool divesting ; //!< Divesting state.
-    std::list<FederateHandle> ownerCandidates ; //!< Federates candidate.
+    std::set<FederateHandle> ownerCandidates ; //!< Federates candidate.
     SpaceHandle space ; //!< Associated routing space
     ObjectClassAttribute *source ; //!< The associated class attribute.
     RTIRegion *region ;
@@ -96,4 +96,4 @@
 
 #endif // CERTI_OBJECT_ATTRIBUTE_HH
 
-// $Id: ObjectAttribute.hh,v 3.18 2009/11/19 18:15:30 erk Exp $
+// $Id: ObjectAttribute.hh,v 3.19 2009/11/20 17:33:57 erk Exp $

Index: ObjectClass.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/ObjectClass.cc,v
retrieving revision 3.70
retrieving revision 3.71
diff -u -b -r3.70 -r3.71
--- ObjectClass.cc      19 Nov 2009 18:15:30 -0000      3.70
+++ ObjectClass.cc      20 Nov 2009 17:33:57 -0000      3.71
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: ObjectClass.cc,v 3.70 2009/11/19 18:15:30 erk Exp $
+// $Id: ObjectClass.cc,v 3.71 2009/11/20 17:33:57 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include  "Object.hh"
@@ -1075,7 +1075,7 @@
                 // with this attribute.
 
                 // Le demandeur le plus recent devient proprietaire
-                NewOwner = oa->getCandidate(1);
+                NewOwner = oa->getFirstCandidate();
 
                 oa->setOwner(NewOwner);
 
@@ -1352,7 +1352,7 @@
                 // on this attribute.
 
                 // Le demandeur le plus recent devient proprietaire
-                NewOwner = oa->getCandidate(1);
+                NewOwner = oa->getFirstCandidate();
 
                 oa->setOwner(NewOwner);
 
@@ -1500,7 +1500,7 @@
                     compteur_divestiture++ ;
                 }
                 //Qu'il soit offert ou libre
-                if (oa->isCandidate(theFederateHandle) != 0)
+                if (oa->isCandidate(theFederateHandle))
                     oa->removeCandidate(theFederateHandle);
                 AnswerNotification->handleArray[compteur_notification]
                     = theAttributeList[i] ;
@@ -1610,7 +1610,7 @@
             oa = object->getAttribute(the_attributes[i]);
 
             //Le demandeur le plus r�cent devient propri�taire
-            newOwner = oa->getCandidate(1);
+            newOwner = oa->getFirstCandidate();
 
             oa->setOwner(newOwner);
 
@@ -1691,7 +1691,7 @@
             if (oa->getOwner() == federate_handle)
                 throw AttributeAlreadyOwned("");
             // Does federate is already doing an acquisition ?
-            if (oa->isCandidate(federate_handle) == 0)
+            if (!oa->isCandidate(federate_handle))
                 throw AttributeAcquisitionWasNotRequested("");
         }
 
@@ -1834,4 +1834,4 @@
 
 } // namespace certi
 
-// $Id: ObjectClass.cc,v 3.70 2009/11/19 18:15:30 erk Exp $
+// $Id: ObjectClass.cc,v 3.71 2009/11/20 17:33:57 erk Exp $




reply via email to

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