From dcd594f052fe8ec5a7dd894e2c3dba2ec80d070e Mon Sep 17 00:00:00 2001
From: Mansard <nmansard@laas.fr>
Date: Fri, 11 Feb 2011 10:53:26 +0100
Subject: [PATCH] Added a function to test for the existence of a named entity.

---
 include/dynamic-graph/pool.h |  5 +++++
 src/dgraph/pool.cpp          | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/dynamic-graph/pool.h b/include/dynamic-graph/pool.h
index a16844e..885b171 100644
--- a/include/dynamic-graph/pool.h
+++ b/include/dynamic-graph/pool.h
@@ -86,6 +86,11 @@ namespace dynamicgraph
     */
     Entity& getEntity (const std::string& name);
 
+    /*! \brief Test if the entity exists. */
+    bool existEntity (const std::string& name);
+    /*! \brief Test if the entity exists. If it does, return a pointer on it. */
+    bool existEntity (const std::string& name, Entity*& ptr);
+
     /*! \brief Disallocate an entity.
       \par[in] entname: The name of the entity,
     */
diff --git a/src/dgraph/pool.cpp b/src/dgraph/pool.cpp
index 28eee63..30054f4 100644
--- a/src/dgraph/pool.cpp
+++ b/src/dgraph/pool.cpp
@@ -115,6 +115,24 @@ getEntity( const std::string& name )
   else return *entPtr->second;
 }
 
+bool PoolStorage::
+existEntity (const std::string& name)
+{
+  return entityMap.find( name ) != entityMap.end();
+}
+bool PoolStorage::
+existEntity (const std::string& name, Entity*& ptr)
+{
+  Entities::iterator entPtr = entityMap.find( name );
+  if( entPtr == entityMap.end () ) return false;
+  else
+    {
+      ptr = entPtr->second;
+      return true;
+    }
+}
+
+
 void PoolStorage::
 clearPlugin( const std::string& name )
 {
-- 
GitLab