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