[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi/libCERTI Object.cc Object.hh
From: |
certi-cvs |
Subject: |
[certi-cvs] certi/libCERTI Object.cc Object.hh |
Date: |
Sun, 11 Oct 2009 17:04:17 +0000 |
CVSROOT: /sources/certi
Module name: certi
Changes by: Eric NOULARD <erk> 09/10/11 17:04:17
Modified files:
libCERTI : Object.cc Object.hh
Log message:
Merge-in (second part)
patch #6942: remove nused/duplicate attributes, avoid linear searches
on instance attributes
Use map instead of dequeue.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Object.cc?cvsroot=certi&r1=3.25&r2=3.26
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/Object.hh?cvsroot=certi&r1=3.21&r2=3.22
Patches:
Index: Object.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/Object.cc,v
retrieving revision 3.25
retrieving revision 3.26
diff -u -b -r3.25 -r3.26
--- Object.cc 11 Oct 2009 14:55:01 -0000 3.25
+++ Object.cc 11 Oct 2009 17:04:17 -0000 3.26
@@ -19,7 +19,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: Object.cc,v 3.25 2009/10/11 14:55:01 erk Exp $
+// $Id: Object.cc,v 3.26 2009/10/11 17:04:17 erk Exp $
// ----------------------------------------------------------------------------
@@ -28,42 +28,30 @@
#include "ObjectAttribute.hh"
#include "RTIRegion.hh"
+#include <sstream>
#include <iostream>
-#include <cstring>
-#include <algorithm>
-#include <functional>
using std::cout ;
using std::endl ;
-using std::deque ;
-using std::list ;
namespace certi {
// ----------------------------------------------------------------------------
//! Constructor.
-Object::Object(FederateHandle the_owner, const char *the_name)
- : Owner(the_owner), handle(0)
+Object::Object(FederateHandle the_owner)
+ : Owner(the_owner)
{
- setName(the_name);
}
-template <class T>
-struct delme : public std::unary_function<T, void> {
- void operator() (T& x) {
- delete x;
- }
-};
-
// ----------------------------------------------------------------------------
//! Destructor.
Object::~Object()
{
// We should delete the pointee because it belongs to the object.
- for (std::deque<ObjectAttribute *>::iterator i = attributeState.begin();
i!=attributeState.end();++i) {
- delete (*i);
+ AttributeMap::const_iterator i;
+ for (i = _attributeMap.begin(); i != _attributeMap.end(); ++i) {
+ delete i->second;
}
- attributeState.clear();
}
// ----------------------------------------------------------------------------
@@ -73,7 +61,7 @@
{
cout << " Instance: handle =" << handle ;
- if (name.length() > 0)
+ if (!name.empty())
cout << ", name=\"" << name << "\"" << endl ;
else
cout << ", (No name)." << endl ;
@@ -83,29 +71,25 @@
void
Object::addAttribute(ObjectAttribute * new_attribute)
{
- attributeState.push_front(new_attribute);
+ AttributeHandle attributeHandle = new_attribute->getHandle();
+ if (_attributeMap.find(attributeHandle) != _attributeMap.end())
+ throw RTIinternalError("Attribute already defined");
+ _attributeMap[attributeHandle] = new_attribute;
}
// ----------------------------------------------------------------------------
//! getAttribute.
ObjectAttribute *
-Object::getAttribute(AttributeHandle the_attribute) const
+Object::getAttribute(AttributeHandle attributeHandle) const
throw (AttributeNotDefined)
{
- deque<ObjectAttribute *>::const_iterator i ;
- for (i = attributeState.begin(); i != attributeState.end(); i++) {
- if ((*i)->getHandle() == the_attribute)
- return (*i);
+ AttributeMap::const_iterator i = _attributeMap.find(attributeHandle);
+ if (i == _attributeMap.end()) {
+ std::stringstream stream;
+ stream << "Unknown attribute handle " << attributeHandle;
+ throw AttributeNotDefined(stream.str());
}
-
- throw AttributeNotDefined("");
-}
-
-// ----------------------------------------------------------------------------
-ObjectClassHandle
-Object::getClass() const
-{
- return classHandle ;
+ return i->second;
}
// ----------------------------------------------------------------------------
@@ -116,13 +100,6 @@
}
// ----------------------------------------------------------------------------
-FederateHandle
-Object::getOwner() const
-{
- return Owner ;
-}
-
-// ----------------------------------------------------------------------------
void
Object::setOwner(FederateHandle the_federate)
{
@@ -136,14 +113,7 @@
AttributeHandle the_attribute) const
throw (AttributeNotDefined, RTIinternalError)
{
- deque<ObjectAttribute *>::const_iterator i ;
- for (i = attributeState.begin(); i != attributeState.end(); i++) {
- if ((*i)->getHandle() == the_attribute) {
- return (*i)->getOwner() == the_federate ;
- }
- }
-
- throw AttributeNotDefined("Instance doesn't have this attribute handle");
+ return getAttribute(the_attribute)->getOwner() == the_federate;
}
// ----------------------------------------------------------------------------
@@ -151,12 +121,12 @@
void
Object::unassociate(RTIRegion *region)
{
- deque<ObjectAttribute *>::const_iterator i ;
- for (i = attributeState.begin(); i != attributeState.end(); i++) {
- (*i)->unassociate(region);
+ AttributeMap::const_iterator i;
+ for (i = _attributeMap.begin(); i != _attributeMap.end(); ++i) {
+ i->second->unassociate(region);
}
}
} // namespace certi
-// $Id: Object.cc,v 3.25 2009/10/11 14:55:01 erk Exp $
+// $Id: Object.cc,v 3.26 2009/10/11 17:04:17 erk Exp $
Index: Object.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/Object.hh,v
retrieving revision 3.21
retrieving revision 3.22
diff -u -b -r3.21 -r3.22
--- Object.hh 11 Oct 2009 14:55:01 -0000 3.21
+++ Object.hh 11 Oct 2009 17:04:17 -0000 3.22
@@ -19,7 +19,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
-// $Id: Object.hh,v 3.21 2009/10/11 14:55:01 erk Exp $
+// $Id: Object.hh,v 3.22 2009/10/11 17:04:17 erk Exp $
// ----------------------------------------------------------------------------
#ifndef _CERTI_OBJECT_HH
@@ -36,19 +36,14 @@
#include "Handled.hh"
#include "Exception.hh"
-#include <deque>
-#include <list>
+#include <map>
namespace certi {
class CERTI_EXPORT Object : public Named, public Handled<ObjectHandle>
{
public:
- Object(FederateHandle the_owner)
- : Owner(the_owner) { handle = 0 ; };
-
- Object(FederateHandle the_owner, const char *the_name);
-
+ Object(FederateHandle the_owner);
virtual ~Object();
void display() const ;
@@ -60,27 +55,24 @@
bool isAttributeOwnedByFederate(FederateHandle, AttributeHandle) const
throw (AttributeNotDefined, RTIinternalError);
- ObjectClassHandle getClass() const ;
+ ObjectClassHandle getClass() const { return classHandle; }
void setClass(ObjectClassHandle h);
- FederateHandle getOwner() const ;
+ FederateHandle getOwner() const { return Owner; }
void setOwner(FederateHandle);
void unassociate(RTIRegion *);
- // -----------------------
- // -- Public Attributes --
- // ----------------------
+private:
/*! Owner Handle
BUG: Should be handled at the attribute level, not instance level.
*/
FederateHandle Owner ;
-private:
- //! Attribute list from object class instance (private).
- std::deque<ObjectAttribute *> attributeState ;
+ typedef std::map<AttributeHandle,ObjectAttribute*> AttributeMap;
+ //! Attribute list from object class instance.
+ AttributeMap _attributeMap;
- ObjectHandle handle ; //!< Object Instance ID
ObjectClassHandle classHandle ; //! Object Class
};
@@ -88,4 +80,4 @@
#endif // _CERTI_OBJECT_HH
-// $Id: Object.hh,v 3.21 2009/10/11 14:55:01 erk Exp $
+// $Id: Object.hh,v 3.22 2009/10/11 17:04:17 erk Exp $
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi/libCERTI Object.cc Object.hh,
certi-cvs <=