ldrtypes.h
1 /***************************************************************************
2  ldrtypes.h - description
3  -------------------
4  begin : Sun Jun 6 2004
5  copyright : (C) 2000-2015 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef LDRTYPES_H
19 #define LDRTYPES_H
20 
21 
22 #include <odinpara/ldrbase.h>
23 
24 
30 
36 class LDRstring : public STD_string, public virtual LDRbase {
37 
38  public:
39 
43  LDRstring () : STD_string() {}
44 
50  LDRstring (const STD_string& ss, const STD_string& name="");
51 
52 
56  LDRstring (int i,const char c=' ') : STD_string(i,c) {}
57 
61  LDRstring (const char *charptr) : STD_string(charptr) {}
62 
67 
71  LDRstring& operator = (const STD_string& ss) {STD_string::operator = (ss); return *this;}
72 
76  LDRstring& operator = (const char *charptr) {STD_string::operator = (charptr); return *this;}
77 
81  LDRstring& operator = (const LDRstring& ss);
82 
86  friend STD_ostream& operator << (STD_ostream& s,const LDRstring& t) {return s << STD_string(t);}
87 
88 
89  // overwriting virtual functions from LDRbase
90  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
91  STD_string printvalstring(const LDRserBase* ser=0) const;
92  STD_string get_parx_code(parxCodeType type) const;
93  STD_string get_typeInfo(bool parx_equivtype=false) const {if(parx_equivtype) return "char"; return "string";}
94  LDRbase* create_copy() const {return new LDRstring(*this);}
95  STD_string* cast(STD_string*) {return this;}
96 
97 
98 };
99 
100 
101 
103 
108 class LDRbool : public virtual LDRbase {
109 
110  public:
111 
115  LDRbool () : val(false) {}
116 
122  LDRbool(bool flag, const STD_string& name="");
123 
128 
132  LDRbool& operator = (bool flag) {val=flag; return *this;}
133 
138  LDRbool& operator = (const STD_string& s) {parsevalstring(s); return *this;}
139 
143  LDRbool& operator = (const LDRbool& jb);
144 
148  operator bool () const {return val;}
149 
150  // overwriting virtual functions from LDRbase
151  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
152  STD_string printvalstring(const LDRserBase* ser=0) const;
153  STD_string get_typeInfo(bool parx_equivtype=false) const {if(parx_equivtype) return "YesNo"; return "bool";}
154  LDRbase* create_copy() const {return new LDRbool(*this);}
155  bool* cast(bool*) {return &val;}
156 
157  private:
158  bool val;
159 };
160 
161 
163 
168 class LDRenum : public virtual LDRbase {
169 
170  public:
171 
175  LDRenum() {actual=entries.end();}
176 
182  LDRenum(const STD_string& first_entry, const STD_string& name="");
183 
188 
189 
193  LDRenum& operator = (const char* item) {set_actual(STD_string(item)); return *this;}
194 
198  LDRenum& operator = (const STD_string& item) {set_actual(item); return *this;}
199 
203  LDRenum& operator = (int item) {set_actual(item); return *this;}
204 
208  LDRenum& operator = (const LDRenum& je);
209 
215  LDRenum& add_item(const STD_string& item, int index=-1);
216 
220  LDRenum& set_actual(const STD_string& item);
221 
225  LDRenum& set_actual(int index);
226 
230  LDRenum& clear();
231 
235  operator int () const;
236 
240  operator STD_string () const;
241 
245  bool operator == (const STD_string& s) const {return (operator STD_string ())==s;}
246 
250  bool operator == (const char* s) const {return (operator STD_string ())==STD_string(s);}
251 
255  bool operator == (int i) const {return (operator int ())==i;}
256 
260  bool operator != (const STD_string& s) const {return (operator STD_string ())!=s;}
261 
265  bool operator != (const char* s) const {return (operator STD_string ())!=STD_string(s);}
266 
270  bool operator != (int i) const {return (operator int ())!=i;}
271 
272 
276  unsigned int n_items() const {return entries.size();}
277 
281  const STD_string& get_item(unsigned int index) const;
282 
286  unsigned int get_item_index() const;
287 
291  LDRenum& set_item_index(unsigned int index);
292 
293 
294  // overwriting virtual functions from LDRbase
295  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
296  STD_string printvalstring(const LDRserBase* ser=0) const;
297  svector get_alternatives() const;
298  STD_string get_typeInfo(bool parx_equivtype=false) const {if(parx_equivtype) toupperstr(get_label()); return "enum";}
299  LDRbase* create_copy() const {return new LDRenum(*this);}
300  LDRenum* cast(LDRenum*) {return this;}
301 
302  private:
303  STD_map<int,STD_string> entries;
304  STD_map<int,STD_string>::const_iterator actual;
305 
306  STD_string parxtype_cache;
307 
308 };
309 
311 
316 class LDRaction : public virtual LDRbase {
317 
318  public:
319 
323  LDRaction() : state(false) {set_filemode(exclude);}
324 
330  LDRaction(bool init_state, const STD_string& name="");
331 
336 
340  LDRaction& operator = (const LDRaction& ja);
341 
345  operator bool () const;
346 
350  LDRaction& trigger_action() {state=true; return *this;}
351 
352  // overwriting virtual functions from LDRbase
353  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
354  STD_string printvalstring(const LDRserBase* ser=0) const;
355  STD_string get_typeInfo(bool parx_equivtype=false) const {return "action";}
356  LDRbase* create_copy() const {return new LDRaction(*this);}
357  LDRaction* cast(LDRaction*) {return this;}
358 
359  private:
360  mutable bool state;
361 };
362 
363 
364 
365 
367 
368 
388 class LDRfileName : public LDRstring {
389 
390 public:
391 
395  LDRfileName () {common_init();}
396 
402  LDRfileName (const STD_string& filename, const STD_string& name="");
403 
407  LDRfileName(const LDRfileName& jf);
408 
412  LDRfileName& operator = (const STD_string& filename);
413 
417  LDRfileName& operator = (const LDRfileName& jf);
418 
422  bool exists() const;
423 
427  STD_string get_basename() const {return basename_cache;}
428 
433  STD_string get_basename_nosuffix() const;
434 
438  STD_string get_dirname() const {return dirname_cache;}
439 
443  STD_string get_suffix() const {return suffix_cache;}
444 
448  LDRfileName& set_suffix(const STD_string& suff) {suffix_cache=suff; return *this;}
449 
453  STD_string get_defaultdir() const {return defaultdir;}
454 
458  LDRfileName& set_defaultdir(const STD_string& defdir);
459 
460 
464  bool is_dir() const {return dir;}
465 
469  LDRfileName& set_dir(bool flag) {dir=flag; return *this;}
470 
471 
472  // overwriting virtual functions from LDRbase
473  bool parsevalstring(const STD_string& parstring, const LDRserBase* ser=0);
474  STD_string get_typeInfo(bool parx_equivtype=false) const {return "fileName";}
475  LDRbase* create_copy() const {return new LDRfileName(*this);}
476  LDRfileName* cast(LDRfileName*) {return this;}
477 
478 private:
479 
480  static void normalize(const STD_string& fname, bool dir, STD_string& result, STD_string& result_dirname, STD_string& result_basename, STD_string& result_suffix);
481 
482  void common_init() {dir=false;}
483 
484  STD_string defaultdir;
485  STD_string dirname_cache;
486  STD_string basename_cache;
487  STD_string suffix_cache;
488 
489  bool dir;
490 
491 };
492 
494 
499 class LDRformula : public LDRstring {
500 
501 public:
502 
507 
513  LDRformula (const STD_string& formula, const STD_string& name="");
514 
519 
523  LDRformula& operator = (const STD_string& formula) {LDRstring::operator = (formula); return *this;}
524 
528  LDRformula& operator = (const LDRformula& jf);
529 
533  LDRformula& set_syntax(const STD_string& syn) {syntax=syn; return *this;}
534 
538  STD_string get_syntax() const {return syntax;}
539 
540  // overwriting virtual functions from LDRbase
541  STD_string get_typeInfo(bool parx_equivtype=false) const {return "formula";}
542  LDRbase* create_copy() const {return new LDRformula(*this);}
543  LDRformula* cast(LDRformula*) {return this;}
544 
545 private:
546  STD_string syntax;
547 };
548 
549 
550 
554 #endif
555 
bool parsevalstring(const STD_string &parstring, const LDRserBase *ser=0)
LDRbase * create_copy() const
Definition: ldrtypes.h:94
bool operator==(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:129
bool operator!=(const TinyVector< T, N_rank > &t1, const TinyVector< T, N_rank > &t2)
Definition: utils.h:139
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:93
parxCodeType
Definition: ldrbase.h:216
LDRaction & trigger_action()
Definition: ldrtypes.h:350
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:355
STD_string get_syntax() const
Definition: ldrtypes.h:538
LDRformula()
Definition: ldrtypes.h:506
LDRbase * create_copy() const
Definition: ldrtypes.h:356
LDRbase * create_copy() const
Definition: ldrtypes.h:475
LDRfileName & set_suffix(const STD_string &suff)
Definition: ldrtypes.h:448
STD_string get_defaultdir() const
Definition: ldrtypes.h:453
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:541
LDRbase * create_copy() const
Definition: ldrtypes.h:299
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:298
LDRbool()
Definition: ldrtypes.h:115
LDRformula & operator=(const STD_string &formula)
Definition: ldrtypes.h:523
LDRbase * create_copy() const
Definition: ldrtypes.h:542
LDRbool(const LDRbool &jb)
Definition: ldrtypes.h:127
LDRaction & operator=(const LDRaction &ja)
LDRaction()
Definition: ldrtypes.h:323
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:474
bool is_dir() const
Definition: ldrtypes.h:464
LDRstring()
Definition: ldrtypes.h:43
LDRformula & set_syntax(const STD_string &syn)
Definition: ldrtypes.h:533
LDRstring & operator=(const STD_string &ss)
Definition: ldrtypes.h:71
LDRstring(const LDRstring &str)
Definition: ldrtypes.h:66
LDRaction(const LDRaction &ja)
Definition: ldrtypes.h:335
const STD_string & get_label() const
Definition: tjlabel.h:48
LDRstring(const char *charptr)
Definition: ldrtypes.h:61
LDRbase * create_copy() const
Definition: ldrtypes.h:154
STD_string get_typeInfo(bool parx_equivtype=false) const
Definition: ldrtypes.h:153
STD_string printvalstring(const LDRserBase *ser=0) const
virtual svector get_alternatives() const
Definition: ldrbase.h:388
STD_string get_dirname() const
Definition: ldrtypes.h:438
virtual LDRbase & set_filemode(fileMode file_mode)
Definition: ldrbase.h:426
STD_string get_parx_code(parxCodeType type) const
LDRenum()
Definition: ldrtypes.h:175
unsigned int n_items() const
Definition: ldrtypes.h:276
LDRenum & operator=(const char *item)
Definition: ldrtypes.h:193
LDRenum(const LDRenum &je)
Definition: ldrtypes.h:187
LDRfileName & set_dir(bool flag)
Definition: ldrtypes.h:469
LDRformula(const LDRformula &jf)
Definition: ldrtypes.h:518
STD_string get_basename() const
Definition: ldrtypes.h:427
STD_string toupperstr(const STD_string &s)
friend STD_ostream & operator<<(STD_ostream &s, const LDRstring &t)
Definition: ldrtypes.h:86
LDRstring(int i, const char c=' ')
Definition: ldrtypes.h:56
LDRbool & operator=(bool flag)
Definition: ldrtypes.h:132
STD_string get_suffix() const
Definition: ldrtypes.h:443