g4tools  5.4.0
field
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_sg_field
5 #define tools_sg_field
6 
7 #include <ostream>
8 
9 #include "../scast"
10 #include "../S_STRING"
11 
12 #ifdef TOOLS_MEM
13 #include "../mem"
14 #endif
15 
16 namespace tools {
17 namespace io {
18 class iwbuf;
19 class irbuf;
20 }}
21 
22 namespace tools {
23 namespace sg {
24 
25 class field {
26 public:
28  virtual void* cast(const std::string& a_class) const {
29  if(void* p = cmp_cast<field>(this,a_class)) {return p;}
30  else return 0;
31  }
32  virtual const std::string& s_cls() const = 0;
33 public:
34  virtual bool write(io::iwbuf&) = 0;
35  virtual bool read(io::irbuf&) = 0;
36  virtual bool dump(std::ostream&) = 0;
37  virtual bool s_value(std::string&) const = 0;
38  virtual bool s2value(const std::string&) = 0;
39 protected:
40  field():m_touched(true){
41 #ifdef TOOLS_MEM
42  mem::increment(s_class().c_str());
43 #endif
44  }
45 public:
46  virtual ~field(){
47 #ifdef TOOLS_MEM
48  mem::decrement(s_class().c_str());
49 #endif
50  }
51 protected:
52  field(const field&):m_touched(true){
53 #ifdef TOOLS_MEM
54  mem::increment(s_class().c_str());
55 #endif
56  }
57  field& operator=(const field&){m_touched=false;return *this;}
58 public:
59  void touch() {m_touched = true;}
60  bool touched() const {return m_touched;}
61  void reset_touched() {m_touched = false;}
62 protected:
63  bool m_touched;
64 };
65 
66 }}
67 
68 #define TOOLS_FIELD_DESC_NODE_CLASS(a__class) \
69  static const std::string s_node_class(#a__class);
70 
71 #define TOOLS_ARG_FIELD_DESC(a__field) \
72  new tools::sg::field_desc(s_node_class+"."+#a__field,this->a__field.s_cls(),(char*)((tools::sg::field*)&(this->a__field))-(char*)((tools::sg::node*)this),true)
73 
74 #define TOOLS_ARG_FIELD_DESC_NOT_EDITABLE(a__field) \
75  new tools::sg::field_desc(s_node_class+"."+#a__field,this->a__field.s_cls(),(char*)((tools::sg::field*)&(this->a__field))-(char*)((tools::sg::node*)this),false)
76 
77 #define TOOLS_ARG_FIELD_DESC_ENUMS_BEG(a__field,a__num) \
78  new tools::sg::field_desc_enums(s_node_class+"."+#a__field,this->a__field.s_cls(),(char*)((tools::sg::field*)&(this->a__field))-(char*)((tools::sg::node*)this),true,a__num,
79 #define TOOLS_ARG_FIELD_DESC_ENUMS_END )
80 
81 #define TOOLS_ARG_FIELD_DESC_NOT_EDITABLE_ENUMS_BEG(a__field,a__num) \
82  new tools::sg::field_desc_enums(s_node_class+"."+#a__field,this->a__field.s_cls(),(char*)((tools::sg::field*)&(this->a__field))-(char*)((tools::sg::node*)this),false,a__num,
83 #define TOOLS_ARG_FIELD_DESC_ENUMS_END )
84 
85 #define TOOLS_ARG_ENUM(a__value) #a__value,a__value
86 
87 #define TOOLS_ARG_FIELD_DESC_OPTS_BEG(a__field,a__num) \
88  new tools::sg::field_desc_opts(s_node_class+"."+#a__field,this->a__field.s_cls(),(char*)((tools::sg::field*)&(this->a__field))-(char*)((tools::sg::node*)this),true,a__num,
89 #define TOOLS_ARG_FIELD_DESC_OPTS_END )
90 
91 #endif
92 
tools::sg::field::touch
void touch()
Definition: field:59
tools::sg::field::s_cls
virtual const std::string & s_cls() const =0
tools::sg::field::m_touched
bool m_touched
Definition: field:63
tools::sg::field::write
virtual bool write(io::iwbuf &)=0
tools::sg::field::field
field(const field &)
Definition: field:52
tools::sg::field::~field
virtual ~field()
Definition: field:46
tools::sg::field::reset_touched
void reset_touched()
Definition: field:61
tools::sg::field
Definition: field:25
TOOLS_SCLASS
#define TOOLS_SCLASS(a_name)
Definition: S_STRING:41
tools::sg::field::s_value
virtual bool s_value(std::string &) const =0
tools::sg::field::touched
bool touched() const
Definition: field:60
tools::sg::field::cast
virtual void * cast(const std::string &a_class) const
Definition: field:28
tools::sg::field::operator=
field & operator=(const field &)
Definition: field:57
tools::sg::field::read
virtual bool read(io::irbuf &)=0
tools::sg::field::s2value
virtual bool s2value(const std::string &)=0
tools::sg::field::dump
virtual bool dump(std::ostream &)=0
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::io::irbuf
Definition: irbuf:19
tools::io::iwbuf
Definition: iwbuf:15
tools::sg::field::field
field()
Definition: field:40