Public Types | |
| typedef std::map< std::string, Type >::iterator | iterator |
Public Member Functions | |
| mxEternal (std::string name="etern.mxdb", mxEternalRW< Type > *typeobj=new mxEternalRW< Type >) | |
| void | setStreamRW (mxEternalRW< Type > *typeobjx) |
| int | read () |
| int | save () |
| const std::string | getName () const |
| Type & | operator[] (std::string n) |
| map< std::string, Type > * | operator-> () |
Definition at line 84 of file mxeternal.h.
| typedef std::map<std::string, Type>::iterator mx::mxEternal< Type >::iterator |
typedef
Definition at line 126 of file mxeternal.h.
| mx::mxEternal< Type >::mxEternal | ( | std::string | name = "etern.mxdb", |
|
| mxEternalRW< Type > * | typeobj = new mxEternalRW<Type> | |||
| ) | [inline] |
mxEternal default constructor
| name | name of file to write object stream to | |
| typeobj | read/write object containing object read/write functions |
Definition at line 174 of file mxeternal.h.
References mx::mxEternal< Type >::read().
00175 { 00176 typeobj = typeobject; 00177 name = vname; 00178 read(); 00179 }
| const std::string mx::mxEternal< Type >::getName | ( | ) | const [inline] |
get the name of the database file
Definition at line 109 of file mxeternal.h.
| map<std::string, Type>* mx::mxEternal< Type >::operator-> | ( | ) | [inline] |
overloaded -> operator
Definition at line 123 of file mxeternal.h.
| Type& mx::mxEternal< Type >::operator[] | ( | std::string | n | ) | [inline] |
overloaded [] operator for access object in array by n
| n | string for array access |
Definition at line 117 of file mxeternal.h.
| int mx::mxEternal< Type >::read | ( | ) | [inline] |
read the database from the file specified in constructor
Definition at line 195 of file mxeternal.h.
Referenced by mx::mxEternal< Type >::mxEternal().
00196 { 00197 00198 if(!this_map.empty()) this_map.erase(this_map.begin(), this_map.end()); 00199 00200 fobj.open(name.c_str(), std::ios::in | std::ios::binary); 00201 if(!fobj.is_open()) return 1; // no db or removed start over 00202 00203 unsigned int number_of_types = 0; 00204 00205 fobj.read((char*)&number_of_types, sizeof(number_of_types)); 00206 00207 for(unsigned int i = 0; (i < number_of_types) && (!fobj.eof()); i++) 00208 { 00209 unsigned int name_index = 0; 00210 fobj.read((char*)&name_index, sizeof(name_index)); 00211 00212 if(static_cast<int>(name_index) < 0) return -1; 00213 00214 char *buf = 0; 00215 00216 try 00217 { 00218 00219 buf = new char [ name_index+1 ]; 00220 fobj.read((char*)buf, name_index); 00221 buf[name_index] = 0; 00222 readType(); 00223 this_map[buf] = typedata; 00224 delete [] buf; 00225 buf = 0; 00226 00227 } 00228 catch (...) 00229 { 00230 00231 if(buf != 0) delete [] buf; 00232 00233 } 00234 00235 } 00236 fobj.close(); 00237 return 0; 00238 }
| int mx::mxEternal< Type >::save | ( | ) | [inline] |
write teh database to file specified in constructor
Definition at line 239 of file mxeternal.h.
00240 { 00241 00242 fobj_write.open(name.c_str(), std::ios::out | std::ios::binary); 00243 if(!fobj_write.is_open()) return -1; 00244 00245 unsigned int length = this_map.size(); 00246 00247 fobj_write.write((char*)&length, sizeof(length)); 00248 00249 typename mxEternal<Type>::iterator i; 00250 00251 for(i= this_map.begin(); i!=this_map.end(); i++) 00252 { 00253 00254 unsigned int len =i->first.length(); 00255 const char *str = i->first.c_str(); 00256 fobj_write.write((char*)&len, sizeof(len)); 00257 fobj_write.write((char*)str,len); 00258 typedata = i->second; 00259 writeType(); 00260 } 00261 00262 fobj_write.close(); 00263 return 0; 00264 00265 }
| void mx::mxEternal< Type >::setStreamRW | ( | mxEternalRW< Type > * | typeobjx | ) | [inline] |
setStreamRW set the current read/write stream
| typeobjx | current stream object pointer |
Definition at line 181 of file mxeternal.h.
1.5.8