g2o
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members
g2o::HyperGraphActionLibrary Class Reference

library of actions, indexed by the action name; More...

#include <hyper_graph_action.h>

Collaboration diagram for g2o::HyperGraphActionLibrary:
Collaboration graph
[legend]

Public Member Functions

HyperGraphElementActionactionByName (const std::string &name)
 
bool registerAction (HyperGraphElementAction *action)
 
bool unregisterAction (HyperGraphElementAction *action)
 
HyperGraphElementAction::ActionMapactionMap ()
 

Static Public Member Functions

static HyperGraphActionLibraryinstance ()
 return the single instance of the HyperGraphActionLibrary More...
 
static void destroy ()
 free the instance More...
 

Protected Member Functions

 HyperGraphActionLibrary ()
 
 ~HyperGraphActionLibrary ()
 

Protected Attributes

HyperGraphElementAction::ActionMap _actionMap
 

Static Private Attributes

static HyperGraphActionLibraryactionLibInstance = 0
 

Detailed Description

library of actions, indexed by the action name;

library of actions, indexed by the action name; one can use ti to register a collection of actions

Definition at line 138 of file hyper_graph_action.h.

Constructor & Destructor Documentation

g2o::HyperGraphActionLibrary::HyperGraphActionLibrary ( )
protected

Definition at line 142 of file hyper_graph_action.cpp.

143  {
144  }
g2o::HyperGraphActionLibrary::~HyperGraphActionLibrary ( )
protected

Definition at line 160 of file hyper_graph_action.cpp.

161  {
162  for (HyperGraphElementAction::ActionMap::iterator it = _actionMap.begin(); it != _actionMap.end(); ++it) {
163  delete it->second;
164  }
165  }
HyperGraphElementAction::ActionMap _actionMap

Member Function Documentation

HyperGraphElementAction * g2o::HyperGraphActionLibrary::actionByName ( const std::string &  name)

Definition at line 167 of file hyper_graph_action.cpp.

Referenced by g2o::G2oQGLViewer::draw(), g2o::DrawAction::initializeDrawActionsCache(), and g2o::deprecated::VertexSE3WriteGnuplotAction::operator()().

168  {
169  HyperGraphElementAction::ActionMap::iterator it=_actionMap.find(name);
170  if (it!=_actionMap.end())
171  return it->second;
172  return 0;
173  }
HyperGraphElementAction::ActionMap _actionMap
HyperGraphElementAction::ActionMap& g2o::HyperGraphActionLibrary::actionMap ( )
inline

Definition at line 151 of file hyper_graph_action.h.

151 {return _actionMap;}
HyperGraphElementAction::ActionMap _actionMap
void g2o::HyperGraphActionLibrary::destroy ( )
static

free the instance

Definition at line 154 of file hyper_graph_action.cpp.

155  {
156  delete actionLibInstance;
157  actionLibInstance = 0;
158  }
static HyperGraphActionLibrary * actionLibInstance
HyperGraphActionLibrary * g2o::HyperGraphActionLibrary::instance ( )
static
bool g2o::HyperGraphActionLibrary::registerAction ( HyperGraphElementAction action)

Definition at line 175 of file hyper_graph_action.cpp.

References __PRETTY_FUNCTION__, g2o::HyperGraphElementAction::name(), and g2o::HyperGraphElementActionCollection::registerAction().

Referenced by g2o::G2O_ATTRIBUTE_CONSTRUCTOR(), and g2o::RegisterActionProxy< T >::RegisterActionProxy().

176  {
177  HyperGraphElementAction* oldAction = actionByName(action->name());
178  HyperGraphElementActionCollection* collection = 0;
179  if (oldAction) {
180  collection = dynamic_cast<HyperGraphElementActionCollection*>(oldAction);
181  if (! collection) {
182  cerr << __PRETTY_FUNCTION__ << ": fatal error, a collection is not at the first level in the library" << endl;
183  return 0;
184  }
185  }
186  if (! collection) {
187 #ifdef G2O_DEBUG_ACTIONLIB
188  cerr << __PRETTY_FUNCTION__ << ": creating collection for \"" << action->name() << "\"" << endl;
189 #endif
190  collection = new HyperGraphElementActionCollection(action->name());
191  _actionMap.insert(make_pair(action->name(), collection));
192  }
193  return collection->registerAction(action);
194  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
HyperGraphElementAction * actionByName(const std::string &name)
HyperGraphElementAction::ActionMap _actionMap
bool g2o::HyperGraphActionLibrary::unregisterAction ( HyperGraphElementAction action)

Definition at line 196 of file hyper_graph_action.cpp.

References g2o::HyperGraphElementActionCollection::actionMap(), and g2o::HyperGraphElementActionCollection::unregisterAction().

Referenced by g2o::RegisterActionProxy< T >::~RegisterActionProxy().

197  {
198  list<HyperGraphElementActionCollection*> collectionDeleteList;
199 
200  // Search all the collections and delete the registered actions; if a collection becomes empty, schedule it for deletion; note that we can't delete the collections as we go because this will screw up the state of the iterators
201  for (HyperGraphElementAction::ActionMap::iterator it=_actionMap.begin(); it != _actionMap.end(); ++it) {
202  HyperGraphElementActionCollection* collection = dynamic_cast<HyperGraphElementActionCollection*> (it->second);
203  if (collection != 0) {
204  collection->unregisterAction(action);
205  if (collection->actionMap().size() == 0) {
206  collectionDeleteList.push_back(collection);
207  }
208  }
209  }
210 
211  // Delete any empty action collections
212  for (list<HyperGraphElementActionCollection*>::iterator itc = collectionDeleteList.begin(); itc != collectionDeleteList.end(); ++itc) {
213  //cout << "Deleting collection " << (*itc)->name() << endl;
214  _actionMap.erase((*itc)->name());
215  }
216 
217  return true;
218  }
HyperGraphElementAction::ActionMap _actionMap

Member Data Documentation

HyperGraphElementAction::ActionMap g2o::HyperGraphActionLibrary::_actionMap
protected

Definition at line 155 of file hyper_graph_action.h.

HyperGraphActionLibrary * g2o::HyperGraphActionLibrary::actionLibInstance = 0
staticprivate

Definition at line 157 of file hyper_graph_action.h.


The documentation for this class was generated from the following files: