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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/sg/mf (Version 11.3.0) and /externals/g4tools/include/tools/sg/mf (Version 10.7.p3)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_sg_mf                               
  5 #define tools_sg_mf                               
  6                                                   
  7 // mf for multiple field.                         
  8                                                   
  9 #include "bmf"                                    
 10                                                   
 11 #include "../stype"                               
 12 #include "../cstr"                                
 13 #include "../io/iwbuf"                            
 14 #include "../io/irbuf"                            
 15 #include "../HEADER"                              
 16                                                   
 17 namespace tools {                                 
 18 namespace sg {                                    
 19                                                   
 20 template <class T>                                
 21 class mf : public bmf<T> {                        
 22   typedef bmf<T> parent;                          
 23 public:                                           
 24   static const std::string& s_class() {           
 25     static const std::string s_v("tools::sg::m    
 26     return s_v;                                   
 27   }                                               
 28   virtual void* cast(const std::string& a_clas    
 29     if(void* p = cmp_cast< mf<T> >(this,a_clas    
 30     return parent::cast(a_class);                 
 31   }                                               
 32   virtual const std::string& s_cls() const {re    
 33 public:                                           
 34   virtual bool write(io::iwbuf& a_buffer) {       
 35     const std::vector<T>& vec = parent::m_valu    
 36     return a_buffer.write_vec((uint32)vec.size    
 37   }                                               
 38   virtual bool read(io::irbuf& a_buffer) {        
 39     std::vector<T>& vec = parent::m_values;       
 40     return a_buffer.read_std_vec(vec);            
 41   }                                               
 42   virtual bool dump(std::ostream& a_out) {        
 43     const std::vector<T>& vec = parent::m_valu    
 44     a_out << "size : " << vec.size() << std::e    
 45     typedef typename std::vector<T>::const_ite    
 46     for(cit_t it=vec.begin();it!=vec.end();++i    
 47       a_out << "  " << (*it) << std::endl;        
 48     }                                             
 49     return true;                                  
 50   }                                               
 51   virtual bool s_value(std::string& a_s) const    
 52   virtual bool s2value(const std::string&) {re    
 53 public:                                           
 54   mf(){}                                          
 55   mf(const T& a_v):parent(a_v){}                  
 56   mf(const std::vector<T>& a_v):parent(a_v){}     
 57   virtual ~mf(){}                                 
 58 public:                                           
 59   mf(const mf& a_from):parent(a_from){}           
 60   mf& operator=(const mf& a_from){                
 61     //typedef typename parent::iterator bmf_t;    
 62     parent::operator=(a_from);                    
 63     return *this;                                 
 64   }                                               
 65 public:                                           
 66   mf& operator=(const std::vector<T>& a_from){    
 67     parent::operator=(a_from);                    
 68     return *this;                                 
 69   }                                               
 70   mf& operator=(const T& a_v){                    
 71     parent::operator=(a_v);                       
 72     return *this;                                 
 73   }                                               
 74 };                                                
 75                                                   
 76 class mf_string : public bmf<std::string> {       
 77   TOOLS_HEADER(mf_string,tools::sg::mf_string,    
 78 public:                                           
 79   virtual bool write(io::iwbuf& a_buffer) {       
 80     return a_buffer.write_vec(m_values);          
 81   }                                               
 82   virtual bool read(io::irbuf& a_buffer) {        
 83     std::vector<std::string>& vec = parent::m_    
 84     return a_buffer.read_vec(vec);                
 85   }                                               
 86   virtual bool dump(std::ostream& a_out) {        
 87     const std::vector<std::string>& vec = pare    
 88     a_out << "size : " << vec.size() << std::e    
 89     std::vector<std::string>::const_iterator i    
 90     for(it=vec.begin();it!=vec.end();++it) {      
 91       a_out << "  \"" << (*it) << "\"" << std:    
 92     }                                             
 93     return true;                                  
 94   }                                               
 95   virtual bool s_value(std::string& a_s) const    
 96   virtual bool s2value(const std::string&) {re    
 97 public:                                           
 98   mf_string():parent(){}                          
 99   mf_string(const std::string& a_v):parent(a_v    
100   mf_string(const std::vector<std::string>& a_    
101   virtual ~mf_string(){}                          
102 public:                                           
103   mf_string(const mf_string& a_from):parent(a_    
104   mf_string& operator=(const mf_string& a_from    
105     parent::operator=(a_from);                    
106     return *this;                                 
107   }                                               
108 public:                                           
109   mf_string& operator=(const std::vector<std::    
110     parent::operator=(a_value);                   
111     return *this;                                 
112   }                                               
113   mf_string& operator=(const char* a_cstr){       
114     parent::operator=(a_cstr);                    
115     return *this;                                 
116   }                                               
117 };                                                
118                                                   
119 //exa tools::sg::entries.mf_vec<entry_type>       
120                                                   
121 template <class T>                                
122 class mf_enum : public bmf<T> {                   
123   typedef bmf<T> parent;                          
124 public:                                           
125   static const std::string& s_class() {           
126     static const std::string s_v("tools::sg::m    
127     return s_v;                                   
128   }                                               
129   virtual void* cast(const std::string& a_clas    
130     if(void* p = cmp_cast< mf_enum<T> >(this,a    
131     return parent::cast(a_class);                 
132   }                                               
133   virtual const std::string& s_cls() const {re    
134 public:                                           
135   virtual bool write(io::iwbuf& a_buffer) {       
136     const std::vector<T>& vec = parent::m_valu    
137     std::vector<int16> v; //an enum can be neg    
138     typedef typename std::vector<T>::const_ite    
139     for(cit_t it=vec.begin();it!=vec.end();++i    
140     return a_buffer.write_vec((uint32)v.size()    
141   }                                               
142   virtual bool read(io::irbuf& a_buffer) {        
143     std::vector<int16> v; //an enum can be neg    
144     if(!a_buffer.read_std_vec(v)) return false    
145     std::vector<T>& vec = parent::m_values;       
146     vec.clear();                                  
147     std::vector<int16>::const_iterator it;        
148     for(it=v.begin();it!=v.end();++it) vec.pus    
149     return true;                                  
150   }                                               
151   virtual bool dump(std::ostream& a_out) {        
152     const std::vector<T>& vec = parent::m_valu    
153     a_out << "size : " << vec.size() << std::e    
154     typedef typename std::vector<T>::const_ite    
155     for(cit_t it=vec.begin();it!=vec.end();++i    
156       a_out << "  " << (*it) << std::endl;        
157     }                                             
158     return true;                                  
159   }                                               
160   virtual bool s_value(std::string& a_s) const    
161   virtual bool s2value(const std::string&) {re    
162 public:                                           
163   mf_enum():parent(){}                            
164   mf_enum(const T& a_v):parent(a_v){}             
165   mf_enum(const std::vector<T>& a_v):parent(a_    
166   virtual ~mf_enum(){}                            
167 public:                                           
168   mf_enum(const mf_enum& a_from):parent(a_from    
169   mf_enum& operator=(const mf_enum& a_from){      
170     parent::operator=(a_from);                    
171     return *this;                                 
172   }                                               
173 };                                                
174                                                   
175 //exa mf_vec<colorf,float>                        
176                                                   
177 //////////////////////////////////////////////    
178 //the three below funcs are for :                 
179 //  mf_vec< std::vector<std::string> ,std::str    
180 //////////////////////////////////////////////    
181 inline std::ostream& operator<<(std::ostream&     
182   //for mf_vec::dump.                             
183   return a_out;                                   
184 }                                                 
185                                                   
186 inline bool set_from_vec(std::vector<std::stri    
187   //for mf_vec::read(io::irbuf&)                  
188   return false;                                   
189 }                                                 
190                                                   
191 inline const std::string* get_data(const std::    
192   return vec_data(a_v);                           
193 }                                                 
194 //////////////////////////////////////////////    
195 //////////////////////////////////////////////    
196 //////////////////////////////////////////////    
197                                                   
198                                                   
199 template <class T,class TT>                       
200 class mf_vec : public bmf<T> {                    
201   typedef bmf<T> parent;                          
202 public:                                           
203   static const std::string& s_class() {           
204     static const std::string s_v("tools::sg::m    
205     return s_v;                                   
206   }                                               
207   virtual void* cast(const std::string& a_clas    
208     if(void* p = cmp_cast< mf_vec<T,TT> >(this    
209     return parent::cast(a_class);                 
210   }                                               
211   virtual const std::string& s_cls() const {re    
212 public:                                           
213   virtual bool write(io::iwbuf& a_buffer) {       
214     const std::vector<T>& vec = parent::m_valu    
215     typedef typename std::vector<TT> vec_t;       
216     std::vector<vec_t> vec_vec;                   
217     typedef typename std::vector<T>::const_ite    
218     for(cit_t it=vec.begin();it!=vec.end();++i    
219                                                   
220       const T& v = (*it);                         
221       size_t num = v.size();                      
222       const TT* d = get_data(v);                  
223                                                   
224       std::vector<TT> std_vec(num);               
225       for(size_t i=0;i<num;i++) std_vec[i] = d    
226                                                   
227       vec_vec.push_back(std_vec);                 
228     }                                             
229     return a_buffer.write_std_vec_vec(vec_vec)    
230   }                                               
231   virtual bool read(io::irbuf& a_buffer) {        
232     std::vector<T>& vec = parent::m_values;       
233     vec.clear();                                  
234     typedef typename std::vector<TT> vec_t;       
235     std::vector<vec_t> vec_vec;                   
236     if(!a_buffer.read_std_vec_vec(vec_vec)) re    
237     typedef typename std::vector<vec_t>::itera    
238     for(_it_t it=vec_vec.begin();it!=vec_vec.e    
239       T x;                                        
240       // x colorf, *it = std::vector<float>       
241       // x vecs, *it = std::vector<std::string    
242       if(!set_from_vec(x,*it)) {vec.clear();re    
243       vec.push_back(x);                           
244     }                                             
245     return true;                                  
246   }                                               
247   virtual bool dump(std::ostream& a_out) {        
248     const std::vector<T>& vec = parent::m_valu    
249     a_out << "size : " << vec.size() << std::e    
250     typedef typename std::vector<T>::const_ite    
251     for(cit_t it=vec.begin();it!=vec.end();++i    
252       a_out << "  " << (*it) << std::endl;        
253     }                                             
254     return true;                                  
255   }                                               
256   virtual bool s_value(std::string& a_s) const    
257   virtual bool s2value(const std::string&) {re    
258 public:                                           
259   mf_vec():parent(){}                             
260   mf_vec(const T& a_v):parent(a_v){}              
261   mf_vec(const std::vector<T>& a_v):parent(a_v    
262   virtual ~mf_vec(){}                             
263 public:                                           
264   mf_vec(const mf_vec& a_from):parent(a_from){    
265   mf_vec& operator=(const mf_vec& a_from){        
266     parent::operator=(a_from);                    
267     return *this;                                 
268   }                                               
269 };                                                
270                                                   
271 template <class T>                                
272 class mf_std_vec : public bmf< std::vector<T>     
273   typedef bmf< std::vector<T> > parent;           
274 public:                                           
275   static const std::string& s_class() {           
276     static const std::string s_v("tools::sg::m    
277     return s_v;                                   
278   }                                               
279   virtual void* cast(const std::string& a_clas    
280     if(void* p = cmp_cast< mf_std_vec<T> >(thi    
281     return parent::cast(a_class);                 
282   }                                               
283   virtual const std::string& s_cls() const {re    
284 public:                                           
285   virtual bool write(io::iwbuf& a_buffer) {       
286     //used in exlib/sg/text_freetype::unitext     
287     const std::vector< std::vector<T> >& vec =    
288     return a_buffer.write_std_vec_vec(vec);       
289   }                                               
290   virtual bool read(io::irbuf& a_buffer) {        
291     std::vector< std::vector<T> >& vec = paren    
292     return a_buffer.read_std_vec_vec(vec);        
293   }                                               
294   virtual bool dump(std::ostream& a_out) {        
295     const std::vector< std::vector<T> >& vec =    
296     a_out << "size : " << vec.size() << std::e    
297     typedef typename std::vector< std::vector<    
298     for(cit_t it=vec.begin();it!=vec.end();++i    
299       //a_out << "  " << (*it) << std::endl;      
300     }                                             
301     return true;                                  
302   }                                               
303   virtual bool s_value(std::string& a_s) const    
304   virtual bool s2value(const std::string&) {re    
305 public:                                           
306   mf_std_vec():parent(){}                         
307   mf_std_vec(const T& a_v):parent(a_v){}          
308   mf_std_vec(const std::vector<T>& a_v):parent    
309   virtual ~mf_std_vec(){}                         
310 public:                                           
311   mf_std_vec(const mf_std_vec& a_from):parent(    
312   mf_std_vec& operator=(const mf_std_vec& a_fr    
313     parent::operator=(a_from);                    
314     return *this;                                 
315   }                                               
316 };                                                
317                                                   
318 }}                                                
319                                                   
320 #endif