inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/sg/sf
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_sg_sf
00005 #define inlib_sg_sf
00006 
00007 // sf for simple field.
00008 
00009 #include "field"
00010 
00011 //#include "../sto"
00012 
00013 namespace inlib {
00014 namespace sg {
00015 
00016 template <class T>
00017 class bsf : public field {
00018   // bsf is intended to have no implementation of :
00019   //   virtual bool write(io::iwbuf&)  
00020   //   virtual bool read(io::irbuf&)  
00021 /*
00022 public:
00023   static const std::string& s_class() {
00024     static const std::string s_v("inlib::sg::bsf");
00025     return s_v;
00026   }
00027   virtual void* cast(const std::string& a_class) const {
00028     if(void* p = inlib::cmp_cast<node>(this,a_class)) {return p;}
00029     else return 0;
00030   }
00031   virtual bool equal(const field& a_field) const {    
00032     bsf<T>* fld = inlib::cast<inlib::sg::field,bsf<T>>(a_field);
00033     if(!fld) return false;
00034     return operator==(*fld);    
00035   }
00036 */
00037 protected:
00038   bsf(){}
00039 public:
00040   bsf(const T& a_value):m_value(a_value){}
00041   virtual ~bsf(){}
00042 public:
00043   bsf(const bsf& a_from)
00044   :field(a_from)
00045   ,m_value(a_from.m_value){}
00046 
00047   bsf& operator=(const bsf& a_from){
00048     field::operator=(a_from);
00049     if(a_from.m_value!=m_value) m_touched = true;
00050     m_value = a_from.m_value;
00051     return *this;
00052   }
00053 public:
00054   bsf& operator=(const T& a_value){
00055     if(a_value!=m_value) m_touched = true;
00056     m_value = a_value;
00057     return *this;
00058   }
00059   bool operator==(const bsf& a_from) const {
00060     return m_value==a_from.m_value;
00061   }
00062   bool operator!=(const bsf& a_from) const {
00063     return !operator==(a_from);
00064   }
00065 
00066   bool operator==(const T& a_value) const {
00067     return m_value==a_value;
00068   }
00069   bool operator!=(const T& a_value) const { 
00070     return !operator==(a_value);
00071   }
00072 
00073   operator const T& () const {return m_value;}
00074   operator T() {return m_value;}
00075 
00076   bsf& operator+=(const T& a_value){
00077     m_value += a_value;
00078     m_touched = true;
00079     return *this;
00080   }
00081 public:
00082   T& value() {return m_value;}
00083   const T& value() const {return m_value;}
00084   void value(const T& a_value) {
00085     if(a_value!=m_value) m_touched = true;
00086     m_value = a_value;
00087   }
00088   void value_no_cmp(const T& a_value) {
00089     //if(a_value!=m_value) m_touched = true;
00090     m_value = a_value;
00091   }
00092 //public: //for style.
00093 //  bool s2v(const std::string& a_s) {
00094 //    T v;
00095 //    if(!inlib::to<T>(a_s,v)) return false;
00096 //    if(v!=m_value) m_touched = true;
00097 //    m_value = v;
00098 //    return true;
00099 //  }  
00100 protected:
00101   T m_value;
00102 };
00103 
00104 }}
00105 
00106 #include "../io/iwbuf"
00107 #include "../io/irbuf"
00108 
00109 namespace inlib {
00110 namespace sg {
00111 
00112 template <class T>
00113 class sf : public bsf<T> {
00114 public:
00115   virtual bool write(io::iwbuf& a_buffer) {
00116     return a_buffer.write(bsf<T>::m_value);
00117   }
00118   virtual bool read(io::irbuf& a_buffer) {
00119     return a_buffer.read(bsf<T>::m_value);
00120   }
00121   virtual bool dump(std::ostream& a_out) {
00122     a_out << bsf<T>::m_value << std::endl;
00123     return true;
00124   }
00125 public:
00126   sf(){}
00127   sf(const T& a_value): bsf<T>(a_value){}
00128 public:
00129   sf(const sf& a_from)
00130   : bsf<T>(a_from)
00131   {}
00132   sf& operator=(const sf& a_from){
00133     bsf<T>::operator=(a_from);
00134     return *this;
00135   }
00136 public:
00137   sf& operator=(const T& a_value){
00138     bsf<T>::operator=(a_value);
00139     return *this;
00140   }
00141 public:
00142 };
00143 
00144 }}
00145 
00146 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines