g2o
Public Member Functions | Protected Attributes | List of all members
g2o::HyperGraphElementActionCollection Class Reference

collection of actions More...

#include <hyper_graph_action.h>

Inheritance diagram for g2o::HyperGraphElementActionCollection:
Inheritance graph
[legend]
Collaboration diagram for g2o::HyperGraphElementActionCollection:
Collaboration graph
[legend]

Public Member Functions

 HyperGraphElementActionCollection (const std::string &name_)
 constructor. name_ is the name of the action e.g.draw). More...
 
virtual ~HyperGraphElementActionCollection ()
 destructor: it deletes all actions in the pool. More...
 
virtual HyperGraphElementActionoperator() (HyperGraph::HyperGraphElement *element, Parameters *parameters)
 
virtual HyperGraphElementActionoperator() (const HyperGraph::HyperGraphElement *element, Parameters *parameters)
 redefine this to do the action stuff. If successful, the action returns a pointer to itself More...
 
ActionMapactionMap ()
 
bool registerAction (HyperGraphElementAction *action)
 
bool unregisterAction (HyperGraphElementAction *action)
 
- Public Member Functions inherited from g2o::HyperGraphElementAction
 HyperGraphElementAction (const std::string &typeName_="")
 
virtual ~HyperGraphElementAction ()
 destroyed actions release the memory More...
 
const std::string & typeName () const
 returns the typeid name of the action More...
 
const std::string & name () const
 returns the name of an action, e.g "draw" More...
 
void setTypeName (const std::string &typeName_)
 sets the type on which an action has to operate More...
 

Protected Attributes

ActionMap _actionMap
 
- Protected Attributes inherited from g2o::HyperGraphElementAction
std::string _typeName
 
std::string _name
 

Additional Inherited Members

- Public Types inherited from g2o::HyperGraphElementAction
typedef std::map< std::string, HyperGraphElementAction * > ActionMap
 

Detailed Description

collection of actions

collection of actions calls contains homogeneous actions operating on different types all collected actions have the same name and should have the same functionality

Definition at line 113 of file hyper_graph_action.h.

Constructor & Destructor Documentation

g2o::HyperGraphElementActionCollection::HyperGraphElementActionCollection ( const std::string &  name_)

constructor. name_ is the name of the action e.g.draw).

Definition at line 88 of file hyper_graph_action.cpp.

89  {
90  _name = name_;
91  }
g2o::HyperGraphElementActionCollection::~HyperGraphElementActionCollection ( )
virtual

destructor: it deletes all actions in the pool.

Definition at line 93 of file hyper_graph_action.cpp.

94  {
95  for (ActionMap::iterator it = _actionMap.begin(); it != _actionMap.end(); ++it) {
96  delete it->second;
97  }
98  }

Member Function Documentation

ActionMap& g2o::HyperGraphElementActionCollection::actionMap ( )
inline
HyperGraphElementAction * g2o::HyperGraphElementActionCollection::operator() ( HyperGraph::HyperGraphElement element,
HyperGraphElementAction::Parameters params 
)
virtual

calling functions, they return a pointer to the instance of action in actionMap that was active on element

Reimplemented from g2o::HyperGraphElementAction.

Definition at line 100 of file hyper_graph_action.cpp.

101  {
102  ActionMap::iterator it=_actionMap.find(typeid(*element).name());
103  //cerr << typeid(*element).name() << endl;
104  if (it==_actionMap.end())
105  return 0;
106  HyperGraphElementAction* action=it->second;
107  return (*action)(element, params);
108  }
HyperGraphElementAction(const std::string &typeName_="")
HyperGraphElementAction * g2o::HyperGraphElementActionCollection::operator() ( const HyperGraph::HyperGraphElement element,
HyperGraphElementAction::Parameters parameters 
)
virtual

redefine this to do the action stuff. If successful, the action returns a pointer to itself

Reimplemented from g2o::HyperGraphElementAction.

Definition at line 110 of file hyper_graph_action.cpp.

111  {
112  ActionMap::iterator it=_actionMap.find(typeid(*element).name());
113  if (it==_actionMap.end())
114  return 0;
115  HyperGraphElementAction* action=it->second;
116  return (*action)(element, params);
117  }
HyperGraphElementAction(const std::string &typeName_="")
bool g2o::HyperGraphElementActionCollection::registerAction ( HyperGraphElementAction action)

inserts an action in the pool. The action should have the same name of the container. returns false on failure (the container has a different name than the action);

Definition at line 119 of file hyper_graph_action.cpp.

References __PRETTY_FUNCTION__, g2o::HyperGraphElementAction::name(), and g2o::HyperGraphElementAction::typeName().

Referenced by g2o::HyperGraphActionLibrary::registerAction().

120  {
121 # ifdef G2O_DEBUG_ACTIONLIB
122  cerr << __PRETTY_FUNCTION__ << " " << action->name() << " " << action->typeName() << endl;
123 # endif
124  if (action->name()!=name()){
125  cerr << __PRETTY_FUNCTION__ << ": invalid attempt to register an action in a collection with a different name " << name() << " " << action->name() << endl;
126  }
127  _actionMap.insert(make_pair ( action->typeName(), action) );
128  return true;
129  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
const std::string & name() const
returns the name of an action, e.g "draw"
bool g2o::HyperGraphElementActionCollection::unregisterAction ( HyperGraphElementAction action)

Definition at line 131 of file hyper_graph_action.cpp.

Referenced by g2o::HyperGraphActionLibrary::unregisterAction().

132  {
133  for (HyperGraphElementAction::ActionMap::iterator it=_actionMap.begin(); it != _actionMap.end(); ++it) {
134  if (it->second == action){
135  _actionMap.erase(it);
136  return true;
137  }
138  }
139  return false;
140  }

Member Data Documentation

ActionMap g2o::HyperGraphElementActionCollection::_actionMap
protected

Definition at line 129 of file hyper_graph_action.h.


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