g2o
Loading...
Searching...
No Matches
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).
 
virtual HyperGraphElementActionoperator() (HyperGraph::HyperGraphElement *element, Parameters *parameters)
 
virtual HyperGraphElementActionoperator() (const HyperGraph::HyperGraphElement *element, Parameters *parameters)
 
ActionMapactionMap ()
 
bool registerAction (const HyperGraphElementAction::HyperGraphElementActionPtr &action)
 
bool unregisterAction (const HyperGraphElementAction::HyperGraphElementActionPtr &action)
 
- Public Member Functions inherited from g2o::HyperGraphElementAction
 HyperGraphElementAction (const std::string &typeName_="")
 
virtual ~HyperGraphElementAction ()
 
const std::string & typeName () const
 returns the typeid name of the action
 
const std::string & name () const
 returns the name of an action, e.g "draw"
 
void setTypeName (const std::string &typeName_)
 sets the type on which an action has to operate
 

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::shared_ptr< HyperGraphElementActionHyperGraphElementActionPtr
 
typedef std::map< std::string, HyperGraphElementActionPtrActionMap
 

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 118 of file hyper_graph_action.h.

Constructor & Destructor Documentation

◆ HyperGraphElementActionCollection()

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

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

Definition at line 76 of file hyper_graph_action.cpp.

77 {
78 _name = name_;
79}

References g2o::HyperGraphElementAction::_name.

Member Function Documentation

◆ actionMap()

ActionMap & g2o::HyperGraphElementActionCollection::actionMap ( )
inline

◆ operator()() [1/2]

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 90 of file hyper_graph_action.cpp.

92 {
93 ActionMap::iterator it = _actionMap.find(typeid(*element).name());
94 if (it == _actionMap.end()) return nullptr;
95 HyperGraphElementAction* action = it->second.get();
96 return (*action)(element, params);
97}
HyperGraphElementAction(const std::string &typeName_="")

References _actionMap.

◆ operator()() [2/2]

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 81 of file hyper_graph_action.cpp.

83 {
84 ActionMap::iterator it = _actionMap.find(typeid(*element).name());
85 if (it == _actionMap.end()) return nullptr;
86 HyperGraphElementAction* action = it->second.get();
87 return (*action)(element, params);
88}

References _actionMap.

◆ registerAction()

bool g2o::HyperGraphElementActionCollection::registerAction ( const HyperGraphElementAction::HyperGraphElementActionPtr 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 99 of file hyper_graph_action.cpp.

100 {
101#ifdef G2O_DEBUG_ACTIONLIB
102 G2O_DEBUG("{} {} {}", __PRETTY_FUNCTION__, action->name(),
103 action->typeName());
104#endif
105 if (action->name() != name()) {
106 G2O_ERROR(
107 "{}: invalid attempt to register an action in a collection with a "
108 "different name {} {}",
109 __PRETTY_FUNCTION__, name(), action->name());
110 }
111 _actionMap.insert(make_pair(action->typeName(), action));
112 return true;
113}
const std::string & name() const
returns the name of an action, e.g "draw"
#define G2O_ERROR(...)
Definition logger.h:89
#define G2O_DEBUG(...)
Definition logger.h:90
#define __PRETTY_FUNCTION__
Definition macros.h:90

References __PRETTY_FUNCTION__, _actionMap, G2O_DEBUG, G2O_ERROR, and g2o::HyperGraphElementAction::name().

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

◆ unregisterAction()

bool g2o::HyperGraphElementActionCollection::unregisterAction ( const HyperGraphElementAction::HyperGraphElementActionPtr action)

Definition at line 115 of file hyper_graph_action.cpp.

116 {
117 for (HyperGraphElementAction::ActionMap::iterator it = _actionMap.begin();
118 it != _actionMap.end(); ++it) {
119 if (it->second == action) {
120 _actionMap.erase(it);
121 return true;
122 }
123 }
124 return false;
125}

References _actionMap.

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

Member Data Documentation

◆ _actionMap

ActionMap g2o::HyperGraphElementActionCollection::_actionMap
protected

Definition at line 141 of file hyper_graph_action.h.

Referenced by operator()(), operator()(), registerAction(), and unregisterAction().


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