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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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_wroot_named
  5 #define tools_wroot_named
  6 
  7 #include "buffer"
  8 #include "../vmanip"
  9 //#include "../vdata"
 10 
 11 namespace tools {
 12 namespace wroot {
 13 
 14 inline bool Object_stream(buffer& a_buffer) {
 15   short v = 1;
 16   if(!a_buffer.write_version(v)) return false;
 17   if(!a_buffer.write((unsigned int)0)) return false;
 18   static const unsigned int kNotDeleted = 0x02000000;
 19   if(!a_buffer.write(kNotDeleted)) return false;
 20   return true;
 21 }
 22 
 23 inline bool Named_stream(buffer& a_buffer,const std::string& a_name,const std::string& a_title) {
 24   unsigned int beg;
 25   if(!a_buffer.write_version(1,beg)) return false;
 26   if(!Object_stream(a_buffer)) return false;
 27   if(!a_buffer.write(a_name)) return false;
 28   if(!a_buffer.write(a_title)) return false;
 29   if(!a_buffer.set_byte_count(beg)) return false;
 30   return true;
 31 }
 32 
 33 template <class T>
 34 class obj_array : public virtual ibo, public std::vector<T*> {
 35   static unsigned int kNullTag() {return 0;}
 36 public: //ibo
 37   virtual const std::string& store_cls() const {
 38     static const std::string s_v("TObjArray");
 39     return s_v;
 40   }
 41   virtual bool stream(buffer& a_buffer) const {
 42     unsigned int c;
 43     if(!a_buffer.write_version(3,c)) return false;
 44     if(!Object_stream(a_buffer)) return false;
 45     if(!a_buffer.write(std::string(""))) return false;
 46     int nobjects = int(std::vector<T*>::size());
 47     if(!a_buffer.write(nobjects)) return false;
 48     int lowerBound = 0;
 49     if(!a_buffer.write(lowerBound)) return false;
 50 
 51     typedef typename std::vector<T*>::const_iterator it_t;
 52     it_t it;
 53     for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) {
 54       if(*it) {
 55         if(!a_buffer.write_object(*(*it))) return false;
 56       } else { //Could happen with branch::m_baskets.
 57         if(!a_buffer.write(kNullTag())) return false;
 58       }
 59     }
 60     if(!a_buffer.set_byte_count(c)) return false;
 61     return true;
 62   }
 63 public:
 64   obj_array(){}
 65   virtual ~obj_array(){safe_clear<T>(*this);}
 66 public:
 67   obj_array(const obj_array& a_from): ibo(a_from),std::vector<T*>() {
 68     typedef typename std::vector<T*>::const_iterator it_t;
 69     it_t it;
 70     for(it=a_from.begin();it!=a_from.end();++it) {
 71       std::vector<T*>::push_back((*it)->copy());
 72     }
 73   }
 74   obj_array& operator=(const obj_array& a_from){
 75     if(&a_from==this) return *this;
 76     safe_clear<T>(*this);
 77 
 78     typedef typename std::vector<T*>::const_iterator it_t;
 79     it_t it;
 80     for(it=a_from.begin();it!=a_from.end();++it) {
 81       std::vector<T*>::push_back((*it)->copy());
 82     }
 83     return *this;
 84   }
 85 public:
 86   void clear_objs() {safe_clear<T>(*this);}
 87 };
 88 
 89 template <class T>
 90 class obj_list : public virtual ibo, public std::vector<T*> {
 91 public: //ibo
 92   virtual const std::string& store_cls() const {
 93     static const std::string s_v("TList");
 94     return s_v;
 95   }
 96   virtual bool stream(buffer& a_buffer) const {
 97     unsigned int c;
 98     if(!a_buffer.write_version(4,c)) return false;
 99     if(!Object_stream(a_buffer)) return false;
100     if(!a_buffer.write(std::string(""))) return false; //fName
101     int nobjects = int(std::vector<T*>::size());
102     if(!a_buffer.write(nobjects)) return false;
103 
104     typedef typename std::vector<T*>::const_iterator it_t;
105     it_t it;
106     for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) {
107       if(!a_buffer.write_object(*(*it))) return false;
108       std::string opt;
109       unsigned char nch = (unsigned char)opt.size();
110       if(!a_buffer.write(nch)) return false;
111       if(!a_buffer.write_fast_array<char>(opt.c_str(),nch)) return false;
112     }
113     if(!a_buffer.set_byte_count(c)) return false;
114     return true;
115   }
116 public:
117   obj_list(){}
118   virtual ~obj_list(){safe_clear<T>(*this);}
119 protected:
120   obj_list(const obj_list& a_from):ibo(a_from),std::vector<T*>(){}
121   obj_list& operator=(const obj_list&){return *this;}
122 };
123 
124 inline bool AttLine_stream(buffer& a_buffer){
125   short fLineColor = 1;
126   short fLineStyle = 1;
127   short fLineWidth = 1;
128   unsigned int c;
129   if(!a_buffer.write_version(1,c)) return false;
130   if(!a_buffer.write(fLineColor)) return false;
131   if(!a_buffer.write(fLineStyle)) return false;
132   if(!a_buffer.write(fLineWidth)) return false;
133   if(!a_buffer.set_byte_count(c)) return false;
134   return true;
135 }
136 
137 inline bool AttFill_stream(buffer& a_buffer){
138   short fFillColor = 0;
139   short fFillStyle = 101;
140   unsigned int c;
141   if(!a_buffer.write_version(1,c)) return false;
142   if(!a_buffer.write(fFillColor)) return false;
143   if(!a_buffer.write(fFillStyle)) return false;
144   if(!a_buffer.set_byte_count(c)) return false;
145   return true;
146 }
147 
148 inline bool AttMarker_stream(buffer& a_buffer) {
149   short fMarkerColor = 1;
150   short fMarkerStyle = 1;
151   float fMarkerWidth = 1;
152   unsigned int c;
153   if(!a_buffer.write_version(1,c)) return false;
154   if(!a_buffer.write(fMarkerColor)) return false;
155   if(!a_buffer.write(fMarkerStyle)) return false;
156   if(!a_buffer.write(fMarkerWidth)) return false;
157   if(!a_buffer.set_byte_count(c)) return false;
158   return true;
159 }
160 
161 inline bool Att3D_stream(buffer& a_buffer){
162   unsigned int c;
163   if(!a_buffer.write_version(1,c)) return false;
164   if(!a_buffer.set_byte_count(c)) return false;
165   return true;
166 }
167 
168 //template <class T>
169 //inline bool Array_stream(buffer& a_buffer,const std::vector<T>& a_v) {
170 //  if(!a_buffer.write((int)a_v.size())) return false;
171 //  if(!a_buffer.write_fast_array(vec_data(a_v),a_v.size())) return false;
172 //  return true;
173 //}
174 
175 }}
176 
177 #endif