C++ main module for gpm Package  1.0
GPM_ModelFunction.h
Go to the documentation of this file.
1 #ifndef GPM_ModelFunction_H
2 #define GPM_ModelFunction_H
3 
4 #include "GPM_PatternFunction.h"
5 
6 #include "GPM_ModelGraph.h"
7 
8 #include "GPM_Variable.h"
9 #include "GPM_Rule.h"
10 
11 
14 
22 
24  SP_OBJECT(GPM_ModelFunction);
25 
26 
27 private:
28 
29 
30 
31  // ASSOCIATIONS
32 
33  //condition on pattern attributes to match mapping
34  SV::GPM_Rule mMappingRules;
35  map<tString,SP::GPM_Variable> mGlobalVariables;
36  SV::GPM_CompositorFunction mGlobalFunctions;
37 
38 protected:
39  // METHODS
40 
41  // CONSTRUCTORS
42 
44  GPM_ModelFunction(void);
45 
46 
47 
48  // DESTRUCTORS
49 
50 
53  virtual ~GPM_ModelFunction(void);
54 
55 
56 public:
57 
58  // NEW methods
59 
62  static inline SP::GPM_ModelFunction New() {
63  SP::GPM_ModelFunction p(new GPM_ModelFunction(),
65  p->setThis(p);
66  return p;
67  }
68 
69 protected:
72  virtual void toDoAfterThisSetting() {
76 
77  }
78  // SET & GET methods
79 public:
80 
81 
84  virtual void copy(const GPM_Function& rule);
85 
86  // GLOBAL VARIABLE
87  // ===============
90  void setGlobalVariables(const map<tString,SP::GPM_Variable>& variables);
91 
94  inline void addGlobalVariables(const tString& variableName,const tFlag& type,const double& value) {
95  GPM_Variable &var=initGlobalVariable(variableName);
96  var.setValue(value);
97  var.setType(type);
98  }
101  inline void addGlobalVariables(const tString& variableName,const tFlag& type,const double* values,const int& n) {
102  GPM_Variable &var=initGlobalVariable(variableName);
103  var.setValue(n,values);
104  var.setType(type);
105  }
108  inline void addGlobalVariables(const tString& variableName,const tString &value) {
109  GPM_Variable &var=initGlobalVariable(variableName);
110  var.setValue(value);
112  }
113 
116  void removeGlobalVariable(const tString& name);
119  inline void clearGlobalVariables() {
120  mGlobalVariables.clear();
121  }
122 
125  inline const map<tString,SP::GPM_Variable>& getGlobalVariables() const {
126  return mGlobalVariables;
127  }
128 private:
131  GPM_Variable& initGlobalVariable(const tString& varName);
134  void setGlobalVariable(const tString& varName,SP::GPM_Variable var);
135 
136 public:
137  // GLOBAL Functions
138  // ================
141  void setGlobalFunctions(const SV::GPM_CompositorFunction& fcts) {
142  int i,n=fcts.getSize();
143  mGlobalFunctions.setSize(n);
144  for (i=0;i<n;i++) mGlobalFunctions[i]=fcts[i];
145  }
146 
150  const tString& name,const vector<tString>& realParameters,const tString& body);
151 
155  const tString& name,
156  const vector<tString>& nameParameters,
157  const vector<tFlag>& typeParameters,
158  const vector<tFlag>& cardParameters,
159  const vector<tFlag>& isConstParameters,
160  const tString& body,
161  const tFlag& returnType);
162 
166  const tString& strFunction);
167 
170  inline void clearGlobalFunctions() {
171  mGlobalFunctions.clear();
172  }
173 
176  inline const SV::GPM_CompositorFunction& getGlobalFunctions() const {
177  return mGlobalFunctions;
178  }
179 
180 
181  // RULES
182 public:
183 
186  virtual void clear();
187 
188 
191  void clearRules();
192 
195  inline void addMappingRule(SP::GPM_Rule rule) {
196  mMappingRules.add(rule);
197  }
198 
201  inline void removeMappingRule(const int& index) {
202  if (index<mMappingRules.getSize())
203  mMappingRules.removeAtIndex(index);
204  }
207  inline const SV::GPM_Rule& getMappingRules() const {
208  return mMappingRules;
209  }
212  inline SV::GPM_Rule& getMappingRules() {
213  return mMappingRules;
214  }
243  tBoolean readRulesFromFile(const tString& fileName,
244  const GPM_ModelClassFactory& cf,
245  CORE_Out& io);
248  tBoolean saveRulesToFile(const tString& fileName) const;
249 
250 
251 
254  virtual tBoolean isMappingValid(const GPM_PortGraph& largeGraph,
255  const SV::GPM_Vertex& smallGraphVertices,
256  const vector<tVertexIID>& mapping,
257  CORE_Out& io) const;
258 
261  void updateRules(const GPM_ModelClassFactory& cf);
262 
263 protected:
264 
267  virtual tBoolean updateTransformerGraphStates(GPM_Graph& largeGraph,
268  const vector<tVertexIID>& mappingP2L,
269  const map<tVertexIID,tVertexIID>& mappingT2L,CORE_Out& io);
272  virtual tBoolean updatePatternGraphStates(GPM_Graph& largeGraph,
273  const vector<tVertexIID>& mappingP2L,CORE_Out& io);
276  virtual tBoolean updatePTEdgesStates(SP::GPM_Edge PTedge,SP::GPM_Edge ledge,
277  GPM_Graph& largeGraph,
278  const vector<tVertexIID>& mappingP2L,
279  const map<tVertexIID,tVertexIID>& mappingT2L,
280  CORE_Out& io);
281 
282 
283 public:
284  /* \brief return the string represantation of the class
285  */
286  tString toString() const;
287 
295  static void expandVariableNames(const vector<tString>& vars,const int& id,
296  tString& value,const tString& graphLetter,const tString& elementLetter);
299  static tBoolean parseVarName(tString& varName,tString& graphLetter,tString& elementLetter,int& id);
302  static tString varNameToString(const tString& varName,const tString& graphLetter,const tString& elementLetter,const int& id);
303 
304 
305 private:
309  static size_t findVariableName(const tString& varName,const tString& value,const int& fromIndex) ;
310 
311 
312 
313 };
314 
315 #endif
void setPatternGraph(SP::GPM_PortGraph f)
set the pattern graph
Definition: GPM_Function.h:71
void setType(const tFlag &t)
set the type of the variable
Definition: GPM_Variable.h:96
static tString varNameToString(const tString &varName, const tString &graphLetter, const tString &elementLetter, const int &id)
useful function to create varname from vertex
Definition: GPM_ModelFunction.cpp:1912
void clearRules()
clear rules
Definition: GPM_ModelFunction.cpp:128
virtual tBoolean updatePTEdgesStates(SP::GPM_Edge PTedge, SP::GPM_Edge ledge, GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, const map< tVertexIID, tVertexIID > &mappingT2L, CORE_Out &io)
update the states of edges betwen pattern & transform graph
Definition: GPM_ModelFunction.cpp:1422
virtual tBoolean updatePatternGraphStates(GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, CORE_Out &io)
update the states of the transformed graph copied in the large graph
Definition: GPM_ModelFunction.cpp:960
void clearGlobalFunctions()
clear global variables
Definition: GPM_ModelFunction.h:170
tBoolean saveRulesToFile(const tString &fileName) const
Definition: GPM_ModelFunction.cpp:144
SV::GPM_Rule & getMappingRules()
get the mapping rules for writing
Definition: GPM_ModelFunction.h:212
void removeMappingRule(const int &index)
remove the mapping rule at index
Definition: GPM_ModelFunction.h:201
tString toString() const
return the string representation of the class
Definition: GPM_ModelFunction.cpp:1552
virtual void toDoAfterThisSetting()
method called after this setting
Definition: GPM_Function.h:53
virtual void toDoAfterThisSetting()
method called after this setting
Definition: GPM_ModelFunction.h:72
This class describes a patten function.
Definition: GPM_Function.h:20
static void expandVariableNames(const vector< tString > &vars, const int &id, tString &value, const tString &graphLetter, const tString &elementLetter)
replace variable names varName -> varName+"_"+graphLetter+"_"+id graphLetter -> graphLetter+"_"+id x ...
Definition: GPM_ModelFunction.cpp:1722
static SP::GPM_ModelFunction New()
create a port
Definition: GPM_ModelFunction.h:62
#define tBoolean
Definition: types.h:35
virtual void copy(const GPM_Function &rule)
copy
Definition: GPM_ModelFunction.cpp:21
const SV::GPM_Rule & getMappingRules() const
get the mapping rules for reading
Definition: GPM_ModelFunction.h:207
virtual ~GPM_ModelFunction(void)
destroy an object.
Definition: GPM_ModelFunction.cpp:17
void setGlobalFunctions(const SV::GPM_CompositorFunction &fcts)
set the global functions
Definition: GPM_ModelFunction.h:141
void addGlobalFunction(const GPM_ModelClassFactory &cf, const tString &name, const vector< tString > &realParameters, const tString &body)
add a real function
Definition: GPM_ModelFunction.cpp:120
void addGlobalVariables(const tString &variableName, const tString &value)
add a string global variable
Definition: GPM_ModelFunction.h:108
GPM_ModelFunction(void)
create an object
Definition: GPM_ModelFunction.cpp:9
void setValue(const int &cardinality, const double *values, const tFlag &type)
set the variable
Definition: GPM_Variable.cpp:74
DEFINE_SPTR(GPM_ModelClassFactory)
void updateRules(const GPM_ModelClassFactory &cf)
update the rule to new type of rule
Definition: GPM_ModelFunction.cpp:43
static const tFlag STRING
Definition: GPM_Variable.h:26
static tBoolean parseVarName(tString &varName, tString &graphLetter, tString &elementLetter, int &id)
useful function to parse varname & id
Definition: GPM_ModelFunction.cpp:1936
const map< tString, SP::GPM_Variable > & getGlobalVariables() const
Definition: GPM_ModelFunction.h:125
This class describes a node.
Definition: GPM_Variable.h:16
This class is the class to save GPM classes.
Definition: GPM_ModelClassFactory.h:16
void clearGlobalVariables()
clear global variables
Definition: GPM_ModelFunction.h:119
void addGlobalVariables(const tString &variableName, const tFlag &type, const double &value)
add a scalar global variable
Definition: GPM_ModelFunction.h:94
DEFINE_SVPTR(GPM_ModelFunction)
tBoolean readRulesFromFile(const tString &fileName, const GPM_ModelClassFactory &cf, CORE_Out &io)
read the rules the rules file format is has folow #size & list of ids of vertices of pattern graph to...
Definition: GPM_ModelFunction.cpp:413
#define tString
Definition: types.h:36
This class describes a graph which is a list of vertices, ports & edges.
Definition: GPM_PortGraph.h:22
virtual tBoolean updateTransformerGraphStates(GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, const map< tVertexIID, tVertexIID > &mappingT2L, CORE_Out &io)
update the states of the transformed graph copied in the large graph
Definition: GPM_ModelFunction.cpp:1175
void addGlobalVariables(const tString &variableName, const tFlag &type, const double *values, const int &n)
add a vector global variable
Definition: GPM_ModelFunction.h:101
This class describes a patten function.
Definition: GPM_PatternFunction.h:20
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
void setGlobalVariables(const map< tString, SP::GPM_Variable > &variables)
set the global variable
Definition: GPM_ModelFunction.cpp:71
This class describes a pattern function.
Definition: GPM_ModelFunction.h:23
void setTransformerGraph(SP::GPM_PortGraph f)
set the transformer graph
Definition: GPM_Function.h:90
This class describes a graph which is a list of nodes & ports.
Definition: GPM_Graph.h:19
static SP::GPM_ModelGraph New()
create a test class
Definition: GPM_ModelGraph.h:56
void removeGlobalVariable(const tString &name)
delete a global variable
Definition: GPM_ModelFunction.cpp:97
const SV::GPM_CompositorFunction & getGlobalFunctions() const
Definition: GPM_ModelFunction.h:176
void addMappingRule(SP::GPM_Rule rule)
add the mapping rule
Definition: GPM_ModelFunction.h:195
virtual void clear()
clear all data for rules
Definition: GPM_ModelFunction.cpp:64
virtual tBoolean isMappingValid(const GPM_PortGraph &largeGraph, const SV::GPM_Vertex &smallGraphVertices, const vector< tVertexIID > &mapping, CORE_Out &io) const
return true if the mapping is valid
Definition: GPM_ModelFunction.cpp:1504
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14