Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_bsf 5 #define tools_sg_bsf 6 7 // sf for simple field. 8 9 // bsf is intended to have no implementation of : 10 // virtual bool write(io::iwbuf&) 11 // virtual bool read(io::irbuf&) 12 13 #include "field" 14 15 namespace tools { 16 namespace sg { 17 18 template <class T> 19 class bsf : public field { 20 typedef field parent; 21 public: 22 static const std::string& s_class() { 23 //we do not use stype(T()). 24 static const std::string s_v("tools::sg::bsf"); 25 return s_v; 26 } 27 virtual void* cast(const std::string& a_class) const { 28 if(void* p = cmp_cast< bsf<T> >(this,a_class)) {return p;} 29 return parent::cast(a_class); 30 } 31 virtual const std::string& s_cls() const {return s_class();} 32 /* 33 virtual bool equal(const field& a_field) const { 34 bsf<T>* fld = safe_cast<field,bsf<T>>(a_field); 35 if(!fld) return false; 36 return operator==(*fld); 37 } 38 */ 39 protected: 40 bsf():m_value(T()){} 41 public: 42 bsf(const T& a_value):m_value(a_value){} 43 virtual ~bsf(){} 44 public: 45 bsf(const bsf& a_from) 46 :parent(a_from) 47 ,m_value(a_from.m_value){} 48 49 bsf& operator=(const bsf& a_from){ 50 parent::operator=(a_from); 51 if(a_from.m_value!=m_value) m_touched = true; 52 m_value = a_from.m_value; 53 return *this; 54 } 55 public: 56 bsf& operator=(const T& a_value){ 57 if(a_value!=m_value) m_touched = true; 58 m_value = a_value; 59 return *this; 60 } 61 bool operator==(const bsf& a_from) const { 62 return m_value==a_from.m_value; 63 } 64 bool operator!=(const bsf& a_from) const { 65 return !operator==(a_from); 66 } 67 68 bool operator==(const T& a_value) const { 69 return m_value==a_value; 70 } 71 bool operator!=(const T& a_value) const { 72 return !operator==(a_value); 73 } 74 75 operator const T& () const {return m_value;} 76 operator T() {return m_value;} 77 78 /* does not work with qrot 79 bsf& operator+=(const T& a_value){ 80 m_value += a_value; 81 m_touched = true; 82 return *this; 83 } 84 */ 85 /* does not work with T=std::string 86 bsf& operator-=(const T& a_value){ 87 m_value -= a_value; 88 m_touched = true; 89 return *this; 90 } 91 bsf& operator*=(const T& a_value){ 92 m_value *= a_value; 93 m_touched = true; 94 return *this; 95 } 96 */ 97 public: 98 T& value() {return m_value;} 99 const T& value() const {return m_value;} 100 void value(const T& a_value) { 101 if(a_value!=m_value) m_touched = true; 102 m_value = a_value; 103 } 104 void value_no_cmp(const T& a_value) { 105 //if(a_value!=m_value) m_touched = true; 106 m_value = a_value; 107 } 108 //public: //for style. 109 // bool s2v(const std::string& a_s) { 110 // T v; 111 // if(!to<T>(a_s,v)) return false; 112 // if(v!=m_value) m_touched = true; 113 // m_value = v; 114 // return true; 115 // } 116 public: //for iv2sg 117 void setValue(const T& a_value) {value(a_value);} 118 const T& getValue() const {return m_value;} 119 protected: 120 T m_value; 121 }; 122 123 }} 124 125 #endif