Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/sf 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_sf
0005 #define tools_sg_sf
0006 
0007 // sf for simple field.
0008 
0009 #include "bsf"
0010 
0011 #include "../io/iwbuf"
0012 #include "../io/irbuf"
0013 #include "../stype"
0014 
0015 #include <sstream>
0016 #include <istream>
0017 
0018 namespace tools {
0019 namespace sg {
0020 
0021 template <class T>
0022 class sf : public bsf<T> {
0023   typedef bsf<T> parent;
0024 public:
0025   static const std::string& s_class() {
0026     static const std::string s_v("tools::sg::sf<"+stype(T())+">");
0027     return s_v;
0028   }
0029   virtual void* cast(const std::string& a_class) const {
0030     if(void* p = cmp_cast< sf<T> >(this,a_class)) {return p;}
0031     return parent::cast(a_class);
0032   }
0033   virtual const std::string& s_cls() const {return s_class();}
0034 public:
0035   virtual bool write(io::iwbuf& a_buffer) {
0036     return a_buffer.write(parent::m_value);
0037   }
0038   virtual bool read(io::irbuf& a_buffer) {
0039     return a_buffer.read(parent::m_value);
0040   }
0041   virtual bool dump(std::ostream& a_out) {
0042     a_out << parent::m_value << std::endl;
0043     return true;
0044   }
0045   virtual bool s_value(std::string& a_s) const {
0046     std::ostringstream strm;
0047     strm << parent::m_value;
0048     a_s = strm.str();
0049     return true;
0050   }
0051   virtual bool s2value(const std::string& a_s) {
0052     std::istringstream strm(a_s.c_str());
0053     T v;
0054     strm >> v;
0055     if(strm.fail()) return false;
0056     parent::value(v);
0057     return true;
0058   }
0059 public:
0060   sf(){}
0061   sf(const T& a_value):parent(a_value){}
0062   virtual ~sf(){}
0063 public:
0064   sf(const sf& a_from)
0065   :parent(a_from)
0066   {}
0067   sf& operator=(const sf& a_from){
0068     parent::operator=(a_from);
0069     return *this;
0070   }
0071 public:
0072   sf& operator=(const T& a_value){
0073     parent::operator=(a_value);
0074     return *this;
0075   }
0076 };
0077 
0078 
0079 }}
0080 
0081 #endif