33 #ifndef __H__UG__SERIALIZATION__
34 #define __H__UG__SERIALIZATION__
155 template <
class TStream,
class T>
158 buf.write((
char*)&val,
sizeof(T));
161 template <
class TStream,
class T>
164 buf.read((
char*)&valOut,
sizeof(T));
168 template<
typename T,
class TIStream>
178 template <
class TStream,
class T>
185 template <
class T1,
class T2,
class TOStream>
186 void Serialize(TOStream& buf,
const std::pair<T1, T2>& v);
188 template <
class T1,
class T2,
class TIStream>
189 void Deserialize(TIStream& buf, std::pair<T1, T2>& v);
191 template <
class T,
class TOStream>
192 void Serialize(TOStream& buf,
const std::set<T>& m);
194 template <
class T,
class TIStream>
195 void Deserialize(TIStream& buf, std::set<T>& myset);
197 template <
class TOStream>
198 void Serialize(TOStream& buf,
const std::string& str);
200 template <
class TIStream>
203 template <
class TOStream>
206 template <
class TIStream>
209 template <
class T,
class TOStream>
210 void Serialize(TOStream& buf,
const std::vector<T>& vec);
212 template <
class T,
class TIStream>
213 void Deserialize(TIStream& buf, std::vector<T>& vec);
215 template <
class TOStream>
216 inline void Serialize(TOStream& buf,
const std::vector<bool>::reference& boolRef);
218 template <
class TIStream>
219 inline void Deserialize(TIStream& buf, std::vector<bool>::reference boolRef);
221 template <
class Key,
class T,
class TOStream>
222 void Serialize(TOStream& buf,
const std::map<Key, T>& m);
224 template <
class Key,
class T,
class TIStream>
225 void Deserialize(TIStream& buf, std::map<Key, T>& m);
231 template <
class T1,
class T2,
class TOStream>
232 void Serialize(TOStream& buf,
const std::pair<T1, T2>& v)
238 template <
class T1,
class T2,
class TIStream>
251 template <
class T,
class TOStream>
254 Serialize<size_t>(buf, m.size());
255 for(
typename std::set<T>::const_iterator it = m.begin(); it != m.end(); ++it)
256 Serialize<T>(buf, *it);
260 template <
class T,
class TIStream>
264 size_t size = Deserialize<size_t>(buf);
266 for(
size_t i = 0; i < size; ++i)
268 Deserialize<T>(buf, t);
270 myset.insert (myset.end(), t);
276 template <
class TOStream>
279 size_t len = str.length();
282 buf.write(str.c_str(),
sizeof(
char) * len);
286 template <
class TIStream>
292 char* flexBuf = NULL;
293 char* tBuf = staticBuf;
295 size_t len = Deserialize<size_t>(buf);
300 flexBuf =
new char[len + 1];
305 buf.read(tBuf,
sizeof(
char) * len);
324 template <
class TOStream>
339 UG_THROW(
"Unknown variant type in Serialize:" << v.
type());
348 template <
class TIStream>
351 int type = Deserialize<int>(buf);
367 UG_THROW(
"Unknown variant type in Deserialize: " << type);
378 template <
class T,
class TOStream>
379 void Serialize(TOStream& buf,
const std::vector<T>& vec)
381 size_t size = vec.size();
383 for(
size_t i = 0; i < size; ++i){
389 template <
class T,
class TIStream>
393 size_t size = Deserialize<size_t>(buf);
395 for(
size_t i = 0; i < size; ++i){
401 template<
class TIStream>
402 void Serialize(TIStream &buf,
const std::vector<bool> &vec)
404 size_t size=vec.size();
405 Serialize<size_t>(buf, size);
408 for(
size_t i = 0; i < size; ++i)
410 if(vec[i]) a |= (1 << j);
413 Serialize<char>(buf, a);
418 if(j) Serialize<char>(buf, a);
421 template<
class TIStream>
425 size_t size = Deserialize<size_t>(buf);
429 for(
size_t i = 0; i < size; ++i, ++j)
433 Deserialize<char>(buf, a);
436 vec[i] = a & (1 << j);
447 template <
class TOStream>
448 inline void Serialize(TOStream& buf,
const std::vector<bool>::reference& boolRef)
450 char b = ((bool)boolRef) ? 1 : 0;
451 buf.write(&b,
sizeof(
char));
457 template <
class TIStream>
458 inline void Deserialize(TIStream& buf, std::vector<bool>::reference boolRef)
461 buf.read(&b,
sizeof(
char));
462 boolRef = (bool)(b == 1);
472 template <
class Key,
class T,
class TOStream>
473 void Serialize(TOStream& buf,
const std::map<Key, T>& m)
477 for(
typename std::map<Key, T>::const_iterator it = m.begin(); it != m.end(); ++it)
485 template <
class Key,
class T,
class TIStream>
489 size_t size = Deserialize<size_t>(buf);
490 for(
size_t i = 0; i < size; ++i)
A variant can represent variables of different types.
Definition: variant.h:87
double to_double() const
Definition: variant.cpp:291
float to_float() const
Definition: variant.cpp:259
bool to_bool() const
Definition: variant.cpp:213
@ VT_STDSTRING
Definition: variant.h:97
@ VT_BOOL
Definition: variant.h:91
@ VT_INT
Definition: variant.h:92
@ VT_CSTRING
Definition: variant.h:96
@ VT_DOUBLE
Definition: variant.h:95
@ VT_INVALID
Definition: variant.h:90
@ VT_FLOAT
Definition: variant.h:94
@ VT_POINTER
Definition: variant.h:98
Type type() const
Definition: variant.h:132
const char * to_c_string() const
Definition: variant.cpp:307
const std::string & to_std_string() const
Definition: variant.cpp:320
int to_int() const
Definition: variant.cpp:229
#define UG_THROW(msg)
Definition: error.h:57
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103