Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_sf 5 #define tools_sg_sf 6 7 // sf for simple field. 8 9 #include "bsf" 10 11 //#include "../sto" 12 13 #include "../io/iwbuf" 14 #include "../io/irbuf" 15 #include "../stype" 16 17 #include <sstream> 18 #include <istream> 19 20 namespace tools { 21 namespace sg { 22 23 template <class T> 24 class sf : public bsf<T> { 25 typedef bsf<T> parent; 26 public: 27 static const std::string& s_class() { 28 static const std::string s_v("tools::sg::s 29 return s_v; 30 } 31 virtual void* cast(const std::string& a_clas 32 if(void* p = cmp_cast< sf<T> >(this,a_clas 33 return parent::cast(a_class); 34 } 35 virtual const std::string& s_cls() const {re 36 public: 37 virtual bool write(io::iwbuf& a_buffer) { 38 return a_buffer.write(parent::m_value); 39 } 40 virtual bool read(io::irbuf& a_buffer) { 41 return a_buffer.read(parent::m_value); 42 } 43 virtual bool dump(std::ostream& a_out) { 44 a_out << parent::m_value << std::endl; 45 return true; 46 } 47 virtual bool s_value(std::string& a_s) const 48 std::ostringstream strm; 49 strm << parent::m_value; 50 a_s = strm.str(); 51 return true; 52 } 53 virtual bool s2value(const std::string& a_s) 54 std::istringstream strm(a_s.c_str()); 55 T v; 56 strm >> v; 57 if(strm.fail()) return false; 58 parent::value(v); 59 return true; 60 } 61 public: 62 sf(){} 63 sf(const T& a_value):parent(a_value){} 64 virtual ~sf(){} 65 public: 66 sf(const sf& a_from) 67 :parent(a_from) 68 {} 69 sf& operator=(const sf& a_from){ 70 parent::operator=(a_from); 71 return *this; 72 } 73 public: 74 sf& operator=(const T& a_value){ 75 parent::operator=(a_value); 76 return *this; 77 } 78 }; 79 80 /* 81 template <class T> 82 class sf_no_io : public bsf<T> { 83 public: 84 virtual bool write(io::iwbuf&) {return true; 85 virtual bool read(io::irbuf&) {return true;} 86 virtual bool dump(std::ostream& a_out) { 87 a_out << parent::m_value << std::endl; 88 return true; 89 } 90 public: 91 sf_no_io(){} 92 sf_no_io(const T& a_value):parent(a_value){} 93 public: 94 sf_no_io(const sf_no_io& a_from) 95 :parent(a_from) 96 {} 97 sf_no_io& operator=(const sf_no_io& a_from){ 98 parent::operator=(a_from); 99 return *this; 100 } 101 public: 102 sf_no_io& operator=(const T& a_value){ 103 parent::operator=(a_value); 104 return *this; 105 } 106 }; 107 */ 108 109 }} 110 111 #endif