29 #include "../stuff/macros.h" 64 _typeName = typeName_;
69 _typeName = typeName_;
94 for (ActionMap::iterator it = _actionMap.begin(); it != _actionMap.end(); ++it) {
101 ActionMap::iterator it=_actionMap.find(
typeid(*element).name());
103 if (it==_actionMap.end())
106 return (*action)(element, params);
111 ActionMap::iterator it=_actionMap.find(
typeid(*element).name());
112 if (it==_actionMap.end())
115 return (*action)(element, params);
120 # ifdef G2O_DEBUG_ACTIONLIB 123 if (action->
name()!=name()){
124 cerr <<
__PRETTY_FUNCTION__ <<
": invalid attempt to register an action in a collection with a different name " << name() <<
" " << action->
name() << endl;
126 _actionMap.insert(make_pair ( action->
typeName(), action) );
132 for (HyperGraphElementAction::ActionMap::iterator it=_actionMap.begin(); it != _actionMap.end(); ++it) {
133 if (it->second == action){
134 _actionMap.erase(it);
147 if (actionLibInstance == 0) {
150 return actionLibInstance;
155 delete actionLibInstance;
156 actionLibInstance = 0;
161 for (HyperGraphElementAction::ActionMap::iterator it = _actionMap.begin(); it != _actionMap.end(); ++it) {
168 HyperGraphElementAction::ActionMap::iterator it=_actionMap.find(name);
169 if (it!=_actionMap.end())
181 cerr <<
__PRETTY_FUNCTION__ <<
": fatal error, a collection is not at the first level in the library" << endl;
186 #ifdef G2O_DEBUG_ACTIONLIB 190 _actionMap.insert(make_pair(action->
name(), collection));
197 list<HyperGraphElementActionCollection*> collectionDeleteList;
200 for (HyperGraphElementAction::ActionMap::iterator it=_actionMap.begin(); it != _actionMap.end(); ++it) {
202 if (collection != 0) {
204 if (collection->
actionMap().size() == 0) {
205 collectionDeleteList.push_back(collection);
211 for (list<HyperGraphElementActionCollection*>::iterator itc = collectionDeleteList.begin(); itc != collectionDeleteList.end(); ++itc) {
213 _actionMap.erase((*itc)->name());
223 _name=
"writeGnuplot";
255 for (HyperGraph::VertexIDMap::iterator it=graph->
vertices().begin();
257 if ( typeName.empty() ||
typeid(*it->second).
name()==
typeName){
258 (*action)(it->second, params);
261 for (HyperGraph::EdgeSet::iterator it=graph->
edges().begin();
262 it!=graph->
edges().end(); ++it){
263 if ( typeName.empty() ||
typeid(**it).name()==
typeName)
264 (*action)(*it, params);
DrawAction(const std::string &typeName_)
#define __PRETTY_FUNCTION__
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, Parameters *parameters)
redefine this to do the action stuff. If successful, the action returns a pointer to itself ...
bool registerAction(HyperGraphElementAction *action)
Abstract action that operates on a graph entity.
Parameters * _previousParams
static void destroy()
free the instance
ParametersIteration(int iter)
HyperGraphElementActionCollection(const std::string &name_)
constructor. name_ is the name of the action e.g.draw).
const VertexIDMap & vertices() const
bool unregisterAction(HyperGraphElementAction *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
P * makeProperty(const std::string &name_, const typename P::ValueType &v)
virtual ~HyperGraphElementActionCollection()
destructor: it deletes all actions in the pool.
const EdgeSet & edges() const
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
bool registerAction(HyperGraphElementAction *action)
HyperGraphElementAction * actionByName(const std::string &name)
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
WriteGnuplotAction(const std::string &typeName_)
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, Parameters *parameters)
HyperGraphElementAction(const std::string &typeName_="")
virtual ~HyperGraphAction()
const std::string & typeName() const
returns the typeid name of the action
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
~HyperGraphActionLibrary()
static HyperGraphActionLibrary * actionLibInstance
bool unregisterAction(HyperGraphElementAction *action)
HyperGraphActionLibrary()
virtual ~HyperGraphElementAction()
destroyed actions release the memory
Abstract action that operates on an entire graph.
library of actions, indexed by the action name;
virtual HyperGraphAction * operator()(const HyperGraph *graph, Parameters *parameters=0)