Commit 96a61150 authored by Mike Kremer's avatar Mike Kremer

BaseObject handles are now stored in a std::map. This reduces complexity of...

BaseObject handles are now stored in a std::map. This reduces complexity of finding nodes from O(n) to O(log(n)).

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8475 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 18d4191a
...@@ -126,6 +126,9 @@ static int objectCounter_ = 0; ...@@ -126,6 +126,9 @@ static int objectCounter_ = 0;
/// Number of current target objects /// Number of current target objects
static int targetCounter_ = 0; static int targetCounter_ = 0;
/// Map that holds the object handles
static std::map<int, BaseObject*> objectMap_;
void setDataRoot( BaseObject* _root ) { void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root; objectRoot_ = _root;
} }
...@@ -267,7 +270,15 @@ bool getObject( const int _identifier , BaseObject*& _object ) { ...@@ -267,7 +270,15 @@ bool getObject( const int _identifier , BaseObject*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
_object = objectRoot_->childExists( _identifier ); // Obsolete:
//_object = objectRoot_->childExists( _identifier );
// Search for specified object in object map:
std::map<int, BaseObject*>::iterator it;
it = objectMap_.find(_identifier);
// Get object
_object = (it != objectMap_.end() ? it->second : 0);
return ( _object != 0 ); return ( _object != 0 );
} }
...@@ -276,7 +287,14 @@ bool getObject( const int _identifier , BaseObjectData*& _object ) { ...@@ -276,7 +287,14 @@ bool getObject( const int _identifier , BaseObjectData*& _object ) {
if ( _identifier == -1 ) if ( _identifier == -1 )
return false; return false;
BaseObject* object = objectRoot_->childExists( _identifier ); // Obsolete: BaseObject* object = objectRoot_->childExists( _identifier );
// Search for specified object in object map:
std::map<int, BaseObject*>::iterator it;
it = objectMap_.find(_identifier);
// Get object
BaseObject* object = (it != objectMap_.end() ? it->second : 0);
_object = dynamic_cast< BaseObjectData* >(object); _object = dynamic_cast< BaseObjectData* >(object);
return ( _object != 0 ); return ( _object != 0 );
} }
...@@ -938,4 +956,33 @@ void decreaseTargetCount() { ...@@ -938,4 +956,33 @@ void decreaseTargetCount() {
std::cerr << "target object counter underflow!!!" << std::endl; std::cerr << "target object counter underflow!!!" << std::endl;
} }
// ===============================================================================
// Add an object to the internal object map
// ===============================================================================
void addObjectToMap(int _objectId, BaseObject* _object) {
// Look if object's id already exists in map
std::map<int, BaseObject*>::iterator it;
it = objectMap_.find(_objectId);
// If so return
if(it != objectMap_.end()) return;
// Add new object to map
objectMap_.insert(std::pair<int, BaseObject*>(_objectId, _object));
}
// ===============================================================================
// Remove an object from the internal object map
// ===============================================================================
void removeObjectFromMap(int _objectId) {
// Look if object exists in map
std::map<int, BaseObject*>::iterator it;
it = objectMap_.find(_objectId);
// Erase entry
if(it != objectMap_.end()) objectMap_.erase(it);
} }
} // End namespace PluginFunctions
\ No newline at end of file
...@@ -116,6 +116,22 @@ void decreaseTargetCount(); ...@@ -116,6 +116,22 @@ void decreaseTargetCount();
/** @} */ /** @} */
//=======================================
// Object container functions
/** @name Internal object handle container
* @{ */
//=======================================
/// Add object to internal object map
DLLEXPORT
void addObjectToMap(int _objectId, BaseObject* _object);
/// Remove object from internal object map
DLLEXPORT
void removeObjectFromMap(int _objectId);
/** @} */
} }
#endif //PLUGINFUNCTIONSCORE_HH #endif //PLUGINFUNCTIONSCORE_HH
...@@ -110,6 +110,9 @@ BaseObject::BaseObject(const BaseObject& _object) : ...@@ -110,6 +110,9 @@ BaseObject::BaseObject(const BaseObject& _object) :
PluginFunctions::increaseObjectCount(); PluginFunctions::increaseObjectCount();
} }
// Add object to object container
PluginFunctions::addObjectToMap( id(), this );
objectManager_.objectCreated(id()); objectManager_.objectCreated(id());
} }
...@@ -142,6 +145,9 @@ BaseObject::BaseObject(BaseObject* _parent) : ...@@ -142,6 +145,9 @@ BaseObject::BaseObject(BaseObject* _parent) :
} }
// Add object to object container
PluginFunctions::addObjectToMap( id(), this );
objectManager_.objectCreated(id()); objectManager_.objectCreated(id());
} }
...@@ -797,6 +803,9 @@ void ObjectManager::objectCreated(int _objectId) ...@@ -797,6 +803,9 @@ void ObjectManager::objectCreated(int _objectId)
void ObjectManager::objectDeleted(int _objectId) void ObjectManager::objectDeleted(int _objectId)
{ {
// Remove deleted object from object container
PluginFunctions::removeObjectFromMap( _objectId );
emit deletedObject(_objectId); emit deletedObject(_objectId);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment