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 "../sto"
0012
0013 #include "../io/iwbuf"
0014 #include "../io/irbuf"
0015 #include "../stype"
0016
0017 #include <sstream>
0018 #include <istream>
0019
0020 namespace tools {
0021 namespace sg {
0022
0023 template <class T>
0024 class sf : public bsf<T> {
0025 typedef bsf<T> parent;
0026 public:
0027 static const std::string& s_class() {
0028 static const std::string s_v("tools::sg::sf<"+stype(T())+">");
0029 return s_v;
0030 }
0031 virtual void* cast(const std::string& a_class) const {
0032 if(void* p = cmp_cast< sf<T> >(this,a_class)) {return p;}
0033 return parent::cast(a_class);
0034 }
0035 virtual const std::string& s_cls() const {return s_class();}
0036 public:
0037 virtual bool write(io::iwbuf& a_buffer) {
0038 return a_buffer.write(parent::m_value);
0039 }
0040 virtual bool read(io::irbuf& a_buffer) {
0041 return a_buffer.read(parent::m_value);
0042 }
0043 virtual bool dump(std::ostream& a_out) {
0044 a_out << parent::m_value << std::endl;
0045 return true;
0046 }
0047 virtual bool s_value(std::string& a_s) const {
0048 std::ostringstream strm;
0049 strm << parent::m_value;
0050 a_s = strm.str();
0051 return true;
0052 }
0053 virtual bool s2value(const std::string& a_s) {
0054 std::istringstream strm(a_s.c_str());
0055 T v;
0056 strm >> v;
0057 if(strm.fail()) return false;
0058 parent::value(v);
0059 return true;
0060 }
0061 public:
0062 sf(){}
0063 sf(const T& a_value):parent(a_value){}
0064 virtual ~sf(){}
0065 public:
0066 sf(const sf& a_from)
0067 :parent(a_from)
0068 {}
0069 sf& operator=(const sf& a_from){
0070 parent::operator=(a_from);
0071 return *this;
0072 }
0073 public:
0074 sf& operator=(const T& a_value){
0075 parent::operator=(a_value);
0076 return *this;
0077 }
0078 };
0079
0080 /*
0081 template <class T>
0082 class sf_no_io : public bsf<T> {
0083 public:
0084 virtual bool write(io::iwbuf&) {return true;}
0085 virtual bool read(io::irbuf&) {return true;}
0086 virtual bool dump(std::ostream& a_out) {
0087 a_out << parent::m_value << std::endl;
0088 return true;
0089 }
0090 public:
0091 sf_no_io(){}
0092 sf_no_io(const T& a_value):parent(a_value){}
0093 public:
0094 sf_no_io(const sf_no_io& a_from)
0095 :parent(a_from)
0096 {}
0097 sf_no_io& operator=(const sf_no_io& a_from){
0098 parent::operator=(a_from);
0099 return *this;
0100 }
0101 public:
0102 sf_no_io& operator=(const T& a_value){
0103 parent::operator=(a_value);
0104 return *this;
0105 }
0106 };
0107 */
0108
0109 }}
0110
0111 #endif