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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/rroot/stl_vector (Version 11.3.0) and /externals/g4tools/include/tools/rroot/stl_vector (Version 11.2.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_rroot_stl_vector                      4 #ifndef tools_rroot_stl_vector
  5 #define tools_rroot_stl_vector                      5 #define tools_rroot_stl_vector
  6                                                     6 
  7 #include "buffer"                                   7 #include "buffer"
  8 #include "cids"                                     8 #include "cids"
  9                                                     9 
 10 #include "../stype"                                10 #include "../stype"
 11 #include "../scast"                                11 #include "../scast"
 12 #include "../cids"                                 12 #include "../cids"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace rroot {                                  15 namespace rroot {
 16                                                    16 
 17 template <class T>                                 17 template <class T>
 18 class stl_vector : public virtual iro, public      18 class stl_vector : public virtual iro, public std::vector<T> {
 19   static const std::string& s_store_class() {      19   static const std::string& s_store_class() {
 20     static const std::string s_v("vector<"+sty     20     static const std::string s_v("vector<"+stype(T())+">");
 21     return s_v;                                    21     return s_v;
 22   }                                                22   }
 23 public:                                            23 public:
 24   static const std::string& s_class() {            24   static const std::string& s_class() {
 25     static const std::string s_v("tools::rroot     25     static const std::string s_v("tools::rroot::stl_vector<"+stype(T())+">");
 26     return s_v;                                    26     return s_v;
 27   }                                                27   }
 28 public: //iro                                      28 public: //iro
 29   virtual void* cast(const std::string& a_clas     29   virtual void* cast(const std::string& a_class) const {
 30     if(void* p = cmp_cast< stl_vector<T> >(thi     30     if(void* p = cmp_cast< stl_vector<T> >(this,a_class)) return p;
 31     return 0;                                      31     return 0;
 32   }                                                32   }
 33   virtual const std::string& s_cls() const {re     33   virtual const std::string& s_cls() const {return s_class();}
 34 public:                                            34 public:
 35   static cid id_class() {return stl_vector_cid     35   static cid id_class() {return stl_vector_cid()+_cid(T());}
 36   virtual void* cast(cid a_class) const {          36   virtual void* cast(cid a_class) const {
 37     if(void* p = cmp_cast< stl_vector<T> >(thi     37     if(void* p = cmp_cast< stl_vector<T> >(this,a_class)) {return p;}
 38     return 0;                                      38     return 0;
 39   }                                                39   }
 40   virtual iro* copy() const {return new stl_ve     40   virtual iro* copy() const {return new stl_vector<T>(*this);}
 41   virtual bool stream(buffer& a_buffer) {          41   virtual bool stream(buffer& a_buffer) {
 42     std::vector<T>::clear();                       42     std::vector<T>::clear();
 43                                                    43 
 44     short v;                                       44     short v;
 45     unsigned int _s,_c;                            45     unsigned int _s,_c;
 46     if(!a_buffer.read_version(v,_s,_c)) return     46     if(!a_buffer.read_version(v,_s,_c)) return false;
 47                                                    47 
 48     //::printf("debug : stl_vector::stream<%s>     48     //::printf("debug : stl_vector::stream<%s> : version %d, byte count %d\n",
 49     //   stype(T()).c_str(),v,c);                  49     //   stype(T()).c_str(),v,c);
 50                                                    50 
 51     unsigned int num;                              51     unsigned int num;
 52     if(!a_buffer.read(num)) return false;          52     if(!a_buffer.read(num)) return false;
 53                                                    53 
 54     //::printf("debug : stl_vector : %d\n",num     54     //::printf("debug : stl_vector : %d\n",num);
 55                                                    55 
 56     if(num) {                                      56     if(num) {
 57       T* vec = new T[num];                         57       T* vec = new T[num];
 58       if(!a_buffer.read_fast_array<T>(vec,num)     58       if(!a_buffer.read_fast_array<T>(vec,num)) {
 59         delete [] vec;                             59         delete [] vec;
 60         return false;                              60         return false;
 61       }                                            61       }
 62       std::vector<T>::resize(num);                 62       std::vector<T>::resize(num);
 63       T* pos = vec;                                63       T* pos = vec;
 64       for(unsigned int index=0;index<num;index     64       for(unsigned int index=0;index<num;index++,pos++) {
 65         std::vector<T>::operator[](index) = *p     65         std::vector<T>::operator[](index) = *pos;
 66       }                                            66       }
 67       delete [] vec;                               67       delete [] vec;
 68     }                                              68     }
 69                                                    69 
 70     return a_buffer.check_byte_count(_s,_c,s_s     70     return a_buffer.check_byte_count(_s,_c,s_store_class());
 71   }                                                71   }
 72 public:                                            72 public:
 73   stl_vector(){                                    73   stl_vector(){
 74 #ifdef TOOLS_MEM                                   74 #ifdef TOOLS_MEM
 75     mem::increment(s_class().c_str());             75     mem::increment(s_class().c_str());
 76 #endif                                             76 #endif
 77   }                                                77   }
 78   virtual ~stl_vector(){                           78   virtual ~stl_vector(){
 79 #ifdef TOOLS_MEM                                   79 #ifdef TOOLS_MEM
 80     mem::decrement(s_class().c_str());             80     mem::decrement(s_class().c_str());
 81 #endif                                             81 #endif
 82   }                                                82   }
 83 public:                                            83 public:
 84   stl_vector(const stl_vector& a_from)             84   stl_vector(const stl_vector& a_from)
 85   :iro(a_from)                                     85   :iro(a_from)
 86   ,std::vector<T>(a_from)                          86   ,std::vector<T>(a_from)
 87   {                                                87   {
 88 #ifdef TOOLS_MEM                                   88 #ifdef TOOLS_MEM
 89     mem::increment(s_class().c_str());             89     mem::increment(s_class().c_str());
 90 #endif                                             90 #endif
 91   }                                                91   }
 92   stl_vector& operator=(const stl_vector& a_fr     92   stl_vector& operator=(const stl_vector& a_from){
 93     std::vector<T>::operator=(a_from);             93     std::vector<T>::operator=(a_from);
 94     return *this;                                  94     return *this;
 95   }                                                95   }
 96 };                                                 96 };
 97                                                    97 
 98 template <class T>                                 98 template <class T>
 99 class stl_vector_vector                            99 class stl_vector_vector
100 :public virtual iro                               100 :public virtual iro
101 ,public std::vector< std::vector<T> >             101 ,public std::vector< std::vector<T> >
102 {                                                 102 {
103   static const std::string& s_store_class() {     103   static const std::string& s_store_class() {
104     static const std::string s_v("vector<vecto    104     static const std::string s_v("vector<vector<"+stype(T())+"> >");
105     return s_v;                                   105     return s_v;
106   }                                               106   }
107 public:                                           107 public:
108   static const std::string& s_class() {           108   static const std::string& s_class() {
109     static const std::string s_v                  109     static const std::string s_v
110       ("tools::rroot::stl_vector_vector<"+styp    110       ("tools::rroot::stl_vector_vector<"+stype(T())+">");
111     return s_v;                                   111     return s_v;
112   }                                               112   }
113 public: //iro                                     113 public: //iro
114   virtual void* cast(const std::string& a_clas    114   virtual void* cast(const std::string& a_class) const {
115     if(void* p=cmp_cast< stl_vector_vector<T>     115     if(void* p=cmp_cast< stl_vector_vector<T> >(this,a_class)) return p;
116     return 0;                                     116     return 0;
117   }                                               117   }
118   virtual const std::string& s_cls() const {re    118   virtual const std::string& s_cls() const {return s_class();}
119 public:                                           119 public:
120   static cid id_class() {return stl_vector_vec    120   static cid id_class() {return stl_vector_vector_cid()+_cid(T());}
121   virtual void* cast(cid a_class) const {         121   virtual void* cast(cid a_class) const {
122     if(void* p = cmp_cast< stl_vector_vector<T    122     if(void* p = cmp_cast< stl_vector_vector<T> >(this,a_class)) {return p;}
123     return 0;                                     123     return 0;
124   }                                               124   }
125   virtual iro* copy() const {return new stl_ve    125   virtual iro* copy() const {return new stl_vector_vector<T>(*this);}
126   virtual bool stream(buffer& a_buffer) {         126   virtual bool stream(buffer& a_buffer) {
127     typedef typename std::vector<T> vec_t;        127     typedef typename std::vector<T> vec_t;
128     std::vector<vec_t>::clear();                  128     std::vector<vec_t>::clear();
129                                                   129 
130     short v;                                      130     short v;
131     unsigned int _s,_c;                           131     unsigned int _s,_c;
132     if(!a_buffer.read_version(v,_s,_c)) return    132     if(!a_buffer.read_version(v,_s,_c)) return false;
133                                                   133 
134     //::printf("debug : stl_vector_vector::str    134     //::printf("debug : stl_vector_vector::stream<%s> : version %d, byte count %d\n",stype(T()).c_str(),v,c);
135                                                   135 
136     unsigned int vecn;                            136     unsigned int vecn;
137     if(!a_buffer.read(vecn)) return false;        137     if(!a_buffer.read(vecn)) return false;
138                                                   138 
139     std::vector<vec_t>::resize(vecn);             139     std::vector<vec_t>::resize(vecn);
140     //::printf("debug : stl_vector_vector : %d    140     //::printf("debug : stl_vector_vector : %d\n",vecn);
141     for(unsigned int veci=0;veci<vecn;veci++)     141     for(unsigned int veci=0;veci<vecn;veci++) {
142       vec_t& elem = std::vector<vec_t>::operat    142       vec_t& elem = std::vector<vec_t>::operator[](veci);
143                                                   143 
144       unsigned int num;                           144       unsigned int num;
145       if(!a_buffer.read(num)) {                   145       if(!a_buffer.read(num)) {
146         std::vector<vec_t>::clear();              146         std::vector<vec_t>::clear();
147         return false;                             147         return false;
148       }                                           148       }
149       //::printf("debug : stl_vector_vector :     149       //::printf("debug : stl_vector_vector :   index %d num %d\n",veci,num);
150       if(num) {                                   150       if(num) {
151         T* vec = new T[num];                      151         T* vec = new T[num];
152         if(!a_buffer.read_fast_array<T>(vec,nu    152         if(!a_buffer.read_fast_array<T>(vec,num)) {
153           delete [] vec;                          153           delete [] vec;
154           std::vector<vec_t>::clear();            154           std::vector<vec_t>::clear();
155           return false;                           155           return false;
156         }                                         156         }
157         elem.resize(num);                         157         elem.resize(num);
158         T* pos = vec;                             158         T* pos = vec;
159         for(unsigned int index=0;index<num;ind    159         for(unsigned int index=0;index<num;index++,pos++) elem[index] = *pos;
160         delete [] vec;                            160         delete [] vec;
161       }                                           161       }
162     }                                             162     }
163                                                   163 
164     return a_buffer.check_byte_count(_s,_c,s_s    164     return a_buffer.check_byte_count(_s,_c,s_store_class());
165   }                                               165   }
166 public:                                           166 public:
167   stl_vector_vector(){                            167   stl_vector_vector(){
168 #ifdef TOOLS_MEM                                  168 #ifdef TOOLS_MEM
169     mem::increment(s_class().c_str());            169     mem::increment(s_class().c_str());
170 #endif                                            170 #endif
171   }                                               171   }
172   virtual ~stl_vector_vector(){                   172   virtual ~stl_vector_vector(){
173 #ifdef TOOLS_MEM                                  173 #ifdef TOOLS_MEM
174     mem::decrement(s_class().c_str());            174     mem::decrement(s_class().c_str());
175 #endif                                            175 #endif
176   }                                               176   }
177 public:                                           177 public:
178   stl_vector_vector(const stl_vector_vector& a    178   stl_vector_vector(const stl_vector_vector& a_from)
179   :iro(a_from)                                    179   :iro(a_from)
180   ,std::vector< std::vector<T> >(a_from)          180   ,std::vector< std::vector<T> >(a_from)
181   {                                               181   {
182 #ifdef TOOLS_MEM                                  182 #ifdef TOOLS_MEM
183     mem::increment(s_class().c_str());            183     mem::increment(s_class().c_str());
184 #endif                                            184 #endif
185   }                                               185   }
186   stl_vector_vector& operator=(const stl_vecto    186   stl_vector_vector& operator=(const stl_vector_vector& a_from){
187     std::vector< std::vector<T> >::operator=(a    187     std::vector< std::vector<T> >::operator=(a_from);
188     return *this;                                 188     return *this;
189   }                                               189   }
190 };                                                190 };
191                                                   191 
192 class stl_vector_string : public virtual iro,     192 class stl_vector_string : public virtual iro, public std::vector<std::string> {
193   static const std::string& s_store_class() {     193   static const std::string& s_store_class() {
194     static const std::string s_v("vector<strin    194     static const std::string s_v("vector<string>");
195     return s_v;                                   195     return s_v;
196   }                                               196   }
197 public:                                           197 public:
198   static const std::string& s_class() {           198   static const std::string& s_class() {
199     static const std::string s_v("tools::rroot    199     static const std::string s_v("tools::rroot::stl_vector_string");
200     return s_v;                                   200     return s_v;
201   }                                               201   }
202 public: //iro                                     202 public: //iro
203   virtual void* cast(const std::string& a_clas    203   virtual void* cast(const std::string& a_class) const {
204     if(void* p = cmp_cast<stl_vector_string>(t    204     if(void* p = cmp_cast<stl_vector_string>(this,a_class)) return p;
205     return 0;                                     205     return 0;
206   }                                               206   }
207   virtual const std::string& s_cls() const {re    207   virtual const std::string& s_cls() const {return s_class();}
208 public:                                           208 public:
209   static cid id_class() {return stl_vector_str    209   static cid id_class() {return stl_vector_string_cid();}
210   virtual void* cast(cid a_class) const {         210   virtual void* cast(cid a_class) const {
211     if(void* p = cmp_cast<stl_vector_string>(t    211     if(void* p = cmp_cast<stl_vector_string>(this,a_class)) {return p;}
212     return 0;                                     212     return 0;
213   }                                               213   }
214   virtual iro* copy() const {return new stl_ve    214   virtual iro* copy() const {return new stl_vector_string(*this);}
215   virtual bool stream(buffer& a_buffer) {         215   virtual bool stream(buffer& a_buffer) {
216     std::vector<std::string>::clear();            216     std::vector<std::string>::clear();
217                                                   217 
218     //uint32 startpos = a_buffer.length();        218     //uint32 startpos = a_buffer.length();
219                                                   219 
220     //WARNING : not tested yet.                   220     //WARNING : not tested yet.
221                                                   221 
222     short v;                                      222     short v;
223     unsigned int _s,_c;                           223     unsigned int _s,_c;
224     if(!a_buffer.read_version(v,_s,_c)) return    224     if(!a_buffer.read_version(v,_s,_c)) return false;
225                                                   225 
226     //::printf("debug : stl_vector_string::str    226     //::printf("debug : stl_vector_string::stream : version %d, byte count %d\n",v,c);
227                                                   227 
228     unsigned int num;                             228     unsigned int num;
229     if(!a_buffer.read(num)) return false;         229     if(!a_buffer.read(num)) return false;
230                                                   230 
231     //::printf("debug : stl_vector_string : %d    231     //::printf("debug : stl_vector_string : %d\n",num);
232                                                   232 
233     std::vector<std::string>::resize(num);        233     std::vector<std::string>::resize(num);
234     for(unsigned int index=0;index<num;index++    234     for(unsigned int index=0;index<num;index++) {
235       std::string& vs = std::vector<std::strin    235       std::string& vs = std::vector<std::string>::operator[](index);
236       if(!a_buffer.read(vs)) {                    236       if(!a_buffer.read(vs)) {
237         std::vector<std::string>::clear();        237         std::vector<std::string>::clear();
238         return false;                             238         return false;
239       }                                           239       }
240     }                                             240     }
241                                                   241 
242     //a_buffer.set_offset(startpos+_c+sizeof(u    242     //a_buffer.set_offset(startpos+_c+sizeof(unsigned int));
243                                                   243 
244     return a_buffer.check_byte_count(_s,_c,s_s    244     return a_buffer.check_byte_count(_s,_c,s_store_class());
245   }                                               245   }
246 public:                                           246 public:
247   stl_vector_string(){                            247   stl_vector_string(){
248 #ifdef TOOLS_MEM                                  248 #ifdef TOOLS_MEM
249     mem::increment(s_class().c_str());            249     mem::increment(s_class().c_str());
250 #endif                                            250 #endif
251   }                                               251   }
252   virtual ~stl_vector_string(){                   252   virtual ~stl_vector_string(){
253 #ifdef TOOLS_MEM                                  253 #ifdef TOOLS_MEM
254     mem::decrement(s_class().c_str());            254     mem::decrement(s_class().c_str());
255 #endif                                            255 #endif
256   }                                               256   }
257 public:                                           257 public:
258   stl_vector_string(const stl_vector_string& a    258   stl_vector_string(const stl_vector_string& a_from)
259   :iro(a_from)                                    259   :iro(a_from)
260   ,std::vector<std::string>(a_from)               260   ,std::vector<std::string>(a_from)
261   {                                               261   {
262 #ifdef TOOLS_MEM                                  262 #ifdef TOOLS_MEM
263     mem::increment(s_class().c_str());            263     mem::increment(s_class().c_str());
264 #endif                                            264 #endif
265   }                                               265   }
266   stl_vector_string& operator=(const stl_vecto    266   stl_vector_string& operator=(const stl_vector_string& a_from){
267     std::vector<std::string>::operator=(a_from    267     std::vector<std::string>::operator=(a_from);
268     return *this;                                 268     return *this;
269   }                                               269   }
270 };                                                270 };
271                                                   271 
272 }}                                                272 }}
273                                                   273 
274 #endif                                            274 #endif