g2o
Loading...
Searching...
No Matches
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>

Public Member Functions

 HyperGraphActionLibrary (HyperGraphActionLibrary const &)=delete
 
HyperGraphActionLibraryoperator= (HyperGraphActionLibrary const &)=delete
 
HyperGraphElementActionactionByName (const std::string &name)
 
bool registerAction (const HyperGraphElementAction::HyperGraphElementActionPtr &action)
 
bool unregisterAction (const HyperGraphElementAction::HyperGraphElementActionPtr &action)
 
HyperGraphElementAction::ActionMapactionMap ()
 

Static Public Member Functions

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

Protected Member Functions

 HyperGraphActionLibrary ()=default
 

Protected Attributes

HyperGraphElementAction::ActionMap _actionMap
 

Static Private Attributes

static std::unique_ptr< HyperGraphActionLibraryactionLibInstance
 

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

Constructor & Destructor Documentation

◆ HyperGraphActionLibrary() [1/2]

g2o::HyperGraphActionLibrary::HyperGraphActionLibrary ( HyperGraphActionLibrary const &  )
delete

◆ HyperGraphActionLibrary() [2/2]

g2o::HyperGraphActionLibrary::HyperGraphActionLibrary ( )
protecteddefault

Member Function Documentation

◆ actionByName()

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

Definition at line 140 of file hyper_graph_action.cpp.

141 {
142 HyperGraphElementAction::ActionMap::iterator it = _actionMap.find(name);
143 if (it != _actionMap.end()) return it->second.get();
144 return nullptr;
145}
HyperGraphElementAction::ActionMap _actionMap

References _actionMap.

Referenced by g2o::G2oQGLViewer::draw(), g2o::dumpEdges(), g2o::DrawAction::initializeDrawActionsCache(), registerAction(), and g2o::saveGnuplot().

◆ actionMap()

HyperGraphElementAction::ActionMap & g2o::HyperGraphActionLibrary::actionMap ( )
inline

Definition at line 168 of file hyper_graph_action.h.

168{ return _actionMap; }

◆ destroy()

void g2o::HyperGraphActionLibrary::destroy ( )
static

free the instance

Definition at line 135 of file hyper_graph_action.cpp.

135 {
136 std::unique_ptr<HyperGraphActionLibrary> aux;
137 actionLibInstance.swap(aux);
138}
static std::unique_ptr< HyperGraphActionLibrary > actionLibInstance

References actionLibInstance.

◆ instance()

HyperGraphActionLibrary * g2o::HyperGraphActionLibrary::instance ( )
static

return the single instance of the HyperGraphActionLibrary

Definition at line 127 of file hyper_graph_action.cpp.

127 {
128 if (actionLibInstance == 0) {
130 std::unique_ptr<HyperGraphActionLibrary>(new HyperGraphActionLibrary);
131 }
132 return actionLibInstance.get();
133}

References actionLibInstance.

Referenced by g2o::G2oQGLViewer::draw(), g2o::dumpEdges(), g2o::G2O_ATTRIBUTE_CONSTRUCTOR(), g2o::DrawAction::initializeDrawActionsCache(), g2o::RegisterActionProxy< T >::RegisterActionProxy(), and g2o::saveGnuplot().

◆ operator=()

HyperGraphActionLibrary & g2o::HyperGraphActionLibrary::operator= ( HyperGraphActionLibrary const &  )
delete

◆ registerAction()

bool g2o::HyperGraphActionLibrary::registerAction ( const HyperGraphElementAction::HyperGraphElementActionPtr action)

Definition at line 147 of file hyper_graph_action.cpp.

148 {
149 HyperGraphElementAction* oldAction = actionByName(action->name());
150 HyperGraphElementActionCollection* collection = nullptr;
151 if (oldAction) {
152 collection = dynamic_cast<HyperGraphElementActionCollection*>(oldAction);
153 if (!collection) {
154 G2O_ERROR(
155 "{}: : fatal error, a collection is not at the first level in the "
156 "library",
158 return false;
159 }
160 }
161 if (collection) {
162 return collection->registerAction(action);
163 }
164#ifdef G2O_DEBUG_ACTIONLIB
165 G2O_DEBUG("{}: creating collection for {}", __PRETTY_FUNCTION__,
166 action->name());
167#endif
168 collection = new HyperGraphElementActionCollection(action->name());
169 _actionMap.insert(make_pair(
170 action->name(),
172 return collection->registerAction(action);
173}
HyperGraphElementAction * actionByName(const std::string &name)
std::shared_ptr< HyperGraphElementAction > HyperGraphElementActionPtr
#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, actionByName(), G2O_DEBUG, G2O_ERROR, and g2o::HyperGraphElementActionCollection::registerAction().

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

◆ unregisterAction()

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

Definition at line 175 of file hyper_graph_action.cpp.

176 {
177 list<HyperGraphElementActionCollection*> collectionDeleteList;
178
179 // Search all the collections and delete the registered actions; if a
180 // collection becomes empty, schedule it for deletion; note that we can't
181 // delete the collections as we go because this will screw up the state of the
182 // iterators
183 for (HyperGraphElementAction::ActionMap::iterator it = _actionMap.begin();
184 it != _actionMap.end(); ++it) {
185 HyperGraphElementActionCollection* collection =
186 dynamic_cast<HyperGraphElementActionCollection*>(it->second.get());
187 if (collection != nullptr) {
188 collection->unregisterAction(action);
189 if (collection->actionMap().size() == 0) {
190 collectionDeleteList.push_back(collection);
191 }
192 }
193 }
194
195 // Delete any empty action collections
196 for (list<HyperGraphElementActionCollection*>::iterator itc =
197 collectionDeleteList.begin();
198 itc != collectionDeleteList.end(); ++itc) {
199 // cout << "Deleting collection " << (*itc)->name() << endl;
200 _actionMap.erase((*itc)->name());
201 }
202
203 return true;
204}

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

Member Data Documentation

◆ _actionMap

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

Definition at line 172 of file hyper_graph_action.h.

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

◆ actionLibInstance

std::unique_ptr< HyperGraphActionLibrary > g2o::HyperGraphActionLibrary::actionLibInstance
staticprivate

Definition at line 175 of file hyper_graph_action.h.

Referenced by destroy(), and instance().


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