Warning, /include/Geant4/tools/rroot/stl_vector 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_rroot_stl_vector
0005 #define tools_rroot_stl_vector
0006
0007 #include "buffer"
0008 #include "cids"
0009
0010 #include "../stype"
0011 #include "../scast"
0012 #include "../cids"
0013
0014 namespace tools {
0015 namespace rroot {
0016
0017 template <class T>
0018 class stl_vector : public virtual iro, public std::vector<T> {
0019 static const std::string& s_store_class() {
0020 static const std::string s_v("vector<"+stype(T())+">");
0021 return s_v;
0022 }
0023 public:
0024 static const std::string& s_class() {
0025 static const std::string s_v("tools::rroot::stl_vector<"+stype(T())+">");
0026 return s_v;
0027 }
0028 public: //iro
0029 virtual void* cast(const std::string& a_class) const {
0030 if(void* p = cmp_cast< stl_vector<T> >(this,a_class)) return p;
0031 return 0;
0032 }
0033 virtual const std::string& s_cls() const {return s_class();}
0034 public:
0035 static cid id_class() {return stl_vector_cid()+_cid(T());}
0036 virtual void* cast(cid a_class) const {
0037 if(void* p = cmp_cast< stl_vector<T> >(this,a_class)) {return p;}
0038 return 0;
0039 }
0040 virtual iro* copy() const {return new stl_vector<T>(*this);}
0041 virtual bool stream(buffer& a_buffer) {
0042 std::vector<T>::clear();
0043
0044 short v;
0045 unsigned int _s,_c;
0046 if(!a_buffer.read_version(v,_s,_c)) return false;
0047
0048 unsigned int num;
0049 if(!a_buffer.read(num)) return false;
0050
0051 if(num) {
0052 T* vec = new T[num];
0053 if(!a_buffer.read_fast_array<T>(vec,num)) {
0054 delete [] vec;
0055 return false;
0056 }
0057 std::vector<T>::resize(num);
0058 T* pos = vec;
0059 for(unsigned int index=0;index<num;index++,pos++) {
0060 std::vector<T>::operator[](index) = *pos;
0061 }
0062 delete [] vec;
0063 }
0064
0065 return a_buffer.check_byte_count(_s,_c,s_store_class());
0066 }
0067 public:
0068 stl_vector(){
0069 }
0070 virtual ~stl_vector(){
0071 }
0072 public:
0073 stl_vector(const stl_vector& a_from)
0074 :iro(a_from)
0075 ,std::vector<T>(a_from)
0076 {
0077 }
0078 stl_vector& operator=(const stl_vector& a_from){
0079 std::vector<T>::operator=(a_from);
0080 return *this;
0081 }
0082 };
0083
0084 template <class T>
0085 class stl_vector_vector
0086 :public virtual iro
0087 ,public std::vector< std::vector<T> >
0088 {
0089 static const std::string& s_store_class() {
0090 static const std::string s_v("vector<vector<"+stype(T())+"> >");
0091 return s_v;
0092 }
0093 public:
0094 static const std::string& s_class() {
0095 static const std::string s_v
0096 ("tools::rroot::stl_vector_vector<"+stype(T())+">");
0097 return s_v;
0098 }
0099 public: //iro
0100 virtual void* cast(const std::string& a_class) const {
0101 if(void* p=cmp_cast< stl_vector_vector<T> >(this,a_class)) return p;
0102 return 0;
0103 }
0104 virtual const std::string& s_cls() const {return s_class();}
0105 public:
0106 static cid id_class() {return stl_vector_vector_cid()+_cid(T());}
0107 virtual void* cast(cid a_class) const {
0108 if(void* p = cmp_cast< stl_vector_vector<T> >(this,a_class)) {return p;}
0109 return 0;
0110 }
0111 virtual iro* copy() const {return new stl_vector_vector<T>(*this);}
0112 virtual bool stream(buffer& a_buffer) {
0113 typedef typename std::vector<T> vec_t;
0114 std::vector<vec_t>::clear();
0115
0116 short v;
0117 unsigned int _s,_c;
0118 if(!a_buffer.read_version(v,_s,_c)) return false;
0119
0120 unsigned int vecn;
0121 if(!a_buffer.read(vecn)) return false;
0122
0123 std::vector<vec_t>::resize(vecn);
0124 for(unsigned int veci=0;veci<vecn;veci++) {
0125 vec_t& elem = std::vector<vec_t>::operator[](veci);
0126
0127 unsigned int num;
0128 if(!a_buffer.read(num)) {
0129 std::vector<vec_t>::clear();
0130 return false;
0131 }
0132 if(num) {
0133 T* vec = new T[num];
0134 if(!a_buffer.read_fast_array<T>(vec,num)) {
0135 delete [] vec;
0136 std::vector<vec_t>::clear();
0137 return false;
0138 }
0139 elem.resize(num);
0140 T* pos = vec;
0141 for(unsigned int index=0;index<num;index++,pos++) elem[index] = *pos;
0142 delete [] vec;
0143 }
0144 }
0145
0146 return a_buffer.check_byte_count(_s,_c,s_store_class());
0147 }
0148 public:
0149 stl_vector_vector(){
0150 }
0151 virtual ~stl_vector_vector(){
0152 }
0153 public:
0154 stl_vector_vector(const stl_vector_vector& a_from)
0155 :iro(a_from)
0156 ,std::vector< std::vector<T> >(a_from)
0157 {
0158 }
0159 stl_vector_vector& operator=(const stl_vector_vector& a_from){
0160 std::vector< std::vector<T> >::operator=(a_from);
0161 return *this;
0162 }
0163 };
0164
0165 class stl_vector_string : public virtual iro, public std::vector<std::string> {
0166 static const std::string& s_store_class() {
0167 static const std::string s_v("vector<string>");
0168 return s_v;
0169 }
0170 public:
0171 static const std::string& s_class() {
0172 static const std::string s_v("tools::rroot::stl_vector_string");
0173 return s_v;
0174 }
0175 public: //iro
0176 virtual void* cast(const std::string& a_class) const {
0177 if(void* p = cmp_cast<stl_vector_string>(this,a_class)) return p;
0178 return 0;
0179 }
0180 virtual const std::string& s_cls() const {return s_class();}
0181 public:
0182 static cid id_class() {return stl_vector_string_cid();}
0183 virtual void* cast(cid a_class) const {
0184 if(void* p = cmp_cast<stl_vector_string>(this,a_class)) {return p;}
0185 return 0;
0186 }
0187 virtual iro* copy() const {return new stl_vector_string(*this);}
0188 virtual bool stream(buffer& a_buffer) {
0189 std::vector<std::string>::clear();
0190
0191 short v;
0192 unsigned int _s,_c;
0193 if(!a_buffer.read_version(v,_s,_c)) return false;
0194
0195 unsigned int num;
0196 if(!a_buffer.read(num)) return false;
0197
0198 std::vector<std::string>::resize(num);
0199 for(unsigned int index=0;index<num;index++) {
0200 std::string& vs = std::vector<std::string>::operator[](index);
0201 if(!a_buffer.read(vs)) {
0202 std::vector<std::string>::clear();
0203 return false;
0204 }
0205 }
0206
0207 return a_buffer.check_byte_count(_s,_c,s_store_class());
0208 }
0209 public:
0210 stl_vector_string(){
0211 }
0212 virtual ~stl_vector_string(){
0213 }
0214 public:
0215 stl_vector_string(const stl_vector_string& a_from)
0216 :iro(a_from)
0217 ,std::vector<std::string>(a_from)
0218 {
0219 }
0220 stl_vector_string& operator=(const stl_vector_string& a_from){
0221 std::vector<std::string>::operator=(a_from);
0222 return *this;
0223 }
0224 };
0225
0226 }}
0227
0228 #endif