g4tools  5.4.0
member_writer
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_wroot_member_writer
5 #define tools_wroot_member_writer
6 
7 #include "../store/iobj_const_visitor"
8 
9 #include "buffer"
10 
11 namespace tools {
12 namespace wroot {
13 
14 class member_writer : public virtual iobj_const_visitor {
15 public:
16  virtual bool begin(const istorable&,const std::string&,local_func) {return true;}
17  virtual bool end(const istorable&){return true;}
18 
19  virtual bool visit(const std::string&,bool a_v){return m_buf.write(a_v);}
20  virtual bool visit(const std::string&,char a_v){return m_buf.write(a_v);}
21  virtual bool visit(const std::string&,short a_v){return m_buf.write(a_v);}
22  virtual bool visit(const std::string&,int a_v){return m_buf.write(a_v);}
23 
24  virtual bool visit(const std::string&,unsigned int a_v) {return m_buf.write(a_v);}
25 
26  virtual bool visit(const std::string&,int64){
27  m_buf.out() << "tools::wroot::member_writer::visit(int64) :"
28  << " dummy." << std::endl;
29  return false; //FIXME
30  }
31 
32  virtual bool visit(const std::string&,uint64){
33  m_buf.out() << "tools::wroot::member_writer::visit(uint64) :"
34  << " dummy." << std::endl;
35  return false; //FIXME
36  }
37 
38  virtual bool visit(const std::string&,float a_v){return m_buf.write(a_v);}
39  virtual bool visit(const std::string&,double a_v){return m_buf.write(a_v);}
40 
41  virtual bool visit(const std::string&,const std::string& a_v) {return m_buf.write(a_v);}
42 
43  //virtual bool visit(const std::string&,const char* a_v){
44  // return m_buf.write(std::string(a_v));
45  //}
46 
47  virtual bool visit(const std::string&,const std::vector<bool>& a_v){
48  size_t number = a_v.size();
49  std::vector<unsigned char> data(number);
50  for(size_t index=0;index<number;index++) {
51  data[index] = (unsigned char)a_v[index];
52  }
53  return m_buf.write_array<unsigned char>(data);
54  }
55 
56  virtual bool visit(const std::string&,const std::vector<char>& a_v) {return m_buf.write_array(a_v);}
57 
58  virtual bool visit(const std::string&,const std::vector<short>& a_v) {return m_buf.write_array(a_v);}
59 
60  virtual bool visit(const std::string&,const std::vector<int>& a_v) {return m_buf.write_array(a_v);}
61 
62  virtual bool visit(const std::string&,const std::vector<int64>& /*a_v*/){
63  //FIXME return ::Rio::writeArray<Slash::int64>(fBuffer,a_v);
64  m_buf.out() << "tools::wroot::member_writer::visit(vector<int64>) :"
65  << " dummy." << std::endl;
66  return false;
67  }
68 
69  virtual bool visit(const std::string&,const std::vector<float>& a_v) {return m_buf.write_array(a_v);}
70 
71  virtual bool visit(const std::string&,const std::vector<double>& a_v) {return m_buf.write_array(a_v);}
72 
73 //virtual bool visit(const std::string&,const std::vector<unsigned char>& a_v) {return m_buf.write_array(a_v);}
74 
75  virtual bool visit(const std::string&,const std::vector<std::string>& a_v) {return m_buf.write(a_v);}
76 
77  virtual bool visit(const std::string&,const std::vector< std::vector<double> >& a_v){
78  return m_buf.write_array2(a_v);
79  }
80 
81  virtual bool visit(const std::string&,const istorable& a_v){
82  // WARNING : can't be called in a object.visit()
83  // over a a_v being a "super" of "object" .
84  if(!a_v.visit(*this)) return false;
85  return true;
86  }
87 public:
88  member_writer(buffer& a_buf):m_buf(a_buf){}
89  virtual ~member_writer(){}
90 private:
91  member_writer(const member_writer& a_from)
92  :iobj_const_visitor(a_from)
93  ,m_buf(a_from.m_buf)
94  {}
95  member_writer& operator=(const member_writer&){return *this;}
96 protected:
98 };
99 
100 }}
101 
102 #endif
tools::iobj_const_visitor
Definition: iobj_const_visitor:27
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::int64
long long int64
Definition: typedefs:67
tools::wroot::member_writer::m_buf
buffer & m_buf
Definition: member_writer:97
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, char a_v)
Definition: member_writer:20
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, float a_v)
Definition: member_writer:38
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, double a_v)
Definition: member_writer:39
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, unsigned int a_v)
Definition: member_writer:24
buffer
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const istorable &a_v)
Definition: member_writer:81
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::string &a_v)
Definition: member_writer:41
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< std::string > &a_v)
Definition: member_writer:75
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, bool a_v)
Definition: member_writer:19
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< bool > &a_v)
Definition: member_writer:47
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, short a_v)
Definition: member_writer:21
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< int > &a_v)
Definition: member_writer:60
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< short > &a_v)
Definition: member_writer:58
tools::istorable
Definition: iobj_const_visitor:16
tools::wroot::buffer::write_array
bool write_array(const T *a_a, uint32 a_n)
Definition: buffer:148
tools::wroot::member_writer::~member_writer
virtual ~member_writer()
Definition: member_writer:89
tools::wroot::buffer::write
bool write(T x)
Definition: buffer:97
tools::wroot::buffer::out
std::ostream & out() const
Definition: buffer:83
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, uint64)
Definition: member_writer:32
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< char > &a_v)
Definition: member_writer:56
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::wroot::member_writer
Definition: member_writer:14
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, int64)
Definition: member_writer:26
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, int a_v)
Definition: member_writer:22
tools::wroot::buffer
Definition: buffer:28
tools::wroot::member_writer::begin
virtual bool begin(const istorable &, const std::string &, local_func)
Definition: member_writer:16
tools::wroot::member_writer::member_writer
member_writer(buffer &a_buf)
Definition: member_writer:88
tools::iobj_const_visitor::local_func
bool(* local_func)(const istorable &, iobj_const_visitor &)
Definition: iobj_const_visitor:31
tools::wroot::member_writer::end
virtual bool end(const istorable &)
Definition: member_writer:17
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< double > &a_v)
Definition: member_writer:71
tools::wroot::buffer::write_array2
bool write_array2(const std::vector< std::vector< T > > a_v)
Definition: buffer:160
tools::istorable::visit
virtual bool visit(iobj_const_visitor &) const =0
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< int64 > &)
Definition: member_writer:62
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< float > &a_v)
Definition: member_writer:69
tools::wroot::member_writer::visit
virtual bool visit(const std::string &, const std::vector< std::vector< double > > &a_v)
Definition: member_writer:77