Warning, /include/Geant4/tools/sg/bsf is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_bsf
0005 #define tools_sg_bsf
0006
0007 // sf for simple field.
0008
0009 // bsf is intended to have no implementation of :
0010 // virtual bool write(io::iwbuf&)
0011 // virtual bool read(io::irbuf&)
0012
0013 #include "field"
0014
0015 namespace tools {
0016 namespace sg {
0017
0018 template <class T>
0019 class bsf : public field {
0020 typedef field parent;
0021 public:
0022 static const std::string& s_class() {
0023 //we do not use stype(T()).
0024 static const std::string s_v("tools::sg::bsf");
0025 return s_v;
0026 }
0027 virtual void* cast(const std::string& a_class) const {
0028 if(void* p = cmp_cast< bsf<T> >(this,a_class)) {return p;}
0029 return parent::cast(a_class);
0030 }
0031 virtual const std::string& s_cls() const {return s_class();}
0032 /*
0033 virtual bool equal(const field& a_field) const {
0034 bsf<T>* fld = safe_cast<field,bsf<T>>(a_field);
0035 if(!fld) return false;
0036 return operator==(*fld);
0037 }
0038 */
0039 protected:
0040 bsf():m_value(T()){}
0041 public:
0042 bsf(const T& a_value):m_value(a_value){}
0043 virtual ~bsf(){}
0044 public:
0045 bsf(const bsf& a_from)
0046 :parent(a_from)
0047 ,m_value(a_from.m_value){}
0048
0049 bsf& operator=(const bsf& a_from){
0050 parent::operator=(a_from);
0051 if(a_from.m_value!=m_value) m_touched = true;
0052 m_value = a_from.m_value;
0053 return *this;
0054 }
0055 public:
0056 bsf& operator=(const T& a_value){
0057 if(a_value!=m_value) m_touched = true;
0058 m_value = a_value;
0059 return *this;
0060 }
0061 bool operator==(const bsf& a_from) const {
0062 return m_value==a_from.m_value;
0063 }
0064 bool operator!=(const bsf& a_from) const {
0065 return !operator==(a_from);
0066 }
0067
0068 bool operator==(const T& a_value) const {
0069 return m_value==a_value;
0070 }
0071 bool operator!=(const T& a_value) const {
0072 return !operator==(a_value);
0073 }
0074
0075 operator const T& () const {return m_value;}
0076 operator T() {return m_value;}
0077
0078 /* does not work with qrot
0079 bsf& operator+=(const T& a_value){
0080 m_value += a_value;
0081 m_touched = true;
0082 return *this;
0083 }
0084 */
0085 /* does not work with T=std::string
0086 bsf& operator-=(const T& a_value){
0087 m_value -= a_value;
0088 m_touched = true;
0089 return *this;
0090 }
0091 bsf& operator*=(const T& a_value){
0092 m_value *= a_value;
0093 m_touched = true;
0094 return *this;
0095 }
0096 */
0097 public:
0098 T& value() {return m_value;}
0099 const T& value() const {return m_value;}
0100 void value(const T& a_value) {
0101 if(a_value!=m_value) m_touched = true;
0102 m_value = a_value;
0103 }
0104 void value_no_cmp(const T& a_value) {
0105 //if(a_value!=m_value) m_touched = true;
0106 m_value = a_value;
0107 }
0108 //public: //for style.
0109 // bool s2v(const std::string& a_s) {
0110 // T v;
0111 // if(!to<T>(a_s,v)) return false;
0112 // if(v!=m_value) m_touched = true;
0113 // m_value = v;
0114 // return true;
0115 // }
0116 public: //for iv2sg
0117 void setValue(const T& a_value) {value(a_value);}
0118 const T& getValue() const {return m_value;}
0119 protected:
0120 T m_value;
0121 };
0122
0123 }}
0124
0125 #endif