Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_named 5 #define tools_wroot_named 6 7 #include "buffer" 8 #include "../vmanip" 9 //#include "../vdata" 10 11 namespace tools { 12 namespace wroot { 13 14 inline bool Object_stream(buffer& a_buffer) { 15 short v = 1; 16 if(!a_buffer.write_version(v)) return false; 17 if(!a_buffer.write((unsigned int)0)) return 18 static const unsigned int kNotDeleted = 0x02 19 if(!a_buffer.write(kNotDeleted)) return fals 20 return true; 21 } 22 23 inline bool Named_stream(buffer& a_buffer,cons 24 unsigned int beg; 25 if(!a_buffer.write_version(1,beg)) return fa 26 if(!Object_stream(a_buffer)) return false; 27 if(!a_buffer.write(a_name)) return false; 28 if(!a_buffer.write(a_title)) return false; 29 if(!a_buffer.set_byte_count(beg)) return fal 30 return true; 31 } 32 33 template <class T> 34 class obj_array : public virtual ibo, public s 35 static unsigned int kNullTag() {return 0;} 36 public: //ibo 37 virtual const std::string& store_cls() const 38 static const std::string s_v("TObjArray"); 39 return s_v; 40 } 41 virtual bool stream(buffer& a_buffer) const 42 unsigned int c; 43 if(!a_buffer.write_version(3,c)) return fa 44 if(!Object_stream(a_buffer)) return false; 45 if(!a_buffer.write(std::string(""))) retur 46 int nobjects = int(std::vector<T*>::size() 47 if(!a_buffer.write(nobjects)) return false 48 int lowerBound = 0; 49 if(!a_buffer.write(lowerBound)) return fal 50 51 typedef typename std::vector<T*>::const_it 52 it_t it; 53 for(it=std::vector<T*>::begin();it!=std::v 54 if(*it) { 55 if(!a_buffer.write_object(*(*it))) ret 56 } else { //Could happen with branch::m_b 57 if(!a_buffer.write(kNullTag())) return 58 } 59 } 60 if(!a_buffer.set_byte_count(c)) return fal 61 return true; 62 } 63 public: 64 obj_array(){} 65 virtual ~obj_array(){safe_clear<T>(*this);} 66 public: 67 obj_array(const obj_array& a_from): ibo(a_fr 68 typedef typename std::vector<T*>::const_it 69 it_t it; 70 for(it=a_from.begin();it!=a_from.end();++i 71 std::vector<T*>::push_back((*it)->copy() 72 } 73 } 74 obj_array& operator=(const obj_array& a_from 75 if(&a_from==this) return *this; 76 safe_clear<T>(*this); 77 78 typedef typename std::vector<T*>::const_it 79 it_t it; 80 for(it=a_from.begin();it!=a_from.end();++i 81 std::vector<T*>::push_back((*it)->copy() 82 } 83 return *this; 84 } 85 public: 86 void clear_objs() {safe_clear<T>(*this);} 87 }; 88 89 template <class T> 90 class obj_list : public virtual ibo, public st 91 public: //ibo 92 virtual const std::string& store_cls() const 93 static const std::string s_v("TList"); 94 return s_v; 95 } 96 virtual bool stream(buffer& a_buffer) const 97 unsigned int c; 98 if(!a_buffer.write_version(4,c)) return fa 99 if(!Object_stream(a_buffer)) return false; 100 if(!a_buffer.write(std::string(""))) retur 101 int nobjects = int(std::vector<T*>::size() 102 if(!a_buffer.write(nobjects)) return false 103 104 typedef typename std::vector<T*>::const_it 105 it_t it; 106 for(it=std::vector<T*>::begin();it!=std::v 107 if(!a_buffer.write_object(*(*it))) retur 108 std::string opt; 109 unsigned char nch = (unsigned char)opt.s 110 if(!a_buffer.write(nch)) return false; 111 if(!a_buffer.write_fast_array<char>(opt. 112 } 113 if(!a_buffer.set_byte_count(c)) return fal 114 return true; 115 } 116 public: 117 obj_list(){} 118 virtual ~obj_list(){safe_clear<T>(*this);} 119 protected: 120 obj_list(const obj_list& a_from):ibo(a_from) 121 obj_list& operator=(const obj_list&){return 122 }; 123 124 inline bool AttLine_stream(buffer& a_buffer){ 125 short fLineColor = 1; 126 short fLineStyle = 1; 127 short fLineWidth = 1; 128 unsigned int c; 129 if(!a_buffer.write_version(1,c)) return fals 130 if(!a_buffer.write(fLineColor)) return false 131 if(!a_buffer.write(fLineStyle)) return false 132 if(!a_buffer.write(fLineWidth)) return false 133 if(!a_buffer.set_byte_count(c)) return false 134 return true; 135 } 136 137 inline bool AttFill_stream(buffer& a_buffer){ 138 short fFillColor = 0; 139 short fFillStyle = 101; 140 unsigned int c; 141 if(!a_buffer.write_version(1,c)) return fals 142 if(!a_buffer.write(fFillColor)) return false 143 if(!a_buffer.write(fFillStyle)) return false 144 if(!a_buffer.set_byte_count(c)) return false 145 return true; 146 } 147 148 inline bool AttMarker_stream(buffer& a_buffer) 149 short fMarkerColor = 1; 150 short fMarkerStyle = 1; 151 float fMarkerWidth = 1; 152 unsigned int c; 153 if(!a_buffer.write_version(1,c)) return fals 154 if(!a_buffer.write(fMarkerColor)) return fal 155 if(!a_buffer.write(fMarkerStyle)) return fal 156 if(!a_buffer.write(fMarkerWidth)) return fal 157 if(!a_buffer.set_byte_count(c)) return false 158 return true; 159 } 160 161 inline bool Att3D_stream(buffer& a_buffer){ 162 unsigned int c; 163 if(!a_buffer.write_version(1,c)) return fals 164 if(!a_buffer.set_byte_count(c)) return false 165 return true; 166 } 167 168 //template <class T> 169 //inline bool Array_stream(buffer& a_buffer,co 170 // if(!a_buffer.write((int)a_v.size())) retur 171 // if(!a_buffer.write_fast_array(vec_data(a_v 172 // return true; 173 //} 174 175 }} 176 177 #endif