g4tools  5.4.0
valop
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_valop
5 #define tools_valop
6 
7 #include "ival_func"
8 
9 namespace tools {
10 
11 class valop {
12  static const std::string& s_class() {
13  static const std::string s_v("tools::valop");
14  return s_v;
15  }
16 public:
17  enum e_type {
18  CMP_GT = 1,
19  CMP_GE = 2,
20  CMP_LT = 3,
21  CMP_LE = 4,
22  CMP_EQ = 5,
23  CMP_NE = 6,
24  CMP_AND = 7,
25  CMP_OR = 8,
26 
27  ADD = 9,
28  MUL = 10,
29  SUB = 11,
30  DIV = 12,
31 
32  ASSIGN = 13,
33  MINUS = 14,
35  REAL = 16,
36  NAME = 17,
37  STRING = 18,
38  //PI = 19,
39  FUNC = 20,
40  BOOL_TRUE = 21,
41  BOOL_FALSE = 22,
42  NOT = 23,
43  // math edition :
44  SYMBOL = 100,
45  ASIDE = 101,
46  NVMUL = 102, //not visible mul
47  EQUAL = 103,
48  SUPS = 104, //super script
49  SUBS = 105 //sub script
50  };
51 
52 public:
53  static bool is_binary(e_type a_type) {
54  switch(a_type) {
55  case CMP_GT:
56  case CMP_GE:
57  case CMP_LT:
58  case CMP_LE:
59  case CMP_EQ:
60  case CMP_NE:
61  case CMP_AND:
62  case CMP_OR:
63 
64  case ADD:
65  case MUL:
66  case SUB:
67  case DIV:
68 
69  case ASIDE:
70  case NVMUL:
71  case EQUAL:
72  case SUPS:
73  case SUBS:
74  return true;
75  default:
76  return false;
77  }
78  }
79 /*
80  static bool is_unary(e_type a_type) {
81  switch(a_type) {
82  case MINUS:
83  return true;
84  default:
85  return false;
86  }
87  }
88  static bool is_edition(e_type a_type) { //for valop2s
89  switch(a_type) {
90  case SYMBOL:
91  case ASIDE:
92  case NVMUL:
93  case EQUAL:
94  case SUPS:
95  case SUBS:
96  return true;
97  default:
98  return false;
99  }
100  }
101 */
102 public:
103  valop(e_type a_type)
104  :m_type(a_type),m_function(0),m_index(not_found())
105  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
106 #ifdef TOOLS_MEM
107  mem::increment(s_class().c_str());
108 #endif
109  }
110 
111  valop(e_type a_type,valop* a_A)
112  :m_type(a_type),m_function(0),m_index(not_found())
113  ,m_A(a_A),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
114 #ifdef TOOLS_MEM
115  mem::increment(s_class().c_str());
116 #endif
117  }
118 
119  valop(e_type a_type,valop* a_A,valop* a_B)
120  :m_type(a_type),m_function(0),m_index(not_found())
121  ,m_A(a_A),m_B(a_B),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
122 #ifdef TOOLS_MEM
123  mem::increment(s_class().c_str());
124 #endif
125  }
126 
127  valop(e_type a_type,ival_func* a_function,valop* a_A)
128  :m_type(a_type),m_function(0),m_index(not_found())
129  ,m_A(a_A),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
130 #ifdef TOOLS_MEM
131  mem::increment(s_class().c_str());
132 #endif
133  m_function = a_function?a_function->copy():0;
134  }
135 
136  valop(e_type a_type,ival_func* a_function,valop* a_A,valop* a_B)
137  :m_type(a_type),m_function(0),m_index(not_found())
138  ,m_A(a_A),m_B(a_B),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
139 #ifdef TOOLS_MEM
140  mem::increment(s_class().c_str());
141 #endif
142  m_function = a_function?a_function->copy():0;
143  }
144 
145  valop(e_type a_type,ival_func* a_function,valop* a_A,valop* a_B,valop* a_C)
146  :m_type(a_type),m_function(0),m_index(not_found())
147  ,m_A(a_A),m_B(a_B),m_C(a_C),m_D(0),m_E(0),m_F(0),m_tag(0){
148 #ifdef TOOLS_MEM
149  mem::increment(s_class().c_str());
150 #endif
151  m_function = a_function?a_function->copy():0;
152  }
153 
154  valop(e_type a_type,ival_func* a_function,valop* a_A,valop* a_B,valop* a_C,valop* a_D)
155  :m_type(a_type),m_function(0),m_index(not_found())
156  ,m_A(a_A),m_B(a_B),m_C(a_C),m_D(a_D),m_E(0),m_F(0),m_tag(0){
157 #ifdef TOOLS_MEM
158  mem::increment(s_class().c_str());
159 #endif
160  m_function = a_function?a_function->copy():0;
161  }
162 
163  valop(e_type a_type,ival_func* a_function,valop* a_A,valop* a_B,valop* a_C,valop* a_D,valop* a_E)
164  :m_type(a_type),m_function(0),m_index(not_found())
165  ,m_A(a_A),m_B(a_B),m_C(a_C),m_D(a_D),m_E(a_E),m_F(0),m_tag(0){
166 #ifdef TOOLS_MEM
167  mem::increment(s_class().c_str());
168 #endif
169  m_function = a_function?a_function->copy():0;
170  }
171 
172  valop(e_type a_type,ival_func* a_function,
173  valop* a_A,valop* a_B,valop* a_C,
174  valop* a_D,valop* a_E,valop* a_F)
175  :m_type(a_type),m_function(0),m_index(not_found())
176  ,m_A(a_A),m_B(a_B),m_C(a_C),m_D(a_D),m_E(a_E),m_F(a_F),m_tag(0){
177 #ifdef TOOLS_MEM
178  mem::increment(s_class().c_str());
179 #endif
180  m_function = a_function?a_function->copy():0;
181  }
182 
183  valop(e_type a_type,bool a_v)
184  :m_type(a_type),m_function(0),m_index(not_found())
185  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
186 #ifdef TOOLS_MEM
187  mem::increment(s_class().c_str());
188 #endif
189  m_variable.set(a_v);
190  }
191 
192  valop(e_type a_type,unsigned int a_number)
193  :m_type(a_type),m_function(0),m_index(not_found())
194  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
195 #ifdef TOOLS_MEM
196  mem::increment(s_class().c_str());
197 #endif
198  m_variable.set(a_number);
199  }
200 
201  valop(e_type a_type,double a_number)
202  :m_type(a_type),m_function(0),m_index(not_found())
203  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
204 #ifdef TOOLS_MEM
205  mem::increment(s_class().c_str());
206 #endif
207  m_variable.set(a_number);
208  }
209 
210  valop(e_type a_type,const std::string& a_string)
211  :m_type(a_type),m_function(0),m_index(not_found())
212  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
213 #ifdef TOOLS_MEM
214  mem::increment(s_class().c_str());
215 #endif
216  m_variable.set(a_string);
217  }
218 
219  //NOTE : the below is needed so that valop("t") not put on valop(bool).
220  valop(e_type a_type,const char* a_cstr)
221  :m_type(a_type),m_function(0),m_index(not_found())
222  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
223 #ifdef TOOLS_MEM
224  mem::increment(s_class().c_str());
225 #endif
226  m_variable.set(a_cstr);
227  }
228 
229  valop(e_type a_type,const std::string& a_name,int a_index)
230  :m_type(a_type),m_function(0),m_name(a_name),m_index(a_index)
231  ,m_A(0),m_B(0),m_C(0),m_D(0),m_E(0),m_F(0),m_tag(0){
232  // a_name needed to not confuse with the constructor (e_type,unsigned int).
233 #ifdef TOOLS_MEM
234  mem::increment(s_class().c_str());
235 #endif
236  }
237 
238  virtual ~valop() {
239  delete m_function;
240  delete m_A;
241  delete m_B;
242  delete m_C;
243  delete m_D;
244  delete m_E;
245  delete m_F;
246 #ifdef TOOLS_MEM
247  mem::decrement(s_class().c_str());
248 #endif
249  }
250 public:
251  valop(const valop& a_from)
252  :m_type(a_from.m_type)
253  ,m_function(a_from.m_function?a_from.m_function->copy():0)
254  ,m_variable(a_from.m_variable)
255  ,m_name(a_from.m_name)
256  ,m_index(a_from.m_index)
257 
258  ,m_A(a_from.m_A?new valop(*a_from.m_A):0)
259  ,m_B(a_from.m_B?new valop(*a_from.m_B):0)
260  ,m_C(a_from.m_C?new valop(*a_from.m_C):0)
261  ,m_D(a_from.m_D?new valop(*a_from.m_D):0)
262  ,m_E(a_from.m_E?new valop(*a_from.m_E):0)
263  ,m_F(a_from.m_F?new valop(*a_from.m_F):0)
264 
265  ,m_tag(a_from.m_tag)
266  {
267 #ifdef TOOLS_MEM
268  mem::increment(s_class().c_str());
269 #endif
270  }
271  valop& operator=(const valop& a_from) {
272  if(&a_from==this) return *this;
273 
274  m_type = a_from.m_type;
275 
276  delete m_function;
277  m_function = a_from.m_function?a_from.m_function->copy():0;
278 
279  m_variable = a_from.m_variable;
280  m_name = a_from.m_name;
281  m_index = a_from.m_index;
282 
283  delete m_A;
284  delete m_B;
285  delete m_C;
286  delete m_D;
287  delete m_E;
288  delete m_F;
289  m_A = a_from.m_A?new valop(*a_from.m_A):0;
290  m_B = a_from.m_B?new valop(*a_from.m_B):0;
291  m_C = a_from.m_C?new valop(*a_from.m_C):0;
292  m_D = a_from.m_D?new valop(*a_from.m_D):0;
293  m_E = a_from.m_E?new valop(*a_from.m_E):0;
294  m_F = a_from.m_F?new valop(*a_from.m_F):0;
295 
296  m_tag = a_from.m_tag;
297  return *this;
298  }
299 public:
300  static valop def() {return valop(REAL,0.0);}
301 
302  valop* copy() const {return new valop(*this);}
303 
304  e_type type() const {return m_type;}
305 
306  void print(std::ostream& a_out) {
307  a_out << "Type : " << this << " " << (int)m_type << std::endl;
308  //if(!m_variable.is_none()) m_variable.print(a_out);
309  if(m_A) m_A->print(a_out);
310  if(m_B) m_B->print(a_out);
311  }
312 
313  bool is_leaf() const {
314  switch(m_type) {
315  case UNSIGNED_INTEGER:
316  case REAL:
317  case STRING:
318  case NAME:
319  //case PI:
320  case SYMBOL:
321  case BOOL_TRUE:
322  case BOOL_FALSE:
323  return true;
324  default:
325  return false;
326  }
327  }
328  bool is_binary() const {
329  switch(m_type) {
330  case CMP_GT:
331  case CMP_GE:
332  case CMP_LT:
333  case CMP_LE:
334  case CMP_EQ:
335  case CMP_NE:
336  case CMP_AND:
337  case CMP_OR:
338 
339  case ADD:
340  case MUL:
341  case SUB:
342  case DIV:
343 
344  case ASIDE:
345  case NVMUL:
346  case EQUAL:
347  case SUPS:
348  case SUBS:
349  return true;
350  default:
351  return false;
352  }
353  }
354  bool is_unary() const {
355  switch(m_type) {
356  case MINUS:
357  case NOT:
358  case ASSIGN:
359  return true;
360  case FUNC:
361  if(!m_A) return false;
362  if(!m_function) return false;
363  if(m_function->number_of_arguments()==1) return true;
364  return false;
365  default:
366  return false;
367  }
368  }
369 
370  //const value& variable() const {return m_variable;}
371  //value& variable() {return m_variable;}
372 
373  void replace(valop* a_node,valop* a_to,bool a_delete) {
374  if(m_A==a_node) {if(a_delete) delete m_A;m_A = a_to;return;}
375  if(m_B==a_node) {if(a_delete) delete m_B;m_B = a_to;return;}
376  if(m_C==a_node) {if(a_delete) delete m_C;m_C = a_to;return;}
377  if(m_D==a_node) {if(a_delete) delete m_D;m_D = a_to;return;}
378  if(m_E==a_node) {if(a_delete) delete m_E;m_E = a_to;return;}
379  if(m_F==a_node) {if(a_delete) delete m_F;m_F = a_to;return;}
380  }
381 
382 protected:
383  static int not_found() {return -1;}
384 public:
388  std::string m_name;
389  int m_index;
396 public:
397  int m_tag;
398 };
399 
401 public:
402  virtual ~valop_visitor() {}
403 public:
404  virtual bool binary(unsigned int,const valop&,const valop&) = 0;
405  virtual bool unary(unsigned int,const valop&) = 0;
406  virtual bool variable(unsigned int,const value&) = 0;
407  virtual bool option(const valop&) = 0;
408  virtual bool func_1(const valop&,const valop&) = 0;
409  virtual bool func_2(const valop&,const valop&,const valop&) = 0;
410  virtual bool func_3(const valop&,const valop&,const valop&,const valop&) = 0;
411  virtual bool func_4(const valop&,const valop&,const valop&,
412  const valop&,const valop&) = 0;
413  virtual bool func_5(const valop&,const valop&,const valop&,
414  const valop&,const valop&,const valop&) = 0;
415  virtual bool func_6(const valop&,const valop&,const valop&,
416  const valop&,const valop&,
417  const valop&,const valop&) = 0;
418 public:
419  bool visit(const valop& a_valop) {
420  switch(a_valop.m_type) {
421  case valop::CMP_GT:
422  case valop::CMP_GE:
423  case valop::CMP_LT:
424  case valop::CMP_LE:
425  case valop::CMP_EQ:
426  case valop::CMP_NE:
427  case valop::CMP_AND:
428  case valop::CMP_OR:
429 
430  case valop::ADD:
431  case valop::MUL:
432  case valop::SUB:
433  case valop::DIV:
434 
435  case valop::ASIDE:
436  case valop::NVMUL:
437  case valop::EQUAL:
438  case valop::SUPS:
439  case valop::SUBS:
440  if(!a_valop.m_A || !a_valop.m_B) break;
441  return binary(a_valop.m_type,*a_valop.m_A,*a_valop.m_B);
442 
443  case valop::BOOL_TRUE:
444  case valop::BOOL_FALSE:
446  case valop::REAL:
447  case valop::STRING:
448  case valop::SYMBOL:
449  return variable(a_valop.m_type,a_valop.m_variable);
450  case valop::NAME:
451  return option(a_valop);
452  case valop::MINUS:
453  case valop::NOT:
454  case valop::ASSIGN:
455  if(!a_valop.m_A) break;
456  return unary(a_valop.m_type,*a_valop.m_A);
457  case valop::FUNC:{
458  if(!a_valop.m_A) break;
459  if(!a_valop.m_function) {
460  //a_error = std::string("valop::execute : null function");
461  return false;
462  }
463  size_t argn = a_valop.m_function->number_of_arguments();
464  if(argn==1) {
465  return func_1(a_valop,*a_valop.m_A);
466  } else if(argn==2) {
467  if(!a_valop.m_B) break;
468  return func_2(a_valop,*a_valop.m_A,*a_valop.m_B);
469  } else if(argn==3) {
470  if(!a_valop.m_B || !a_valop.m_C) break;
471  return func_3(a_valop,*a_valop.m_A,*a_valop.m_B,*a_valop.m_C);
472  } else if(argn==4) {
473  if(!a_valop.m_B || !a_valop.m_C || !a_valop.m_D) break;
474  return func_4(a_valop,*a_valop.m_A,*a_valop.m_B,*a_valop.m_C,*a_valop.m_D);
475  } else if(argn==5) {
476  if(!a_valop.m_B || !a_valop.m_C || !a_valop.m_D || !a_valop.m_E) break;
477  return func_5(a_valop,*a_valop.m_A,*a_valop.m_B,*a_valop.m_C,*a_valop.m_D,*a_valop.m_E);
478  } else if(argn==6) {
479  if(!a_valop.m_B || !a_valop.m_C || !a_valop.m_D || !a_valop.m_E || !a_valop.m_F) break;
480  return func_6(a_valop,*a_valop.m_A,*a_valop.m_B,*a_valop.m_C,*a_valop.m_D,*a_valop.m_E,*a_valop.m_F);
481  } else {
482  return false;
483  }}
484  default:
485  break;
486  }
487  return false;
488  }
489 };
490 
491 class get_path : public virtual valop_visitor {
492 public:
493  virtual bool binary(unsigned int,const valop& a_1,const valop& a_2) {
494  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
495  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
496  m_path.push_back((valop*)&a_1);
497  if(!visit(a_1)) return false; //found in sub hierachy
498  m_path.pop_back();
499  m_path.push_back((valop*)&a_2);
500  if(!visit(a_2)) return false;
501  m_path.pop_back();
502  return true; //continue searching
503  }
504 
505  virtual bool unary(unsigned int,const valop& a_1) {
506  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
507  m_path.push_back((valop*)&a_1);
508  if(!visit(a_1)) return false; //found in sub hierachy
509  m_path.pop_back();
510  return true; //continue searching
511  }
512 
513  virtual bool variable(unsigned int,const value&) {return true;}
514  virtual bool option(const valop&) {return true;}
515 
516  virtual bool func_1(const valop&,const valop& a_1) {
517  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
518  m_path.push_back((valop*)&a_1);
519  if(!visit(a_1)) return false; //found in sub hierachy
520  m_path.pop_back();
521  return true; //continue searching
522  }
523  virtual bool func_2(const valop&,const valop& a_1,const valop& a_2) {
524  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
525  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
526  m_path.push_back((valop*)&a_1);
527  if(!visit(a_1)) return false; //found in sub hierachy
528  m_path.pop_back();
529  m_path.push_back((valop*)&a_2);
530  if(!visit(a_2)) return false;
531  m_path.pop_back();
532  return true; //continue searching
533  }
534  virtual bool func_3(const valop&,
535  const valop& a_1,const valop& a_2,const valop& a_3) {
536  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
537  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
538  if(match(a_3)) {m_path.push_back(m_node);return false;} //stop searching
539  m_path.push_back((valop*)&a_1);
540  if(!visit(a_1)) return false; //found in sub hierachy
541  m_path.pop_back();
542  m_path.push_back((valop*)&a_2);
543  if(!visit(a_2)) return false;
544  m_path.pop_back();
545  m_path.push_back((valop*)&a_3);
546  if(!visit(a_3)) return false;
547  m_path.pop_back();
548  return true; //continue searching
549  }
550  virtual bool func_4(const valop&,
551  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4) {
552  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
553  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
554  if(match(a_3)) {m_path.push_back(m_node);return false;} //stop searching
555  if(match(a_4)) {m_path.push_back(m_node);return false;} //stop searching
556  m_path.push_back((valop*)&a_1);
557  if(!visit(a_1)) return false; //found in sub hierachy
558  m_path.pop_back();
559  m_path.push_back((valop*)&a_2);
560  if(!visit(a_2)) return false;
561  m_path.pop_back();
562  m_path.push_back((valop*)&a_3);
563  if(!visit(a_3)) return false;
564  m_path.pop_back();
565  m_path.push_back((valop*)&a_4);
566  if(!visit(a_4)) return false;
567  m_path.pop_back();
568  return true; //continue searching
569  }
570  virtual bool func_5(const valop&,
571  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4,const valop& a_5) {
572  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
573  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
574  if(match(a_3)) {m_path.push_back(m_node);return false;} //stop searching
575  if(match(a_4)) {m_path.push_back(m_node);return false;} //stop searching
576  if(match(a_5)) {m_path.push_back(m_node);return false;} //stop searching
577  m_path.push_back((valop*)&a_1);
578  if(!visit(a_1)) return false; //found in sub hierachy
579  m_path.pop_back();
580  m_path.push_back((valop*)&a_2);
581  if(!visit(a_2)) return false;
582  m_path.pop_back();
583  m_path.push_back((valop*)&a_3);
584  if(!visit(a_3)) return false;
585  m_path.pop_back();
586  m_path.push_back((valop*)&a_4);
587  if(!visit(a_4)) return false;
588  m_path.pop_back();
589  m_path.push_back((valop*)&a_5);
590  if(!visit(a_5)) return false;
591  m_path.pop_back();
592  return true; //continue searching
593  }
594  virtual bool func_6(const valop&,
595  const valop& a_1,const valop& a_2,const valop& a_3,
596  const valop& a_4,const valop& a_5,const valop& a_6) {
597  if(match(a_1)) {m_path.push_back(m_node);return false;} //stop searching
598  if(match(a_2)) {m_path.push_back(m_node);return false;} //stop searching
599  if(match(a_3)) {m_path.push_back(m_node);return false;} //stop searching
600  if(match(a_4)) {m_path.push_back(m_node);return false;} //stop searching
601  if(match(a_5)) {m_path.push_back(m_node);return false;} //stop searching
602  if(match(a_6)) {m_path.push_back(m_node);return false;} //stop searching
603  m_path.push_back((valop*)&a_1);
604  if(!visit(a_1)) return false; //found in sub hierachy
605  m_path.pop_back();
606  m_path.push_back((valop*)&a_2);
607  if(!visit(a_2)) return false;
608  m_path.pop_back();
609  m_path.push_back((valop*)&a_3);
610  if(!visit(a_3)) return false;
611  m_path.pop_back();
612  m_path.push_back((valop*)&a_4);
613  if(!visit(a_4)) return false;
614  m_path.pop_back();
615  m_path.push_back((valop*)&a_5);
616  if(!visit(a_5)) return false;
617  m_path.pop_back();
618  m_path.push_back((valop*)&a_6);
619  if(!visit(a_6)) return false;
620  m_path.pop_back();
621  return true; //continue searching
622  }
623 public:
625  virtual ~get_path() {}
626 public:
627  get_path(const get_path& a_from)
628  :valop_visitor(a_from)
629  ,m_node(a_from.m_node)
630  ,m_tag(a_from.m_tag)
631  {}
632  get_path& operator=(const get_path& a_from){
633  m_node = a_from.m_node;
634  m_tag = a_from.m_tag;
635  return *this;
636  }
637 protected:
638  bool match(const valop& a_node) {
639  if(m_node) {
640  if((&a_node)==m_node) return true;
641  } else {
642  if(a_node.m_tag==m_tag) return true;
643  }
644  return false;
645  }
646 public:
648  int m_tag;
649  std::vector<valop*> m_path;
650 };
651 
652 class get_named : public virtual valop_visitor {
653 public:
654  virtual bool binary(unsigned int,const valop& a_1,const valop& a_2) {
655  if(!visit(a_1)) return false;
656  if(!visit(a_2)) return false;
657  return true; //continue searching
658  }
659 
660  virtual bool unary(unsigned int,const valop& a_1) {
661  if(!visit(a_1)) return false;
662  return true;
663  }
664 
665  virtual bool variable(unsigned int,const value&) {return true;}
666  virtual bool option(const valop& a_node) {
667  m_nodes.push_back((valop*)&a_node);
668  return true;
669  }
670 
671  virtual bool func_1(const valop&,const valop& a_1) {
672  if(!visit(a_1)) return false;
673  return true;
674  }
675 
676  virtual bool func_2(const valop&,const valop& a_1,const valop& a_2) {
677  if(!visit(a_1)) return false;
678  if(!visit(a_2)) return false;
679  return true;
680  }
681  virtual bool func_3(const valop&,
682  const valop& a_1,const valop& a_2,const valop& a_3) {
683  if(!visit(a_1)) return false;
684  if(!visit(a_2)) return false;
685  if(!visit(a_3)) return false;
686  return true;
687  }
688  virtual bool func_4(const valop&,
689  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4) {
690  if(!visit(a_1)) return false;
691  if(!visit(a_2)) return false;
692  if(!visit(a_3)) return false;
693  if(!visit(a_4)) return false;
694  return true;
695  }
696  virtual bool func_5(const valop&,
697  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4,const valop& a_5) {
698  if(!visit(a_1)) return false;
699  if(!visit(a_2)) return false;
700  if(!visit(a_3)) return false;
701  if(!visit(a_4)) return false;
702  if(!visit(a_5)) return false;
703  return true;
704  }
705  virtual bool func_6(const valop&,
706  const valop& a_1,const valop& a_2,const valop& a_3,
707  const valop& a_4,const valop& a_5,const valop& a_6) {
708  if(!visit(a_1)) return false;
709  if(!visit(a_2)) return false;
710  if(!visit(a_3)) return false;
711  if(!visit(a_4)) return false;
712  if(!visit(a_5)) return false;
713  if(!visit(a_6)) return false;
714  return true;
715  }
716 public:
718  virtual ~get_named() {}
719 public:
720  get_named(const get_named& a_from):valop_visitor(a_from){}
721  get_named& operator=(const get_named&){return *this;}
722 public:
723  std::vector<valop*> m_nodes;
724 };
725 
726 class get_funcs : public virtual valop_visitor {
727 public:
728  virtual bool binary(unsigned int,const valop& a_1,const valop& a_2) {
729  if(!visit(a_1)) return false;
730  if(!visit(a_2)) return false;
731  return true; //continue searching
732  }
733 
734  virtual bool unary(unsigned int,const valop& a_1) {
735  if(!visit(a_1)) return false;
736  return true;
737  }
738 
739  virtual bool variable(unsigned int,const value&) {return true;}
740  virtual bool option(const valop&) {return true;}
741 
742  virtual bool func_1(const valop& a_node,const valop& a_1) {
743  m_nodes.push_back((valop*)&a_node);
744  if(!visit(a_1)) return false;
745  return true;
746  }
747 
748  virtual bool func_2(const valop& a_node,const valop& a_1,const valop& a_2) {
749  m_nodes.push_back((valop*)&a_node);
750  if(!visit(a_1)) return false;
751  if(!visit(a_2)) return false;
752  return true;
753  }
754  virtual bool func_3(const valop& a_node,
755  const valop& a_1,const valop& a_2,const valop& a_3) {
756  m_nodes.push_back((valop*)&a_node);
757  if(!visit(a_1)) return false;
758  if(!visit(a_2)) return false;
759  if(!visit(a_3)) return false;
760  return true;
761  }
762  virtual bool func_4(const valop& a_node,
763  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4) {
764  m_nodes.push_back((valop*)&a_node);
765  if(!visit(a_1)) return false;
766  if(!visit(a_2)) return false;
767  if(!visit(a_3)) return false;
768  if(!visit(a_4)) return false;
769  return true;
770  }
771  virtual bool func_5(const valop& a_node,
772  const valop& a_1,const valop& a_2,const valop& a_3,const valop& a_4,const valop& a_5) {
773  m_nodes.push_back((valop*)&a_node);
774  if(!visit(a_1)) return false;
775  if(!visit(a_2)) return false;
776  if(!visit(a_3)) return false;
777  if(!visit(a_4)) return false;
778  if(!visit(a_5)) return false;
779  return true;
780  }
781  virtual bool func_6(const valop& a_node,
782  const valop& a_1,const valop& a_2,const valop& a_3,
783  const valop& a_4,const valop& a_5,const valop& a_6) {
784  m_nodes.push_back((valop*)&a_node);
785  if(!visit(a_1)) return false;
786  if(!visit(a_2)) return false;
787  if(!visit(a_3)) return false;
788  if(!visit(a_4)) return false;
789  if(!visit(a_5)) return false;
790  if(!visit(a_6)) return false;
791  return true;
792  }
793 public:
795  virtual ~get_funcs() {}
796 public:
797  get_funcs(const get_funcs& a_from):valop_visitor(a_from){}
798  get_funcs& operator=(const get_funcs&){return *this;}
799 public:
800  std::vector<valop*> m_nodes;
801 };
802 
803 }
804 
805 #endif
tools::valop::m_C
valop * m_C
Definition: valop:392
tools::get_named::binary
virtual bool binary(unsigned int, const valop &a_1, const valop &a_2)
Definition: valop:654
tools::valop::valop
valop(e_type a_type, const std::string &a_name, int a_index)
Definition: valop:229
tools::valop::e_type
e_type
Definition: valop:17
tools::valop::is_leaf
bool is_leaf() const
Definition: valop:313
tools::get_funcs::func_6
virtual bool func_6(const valop &a_node, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5, const valop &a_6)
Definition: valop:781
tools::valop::SYMBOL
@ SYMBOL
Definition: valop:44
tools::value
Definition: value:18
tools::valop::CMP_GE
@ CMP_GE
Definition: valop:19
tools::valop::valop
valop(e_type a_type, bool a_v)
Definition: valop:183
tools::valop::print
void print(std::ostream &a_out)
Definition: valop:306
tools::get_path::unary
virtual bool unary(unsigned int, const valop &a_1)
Definition: valop:505
tools::get_path::func_6
virtual bool func_6(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5, const valop &a_6)
Definition: valop:594
tools::valop::m_F
valop * m_F
Definition: valop:395
tools::get_path::get_path
get_path(const get_path &a_from)
Definition: valop:627
tools::valop::SUPS
@ SUPS
Definition: valop:48
tools::get_named
Definition: valop:652
tools::ival_func
Definition: ival_func:11
tools::get_named::variable
virtual bool variable(unsigned int, const value &)
Definition: valop:665
tools::valop::operator=
valop & operator=(const valop &a_from)
Definition: valop:271
tools::valop::m_E
valop * m_E
Definition: valop:394
tools::valop::m_D
valop * m_D
Definition: valop:393
tools::valop::NVMUL
@ NVMUL
Definition: valop:46
tools::valop::ADD
@ ADD
Definition: valop:27
tools::get_funcs::option
virtual bool option(const valop &)
Definition: valop:740
tools::valop::m_index
int m_index
Definition: valop:389
tools::valop::BOOL_TRUE
@ BOOL_TRUE
Definition: valop:40
tools::valop::valop
valop(e_type a_type, valop *a_A)
Definition: valop:111
tools::valop::CMP_EQ
@ CMP_EQ
Definition: valop:22
tools::get_path::func_4
virtual bool func_4(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4)
Definition: valop:550
tools::valop_visitor::~valop_visitor
virtual ~valop_visitor()
Definition: valop:402
tools::valop::m_tag
int m_tag
Definition: valop:397
tools::get_funcs::func_1
virtual bool func_1(const valop &a_node, const valop &a_1)
Definition: valop:742
tools::ival_func::copy
virtual ival_func * copy() const =0
tools::get_funcs::binary
virtual bool binary(unsigned int, const valop &a_1, const valop &a_2)
Definition: valop:728
tools::get_path::~get_path
virtual ~get_path()
Definition: valop:625
tools::get_funcs::func_4
virtual bool func_4(const valop &a_node, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4)
Definition: valop:762
tools::valop::m_A
valop * m_A
Definition: valop:390
tools::get_funcs::func_5
virtual bool func_5(const valop &a_node, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5)
Definition: valop:771
tools::get_path::operator=
get_path & operator=(const get_path &a_from)
Definition: valop:632
tools::valop_visitor::func_4
virtual bool func_4(const valop &, const valop &, const valop &, const valop &, const valop &)=0
tools::valop::valop
valop(e_type a_type, const char *a_cstr)
Definition: valop:220
tools::valop
Definition: valop:11
tools::get_named::func_1
virtual bool func_1(const valop &, const valop &a_1)
Definition: valop:671
tools::ival_func::number_of_arguments
virtual size_t number_of_arguments() const =0
tools::get_named::~get_named
virtual ~get_named()
Definition: valop:718
tools::valop::def
static valop def()
Definition: valop:300
tools::valop::BOOL_FALSE
@ BOOL_FALSE
Definition: valop:41
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A)
Definition: valop:127
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A, valop *a_B, valop *a_C, valop *a_D, valop *a_E)
Definition: valop:163
tools::value::set
void set(short a_value)
Definition: value:499
tools::valop::valop
valop(e_type a_type, unsigned int a_number)
Definition: valop:192
tools::get_named::func_4
virtual bool func_4(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4)
Definition: valop:688
tools::valop::CMP_GT
@ CMP_GT
Definition: valop:18
tools::get_path::m_node
valop * m_node
Definition: valop:647
tools::valop::DIV
@ DIV
Definition: valop:30
tools::valop::valop
valop(e_type a_type, double a_number)
Definition: valop:201
tools::valop_visitor::func_5
virtual bool func_5(const valop &, const valop &, const valop &, const valop &, const valop &, const valop &)=0
tools::get_named::operator=
get_named & operator=(const get_named &)
Definition: valop:721
tools::valop::is_binary
static bool is_binary(e_type a_type)
Definition: valop:53
tools::valop_visitor::variable
virtual bool variable(unsigned int, const value &)=0
tools::get_named::func_3
virtual bool func_3(const valop &, const valop &a_1, const valop &a_2, const valop &a_3)
Definition: valop:681
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A, valop *a_B, valop *a_C, valop *a_D, valop *a_E, valop *a_F)
Definition: valop:172
tools::get_named::func_6
virtual bool func_6(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5, const valop &a_6)
Definition: valop:705
tools::valop::NAME
@ NAME
Definition: valop:36
tools::valop::valop
valop(const valop &a_from)
Definition: valop:251
tools::valop_visitor::visit
bool visit(const valop &a_valop)
Definition: valop:419
tools::get_path::match
bool match(const valop &a_node)
Definition: valop:638
tools::get_funcs::variable
virtual bool variable(unsigned int, const value &)
Definition: valop:739
tools::get_funcs::func_3
virtual bool func_3(const valop &a_node, const valop &a_1, const valop &a_2, const valop &a_3)
Definition: valop:754
ival_func
tools::get_path::m_path
std::vector< valop * > m_path
Definition: valop:649
tools::valop::m_B
valop * m_B
Definition: valop:391
tools::get_funcs::~get_funcs
virtual ~get_funcs()
Definition: valop:795
tools::valop::is_binary
bool is_binary() const
Definition: valop:328
tools::get_path
Definition: valop:491
tools::valop::NOT
@ NOT
Definition: valop:42
tools::get_named::func_2
virtual bool func_2(const valop &, const valop &a_1, const valop &a_2)
Definition: valop:676
tools::get_path::m_tag
int m_tag
Definition: valop:648
tools::get_path::option
virtual bool option(const valop &)
Definition: valop:514
tools::valop::MUL
@ MUL
Definition: valop:28
tools::valop::copy
valop * copy() const
Definition: valop:302
tools::valop::valop
valop(e_type a_type, const std::string &a_string)
Definition: valop:210
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A, valop *a_B)
Definition: valop:136
tools::get_path::binary
virtual bool binary(unsigned int, const valop &a_1, const valop &a_2)
Definition: valop:493
tools::valop::m_variable
value m_variable
Definition: valop:387
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::get_named::get_named
get_named(const get_named &a_from)
Definition: valop:720
tools::get_named::unary
virtual bool unary(unsigned int, const valop &a_1)
Definition: valop:660
tools::valop_visitor::option
virtual bool option(const valop &)=0
tools::valop::SUB
@ SUB
Definition: valop:29
tools::get_funcs::get_funcs
get_funcs(const get_funcs &a_from)
Definition: valop:797
tools::get_named::m_nodes
std::vector< valop * > m_nodes
Definition: valop:723
tools::valop::is_unary
bool is_unary() const
Definition: valop:354
tools::valop_visitor::unary
virtual bool unary(unsigned int, const valop &)=0
tools::valop::m_type
e_type m_type
Definition: valop:385
tools::valop::CMP_OR
@ CMP_OR
Definition: valop:25
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A, valop *a_B, valop *a_C)
Definition: valop:145
tools::valop::~valop
virtual ~valop()
Definition: valop:238
tools::valop_visitor::func_2
virtual bool func_2(const valop &, const valop &, const valop &)=0
tools::valop::CMP_LT
@ CMP_LT
Definition: valop:20
tools::valop::MINUS
@ MINUS
Definition: valop:33
tools::get_path::func_2
virtual bool func_2(const valop &, const valop &a_1, const valop &a_2)
Definition: valop:523
tools::valop::STRING
@ STRING
Definition: valop:37
tools::valop::type
e_type type() const
Definition: valop:304
tools::valop::m_function
ival_func * m_function
Definition: valop:386
tools::get_path::func_1
virtual bool func_1(const valop &, const valop &a_1)
Definition: valop:516
tools::get_funcs::unary
virtual bool unary(unsigned int, const valop &a_1)
Definition: valop:734
tools::valop::ASSIGN
@ ASSIGN
Definition: valop:32
tools::valop::CMP_NE
@ CMP_NE
Definition: valop:23
tools::get_named::func_5
virtual bool func_5(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5)
Definition: valop:696
tools::valop_visitor::binary
virtual bool binary(unsigned int, const valop &, const valop &)=0
tools::valop::UNSIGNED_INTEGER
@ UNSIGNED_INTEGER
Definition: valop:34
tools::valop::REAL
@ REAL
Definition: valop:35
tools::get_named::get_named
get_named()
Definition: valop:717
tools::get_funcs::m_nodes
std::vector< valop * > m_nodes
Definition: valop:800
tools::get_funcs::get_funcs
get_funcs()
Definition: valop:794
tools::get_funcs::operator=
get_funcs & operator=(const get_funcs &)
Definition: valop:798
tools::get_path::func_5
virtual bool func_5(const valop &, const valop &a_1, const valop &a_2, const valop &a_3, const valop &a_4, const valop &a_5)
Definition: valop:570
tools::valop_visitor::func_3
virtual bool func_3(const valop &, const valop &, const valop &, const valop &)=0
tools::valop::ASIDE
@ ASIDE
Definition: valop:45
tools::valop::CMP_LE
@ CMP_LE
Definition: valop:21
tools::valop::valop
valop(e_type a_type, valop *a_A, valop *a_B)
Definition: valop:119
tools::get_path::variable
virtual bool variable(unsigned int, const value &)
Definition: valop:513
tools::valop::valop
valop(e_type a_type)
Definition: valop:103
tools::get_path::get_path
get_path()
Definition: valop:624
tools::get_funcs::func_2
virtual bool func_2(const valop &a_node, const valop &a_1, const valop &a_2)
Definition: valop:748
tools::valop_visitor::func_1
virtual bool func_1(const valop &, const valop &)=0
tools::valop::m_name
std::string m_name
Definition: valop:388
tools::valop::SUBS
@ SUBS
Definition: valop:49
tools::valop::replace
void replace(valop *a_node, valop *a_to, bool a_delete)
Definition: valop:373
tools::valop::EQUAL
@ EQUAL
Definition: valop:47
tools::get_funcs
Definition: valop:726
tools::get_named::option
virtual bool option(const valop &a_node)
Definition: valop:666
tools::valop::FUNC
@ FUNC
Definition: valop:39
tools::valop::not_found
static int not_found()
Definition: valop:383
tools::valop::CMP_AND
@ CMP_AND
Definition: valop:24
tools::valop::valop
valop(e_type a_type, ival_func *a_function, valop *a_A, valop *a_B, valop *a_C, valop *a_D)
Definition: valop:154
tools::valop_visitor::func_6
virtual bool func_6(const valop &, const valop &, const valop &, const valop &, const valop &, const valop &, const valop &)=0
tools::get_path::func_3
virtual bool func_3(const valop &, const valop &a_1, const valop &a_2, const valop &a_3)
Definition: valop:534
tools::valop_visitor
Definition: valop:400