g4tools  5.4.0
sf
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
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::sf<"+stype(T())+">");
29  return s_v;
30  }
31  virtual void* cast(const std::string& a_class) const {
32  if(void* p = cmp_cast< sf<T> >(this,a_class)) {return p;}
33  return parent::cast(a_class);
34  }
35  virtual const std::string& s_cls() const {return s_class();}
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
tools::io::irbuf::read
virtual bool read(uchar &)=0
tools::sg::bsf
Definition: bsf:19
bsf
tools::sg::bsf::m_value
T m_value
Definition: bsf:120
tools::sg::sf::read
virtual bool read(io::irbuf &a_buffer)
Definition: sf:40
tools::sg::field
Definition: field:25
tools::sg::sf::s_class
static const std::string & s_class()
Definition: sf:27
tools::sg::bsf::cast
virtual void * cast(const std::string &a_class) const
Definition: bsf:27
tools::sg::sf::operator=
sf & operator=(const T &a_value)
Definition: sf:74
tools::sg::sf::sf
sf(const sf &a_from)
Definition: sf:66
tools::sg::sf::~sf
virtual ~sf()
Definition: sf:64
tools::sg::sf::cast
virtual void * cast(const std::string &a_class) const
Definition: sf:31
tools::sg::sf::operator=
sf & operator=(const sf &a_from)
Definition: sf:69
tools::sg::sf::dump
virtual bool dump(std::ostream &a_out)
Definition: sf:43
tools::sg::sf::sf
sf()
Definition: sf:62
tools::io::iwbuf::write
virtual bool write(uchar)=0
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::io::irbuf
Definition: irbuf:19
tools::cmp_cast
void * cmp_cast(const TO *a_this, const std::string &a_class)
Definition: scast:15
tools::sg::sf::s_value
virtual bool s_value(std::string &a_s) const
Definition: sf:47
tools::sg::bsf::operator=
bsf & operator=(const bsf &a_from)
Definition: bsf:49
tools::io::iwbuf
Definition: iwbuf:15
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::sf::s_cls
virtual const std::string & s_cls() const
Definition: sf:35
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73
tools::sg::sf::sf
sf(const T &a_value)
Definition: sf:63
tools::sg::sf::s2value
virtual bool s2value(const std::string &a_s)
Definition: sf:53
tools::sg::sf::write
virtual bool write(io::iwbuf &a_buffer)
Definition: sf:37
tools::sg::sf
Definition: sf:24