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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/sf_vec (Version 11.3.0) and /externals/g4tools/include/tools/sg/sf_vec (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_sg_sf_vec                             4 #ifndef tools_sg_sf_vec
  5 #define tools_sg_sf_vec                             5 #define tools_sg_sf_vec
  6                                                     6 
  7 #include "sf"                                       7 #include "sf"
  8                                                     8 
  9 #include "../words"                                 9 #include "../words"
 10                                                    10 
 11 namespace tools {                                  11 namespace tools {
 12 namespace sg {                                     12 namespace sg {
 13                                                    13 
 14 template <class T,class TT>  //exa sf_vec<colo     14 template <class T,class TT>  //exa sf_vec<colorf,float>
 15 class sf_vec : public bsf<T> {                     15 class sf_vec : public bsf<T> {
 16   typedef bsf<T> parent;                           16   typedef bsf<T> parent;
 17 public:                                            17 public:
 18   static const std::string& s_class() {            18   static const std::string& s_class() {
 19     static const std::string s_v("tools::sg::s     19     static const std::string s_v("tools::sg::sf_vec<"+stype(T())+","+stype(TT())+">");
 20     return s_v;                                    20     return s_v;
 21   }                                                21   }
 22   virtual void* cast(const std::string& a_clas     22   virtual void* cast(const std::string& a_class) const {
 23     if(void* p = cmp_cast< sf_vec<T,TT> >(this     23     if(void* p = cmp_cast< sf_vec<T,TT> >(this,a_class)) {return p;}
 24     return parent::cast(a_class);                  24     return parent::cast(a_class);
 25   }                                                25   }
 26   virtual const std::string& s_cls() const {re     26   virtual const std::string& s_cls() const {return s_class();}
 27 public:                                            27 public:
 28   virtual bool write(io::iwbuf& a_buffer) {        28   virtual bool write(io::iwbuf& a_buffer) {
 29     const T& vec = parent::m_value;                29     const T& vec = parent::m_value;
 30     const TT* d = get_data(vec);                   30     const TT* d = get_data(vec);
 31     return a_buffer.write_vec(vec.size(),d);       31     return a_buffer.write_vec(vec.size(),d);
 32   }                                                32   }
 33   virtual bool read(io::irbuf& a_buffer) {         33   virtual bool read(io::irbuf& a_buffer) {
 34     T& vec = parent::m_value;                      34     T& vec = parent::m_value;
 35     uint32 n;                                      35     uint32 n;
 36     TT* v;                                         36     TT* v;
 37     if(!a_buffer.read_vec(n,v)) {                  37     if(!a_buffer.read_vec(n,v)) {
 38       //::printf("debug : sf_vec::read : faile     38       //::printf("debug : sf_vec::read : failed(0).\n");
 39       return false;                                39       return false;
 40     }                                              40     }
 41     if(n!=vec.size()) {                            41     if(n!=vec.size()) {
 42       delete [] v;                                 42       delete [] v;
 43 #ifdef TOOLS_MEM                                   43 #ifdef TOOLS_MEM
 44       mem::decrement(s_new().c_str());             44       mem::decrement(s_new().c_str());
 45 #endif                                             45 #endif
 46       //::printf("debug : sf_vec::read : faile     46       //::printf("debug : sf_vec::read : failed(1) : %d (expected %d).\n",
 47       //    n,vec.size());                         47       //    n,vec.size());
 48       return false;                                48       return false;
 49     }                                              49     }
 50     for(uint32 index=0;index<n;index++) vec[in     50     for(uint32 index=0;index<n;index++) vec[index] = v[index];
 51     delete [] v;                                   51     delete [] v;
 52 #ifdef TOOLS_MEM                                   52 #ifdef TOOLS_MEM
 53     mem::decrement(s_new().c_str());               53     mem::decrement(s_new().c_str());
 54 #endif                                             54 #endif
 55     return true;                                   55     return true;
 56   }                                                56   }
 57   virtual bool dump(std::ostream& a_out) {         57   virtual bool dump(std::ostream& a_out) {
 58     a_out << parent::m_value << std::endl;         58     a_out << parent::m_value << std::endl;
 59     return true;                                   59     return true;
 60   }                                                60   }
 61   virtual bool s_value(std::string& a_s) const     61   virtual bool s_value(std::string& a_s) const {
 62     a_s.clear();                                   62     a_s.clear();
 63     const T& vec = parent::m_value;                63     const T& vec = parent::m_value;
 64     for(size_t index=0;index<vec.size();index+     64     for(size_t index=0;index<vec.size();index++) {
 65       if(index) a_s += ' ';                        65       if(index) a_s += ' ';
 66       std::ostringstream strm;                     66       std::ostringstream strm;
 67       strm << vec[index];                          67       strm << vec[index];
 68       a_s += strm.str();                           68       a_s += strm.str();
 69     }                                              69     }
 70     return true;                                   70     return true;
 71   }                                                71   }
 72   virtual bool s2value(const std::string& a_s)     72   virtual bool s2value(const std::string& a_s) {
 73     std::vector<std::string> ws;                   73     std::vector<std::string> ws;
 74     words(a_s," ",false,ws);                       74     words(a_s," ",false,ws);
 75     T& vec = parent::m_value;                      75     T& vec = parent::m_value;
 76     if(ws.size()!=vec.size()) return false;        76     if(ws.size()!=vec.size()) return false;
 77     T old_vec = vec;                               77     T old_vec = vec;
 78     for(size_t index=0;index<vec.size();index+     78     for(size_t index=0;index<vec.size();index++) {
 79       std::istringstream strm(ws[index].c_str(     79       std::istringstream strm(ws[index].c_str());
 80       TT v;                                        80       TT v;
 81       strm >> v;                                   81       strm >> v;
 82       if(strm.fail()) {                            82       if(strm.fail()) {
 83         vec = old_vec;                             83         vec = old_vec;
 84         return false;                              84         return false;
 85       }                                            85       }
 86       if(vec[index]!=v) parent::m_touched = tr     86       if(vec[index]!=v) parent::m_touched = true;
 87       vec[index] = v;                              87       vec[index] = v;
 88     }                                              88     }
 89     return true;                                   89     return true;
 90   }                                                90   }
 91 public:                                            91 public:
 92   sf_vec():parent(){}                              92   sf_vec():parent(){}
 93   sf_vec(const T& a_value):parent(a_value){}       93   sf_vec(const T& a_value):parent(a_value){}
 94   virtual ~sf_vec(){}                              94   virtual ~sf_vec(){}
 95 public:                                            95 public:
 96   sf_vec(const sf_vec& a_from)                     96   sf_vec(const sf_vec& a_from)
 97   :parent(a_from){}                                97   :parent(a_from){}
 98   sf_vec& operator=(const sf_vec& a_from){         98   sf_vec& operator=(const sf_vec& a_from){
 99     parent::operator=(a_from);                     99     parent::operator=(a_from);
100     return *this;                                 100     return *this;
101   }                                               101   }
102 public:                                           102 public:
103   sf_vec& operator=(const T& a_value){            103   sf_vec& operator=(const T& a_value){
104     parent::operator=(a_value);                   104     parent::operator=(a_value);
105     return *this;                                 105     return *this;
106   }                                               106   }
107   sf_vec& operator+=(const T& a_value) {          107   sf_vec& operator+=(const T& a_value) {
108     parent::value(parent::value()+a_value);       108     parent::value(parent::value()+a_value);
109     return *this;                                 109     return *this;
110   }                                               110   }
111 };                                                111 };
112                                                   112 
113 }}                                                113 }}
114                                                   114 
115 #endif                                            115 #endif