Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_rroot_named 5 #define tools_rroot_named 6 7 #include "object" 8 #include "../scast" 9 #include "../vdata" 10 #include "cids" 11 12 namespace tools { 13 namespace rroot { 14 15 inline bool Named_stream(buffer& a_buffer,std::string& a_name,std::string& a_title) { 16 short v; 17 unsigned int _s, _c; 18 if(!a_buffer.read_version(v,_s,_c)) return false; 19 {uint32 id,bits; 20 if(!Object_stream(a_buffer,id,bits)) return false;} 21 if(!a_buffer.read(a_name)) return false; 22 if(!a_buffer.read(a_title)) return false; 23 if(!a_buffer.check_byte_count(_s,_c,"TNamed")) return false; 24 return true; 25 } 26 27 inline bool AttLine_stream(buffer& a_buffer,short& a_color,short& a_style,short& a_width){ 28 short v; 29 unsigned int _s, _c; 30 if(!a_buffer.read_version(v,_s,_c)) return false; 31 if(!a_buffer.read(a_color)) return false; 32 if(!a_buffer.read(a_style)) return false; 33 if(!a_buffer.read(a_width)) return false; 34 if(!a_buffer.check_byte_count(_s,_c,"TAttLine")) return false; 35 return true; 36 } 37 38 inline bool AttFill_stream(buffer& a_buffer,short& a_color,short& a_style){ 39 short v; 40 unsigned int _s, _c; 41 if(!a_buffer.read_version(v,_s,_c)) return false; 42 if(!a_buffer.read(a_color)) return false; 43 if(!a_buffer.read(a_style)) return false; 44 if(!a_buffer.check_byte_count(_s,_c,"TAttFill")) return false; 45 return true; 46 } 47 48 inline bool AttMarker_stream(buffer& a_buffer) { 49 short fMarkerColor; 50 short fMarkerStyle; 51 float fMarkerWidth; 52 short v; 53 unsigned int _s, _c; 54 if(!a_buffer.read_version(v,_s,_c)) return false; 55 if(!a_buffer.read(fMarkerColor)) return false; 56 if(!a_buffer.read(fMarkerStyle)) return false; 57 if(!a_buffer.read(fMarkerWidth)) return false; 58 if(!a_buffer.check_byte_count(_s,_c,"TAttMarker")) return false; 59 return true; 60 } 61 62 inline bool GeoAtt_stream(buffer& a_buffer) { 63 unsigned int fGeoAtt; // option flags 64 short v; 65 unsigned int _s, _c; 66 if(!a_buffer.read_version(v,_s,_c)) return false; 67 if(!a_buffer.read(fGeoAtt)) return false; 68 if(!a_buffer.check_byte_count(_s,_c,"TGeoAtt")) return false; 69 return true; 70 } 71 72 inline bool Att3D_stream(buffer& a_buffer) { 73 short v; 74 unsigned int _s, _c; 75 if(!a_buffer.read_version(v,_s,_c)) return false; 76 if(!a_buffer.check_byte_count(_s,_c,"TAtt3D")) return false; 77 return true; 78 } 79 80 template <class T> 81 inline bool Array_stream(buffer& a_buffer,std::vector<T>& a_v) { 82 a_v.clear(); 83 int sz; 84 if(!a_buffer.read(sz)) return false; 85 //check sz is not crazy : 86 if(!a_buffer.check_eob(sz)) return false; 87 a_v.resize(sz); 88 if(!a_buffer.read_fast_array<T>(vec_data(a_v),sz)) return false; 89 return true; 90 } 91 92 template <class T> 93 inline bool dummy_array_stream(buffer& a_buffer,int a_n){ 94 char is_array; 95 if(!a_buffer.read(is_array)) return false; 96 if(!is_array) return true; 97 if(!a_n) return true; 98 T* v = new T[a_n]; 99 bool status = a_buffer.read_fast_array<T>(v,a_n); 100 delete [] v; 101 return status; 102 } 103 104 class named : public virtual iro { 105 static const std::string& s_store_class() { 106 static const std::string s_v("TNamed"); 107 return s_v; 108 } 109 public: 110 static const std::string& s_class() { 111 static const std::string s_v("tools::rroot::named"); 112 return s_v; 113 } 114 public: //iro 115 virtual void* cast(const std::string& a_class) const { 116 if(void* p = cmp_cast<named>(this,a_class)) return p; 117 return 0; 118 } 119 virtual const std::string& s_cls() const {return s_class();} 120 public: 121 static cid id_class() {return named_cid();} 122 virtual void* cast(cid a_class) const { 123 if(void* p = cmp_cast<named>(this,a_class)) {return p;} 124 else return 0; 125 } 126 //virtual void* cast(cid) const {return named_cid();} 127 public: 128 virtual iro* copy() const {return new named(*this);} 129 virtual bool stream(buffer& a_buffer) { 130 return Named_stream(a_buffer,m_name,m_title); 131 } 132 public: 133 named() { 134 #ifdef TOOLS_MEM 135 mem::increment(s_class().c_str()); 136 #endif 137 } 138 virtual ~named() { 139 #ifdef TOOLS_MEM 140 mem::decrement(s_class().c_str()); 141 #endif 142 } 143 protected: 144 named(const named& a_from):iro(a_from),m_name(a_from.m_name),m_title(a_from.m_title) { 145 #ifdef TOOLS_MEM 146 mem::increment(s_class().c_str()); 147 #endif 148 } 149 named& operator=(const named& a_from){ 150 m_name = a_from.m_name; 151 m_title = a_from.m_title; 152 return *this; 153 } 154 protected: 155 std::string m_name; 156 std::string m_title; 157 }; 158 159 }} 160 161 #endif