C++ main module for gpm Package  1.0
GPM_GraphElement.h
Go to the documentation of this file.
1 #ifndef GPM_GraphElement_H
2 #define GPM_GraphElement_H
3 
4 #include "GPM_Object.h"
5 
6 #include "GPM_Variable.h"
7 
9 
17 class GPM_GraphElement : public virtual GPM_Object{
19  // ATTRIBUTES
20 
21  // topological actions
22  static const tFlag REMOVE;
23  static const tFlag KEEP;
24 
25  //variables action
26  static const tFlag UNSET;
27  static const tFlag SET;
28  static const tFlag ADD;
29  static const tFlag VALID;
30 
31 
32 private:
33 
34  int mId;
35  tString mGroupName;
36 
37 
38  //variable Name -> list of variables
39  map<tString,SV::GPM_Variable> mVariables;
40 
41  //variable name of trigger variable --> trigger value
42  map<tString,SV::GPM_Variable> mActionVariables;
43  //variable name of trigger variable -> trigger action
44  map<tString,tFlag> mVariableActions;
45 
46  // toppological action for graph
47  tFlag mTopologicalAction;
48 
49  //group name action
50  tFlag mGroupNameAction;
51  tString mTriggerGroupName;
52 
53  WP::GPM_Graph mGraph;
54 
55 protected:
56  // METHODS
57 
58  // CONSTRUCTORS
59 
61  GPM_GraphElement(void);
62 
63 
64 
65  // DESTRUCTORS
66 
67 
70  virtual ~GPM_GraphElement(void);
71 
72 
73 protected:
76  virtual void toDoAfterThisSetting() {
78  clearActions();
79  }
80 
81 
82 public:
83 
84 
87  virtual SP::GPM_GraphElement NewInstance() const=0;
88 
89 
90 
91  // SET & GET methods
92 
95  inline void setGraph(SP::GPM_Graph graph) {
96  mGraph=graph;
97  }
100  void setGraph(GPM_Graph& graph);
101 
104  void setGraph(GPM_Graph* graph);
105 
108  GPM_Graph* getGraph() const;
109 
110 
113  virtual void copy(const GPM_GraphElement& node);
114 
115  // VARIABLES
116  // =========
117 
120  void setEnvironment(const map<tString,SP::GPM_Variable>& env);
121 
124  virtual void updateEnvironment(const map<tString,SP::GPM_Variable>& env);
125 
128  SV::GPM_Variable addToVariables(const tString &variableName,SP::GPM_Variable var);
129 
132  GPM_Variable& initVariable(const tString &variableName);
133 
134 
137  void setVariable(const tString &variableName,const GPM_Variable& var);
138 
141  void setVariable(const tString &variableName,SP::GPM_Variable var);
142 
145  void setVariableValue(const tString &variableName,const tString& value);
148  void setVariableValue(const tString &variableName,const double& value);
151  void setVariableValue(const tString &variableName,const int& n,const double* value);
154  void setVariableValue(const tString &variableName,const tFlag& type,const int& n,const double* value);
157  tBoolean setVariableValuesFromString(const tString& variableName,const tFlag& type,const tString& values);
158 
161  void removeVariable(const tString& varName) {
162  mVariables.erase(varName);
163  }
166  inline void getVariableNames(vector<tString>& names) const {
167  names.clear();
168  map<tString,SV::GPM_Variable>::const_iterator iter=mVariables.begin();
169  while (iter!=mVariables.end()) {
170  names.push_back(iter->first);
171  iter++;
172  }
173  }
174 
177  inline tBoolean getVariables(const tString& variableName,SV::GPM_Variable& variable) const {
178 
179  map<tString,SV::GPM_Variable>::const_iterator iter=mVariables.find(variableName);
180  if (iter!=mVariables.end()) {
181  variable=iter->second;
182  return true;
183  }
184  return false;
185  }
188  tString getVariableValuesToString(const tString& variableName) const;
189 
192  SP::GPM_Variable getVariable(const tString& variableName) const;
193 
196  tBoolean getVariableValue(const tString &variableName,tString& value) const;
199  tBoolean getVariableValue(const tString &variableName,double& value) const;
202  tBoolean getVariableValue(const tString &variableName,int& n,double* value) const;
203 
206  tFlag getVariableType(const tString& variableName) const;
207 
210  virtual void clearVariables() {
211  mVariables.clear();
212  }
213 
214 
215 
216  // GROUP ID
217  // ========
218 public:
219 
222  virtual tString getGroupTypeName() const=0;
223 
224 
225 
228  inline void setGroupName(const tString& v) {
229  mGroupName=v;
230 
231  }
234  inline tString getGroupName() const {
235  return mGroupName;
236 
237  }
238 
239 
240 
241 
242 
243 
244  // ACTIONS
245  // ========
246 
247 
250  virtual tBoolean setTopologicalAction(const tFlag& action);
253  inline tFlag getTopologicalAction() const {
254  return mTopologicalAction;
255  }
258  inline tBoolean hasTriggerCutAction() const {
259  return (mTopologicalAction==REMOVE);
260  }
263  virtual tBoolean setTriggerGroupNameAction(const tFlag& action,const tString& value);
264 
267  virtual tBoolean setTriggerAction(const tFlag& action,const tString& varName,SP::GPM_Variable var);
270  virtual tBoolean setTriggerAction(const tFlag& action,const tString& varName,const tString& value);
273  virtual tBoolean setTriggerAction(const tFlag& action,const tString& varName,const double& value);
276  virtual tBoolean setTriggerAction(const tFlag& action,const tString& varName,const int& n,const double* value);
279  virtual tBoolean setTriggerAction(const tFlag& action,const tString& varName,const tFlag& type,const int& n,const double* value);
280 
283  inline tBoolean getTriggerActionValues(const tString& variableName,SV::GPM_Variable& variable) const {
284 
285  map<tString,SV::GPM_Variable>::const_iterator iter=mActionVariables.find(variableName);
286  if (iter!=mActionVariables.end()) {
287  variable=iter->second;
288  return true;
289  }
290  return false;
291  }
294  inline tFlag getTriggerAction(const tString & varName) const {
295  map<tString,tFlag>::const_iterator iter=mVariableActions.find(varName);
296  if (iter!=mVariableActions.end()) {
297  return iter->second;
298  }
299  return UNSET;
300  }
303  virtual void clearActions();
304 
307  virtual void executeTriggerActions();
308 
309 
310 
311 protected:
312 
313 
314 public:
315 
316  // GRAPH
317  // =====
318 
319  // /*! \brief set graph
320  // */
321  // void setGraph(SP::GPM_Graph g) {
322  // mGraph=graph;
323  // }
324  // /*! \brief get graph
325  // */
326  // SP::GPM_Graph getGraph() const {
327  // SP::GPM_Graph gr=mGraph.lock();
328  // return gr;
329  // }
332  inline void setId(const int& id) {
333  mId=id;
334  }
337  inline int getId() const {
338  return mId;
339  }
340 
341 
342 
343  // IO
344  // ==
345 
349  tBoolean parseValues(tString& f,vector<tString>& values) const;
350 
354  virtual void saveToStream(ofstream& f) const;
357  virtual tBoolean loadFromStream(tString& f);
358 
361  virtual tString toString() const;
362 
363 
364 };
365 
366 #endif
tBoolean getTriggerActionValues(const tString &variableName, SV::GPM_Variable &variable) const
get action variables
Definition: GPM_GraphElement.h:283
void setGraph(SP::GPM_Graph graph)
set the attached graph
Definition: GPM_GraphElement.h:95
virtual void toDoAfterThisSetting()
method called after This setting
Definition: GPM_GraphElement.h:76
void setGroupName(const tString &v)
set group name
Definition: GPM_GraphElement.h:228
#define tBoolean
Definition: types.h:35
tBoolean hasTriggerCutAction() const
return true if the element has a trigger cut action
Definition: GPM_GraphElement.h:258
void removeVariable(const tString &varName)
remove the variable
Definition: GPM_GraphElement.h:161
tBoolean getVariables(const tString &variableName, SV::GPM_Variable &variable) const
get variables
Definition: GPM_GraphElement.h:177
tFlag getTriggerAction(const tString &varName) const
get the variable action
Definition: GPM_GraphElement.h:294
void setId(const int &id)
set graph
Definition: GPM_GraphElement.h:332
tFlag getTopologicalAction() const
get toppologial action
Definition: GPM_GraphElement.h:253
#define SP_OBJECT(X)
Definition: CORE_Pointers.h:176
This class describes a node.
Definition: GPM_Variable.h:16
DEFINE_SPTR(GPM_Graph)
#define DEFINE_SVPTR(X)
Definition: CORE_ListPointers.h:21
void getVariableNames(vector< tString > &names) const
get the variable names
Definition: GPM_GraphElement.h:166
#define tString
Definition: types.h:36
virtual void clearVariables()
clear the variables
Definition: GPM_GraphElement.h:210
virtual void toDoAfterThisSetting()
method called after setThis() method this method can oly be called once.
Definition: CORE_Object.h:188
int getId() const
get id
Definition: GPM_GraphElement.h:337
This class is the base class of all graph classes.
Definition: GPM_Object.h:17
This class describes a graph which is a list of nodes & ports.
Definition: GPM_Graph.h:19
tString getGroupName() const
set group name
Definition: GPM_GraphElement.h:234
This class describes an element of a graph.
Definition: GPM_GraphElement.h:17
#define tFlag
Definition: types.h:14