g4tools  5.4.0
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
tools::columns::finder Class Reference
Inheritance diagram for tools::columns::finder:
Inheritance graph
[legend]
Collaboration diagram for tools::columns::finder:
Collaboration graph
[legend]

Public Member Functions

 finder (std::ostream &a_out, const std::string &a_script)
 
virtual ~finder ()
 
bool find_variables ()
 
void result (std::vector< value > &a_vars) const
 
void clear ()
 
- Public Member Functions inherited from tools::columns::parser
 parser ()
 
virtual ~parser ()
 
bool parse (const std::string &a_s)
 
void dump (std::ostream &a_out)
 

Public Attributes

std::ostream & m_out
 
std::string m_script
 
std::vector< valuem_stack
 
value::e_type m_cur_type
 

Protected Member Functions

 finder (const finder &a_from)
 
finderoperator= (const finder &)
 
bool analyse (columns::tree &a_tree, std::vector< value > &a_stack)
 
valueanalyse_dcl (const std::string &a_s)
 
- Protected Member Functions inherited from tools::columns::parser
 parser (const parser &)
 
parseroperator= (const parser &)
 

Static Protected Member Functions

static bool s2type (const std::string &a_s, value::e_type &a_type)
 
static valuenew_value (value::e_type a_type, const std::string &a_v)
 

Additional Inherited Members

- Protected Attributes inherited from tools::columns::parser
tree m_top
 

Detailed Description

Definition at line 180 of file columns.

Constructor & Destructor Documentation

◆ finder() [1/2]

tools::columns::finder::finder ( std::ostream &  a_out,
const std::string &  a_script 
)
inline

Definition at line 183 of file columns.

184  :m_out(a_out)
185  ,m_script(a_script)
186  //,fSuccess(false)
188  {}

◆ ~finder()

virtual tools::columns::finder::~finder ( )
inlinevirtual

Definition at line 189 of file columns.

189 {clear();}

◆ finder() [2/2]

tools::columns::finder::finder ( const finder a_from)
inlineprotected

Definition at line 191 of file columns.

191 :parent(a_from),m_out(a_from.m_out){}

Member Function Documentation

◆ analyse()

bool tools::columns::finder::analyse ( columns::tree a_tree,
std::vector< value > &  a_stack 
)
inlineprotected

Definition at line 221 of file columns.

221  {
222  if(a_tree.m_dcl.empty()) { //top
223  //std::cout << "debug : dcl empty" << std::endl;
224  tools_vforit(columns::tree*,a_tree.m_sub,it) {
225  if(!analyse(*(*it),a_stack)) return false;
226  }
227  } else {
228  //std::cout << "debug : dcl not empty" << std::endl;
229  if(is_spaces(a_tree.m_dcl)) return true;
230  value* v = analyse_dcl(a_tree.m_dcl);
231  if(!v) return false;
232  //std::cout << "debug : dcl label " << v->label() << std::endl;
233  if(a_tree.m_sub.size()) {
234  if(v->type()!=value::VOID_STAR) {
235  m_out << "tools::columns::finder::analyse :"
236  << " Expect a VOID_STAR."
237  << std::endl;
238  delete v;
239  return false;
240  }
242  std::vector<value>* stk = new std::vector<value>();
243  tools_vforit(columns::tree*,a_tree.m_sub,it) {
244  if(!analyse(*(*it),*stk)) {
245  delete v;
246  return false;
247  }
248  }
249  v->set((void*)stk);
250  } else {
251  m_cur_type = v->type();
252  }
253  a_stack.push_back(*v);
254  delete v;
255  }
256  return true;
257  }

◆ analyse_dcl()

value* tools::columns::finder::analyse_dcl ( const std::string &  a_s)
inlineprotected

Definition at line 258 of file columns.

258  {
259  std::vector<std::string> ws;
260  words(a_s,"=",false,ws);
261  if(ws.size()==2) { //<type> <name>=<value>
262  std::vector<std::string> swords;
263  words(ws[0]," ",false,swords);
264  if(swords.size()==2) {
265 
266  strip(swords[0]);
267  strip(swords[1]);
268 
269  if(swords[0]=="ITuple") {
270 
271  //create a value::VOID_STAR :
272  value* v = new value((void*)0);
273  v->set_label(swords[1]);
274  return v;
275 
276  } else {
277 
278  value::e_type type;
279  if(!s2type(swords[0],type)){
280  m_out << "tools::columns::finder::analyse_dcl :"
281  << " s2type failed for " << sout(swords[0]) << "."
282  << std::endl;
283  return 0;
284  }
285 
286  strip(ws[1]);
287  value* v = new_value(type,ws[1]);
288  if(!v) {
289  m_out << "tools::columns::finder::analyse_dcl :"
290  << " syntax error in " << sout(a_s) << "."
291  << " new_value() failed."
292  << std::endl;
293  return 0;
294  }
295  v->set_label(swords[1]);
296  return v;
297 
298  }
299 
300  } else if(swords.size()==1) {
301  if(m_cur_type==value::NONE) {
302  m_out << "tools::columns::finder::analyse_dcl :"
303  << " (1) current type is NONE."
304  << std::endl;
305  return 0;
306  }
307 
308  strip(ws[1]);
309  value* v = new_value(m_cur_type,ws[1]);
310  if(!v) {
311  m_out << "tools::columns::finder::analyse_dcl :"
312  << " syntax error in " << sout(a_s) << "."
313  << " Bad value " << sout(ws[1]) << "."
314  << std::endl;
315  return 0;
316  }
317  v->set_label(swords[0]);
318  return v;
319 
320  } else {
321  m_out << "tools::columns::finder::analyse_dcl :"
322  << " syntax error in " << sout(a_s)
323  << ". Case 1."
324  << std::endl;
325  return 0;
326  }
327 
328  } else if(ws.size()==1) {
329  //<type> <name>
330  //<type> <name>={
331  std::vector<std::string> swords;
332  words(ws[0]," ",false,swords);
333  if(swords.size()==2) {
334  strip(swords[0]);
335  strip(swords[1]);
336 
337  if(swords[0]=="ITuple") {
338 
339  //create a value::VOID_STAR :
340  value* v = new value((void*)0);
341  v->set_label(swords[1]);
342  return v;
343 
344  } else {
345  value::e_type type;
346  if(!s2type(swords[0],type)){
347  m_out << "tools::columns::finder::analyse_dcl :"
348  << " s2type failed for " << sout(swords[0]) << "."
349  << std::endl;
350  return 0;
351  }
352 
353  value* v = new_value(type,"");
354  if(!v) {
355  m_out << "tools::columns::finder::analyse_dcl :"
356  << " (2) syntax error in " << sout(ws[0]) << "."
357  << " Unknown type " << sout(swords[0]) << "."
358  << std::endl;
359  return 0;
360  }
361  v->set_label(swords[1]);
362  return v;
363  }
364 
365  } else if(swords.size()==1) {
366 
367  if(m_cur_type==value::NONE) {
368  m_out << "tools::columns::finder::analyse_dcl :"
369  << " (1) current type is NONE."
370  << std::endl;
371  return 0;
372  }
373 
374  value* v = new value();
375  v->set_type(m_cur_type);
376  v->set_label(swords[0]);
377  return v;
378 
379  } else {
380  m_out << "tools::columns::finder::analyse_dcl :"
381  << " syntax error in " << sout(a_s)
382  << ". Case 2."
383  << std::endl;
384  return 0;
385  }
386 
387  } else {
388  m_out << "tools::columns::finder::analyse_dcl :"
389  << " syntax error in " << sout(a_s)
390  << ". Case 3."
391  << std::endl;
392  return 0;
393  }
394  }

◆ clear()

void tools::columns::finder::clear ( )
inline

Definition at line 210 of file columns.

210  {
211  m_top.clear();
214  }

◆ find_variables()

bool tools::columns::finder::find_variables ( )
inline

Definition at line 195 of file columns.

195  {
196  clear();
197  if(m_script.empty()) return false; //keep old version logic.
198  if(!parse(m_script)) return false;
199  //dump(m_out);
200  //analyse m_top :
201  if(!analyse(m_top,m_stack)) {clear();return false;}
202  return true;
203  }

◆ new_value()

static value* tools::columns::finder::new_value ( value::e_type  a_type,
const std::string &  a_v 
)
inlinestaticprotected

Definition at line 449 of file columns.

449  {
450  if(a_type==value::FLOAT) {
451  float v = 0;
452  if(a_v.size()) {if(!to<float>(a_v,v)) return 0;}
453  return new value(v);
454  } else if(a_type==value::DOUBLE) {
455  double v = 0;
456  if(a_v.size()) {if(!to<double>(a_v,v)) return 0;}
457  return new value(v);
458  //} else if(a_type==value::CHAR) {
459  // char v = 0;
460  // if(a_v.size()) {if(!to<char>(a_v,v)) return 0;}
461  // return new value(v);
462  } else if(a_type==value::SHORT) {
463  short v = 0;
464  if(a_v.size()) {if(!to<short>(a_v,v)) return 0;}
465  return new value(v);
466  } else if(a_type==value::INT) {
467  int v = 0;
468  if(a_v.size()) {if(!to<int>(a_v,v)) return 0;}
469  return new value(v);
470 
471  } else if(a_type==value::INT64) {
472  int64 v = 0;
473  if(a_v.size()) {if(!to<int64>(a_v,v)) return 0;}
474  return new value(v);
475  } else if(a_type==value::BOOL) {
476  bool v = false;
477  if(a_v.size()) {if(!to(a_v,v)) return 0;}
478  return new value(v);
479 
480  } else if(a_type==value::STRING) {
481  if( (a_v.size()>=2) && (a_v[0]=='"') && (a_v[a_v.size()-1]=='"') ){
482  return new value(a_v.substr(1,a_v.size()-2));
483  } else {
484  return new value(a_v);
485  }
486 
487  //} else if(a_type==value::UNSIGNED_CHAR) {
488  // unsigned short v = 0;
489  // if(a_v.size()) {if(!to<unsigned short>(a_v,v)) return 0;}
490  // return new value((unsigned char)v);
491 
492  } else if(a_type==value::UNSIGNED_SHORT) {
493  unsigned short v = 0;
494  if(a_v.size()) {if(!to<unsigned short>(a_v,v)) return 0;}
495  return new value(v);
496  } else if(a_type==value::UNSIGNED_INT) {
497  unsigned int v = 0;
498  if(a_v.size()) {if(!to<unsigned int>(a_v,v)) return 0;}
499  return new value(v);
500 
501  } else if(a_type==value::UNSIGNED_INT64) {
502  uint64 v = 0;
503  if(a_v.size()) {if(!to<uint64>(a_v,v)) return 0;}
504  return new value(v);
505 
506  } else if(a_type==value::ARRAY_FLOAT) {
507  if(a_v.size()) return 0;
508  value* v = new value();
509  v->set_type(value::ARRAY_FLOAT);
510  return v;
511  } else if(a_type==value::ARRAY_DOUBLE) {
512  if(a_v.size()) return 0;
513  value* v = new value();
514  v->set_type(value::ARRAY_DOUBLE);
515  return v;
516  //} else if(a_type==value::ARRAY_UNSIGNED_CHAR) {
517  // if(a_v.size()) return 0;
518  // value* v = new value();
519  // v->set_type(value::ARRAY_UNSIGNED_CHAR);
520  // return v;
521  //} else if(a_type==value::ARRAY_CHAR) {
522  // if(a_v.size()) return 0;
523  // value* v = new value();
524  // v->set_type(value::ARRAY_CHAR);
525  // return v;
526  } else if(a_type==value::ARRAY_SHORT) {
527  if(a_v.size()) return 0;
528  value* v = new value();
529  v->set_type(value::ARRAY_SHORT);
530  return v;
531  } else if(a_type==value::ARRAY_INT) {
532  if(a_v.size()) return 0;
533  value* v = new value();
534  v->set_type(value::ARRAY_INT);
535  return v;
536  } else if(a_type==value::ARRAY_INT64) {
537  if(a_v.size()) return 0;
538  value* v = new value();
539  v->set_type(value::ARRAY_INT64);
540  return v;
541  } else if(a_type==value::ARRAY_BOOL) {
542  if(a_v.size()) return 0;
543  value* v = new value();
544  v->set_type(value::ARRAY_BOOL);
545  return v;
546  } else if(a_type==value::ARRAY_STRING) {
547  if(a_v.size()) return 0;
548  value* v = new value();
549  v->set_type(value::ARRAY_STRING);
550  return v;
551  } else {
552  return 0;
553  }
554  }

◆ operator=()

finder& tools::columns::finder::operator= ( const finder )
inlineprotected

Definition at line 192 of file columns.

192 {return *this;}

◆ result()

void tools::columns::finder::result ( std::vector< value > &  a_vars) const
inline

Definition at line 205 of file columns.

205  {
206  a_vars.clear();
207  copy_columns(m_stack,a_vars);
208  }

◆ s2type()

static bool tools::columns::finder::s2type ( const std::string &  a_s,
value::e_type a_type 
)
inlinestaticprotected

Definition at line 396 of file columns.

396  {
397  if(a_s=="float") {
398  a_type = value::FLOAT;
399  } else if(a_s=="double") {
400  a_type = value::DOUBLE;
401  //} else if(a_s=="char") {
402  // a_type = value::CHAR;
403  } else if(a_s=="short") {
404  a_type = value::SHORT;
405  } else if(a_s=="int") {
406  a_type = value::INT;
407  } else if(a_s=="long") {
408  a_type = value::INT64;
409  } else if((a_s=="bool")||(a_s=="boolean")) {
410  a_type = value::BOOL;
411  } else if((a_s=="string")||(a_s=="java.lang.String")){
412  a_type = value::STRING;
413  //} else if(a_s=="byte") {
414  // a_type = value::UNSIGNED_CHAR;
415 
416  } else if(a_s=="float[]") {
417  a_type = value::ARRAY_FLOAT;
418  } else if(a_s=="double[]") {
419  a_type = value::ARRAY_DOUBLE;
420  //} else if(a_s=="char[]") {
421  // a_type = value::ARRAY_CHAR;
422  //} else if(a_s=="byte[]") {
423  // a_type = value::ARRAY_UNSIGNED_CHAR;
424  } else if(a_s=="short[]") {
425  a_type = value::ARRAY_SHORT;
426  } else if(a_s=="int[]") {
427  a_type = value::ARRAY_INT;
428  } else if(a_s=="long[]") {
429  a_type = value::ARRAY_INT64;
430  } else if((a_s=="bool[]")||(a_s=="boolean[]")) {
431  a_type = value::ARRAY_BOOL;
432  } else if((a_s=="string[]")||(a_s=="java.lang.String[]")){
433  a_type = value::ARRAY_STRING;
434 
435  // not AIDA :
436  //} else if(a_s=="uchar") {
437  // a_type = value::UNSIGNED_CHAR;
438  } else if(a_s=="ushort") {
439  a_type = value::UNSIGNED_SHORT;
440  } else if(a_s=="uint") {
441  a_type = value::UNSIGNED_INT;
442  } else if(a_s=="ulong") {
443  a_type = value::UNSIGNED_INT64;
444  } else {
445  return false;
446  }
447  return true;
448  }

Member Data Documentation

◆ m_cur_type

value::e_type tools::columns::finder::m_cur_type

Definition at line 559 of file columns.

◆ m_out

std::ostream& tools::columns::finder::m_out

Definition at line 556 of file columns.

◆ m_script

std::string tools::columns::finder::m_script

Definition at line 557 of file columns.

◆ m_stack

std::vector<value> tools::columns::finder::m_stack

Definition at line 558 of file columns.


The documentation for this class was generated from the following file:
tools::value::ARRAY_SHORT
@ ARRAY_SHORT
Definition: value:51
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::int64
long long int64
Definition: typedefs:67
tools::value::ARRAY_FLOAT
@ ARRAY_FLOAT
Definition: value:56
tools::columns::finder::clear
void clear()
Definition: columns:210
tools::value::FLOAT
@ FLOAT
Definition: value:36
tools::value::UNSIGNED_SHORT
@ UNSIGNED_SHORT
Definition: value:29
tools::columns::copy_columns
void copy_columns(const std::vector< value > &a_from, std::vector< value > &a_to)
Definition: columns:136
tools::columns::finder::m_stack
std::vector< value > m_stack
Definition: columns:558
tools::columns::finder::analyse
bool analyse(columns::tree &a_tree, std::vector< value > &a_stack)
Definition: columns:221
tools::value::e_type
e_type
Definition: value:24
tools::value::ARRAY_DOUBLE
@ ARRAY_DOUBLE
Definition: value:57
tools::value::DOUBLE
@ DOUBLE
Definition: value:37
tools::value::ARRAY_STRING
@ ARRAY_STRING
Definition: value:59
tools::columns::tree::clear
void clear()
Definition: columns:42
tools::value::ARRAY_INT64
@ ARRAY_INT64
Definition: value:55
tools::value::ARRAY_INT
@ ARRAY_INT
Definition: value:53
tools::value::VOID_STAR
@ VOID_STAR
Definition: value:42
tools::columns::parser::m_top
tree m_top
Definition: columns:113
tools::value::STRING
@ STRING
Definition: value:40
tools::columns::parser::parse
bool parse(const std::string &a_s)
Definition: columns:73
tools::to
std::vector< std::string > to(int a_argc, char **a_argv)
Definition: args:507
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
tools::columns::finder::m_cur_type
value::e_type m_cur_type
Definition: columns:559
tools::is_spaces
bool is_spaces(const std::string &a_string)
Definition: schar:28
tools::value::UNSIGNED_INT
@ UNSIGNED_INT
Definition: value:31
tools::value::ARRAY_BOOL
@ ARRAY_BOOL
Definition: value:58
tools::value::UNSIGNED_INT64
@ UNSIGNED_INT64
Definition: value:33
tools::columns::finder::m_script
std::string m_script
Definition: columns:557
tools::columns::finder::analyse_dcl
value * analyse_dcl(const std::string &a_s)
Definition: columns:258
tools::columns::finder::m_out
std::ostream & m_out
Definition: columns:556
tools::strip
bool strip(std::string &a_string, what a_type=both, char a_char=' ')
Definition: strip:14
tools::value::SHORT
@ SHORT
Definition: value:30
tools::columns::delete_columns
void delete_columns(std::vector< value > &a_vars)
Definition: columns:124
tools::value::INT
@ INT
Definition: value:32
tools::columns::finder::s2type
static bool s2type(const std::string &a_s, value::e_type &a_type)
Definition: columns:396
tools::columns::finder::new_value
static value * new_value(value::e_type a_type, const std::string &a_v)
Definition: columns:449
tools::value::INT64
@ INT64
Definition: value:34
tools::value::BOOL
@ BOOL
Definition: value:39
tools::value::NONE
@ NONE
Definition: value:25