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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/bmf (Version 11.3.0) and /externals/g4tools/include/tools/sg/bmf (Version 11.1.1)


  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_bmf                                4 #ifndef tools_sg_bmf
  5 #define tools_sg_bmf                                5 #define tools_sg_bmf
  6                                                     6 
  7 // mf for multiple field.                           7 // mf for multiple field.
  8                                                     8 
  9 // bmf is intended to have no implementation o      9 // bmf is intended to have no implementation of :
 10 //   virtual bool write(io::iwbuf&)                10 //   virtual bool write(io::iwbuf&)
 11 //   virtual bool read(io::irbuf&)                 11 //   virtual bool read(io::irbuf&)
 12                                                    12 
 13 #include "field"                                   13 #include "field"
 14                                                    14 
 15 #include "../vdata"                                15 #include "../vdata"
 16                                                    16 
 17 namespace tools {                                  17 namespace tools {
 18 namespace sg {                                     18 namespace sg {
 19                                                    19 
 20 template <class T>                                 20 template <class T>
 21 class bmf : public field {                         21 class bmf : public field {
 22   typedef field parent;                            22   typedef field parent;
 23 public:                                            23 public:
 24   static const std::string& s_class() {            24   static const std::string& s_class() {
 25     //we do not use stype(T()).                    25     //we do not use stype(T()).
 26     static const std::string s_v("tools::sg::b     26     static const std::string s_v("tools::sg::bmf");
 27     return s_v;                                    27     return s_v;
 28   }                                                28   }
 29 //static bool is_a(const std::string& a_class)     29 //static bool is_a(const std::string& a_class) {return rcmp(a_class,s_class());}
 30   virtual void* cast(const std::string& a_clas     30   virtual void* cast(const std::string& a_class) const {
 31     if(void* p = cmp_cast< bmf<T> >(this,a_cla     31     if(void* p = cmp_cast< bmf<T> >(this,a_class)) {return p;}
 32     return parent::cast(a_class);                  32     return parent::cast(a_class);
 33   }                                                33   }
 34   virtual const std::string& s_cls() const {re     34   virtual const std::string& s_cls() const {return s_class();}
 35 public:                                            35 public:
 36   bmf(){}                                          36   bmf(){}
 37   bmf(const T& a_value) {m_values.push_back(a_     37   bmf(const T& a_value) {m_values.push_back(a_value);}
 38   bmf(const std::vector<T>& a_v) {m_values = a     38   bmf(const std::vector<T>& a_v) {m_values = a_v;}
 39   virtual ~bmf(){m_values.clear();}                39   virtual ~bmf(){m_values.clear();}
 40 public:                                            40 public:
 41   bmf(const bmf& a_from):parent(a_from),m_valu     41   bmf(const bmf& a_from):parent(a_from),m_values(a_from.m_values){}
 42   bmf& operator=(const bmf& a_from){               42   bmf& operator=(const bmf& a_from){
 43     parent::operator=(a_from);                     43     parent::operator=(a_from);
 44     if(a_from.m_values!=m_values) m_touched =      44     if(a_from.m_values!=m_values) m_touched = true;
 45     m_values = a_from.m_values;                    45     m_values = a_from.m_values;
 46     return *this;                                  46     return *this;
 47   }                                                47   }
 48 public:                                            48 public:
 49   bmf& operator=(const std::vector<T>& a_from)     49   bmf& operator=(const std::vector<T>& a_from){
 50     if(a_from!=m_values) m_touched = true;         50     if(a_from!=m_values) m_touched = true;
 51     m_values = a_from;                             51     m_values = a_from;
 52     return *this;                                  52     return *this;
 53   }                                                53   }
 54   bool operator==(const bmf& a_from) const {       54   bool operator==(const bmf& a_from) const {
 55     return m_values==a_from.m_values;              55     return m_values==a_from.m_values;
 56   }                                                56   }
 57   bool operator!=(const bmf& a_from) const {       57   bool operator!=(const bmf& a_from) const {
 58     return !operator==(a_from);                    58     return !operator==(a_from);
 59   }                                                59   }
 60   const T& operator[](size_t a_index) const {      60   const T& operator[](size_t a_index) const {
 61     //WARNING : no check is done on a_index.       61     //WARNING : no check is done on a_index.
 62     return m_values[a_index];                      62     return m_values[a_index];
 63   }                                                63   }
 64   T& operator[](size_t a_index) {                  64   T& operator[](size_t a_index) {
 65     //WARNING : no check is done on a_index.       65     //WARNING : no check is done on a_index.
 66     return m_values[a_index];                      66     return m_values[a_index];
 67   }                                                67   }
 68 public:                                            68 public:
 69   size_t size() const {return m_values.size();     69   size_t size() const {return m_values.size();}
 70   bool empty() const {return m_values.empty();     70   bool empty() const {return m_values.empty();}
 71   const std::vector<T>& values() const {return     71   const std::vector<T>& values() const {return m_values;}
 72   std::vector<T>& values() {return m_values;}      72   std::vector<T>& values() {return m_values;}
 73   void add(const T& a_value) {                     73   void add(const T& a_value) {
 74     m_values.push_back(a_value);                   74     m_values.push_back(a_value);
 75     m_touched = true;                              75     m_touched = true;
 76   }                                                76   }
 77   void add(const std::vector<T>& a_vals) {         77   void add(const std::vector<T>& a_vals) {
 78     if(a_vals.empty()) return;                     78     if(a_vals.empty()) return;
 79     typedef typename std::vector<T>::const_ite     79     typedef typename std::vector<T>::const_iterator const_it_t;
 80     for(const_it_t it=a_vals.begin();it!=a_val     80     for(const_it_t it=a_vals.begin();it!=a_vals.end();++it){
 81       m_values.push_back(*it);                     81       m_values.push_back(*it);
 82     }                                              82     }
 83     m_touched = true;                              83     m_touched = true;
 84   }                                                84   }
 85   void add_allocated(size_t& a_pos,const T& a_     85   void add_allocated(size_t& a_pos,const T& a_1,const T& a_2,const T& a_3) { //used in sg::plotter.
 86     std::vector<T>& v = m_values;                  86     std::vector<T>& v = m_values;
 87     v[a_pos] = a_1;a_pos++;                        87     v[a_pos] = a_1;a_pos++;
 88     v[a_pos] = a_2;a_pos++;                        88     v[a_pos] = a_2;a_pos++;
 89     v[a_pos] = a_3;a_pos++;                        89     v[a_pos] = a_3;a_pos++;
 90     m_touched = true;                              90     m_touched = true;
 91   }                                                91   }
 92   typedef typename std::vector<T>::iterator it     92   typedef typename std::vector<T>::iterator it_t;
 93   void insert(const it_t& a_it,const T& a_valu     93   void insert(const it_t& a_it,const T& a_value) {
 94     m_values.insert(a_it,a_value);                 94     m_values.insert(a_it,a_value);
 95     m_touched = true;                              95     m_touched = true;
 96   }                                                96   }
 97   bool set_value(size_t a_index,const T& a_val     97   bool set_value(size_t a_index,const T& a_value) {
 98     if(a_index>=m_values.size()) return false;     98     if(a_index>=m_values.size()) return false;
 99     if(m_values[a_index]!=a_value) m_touched =     99     if(m_values[a_index]!=a_value) m_touched = true;
100     m_values[a_index] = a_value;                  100     m_values[a_index] = a_value;
101     return true;                                  101     return true;
102   }                                               102   }
103   bool get_value(size_t a_index,T& a_value) {     103   bool get_value(size_t a_index,T& a_value) {
104     if(a_index>=m_values.size()) {a_value=T();    104     if(a_index>=m_values.size()) {a_value=T();return false;}
105     a_value = m_values[a_index];                  105     a_value = m_values[a_index];
106     return true;                                  106     return true;
107   }                                               107   }
108   void clear() {                                  108   void clear() {
109     if(m_values.size()) m_touched = true;         109     if(m_values.size()) m_touched = true;
110     m_values.clear();                             110     m_values.clear();
111   }                                               111   }
112                                                   112 
113   void set_values(const std::vector<T>& a_valu    113   void set_values(const std::vector<T>& a_values) {
114     if(a_values!=m_values) m_touched = true;      114     if(a_values!=m_values) m_touched = true;
115     m_values = a_values;                          115     m_values = a_values;
116   }                                               116   }
117   void set_value(const T& a_value) { //used in    117   void set_value(const T& a_value) { //used in ArcheryTune.
118     bool to_resize = m_values.size()==1?false:    118     bool to_resize = m_values.size()==1?false:true;
119     bool is_eq = ( (m_values.size()>=1) && (m_    119     bool is_eq = ( (m_values.size()>=1) && (m_values[0]==a_value) ) ? true : false;
120     if(to_resize) m_values.resize(1);             120     if(to_resize) m_values.resize(1);
121     if(to_resize || !is_eq) m_touched = true;     121     if(to_resize || !is_eq) m_touched = true;
122     m_values[0] = a_value;                        122     m_values[0] = a_value;
123   }                                               123   }
124                                                   124 
125 public: //for iv2sg                               125 public: //for iv2sg
126   //bool setValues(size_t a_index,size_t a_num    126   //bool setValues(size_t a_index,size_t a_num,const T* a_vs) {
127   //  for(size_t index=0;index<a_num;index++)     127   //  for(size_t index=0;index<a_num;index++) {
128   //    if(!set1Value(a_index+index,a_vs[index    128   //    if(!set1Value(a_index+index,a_vs[index])) return false;
129   //  }                                           129   //  }
130   //  return true;                                130   //  return true;
131   //}                                             131   //}
132                                                   132 
133   bool setValues(size_t a_index,size_t a_num,c    133   bool setValues(size_t a_index,size_t a_num,const T* a_vs) {
134     //  012345678                                 134     //  012345678
135     //    234                                     135     //    234
136     if((a_index+a_num)>=m_values.size()) m_val    136     if((a_index+a_num)>=m_values.size()) m_values.resize(a_index+a_num);
137     for(size_t index=0;index<a_num;index++) {     137     for(size_t index=0;index<a_num;index++) {
138       if(a_vs[index]!=m_values[a_index+index])    138       if(a_vs[index]!=m_values[a_index+index]) m_touched = true;
139       m_values[a_index+index] = a_vs[index];      139       m_values[a_index+index] = a_vs[index];
140     }                                             140     }
141     return true;                                  141     return true;
142   }                                               142   }
143                                                   143 
144   bool set1Value(size_t a_index,const T& a_val    144   bool set1Value(size_t a_index,const T& a_value) {
145     if(a_index>=m_values.size()) m_values.resi    145     if(a_index>=m_values.size()) m_values.resize(a_index+1);
146     if(m_values[a_index]!=a_value) m_touched =    146     if(m_values[a_index]!=a_value) m_touched = true;
147     m_values[a_index] = a_value;                  147     m_values[a_index] = a_value;
148     return true;                                  148     return true;
149   }                                               149   }
150   bool setValue(const T& a_value) {set_value(a    150   bool setValue(const T& a_value) {set_value(a_value);return true;}
151                                                   151 
152   bmf& operator=(const T& a_v){                   152   bmf& operator=(const T& a_v){
153     if(!setValue(a_v)) {}                         153     if(!setValue(a_v)) {}
154     return *this;                                 154     return *this;
155   }                                               155   }
156   size_t getNum() const {return m_values.size(    156   size_t getNum() const {return m_values.size();}
157   T* getValues(size_t a_start) { //for gopaw.     157   T* getValues(size_t a_start) { //for gopaw.
158     if(a_start>=(m_values.size()+1)) return 0;    158     if(a_start>=(m_values.size()+1)) return 0;
159     T* data = vec_data(m_values);                 159     T* data = vec_data(m_values);
160     return data+a_start;                          160     return data+a_start;
161   }                                               161   }
162 protected:                                        162 protected:
163   std::vector<T> m_values;                        163   std::vector<T> m_values;
164 };                                                164 };
165                                                   165 
166 }}                                                166 }}
167                                                   167 
168 #endif                                            168 #endif