Warning, /include/Geant4/tools/wroot/named 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_wroot_named
0005 #define tools_wroot_named
0006
0007 #include "buffer"
0008 #include "../vmanip"
0009 //#include "../vdata"
0010
0011 namespace tools {
0012 namespace wroot {
0013
0014 inline bool Object_stream(buffer& a_buffer) {
0015 short v = 1;
0016 if(!a_buffer.write_version(v)) return false;
0017 if(!a_buffer.write((unsigned int)0)) return false;
0018 static const unsigned int kNotDeleted = 0x02000000;
0019 if(!a_buffer.write(kNotDeleted)) return false;
0020 return true;
0021 }
0022
0023 inline bool Named_stream(buffer& a_buffer,const std::string& a_name,const std::string& a_title) {
0024 unsigned int beg;
0025 if(!a_buffer.write_version(1,beg)) return false;
0026 if(!Object_stream(a_buffer)) return false;
0027 if(!a_buffer.write(a_name)) return false;
0028 if(!a_buffer.write(a_title)) return false;
0029 if(!a_buffer.set_byte_count(beg)) return false;
0030 return true;
0031 }
0032
0033 template <class T>
0034 class obj_array : public virtual ibo, public std::vector<T*> {
0035 static unsigned int kNullTag() {return 0;}
0036 public: //ibo
0037 virtual const std::string& store_cls() const {
0038 static const std::string s_v("TObjArray");
0039 return s_v;
0040 }
0041 virtual bool stream(buffer& a_buffer) const {
0042 unsigned int c;
0043 if(!a_buffer.write_version(3,c)) return false;
0044 if(!Object_stream(a_buffer)) return false;
0045 if(!a_buffer.write(std::string(""))) return false;
0046 int nobjects = int(std::vector<T*>::size());
0047 if(!a_buffer.write(nobjects)) return false;
0048 int lowerBound = 0;
0049 if(!a_buffer.write(lowerBound)) return false;
0050
0051 typedef typename std::vector<T*>::const_iterator it_t;
0052 it_t it;
0053 for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) {
0054 if(*it) {
0055 if(!a_buffer.write_object(*(*it))) return false;
0056 } else { //Could happen with branch::m_baskets.
0057 if(!a_buffer.write(kNullTag())) return false;
0058 }
0059 }
0060 if(!a_buffer.set_byte_count(c)) return false;
0061 return true;
0062 }
0063 public:
0064 obj_array(){}
0065 virtual ~obj_array(){safe_clear<T>(*this);}
0066 public:
0067 obj_array(const obj_array& a_from): ibo(a_from),std::vector<T*>() {
0068 typedef typename std::vector<T*>::const_iterator it_t;
0069 it_t it;
0070 for(it=a_from.begin();it!=a_from.end();++it) {
0071 std::vector<T*>::push_back((*it)->copy());
0072 }
0073 }
0074 obj_array& operator=(const obj_array& a_from){
0075 if(&a_from==this) return *this;
0076 safe_clear<T>(*this);
0077
0078 typedef typename std::vector<T*>::const_iterator it_t;
0079 it_t it;
0080 for(it=a_from.begin();it!=a_from.end();++it) {
0081 std::vector<T*>::push_back((*it)->copy());
0082 }
0083 return *this;
0084 }
0085 public:
0086 void clear_objs() {safe_clear<T>(*this);}
0087 };
0088
0089 template <class T>
0090 class obj_list : public virtual ibo, public std::vector<T*> {
0091 public: //ibo
0092 virtual const std::string& store_cls() const {
0093 static const std::string s_v("TList");
0094 return s_v;
0095 }
0096 virtual bool stream(buffer& a_buffer) const {
0097 unsigned int c;
0098 if(!a_buffer.write_version(4,c)) return false;
0099 if(!Object_stream(a_buffer)) return false;
0100 if(!a_buffer.write(std::string(""))) return false; //fName
0101 int nobjects = int(std::vector<T*>::size());
0102 if(!a_buffer.write(nobjects)) return false;
0103
0104 typedef typename std::vector<T*>::const_iterator it_t;
0105 it_t it;
0106 for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) {
0107 if(!a_buffer.write_object(*(*it))) return false;
0108 std::string opt;
0109 unsigned char nch = (unsigned char)opt.size();
0110 if(!a_buffer.write(nch)) return false;
0111 if(!a_buffer.write_fast_array<char>(opt.c_str(),nch)) return false;
0112 }
0113 if(!a_buffer.set_byte_count(c)) return false;
0114 return true;
0115 }
0116 public:
0117 obj_list(){}
0118 virtual ~obj_list(){safe_clear<T>(*this);}
0119 protected:
0120 obj_list(const obj_list& a_from):ibo(a_from),std::vector<T*>(){}
0121 obj_list& operator=(const obj_list&){return *this;}
0122 };
0123
0124 inline bool AttLine_stream(buffer& a_buffer){
0125 short fLineColor = 1;
0126 short fLineStyle = 1;
0127 short fLineWidth = 1;
0128 unsigned int c;
0129 if(!a_buffer.write_version(1,c)) return false;
0130 if(!a_buffer.write(fLineColor)) return false;
0131 if(!a_buffer.write(fLineStyle)) return false;
0132 if(!a_buffer.write(fLineWidth)) return false;
0133 if(!a_buffer.set_byte_count(c)) return false;
0134 return true;
0135 }
0136
0137 inline bool AttFill_stream(buffer& a_buffer){
0138 short fFillColor = 0;
0139 short fFillStyle = 101;
0140 unsigned int c;
0141 if(!a_buffer.write_version(1,c)) return false;
0142 if(!a_buffer.write(fFillColor)) return false;
0143 if(!a_buffer.write(fFillStyle)) return false;
0144 if(!a_buffer.set_byte_count(c)) return false;
0145 return true;
0146 }
0147
0148 inline bool AttMarker_stream(buffer& a_buffer) {
0149 short fMarkerColor = 1;
0150 short fMarkerStyle = 1;
0151 float fMarkerWidth = 1;
0152 unsigned int c;
0153 if(!a_buffer.write_version(1,c)) return false;
0154 if(!a_buffer.write(fMarkerColor)) return false;
0155 if(!a_buffer.write(fMarkerStyle)) return false;
0156 if(!a_buffer.write(fMarkerWidth)) return false;
0157 if(!a_buffer.set_byte_count(c)) return false;
0158 return true;
0159 }
0160
0161 inline bool Att3D_stream(buffer& a_buffer){
0162 unsigned int c;
0163 if(!a_buffer.write_version(1,c)) return false;
0164 if(!a_buffer.set_byte_count(c)) return false;
0165 return true;
0166 }
0167
0168 //template <class T>
0169 //inline bool Array_stream(buffer& a_buffer,const std::vector<T>& a_v) {
0170 // if(!a_buffer.write((int)a_v.size())) return false;
0171 // if(!a_buffer.write_fast_array(vec_data(a_v),a_v.size())) return false;
0172 // return true;
0173 //}
0174
0175 }}
0176
0177 #endif