inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_wroot_named 00005 #define inlib_wroot_named 00006 00007 #include "buffer" 00008 #include "../vmanip" 00009 #include "../vdata" 00010 00011 namespace inlib { 00012 namespace wroot { 00013 00014 inline bool Object_stream(buffer& a_buffer) { 00015 short v = 1; 00016 if(!a_buffer.write_version(v)) return false; 00017 if(!a_buffer.write((unsigned int)0)) return false; 00018 static const unsigned int kNotDeleted = 0x02000000; 00019 if(!a_buffer.write(kNotDeleted)) return false; 00020 return true; 00021 } 00022 00023 inline bool Named_stream(buffer& a_buffer, 00024 const std::string& a_name, 00025 const std::string& a_title) { 00026 unsigned int beg; 00027 if(!a_buffer.write_version(1,beg)) return false; 00028 if(!Object_stream(a_buffer)) return false; 00029 if(!a_buffer.write(a_name)) return false; 00030 if(!a_buffer.write(a_title)) return false; 00031 if(!a_buffer.set_byte_count(beg)) return false; 00032 return true; 00033 } 00034 00035 template <class T> 00036 class ObjArray : public virtual ibo, public std::vector<T*> { 00037 static unsigned int kNullTag() {return 0;} 00038 public: //ibo 00039 virtual const std::string& store_cls() const { 00040 static const std::string s_v("TObjArray"); 00041 return s_v; 00042 } 00043 virtual bool stream(buffer& a_buffer) const { 00044 unsigned int c; 00045 if(!a_buffer.write_version(3,c)) return false; 00046 if(!Object_stream(a_buffer)) return false; 00047 if(!a_buffer.write(std::string(""))) return false; 00048 int nobjects = std::vector<T*>::size(); 00049 if(!a_buffer.write(nobjects)) return false; 00050 int lowerBound = 0; 00051 if(!a_buffer.write(lowerBound)) return false; 00052 00053 typedef typename std::vector<T*>::const_iterator it_t; 00054 it_t it; 00055 for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) { 00056 if(*it) { 00057 if(!a_buffer.write_object(*(*it))) return false; 00058 } else { //Could happen with branch::m_baskets. 00059 if(!a_buffer.write(kNullTag())) return false; 00060 } 00061 } 00062 if(!a_buffer.set_byte_count(c)) return false; 00063 return true; 00064 } 00065 public: 00066 ObjArray(){} 00067 virtual ~ObjArray(){inlib::clear<T>(*this);} //WIN32 wants inlib:: 00068 public: 00069 ObjArray(const ObjArray& a_from): ibo(a_from),std::vector<T*>() { 00070 typedef typename std::vector<T*>::const_iterator it_t; 00071 it_t it; 00072 for(it=a_from.begin();it!=a_from.end();++it) { 00073 std::vector<T*>::push_back((*it)->copy()); 00074 } 00075 } 00076 ObjArray& operator=(const ObjArray& a_from){ 00077 inlib::clear<T>(*this); 00078 00079 typedef typename std::vector<T*>::const_iterator it_t; 00080 it_t it; 00081 for(it=a_from.begin();it!=a_from.end();++it) { 00082 std::vector<T*>::push_back((*it)->copy()); 00083 } 00084 return *this; 00085 } 00086 }; 00087 00088 template <class T> 00089 class List : public virtual ibo, public std::vector<T*> { 00090 public: //ibo 00091 virtual const std::string& store_cls() const { 00092 static const std::string s_v("TList"); 00093 return s_v; 00094 } 00095 virtual bool stream(buffer& a_buffer) const { 00096 unsigned int c; 00097 if(!a_buffer.write_version(4,c)) return false; 00098 if(!Object_stream(a_buffer)) return false; 00099 if(!a_buffer.write(std::string(""))) return false; //fName 00100 int nobjects = std::vector<T*>::size(); 00101 if(!a_buffer.write(nobjects)) return false; 00102 00103 typedef typename std::vector<T*>::const_iterator it_t; 00104 it_t it; 00105 for(it=std::vector<T*>::begin();it!=std::vector<T*>::end();++it) { 00106 if(!a_buffer.write_object(*(*it))) return false; 00107 std::string opt; 00108 unsigned char nch = opt.size(); 00109 if(!a_buffer.write(nch)) return false; 00110 if(!a_buffer.write_fast_array<char>(opt.c_str(),nch)) return false; 00111 } 00112 if(!a_buffer.set_byte_count(c)) return false; 00113 return true; 00114 } 00115 public: 00116 List(){} 00117 virtual ~List(){inlib::clear<T>(*this);} //WIN32 wants inlib:: 00118 protected: 00119 List(const List& a_from): ibo(a_from),std::vector<T*>(){} 00120 List& operator=(const List&){return *this;} 00121 }; 00122 00123 inline bool AttLine_stream(buffer& a_buffer){ 00124 short fLineColor = 1; 00125 short fLineStyle = 1; 00126 short fLineWidth = 1; 00127 unsigned int c; 00128 if(!a_buffer.write_version(1,c)) return false; 00129 if(!a_buffer.write(fLineColor)) return false; 00130 if(!a_buffer.write(fLineStyle)) return false; 00131 if(!a_buffer.write(fLineWidth)) return false; 00132 if(!a_buffer.set_byte_count(c)) return false; 00133 return true; 00134 } 00135 00136 inline bool AttFill_stream(buffer& a_buffer){ 00137 short fFillColor = 0; 00138 short fFillStyle = 101; 00139 unsigned int c; 00140 if(!a_buffer.write_version(1,c)) return false; 00141 if(!a_buffer.write(fFillColor)) return false; 00142 if(!a_buffer.write(fFillStyle)) return false; 00143 if(!a_buffer.set_byte_count(c)) return false; 00144 return true; 00145 } 00146 00147 inline bool AttMarker_stream(buffer& a_buffer) { 00148 short fMarkerColor = 1; 00149 short fMarkerStyle = 1; 00150 float fMarkerWidth = 1; 00151 unsigned int c; 00152 if(!a_buffer.write_version(1,c)) return false; 00153 if(!a_buffer.write(fMarkerColor)) return false; 00154 if(!a_buffer.write(fMarkerStyle)) return false; 00155 if(!a_buffer.write(fMarkerWidth)) return false; 00156 if(!a_buffer.set_byte_count(c)) return false; 00157 return true; 00158 } 00159 00160 template <class T> 00161 inline bool Array_stream(buffer& a_buffer,const std::vector<T>& a_v) { 00162 if(!a_buffer.write((int)a_v.size())) return false; 00163 if(!a_buffer.write_fast_array(vec_data(a_v),a_v.size())) return false; 00164 return true; 00165 } 00166 00167 }} 00168 00169 #endif