experimental-genesis 1
experimental-genesis 2
experimental-genesis 3
experimental-genesis 4
experimental-genesis 5
experimental-genesis 6
experimental-genesis 7
experimental-genesis 8
experimental-genesis 9
experimental-genesis 10
experimental-genesis 11
experimental-genesis 12
experimental-genesis 13
experimental-genesis 14
experimental-genesis 15
experimental-genesis 16
experimental-genesis 17
experimental-genesis 18
experimental-genesis 19
experimental-genesis 20
experimental-genesis 21
experimental-genesis 22
experimental-genesis 23
experimental-genesis 24
experimental-genesis 25
experimental-genesis 26
experimental-genesis 27
experimental-genesis 28
experimental-genesis 29
experimental-genesis 30
experimental-genesis 31
experimental-genesis 32
experimental-genesis 33
experimental-genesis 34
experimental-genesis 35
experimental-genesis 36 #ifndef BITCOIN_SERIALIZE_H
experimental-genesis 37 #define BITCOIN_SERIALIZE_H
experimental-genesis 38
experimental-genesis 39 #include <string>
experimental-genesis 40 #include <vector>
experimental-genesis 41 #include <map>
experimental-genesis 42 #include <set>
experimental-genesis 43 #include <cassert>
experimental-genesis 44 #include <climits>
experimental-genesis 45 #include <cstring>
experimental-genesis 46 #include <cstdio>
experimental-genesis 47
experimental-genesis 48 #include <boost/type_traits/is_fundamental.hpp>
experimental-genesis 49 #include <boost/tuple/tuple.hpp>
experimental-genesis 50 #include <boost/tuple/tuple_comparison.hpp>
experimental-genesis 51 #include <boost/tuple/tuple_io.hpp>
experimental-genesis 52
experimental-genesis 53 #if defined(_MSC_VER) || defined(__BORLANDC__)
experimental-genesis 54 typedef __int64 int64;
experimental-genesis 55 typedef unsigned __int64 uint64;
experimental-genesis 56 #else
experimental-genesis 57 typedef long long int64;
experimental-genesis 58 typedef unsigned long long uint64;
experimental-genesis 59 #endif
experimental-genesis 60 #if defined(_MSC_VER) && _MSC_VER < 1300
experimental-genesis 61 #define for if (false) ; else for
experimental-genesis 62 #endif
experimental-genesis 63
experimental-genesis 64 #ifdef WIN32
experimental-genesis 65 #include <windows.h>
experimental-genesis 66
experimental-genesis 67
experimental-genesis 68
experimental-genesis 69
experimental-genesis 70 #include <windows.h>
experimental-genesis 71 #define mlock(p, n) VirtualLock((p), (n));
experimental-genesis 72 #define munlock(p, n) VirtualUnlock((p), (n));
experimental-genesis 73 #else
experimental-genesis 74 #include <sys/mman.h>
experimental-genesis 75 #include <limits.h>
experimental-genesis 76
experimental-genesis 77 #ifndef PAGESIZE
experimental-genesis 78 #include <unistd.h>
experimental-genesis 79 #define PAGESIZE sysconf(_SC_PAGESIZE)
experimental-genesis 80 #endif
experimental-genesis 81 #define mlock(a,b) \
experimental-genesis 82 mlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
experimental-genesis 83 (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
experimental-genesis 84 #define munlock(a,b) \
experimental-genesis 85 munlock(((void *)(((size_t)(a)) & (~((PAGESIZE)-1)))),\
experimental-genesis 86 (((((size_t)(a)) + (b) - 1) | ((PAGESIZE) - 1)) + 1) - (((size_t)(a)) & (~((PAGESIZE) - 1))))
experimental-genesis 87 #endif
experimental-genesis 88
experimental-genesis 89 class CScript;
experimental-genesis 90 class CDataStream;
experimental-genesis 91 class CAutoFile;
experimental-genesis 92 static const unsigned int MAX_SIZE = 0x02000000;
experimental-genesis 93
experimental-genesis 94 static const int VERSION = 50300;
experimental-genesis 95 static const char* pszSubVer = "";
experimental-genesis 96 static const bool VERSION_IS_BETA = true;
experimental-genesis 97
experimental-genesis 98
experimental-genesis 99
experimental-genesis 100 template<typename T>
experimental-genesis 101 inline T& REF(const T& val)
experimental-genesis 102 {
experimental-genesis 103 return const_cast<T&>(val);
experimental-genesis 104 }
experimental-genesis 105
experimental-genesis 106
experimental-genesis 107
experimental-genesis 108
experimental-genesis 109
experimental-genesis 110
experimental-genesis 111
experimental-genesis 112 enum
experimental-genesis 113 {
experimental-genesis 114
experimental-genesis 115 SER_NETWORK = (1 << 0),
experimental-genesis 116 SER_DISK = (1 << 1),
experimental-genesis 117 SER_GETHASH = (1 << 2),
experimental-genesis 118
experimental-genesis 119
experimental-genesis 120 SER_SKIPSIG = (1 << 16),
experimental-genesis 121 SER_BLOCKHEADERONLY = (1 << 17),
experimental-genesis 122 };
experimental-genesis 123
experimental-genesis 124 #define IMPLEMENT_SERIALIZE(statements) \
experimental-genesis 125 unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const \
experimental-genesis 126 { \
experimental-genesis 127 CSerActionGetSerializeSize ser_action; \
experimental-genesis 128 const bool fGetSize = true; \
experimental-genesis 129 const bool fWrite = false; \
experimental-genesis 130 const bool fRead = false; \
experimental-genesis 131 unsigned int nSerSize = 0; \
experimental-genesis 132 ser_streamplaceholder s; \
experimental-genesis 133 assert(fGetSize||fWrite||fRead); \
experimental-genesis 134 s.nType = nType; \
experimental-genesis 135 s.nVersion = nVersion; \
experimental-genesis 136 {statements} \
experimental-genesis 137 return nSerSize; \
experimental-genesis 138 } \
experimental-genesis 139 template<typename Stream> \
experimental-genesis 140 void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const \
experimental-genesis 141 { \
experimental-genesis 142 CSerActionSerialize ser_action; \
experimental-genesis 143 const bool fGetSize = false; \
experimental-genesis 144 const bool fWrite = true; \
experimental-genesis 145 const bool fRead = false; \
experimental-genesis 146 unsigned int nSerSize = 0; \
experimental-genesis 147 assert(fGetSize||fWrite||fRead); \
experimental-genesis 148 {statements} \
experimental-genesis 149 } \
experimental-genesis 150 template<typename Stream> \
experimental-genesis 151 void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) \
experimental-genesis 152 { \
experimental-genesis 153 CSerActionUnserialize ser_action; \
experimental-genesis 154 const bool fGetSize = false; \
experimental-genesis 155 const bool fWrite = false; \
experimental-genesis 156 const bool fRead = true; \
experimental-genesis 157 unsigned int nSerSize = 0; \
experimental-genesis 158 assert(fGetSize||fWrite||fRead); \
experimental-genesis 159 {statements} \
experimental-genesis 160 }
experimental-genesis 161
experimental-genesis 162 #define READWRITE(obj) (nSerSize += ::SerReadWrite(s, (obj), nType, nVersion, ser_action))
experimental-genesis 163
experimental-genesis 164
experimental-genesis 165
experimental-genesis 166
experimental-genesis 167
experimental-genesis 168
experimental-genesis 169
experimental-genesis 170
experimental-genesis 171
experimental-genesis 172 #define WRITEDATA(s, obj) s.write((char*)&(obj), sizeof(obj))
experimental-genesis 173 #define READDATA(s, obj) s.read((char*)&(obj), sizeof(obj))
experimental-genesis 174
experimental-genesis 175 inline unsigned int GetSerializeSize(char a, int, int=0) { return sizeof(a); }
experimental-genesis 176 inline unsigned int GetSerializeSize(signed char a, int, int=0) { return sizeof(a); }
experimental-genesis 177 inline unsigned int GetSerializeSize(unsigned char a, int, int=0) { return sizeof(a); }
experimental-genesis 178 inline unsigned int GetSerializeSize(signed short a, int, int=0) { return sizeof(a); }
experimental-genesis 179 inline unsigned int GetSerializeSize(unsigned short a, int, int=0) { return sizeof(a); }
experimental-genesis 180 inline unsigned int GetSerializeSize(signed int a, int, int=0) { return sizeof(a); }
experimental-genesis 181 inline unsigned int GetSerializeSize(unsigned int a, int, int=0) { return sizeof(a); }
experimental-genesis 182 inline unsigned int GetSerializeSize(signed long a, int, int=0) { return sizeof(a); }
experimental-genesis 183 inline unsigned int GetSerializeSize(unsigned long a, int, int=0) { return sizeof(a); }
experimental-genesis 184 inline unsigned int GetSerializeSize(int64 a, int, int=0) { return sizeof(a); }
experimental-genesis 185 inline unsigned int GetSerializeSize(uint64 a, int, int=0) { return sizeof(a); }
experimental-genesis 186 inline unsigned int GetSerializeSize(float a, int, int=0) { return sizeof(a); }
experimental-genesis 187 inline unsigned int GetSerializeSize(double a, int, int=0) { return sizeof(a); }
experimental-genesis 188
experimental-genesis 189 template<typename Stream> inline void Serialize(Stream& s, char a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 190 template<typename Stream> inline void Serialize(Stream& s, signed char a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 191 template<typename Stream> inline void Serialize(Stream& s, unsigned char a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 192 template<typename Stream> inline void Serialize(Stream& s, signed short a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 193 template<typename Stream> inline void Serialize(Stream& s, unsigned short a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 194 template<typename Stream> inline void Serialize(Stream& s, signed int a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 195 template<typename Stream> inline void Serialize(Stream& s, unsigned int a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 196 template<typename Stream> inline void Serialize(Stream& s, signed long a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 197 template<typename Stream> inline void Serialize(Stream& s, unsigned long a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 198 template<typename Stream> inline void Serialize(Stream& s, int64 a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 199 template<typename Stream> inline void Serialize(Stream& s, uint64 a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 200 template<typename Stream> inline void Serialize(Stream& s, float a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 201 template<typename Stream> inline void Serialize(Stream& s, double a, int, int=0) { WRITEDATA(s, a); }
experimental-genesis 202
experimental-genesis 203 template<typename Stream> inline void Unserialize(Stream& s, char& a, int, int=0) { READDATA(s, a); }
experimental-genesis 204 template<typename Stream> inline void Unserialize(Stream& s, signed char& a, int, int=0) { READDATA(s, a); }
experimental-genesis 205 template<typename Stream> inline void Unserialize(Stream& s, unsigned char& a, int, int=0) { READDATA(s, a); }
experimental-genesis 206 template<typename Stream> inline void Unserialize(Stream& s, signed short& a, int, int=0) { READDATA(s, a); }
experimental-genesis 207 template<typename Stream> inline void Unserialize(Stream& s, unsigned short& a, int, int=0) { READDATA(s, a); }
experimental-genesis 208 template<typename Stream> inline void Unserialize(Stream& s, signed int& a, int, int=0) { READDATA(s, a); }
experimental-genesis 209 template<typename Stream> inline void Unserialize(Stream& s, unsigned int& a, int, int=0) { READDATA(s, a); }
experimental-genesis 210 template<typename Stream> inline void Unserialize(Stream& s, signed long& a, int, int=0) { READDATA(s, a); }
experimental-genesis 211 template<typename Stream> inline void Unserialize(Stream& s, unsigned long& a, int, int=0) { READDATA(s, a); }
experimental-genesis 212 template<typename Stream> inline void Unserialize(Stream& s, int64& a, int, int=0) { READDATA(s, a); }
experimental-genesis 213 template<typename Stream> inline void Unserialize(Stream& s, uint64& a, int, int=0) { READDATA(s, a); }
experimental-genesis 214 template<typename Stream> inline void Unserialize(Stream& s, float& a, int, int=0) { READDATA(s, a); }
experimental-genesis 215 template<typename Stream> inline void Unserialize(Stream& s, double& a, int, int=0) { READDATA(s, a); }
experimental-genesis 216
experimental-genesis 217 inline unsigned int GetSerializeSize(bool a, int, int=0) { return sizeof(char); }
experimental-genesis 218 template<typename Stream> inline void Serialize(Stream& s, bool a, int, int=0) { char f=a; WRITEDATA(s, f); }
experimental-genesis 219 template<typename Stream> inline void Unserialize(Stream& s, bool& a, int, int=0) { char f; READDATA(s, f); a=f; }
experimental-genesis 220
experimental-genesis 221
experimental-genesis 222
experimental-genesis 223
experimental-genesis 224
experimental-genesis 225
experimental-genesis 226
experimental-genesis 227
experimental-genesis 228
experimental-genesis 229
experimental-genesis 230
experimental-genesis 231
experimental-genesis 232
experimental-genesis 233 inline unsigned int GetSizeOfCompactSize(uint64 nSize)
experimental-genesis 234 {
experimental-genesis 235 if (nSize < 253) return sizeof(unsigned char);
experimental-genesis 236 else if (nSize <= USHRT_MAX) return sizeof(unsigned char) + sizeof(unsigned short);
experimental-genesis 237 else if (nSize <= UINT_MAX) return sizeof(unsigned char) + sizeof(unsigned int);
experimental-genesis 238 else return sizeof(unsigned char) + sizeof(uint64);
experimental-genesis 239 }
experimental-genesis 240
experimental-genesis 241 template<typename Stream>
experimental-genesis 242 void WriteCompactSize(Stream& os, uint64 nSize)
experimental-genesis 243 {
experimental-genesis 244 if (nSize < 253)
experimental-genesis 245 {
experimental-genesis 246 unsigned char chSize = nSize;
experimental-genesis 247 WRITEDATA(os, chSize);
experimental-genesis 248 }
experimental-genesis 249 else if (nSize <= USHRT_MAX)
experimental-genesis 250 {
experimental-genesis 251 unsigned char chSize = 253;
experimental-genesis 252 unsigned short xSize = nSize;
experimental-genesis 253 WRITEDATA(os, chSize);
experimental-genesis 254 WRITEDATA(os, xSize);
experimental-genesis 255 }
experimental-genesis 256 else if (nSize <= UINT_MAX)
experimental-genesis 257 {
experimental-genesis 258 unsigned char chSize = 254;
experimental-genesis 259 unsigned int xSize = nSize;
experimental-genesis 260 WRITEDATA(os, chSize);
experimental-genesis 261 WRITEDATA(os, xSize);
experimental-genesis 262 }
experimental-genesis 263 else
experimental-genesis 264 {
experimental-genesis 265 unsigned char chSize = 255;
experimental-genesis 266 uint64 xSize = nSize;
experimental-genesis 267 WRITEDATA(os, chSize);
experimental-genesis 268 WRITEDATA(os, xSize);
experimental-genesis 269 }
experimental-genesis 270 return;
experimental-genesis 271 }
experimental-genesis 272
experimental-genesis 273 template<typename Stream>
experimental-genesis 274 uint64 ReadCompactSize(Stream& is)
experimental-genesis 275 {
experimental-genesis 276 unsigned char chSize;
experimental-genesis 277 READDATA(is, chSize);
experimental-genesis 278 uint64 nSizeRet = 0;
experimental-genesis 279 if (chSize < 253)
experimental-genesis 280 {
experimental-genesis 281 nSizeRet = chSize;
experimental-genesis 282 }
experimental-genesis 283 else if (chSize == 253)
experimental-genesis 284 {
experimental-genesis 285 unsigned short xSize;
experimental-genesis 286 READDATA(is, xSize);
experimental-genesis 287 nSizeRet = xSize;
experimental-genesis 288 }
experimental-genesis 289 else if (chSize == 254)
experimental-genesis 290 {
experimental-genesis 291 unsigned int xSize;
experimental-genesis 292 READDATA(is, xSize);
experimental-genesis 293 nSizeRet = xSize;
experimental-genesis 294 }
experimental-genesis 295 else
experimental-genesis 296 {
experimental-genesis 297 uint64 xSize;
experimental-genesis 298 READDATA(is, xSize);
experimental-genesis 299 nSizeRet = xSize;
experimental-genesis 300 }
experimental-genesis 301 if (nSizeRet > (uint64)MAX_SIZE)
experimental-genesis 302 throw std::ios_base::failure("ReadCompactSize() : size too large");
experimental-genesis 303 return nSizeRet;
experimental-genesis 304 }
experimental-genesis 305
experimental-genesis 306
experimental-genesis 307
experimental-genesis 308
experimental-genesis 309
experimental-genesis 310
experimental-genesis 311
experimental-genesis 312 #define FLATDATA(obj) REF(CFlatData((char*)&(obj), (char*)&(obj) + sizeof(obj)))
experimental-genesis 313 class CFlatData
experimental-genesis 314 {
experimental-genesis 315 protected:
experimental-genesis 316 char* pbegin;
experimental-genesis 317 char* pend;
experimental-genesis 318 public:
experimental-genesis 319 CFlatData(void* pbeginIn, void* pendIn) : pbegin((char*)pbeginIn), pend((char*)pendIn) { }
experimental-genesis 320 char* begin() { return pbegin; }
experimental-genesis 321 const char* begin() const { return pbegin; }
experimental-genesis 322 char* end() { return pend; }
experimental-genesis 323 const char* end() const { return pend; }
experimental-genesis 324
experimental-genesis 325 unsigned int GetSerializeSize(int, int=0) const
experimental-genesis 326 {
experimental-genesis 327 return pend - pbegin;
experimental-genesis 328 }
experimental-genesis 329
experimental-genesis 330 template<typename Stream>
experimental-genesis 331 void Serialize(Stream& s, int, int=0) const
experimental-genesis 332 {
experimental-genesis 333 s.write(pbegin, pend - pbegin);
experimental-genesis 334 }
experimental-genesis 335
experimental-genesis 336 template<typename Stream>
experimental-genesis 337 void Unserialize(Stream& s, int, int=0)
experimental-genesis 338 {
experimental-genesis 339 s.read(pbegin, pend - pbegin);
experimental-genesis 340 }
experimental-genesis 341 };
experimental-genesis 342
experimental-genesis 343
experimental-genesis 344
experimental-genesis 345
experimental-genesis 346
experimental-genesis 347
experimental-genesis 348 template<std::size_t LEN>
experimental-genesis 349 class CFixedFieldString
experimental-genesis 350 {
experimental-genesis 351 protected:
experimental-genesis 352 const std::string* pcstr;
experimental-genesis 353 std::string* pstr;
experimental-genesis 354 public:
experimental-genesis 355 explicit CFixedFieldString(const std::string& str) : pcstr(&str), pstr(NULL) { }
experimental-genesis 356 explicit CFixedFieldString(std::string& str) : pcstr(&str), pstr(&str) { }
experimental-genesis 357
experimental-genesis 358 unsigned int GetSerializeSize(int, int=0) const
experimental-genesis 359 {
experimental-genesis 360 return LEN;
experimental-genesis 361 }
experimental-genesis 362
experimental-genesis 363 template<typename Stream>
experimental-genesis 364 void Serialize(Stream& s, int, int=0) const
experimental-genesis 365 {
experimental-genesis 366 char pszBuf[LEN];
experimental-genesis 367 strncpy(pszBuf, pcstr->c_str(), LEN);
experimental-genesis 368 s.write(pszBuf, LEN);
experimental-genesis 369 }
experimental-genesis 370
experimental-genesis 371 template<typename Stream>
experimental-genesis 372 void Unserialize(Stream& s, int, int=0)
experimental-genesis 373 {
experimental-genesis 374 if (pstr == NULL)
experimental-genesis 375 throw std::ios_base::failure("CFixedFieldString::Unserialize : trying to unserialize to const string");
experimental-genesis 376 char pszBuf[LEN+1];
experimental-genesis 377 s.read(pszBuf, LEN);
experimental-genesis 378 pszBuf[LEN] = '\0';
experimental-genesis 379 *pstr = pszBuf;
experimental-genesis 380 }
experimental-genesis 381 };
experimental-genesis 382
experimental-genesis 383
experimental-genesis 384
experimental-genesis 385
experimental-genesis 386
experimental-genesis 387
experimental-genesis 388
experimental-genesis 389
experimental-genesis 390
experimental-genesis 391
experimental-genesis 392 template<typename C> unsigned int GetSerializeSize(const std::basic_string<C>& str, int, int=0);
experimental-genesis 393 template<typename Stream, typename C> void Serialize(Stream& os, const std::basic_string<C>& str, int, int=0);
experimental-genesis 394 template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_string<C>& str, int, int=0);
experimental-genesis 395
experimental-genesis 396
experimental-genesis 397 template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
experimental-genesis 398 template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
experimental-genesis 399 template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion=VERSION);
experimental-genesis 400 template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
experimental-genesis 401 template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
experimental-genesis 402 template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion=VERSION);
experimental-genesis 403 template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&);
experimental-genesis 404 template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&);
experimental-genesis 405 template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion=VERSION);
experimental-genesis 406
experimental-genesis 407
experimental-genesis 408 extern inline unsigned int GetSerializeSize(const CScript& v, int nType, int nVersion=VERSION);
experimental-genesis 409 template<typename Stream> void Serialize(Stream& os, const CScript& v, int nType, int nVersion=VERSION);
experimental-genesis 410 template<typename Stream> void Unserialize(Stream& is, CScript& v, int nType, int nVersion=VERSION);
experimental-genesis 411
experimental-genesis 412
experimental-genesis 413 template<typename K, typename T> unsigned int GetSerializeSize(const std::pair<K, T>& item, int nType, int nVersion=VERSION);
experimental-genesis 414 template<typename Stream, typename K, typename T> void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion=VERSION);
experimental-genesis 415 template<typename Stream, typename K, typename T> void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion=VERSION);
experimental-genesis 416
experimental-genesis 417
experimental-genesis 418 template<typename T0, typename T1, typename T2> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);
experimental-genesis 419 template<typename Stream, typename T0, typename T1, typename T2> void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);
experimental-genesis 420 template<typename Stream, typename T0, typename T1, typename T2> void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);
experimental-genesis 421
experimental-genesis 422
experimental-genesis 423 template<typename T0, typename T1, typename T2, typename T3> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);
experimental-genesis 424 template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);
experimental-genesis 425 template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);
experimental-genesis 426
experimental-genesis 427
experimental-genesis 428 template<typename K, typename T, typename Pred, typename A> unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 429 template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 430 template<typename Stream, typename K, typename T, typename Pred, typename A> void Unserialize(Stream& is, std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 431
experimental-genesis 432
experimental-genesis 433 template<typename K, typename Pred, typename A> unsigned int GetSerializeSize(const std::set<K, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 434 template<typename Stream, typename K, typename Pred, typename A> void Serialize(Stream& os, const std::set<K, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 435 template<typename Stream, typename K, typename Pred, typename A> void Unserialize(Stream& is, std::set<K, Pred, A>& m, int nType, int nVersion=VERSION);
experimental-genesis 436
experimental-genesis 437
experimental-genesis 438
experimental-genesis 439
experimental-genesis 440
experimental-genesis 441
experimental-genesis 442
experimental-genesis 443
experimental-genesis 444
experimental-genesis 445
experimental-genesis 446
experimental-genesis 447 template<typename T>
experimental-genesis 448 inline unsigned int GetSerializeSize(const T& a, long nType, int nVersion=VERSION)
experimental-genesis 449 {
experimental-genesis 450 return a.GetSerializeSize((int)nType, nVersion);
experimental-genesis 451 }
experimental-genesis 452
experimental-genesis 453 template<typename Stream, typename T>
experimental-genesis 454 inline void Serialize(Stream& os, const T& a, long nType, int nVersion=VERSION)
experimental-genesis 455 {
experimental-genesis 456 a.Serialize(os, (int)nType, nVersion);
experimental-genesis 457 }
experimental-genesis 458
experimental-genesis 459 template<typename Stream, typename T>
experimental-genesis 460 inline void Unserialize(Stream& is, T& a, long nType, int nVersion=VERSION)
experimental-genesis 461 {
experimental-genesis 462 a.Unserialize(is, (int)nType, nVersion);
experimental-genesis 463 }
experimental-genesis 464
experimental-genesis 465
experimental-genesis 466
experimental-genesis 467
experimental-genesis 468
experimental-genesis 469
experimental-genesis 470
experimental-genesis 471
experimental-genesis 472 template<typename C>
experimental-genesis 473 unsigned int GetSerializeSize(const std::basic_string<C>& str, int, int)
experimental-genesis 474 {
experimental-genesis 475 return GetSizeOfCompactSize(str.size()) + str.size() * sizeof(str[0]);
experimental-genesis 476 }
experimental-genesis 477
experimental-genesis 478 template<typename Stream, typename C>
experimental-genesis 479 void Serialize(Stream& os, const std::basic_string<C>& str, int, int)
experimental-genesis 480 {
experimental-genesis 481 WriteCompactSize(os, str.size());
experimental-genesis 482 if (!str.empty())
experimental-genesis 483 os.write((char*)&str[0], str.size() * sizeof(str[0]));
experimental-genesis 484 }
experimental-genesis 485
experimental-genesis 486 template<typename Stream, typename C>
experimental-genesis 487 void Unserialize(Stream& is, std::basic_string<C>& str, int, int)
experimental-genesis 488 {
experimental-genesis 489 unsigned int nSize = ReadCompactSize(is);
experimental-genesis 490 str.resize(nSize);
experimental-genesis 491 if (nSize != 0)
experimental-genesis 492 is.read((char*)&str[0], nSize * sizeof(str[0]));
experimental-genesis 493 }
experimental-genesis 494
experimental-genesis 495
experimental-genesis 496
experimental-genesis 497
experimental-genesis 498
experimental-genesis 499
experimental-genesis 500 template<typename T, typename A>
experimental-genesis 501 unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
experimental-genesis 502 {
experimental-genesis 503 return (GetSizeOfCompactSize(v.size()) + v.size() * sizeof(T));
experimental-genesis 504 }
experimental-genesis 505
experimental-genesis 506 template<typename T, typename A>
experimental-genesis 507 unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
experimental-genesis 508 {
experimental-genesis 509 unsigned int nSize = GetSizeOfCompactSize(v.size());
experimental-genesis 510 for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
experimental-genesis 511 nSize += GetSerializeSize((*vi), nType, nVersion);
experimental-genesis 512 return nSize;
experimental-genesis 513 }
experimental-genesis 514
experimental-genesis 515 template<typename T, typename A>
experimental-genesis 516 inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion)
experimental-genesis 517 {
experimental-genesis 518 return GetSerializeSize_impl(v, nType, nVersion, boost::is_fundamental<T>());
experimental-genesis 519 }
experimental-genesis 520
experimental-genesis 521
experimental-genesis 522 template<typename Stream, typename T, typename A>
experimental-genesis 523 void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
experimental-genesis 524 {
experimental-genesis 525 WriteCompactSize(os, v.size());
experimental-genesis 526 if (!v.empty())
experimental-genesis 527 os.write((char*)&v[0], v.size() * sizeof(T));
experimental-genesis 528 }
experimental-genesis 529
experimental-genesis 530 template<typename Stream, typename T, typename A>
experimental-genesis 531 void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
experimental-genesis 532 {
experimental-genesis 533 WriteCompactSize(os, v.size());
experimental-genesis 534 for (typename std::vector<T, A>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
experimental-genesis 535 ::Serialize(os, (*vi), nType, nVersion);
experimental-genesis 536 }
experimental-genesis 537
experimental-genesis 538 template<typename Stream, typename T, typename A>
experimental-genesis 539 inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion)
experimental-genesis 540 {
experimental-genesis 541 Serialize_impl(os, v, nType, nVersion, boost::is_fundamental<T>());
experimental-genesis 542 }
experimental-genesis 543
experimental-genesis 544
experimental-genesis 545 template<typename Stream, typename T, typename A>
experimental-genesis 546 void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&)
experimental-genesis 547 {
experimental-genesis 548
experimental-genesis 549
experimental-genesis 550
experimental-genesis 551
experimental-genesis 552
experimental-genesis 553 v.clear();
experimental-genesis 554 unsigned int nSize = ReadCompactSize(is);
experimental-genesis 555 unsigned int i = 0;
experimental-genesis 556 while (i < nSize)
experimental-genesis 557 {
experimental-genesis 558 unsigned int blk = std::min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T)));
experimental-genesis 559 v.resize(i + blk);
experimental-genesis 560 is.read((char*)&v[i], blk * sizeof(T));
experimental-genesis 561 i += blk;
experimental-genesis 562 }
experimental-genesis 563 }
experimental-genesis 564
experimental-genesis 565 template<typename Stream, typename T, typename A>
experimental-genesis 566 void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&)
experimental-genesis 567 {
experimental-genesis 568
experimental-genesis 569
experimental-genesis 570
experimental-genesis 571
experimental-genesis 572
experimental-genesis 573 v.clear();
experimental-genesis 574 unsigned int nSize = ReadCompactSize(is);
experimental-genesis 575 unsigned int i = 0;
experimental-genesis 576 unsigned int nMid = 0;
experimental-genesis 577 while (nMid < nSize)
experimental-genesis 578 {
experimental-genesis 579 nMid += 5000000 / sizeof(T);
experimental-genesis 580 if (nMid > nSize)
experimental-genesis 581 nMid = nSize;
experimental-genesis 582 v.resize(nMid);
experimental-genesis 583 for (; i < nMid; i++)
experimental-genesis 584 Unserialize(is, v[i], nType, nVersion);
experimental-genesis 585 }
experimental-genesis 586 }
experimental-genesis 587
experimental-genesis 588 template<typename Stream, typename T, typename A>
experimental-genesis 589 inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion)
experimental-genesis 590 {
experimental-genesis 591 Unserialize_impl(is, v, nType, nVersion, boost::is_fundamental<T>());
experimental-genesis 592 }
experimental-genesis 593
experimental-genesis 594
experimental-genesis 595
experimental-genesis 596
experimental-genesis 597
experimental-genesis 598
experimental-genesis 599 inline unsigned int GetSerializeSize(const CScript& v, int nType, int nVersion)
experimental-genesis 600 {
experimental-genesis 601 return GetSerializeSize((const std::vector<unsigned char>&)v, nType, nVersion);
experimental-genesis 602 }
experimental-genesis 603
experimental-genesis 604 template<typename Stream>
experimental-genesis 605 void Serialize(Stream& os, const CScript& v, int nType, int nVersion)
experimental-genesis 606 {
experimental-genesis 607 Serialize(os, (const std::vector<unsigned char>&)v, nType, nVersion);
experimental-genesis 608 }
experimental-genesis 609
experimental-genesis 610 template<typename Stream>
experimental-genesis 611 void Unserialize(Stream& is, CScript& v, int nType, int nVersion)
experimental-genesis 612 {
experimental-genesis 613 Unserialize(is, (std::vector<unsigned char>&)v, nType, nVersion);
experimental-genesis 614 }
experimental-genesis 615
experimental-genesis 616
experimental-genesis 617
experimental-genesis 618
experimental-genesis 619
experimental-genesis 620
experimental-genesis 621 template<typename K, typename T>
experimental-genesis 622 unsigned int GetSerializeSize(const std::pair<K, T>& item, int nType, int nVersion)
experimental-genesis 623 {
experimental-genesis 624 return GetSerializeSize(item.first, nType, nVersion) + GetSerializeSize(item.second, nType, nVersion);
experimental-genesis 625 }
experimental-genesis 626
experimental-genesis 627 template<typename Stream, typename K, typename T>
experimental-genesis 628 void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion)
experimental-genesis 629 {
experimental-genesis 630 Serialize(os, item.first, nType, nVersion);
experimental-genesis 631 Serialize(os, item.second, nType, nVersion);
experimental-genesis 632 }
experimental-genesis 633
experimental-genesis 634 template<typename Stream, typename K, typename T>
experimental-genesis 635 void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion)
experimental-genesis 636 {
experimental-genesis 637 Unserialize(is, item.first, nType, nVersion);
experimental-genesis 638 Unserialize(is, item.second, nType, nVersion);
experimental-genesis 639 }
experimental-genesis 640
experimental-genesis 641
experimental-genesis 642
experimental-genesis 643
experimental-genesis 644
experimental-genesis 645
experimental-genesis 646 template<typename T0, typename T1, typename T2>
experimental-genesis 647 unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
experimental-genesis 648 {
experimental-genesis 649 unsigned int nSize = 0;
experimental-genesis 650 nSize += GetSerializeSize(boost::get<0>(item), nType, nVersion);
experimental-genesis 651 nSize += GetSerializeSize(boost::get<1>(item), nType, nVersion);
experimental-genesis 652 nSize += GetSerializeSize(boost::get<2>(item), nType, nVersion);
experimental-genesis 653 return nSize;
experimental-genesis 654 }
experimental-genesis 655
experimental-genesis 656 template<typename Stream, typename T0, typename T1, typename T2>
experimental-genesis 657 void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
experimental-genesis 658 {
experimental-genesis 659 Serialize(os, boost::get<0>(item), nType, nVersion);
experimental-genesis 660 Serialize(os, boost::get<1>(item), nType, nVersion);
experimental-genesis 661 Serialize(os, boost::get<2>(item), nType, nVersion);
experimental-genesis 662 }
experimental-genesis 663
experimental-genesis 664 template<typename Stream, typename T0, typename T1, typename T2>
experimental-genesis 665 void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion)
experimental-genesis 666 {
experimental-genesis 667 Unserialize(is, boost::get<0>(item), nType, nVersion);
experimental-genesis 668 Unserialize(is, boost::get<1>(item), nType, nVersion);
experimental-genesis 669 Unserialize(is, boost::get<2>(item), nType, nVersion);
experimental-genesis 670 }
experimental-genesis 671
experimental-genesis 672
experimental-genesis 673
experimental-genesis 674
experimental-genesis 675
experimental-genesis 676
experimental-genesis 677 template<typename T0, typename T1, typename T2, typename T3>
experimental-genesis 678 unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
experimental-genesis 679 {
experimental-genesis 680 unsigned int nSize = 0;
experimental-genesis 681 nSize += GetSerializeSize(boost::get<0>(item), nType, nVersion);
experimental-genesis 682 nSize += GetSerializeSize(boost::get<1>(item), nType, nVersion);
experimental-genesis 683 nSize += GetSerializeSize(boost::get<2>(item), nType, nVersion);
experimental-genesis 684 nSize += GetSerializeSize(boost::get<3>(item), nType, nVersion);
experimental-genesis 685 return nSize;
experimental-genesis 686 }
experimental-genesis 687
experimental-genesis 688 template<typename Stream, typename T0, typename T1, typename T2, typename T3>
experimental-genesis 689 void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
experimental-genesis 690 {
experimental-genesis 691 Serialize(os, boost::get<0>(item), nType, nVersion);
experimental-genesis 692 Serialize(os, boost::get<1>(item), nType, nVersion);
experimental-genesis 693 Serialize(os, boost::get<2>(item), nType, nVersion);
experimental-genesis 694 Serialize(os, boost::get<3>(item), nType, nVersion);
experimental-genesis 695 }
experimental-genesis 696
experimental-genesis 697 template<typename Stream, typename T0, typename T1, typename T2, typename T3>
experimental-genesis 698 void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)
experimental-genesis 699 {
experimental-genesis 700 Unserialize(is, boost::get<0>(item), nType, nVersion);
experimental-genesis 701 Unserialize(is, boost::get<1>(item), nType, nVersion);
experimental-genesis 702 Unserialize(is, boost::get<2>(item), nType, nVersion);
experimental-genesis 703 Unserialize(is, boost::get<3>(item), nType, nVersion);
experimental-genesis 704 }
experimental-genesis 705
experimental-genesis 706
experimental-genesis 707
experimental-genesis 708
experimental-genesis 709
experimental-genesis 710
experimental-genesis 711 template<typename K, typename T, typename Pred, typename A>
experimental-genesis 712 unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion)
experimental-genesis 713 {
experimental-genesis 714 unsigned int nSize = GetSizeOfCompactSize(m.size());
experimental-genesis 715 for (typename std::map<K, T, Pred, A>::const_iterator mi = m.begin(); mi != m.end(); ++mi)
experimental-genesis 716 nSize += GetSerializeSize((*mi), nType, nVersion);
experimental-genesis 717 return nSize;
experimental-genesis 718 }
experimental-genesis 719
experimental-genesis 720 template<typename Stream, typename K, typename T, typename Pred, typename A>
experimental-genesis 721 void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion)
experimental-genesis 722 {
experimental-genesis 723 WriteCompactSize(os, m.size());
experimental-genesis 724 for (typename std::map<K, T, Pred, A>::const_iterator mi = m.begin(); mi != m.end(); ++mi)
experimental-genesis 725 Serialize(os, (*mi), nType, nVersion);
experimental-genesis 726 }
experimental-genesis 727
experimental-genesis 728 template<typename Stream, typename K, typename T, typename Pred, typename A>
experimental-genesis 729 void Unserialize(Stream& is, std::map<K, T, Pred, A>& m, int nType, int nVersion)
experimental-genesis 730 {
experimental-genesis 731 m.clear();
experimental-genesis 732 unsigned int nSize = ReadCompactSize(is);
experimental-genesis 733 typename std::map<K, T, Pred, A>::iterator mi = m.begin();
experimental-genesis 734 for (unsigned int i = 0; i < nSize; i++)
experimental-genesis 735 {
experimental-genesis 736 std::pair<K, T> item;
experimental-genesis 737 Unserialize(is, item, nType, nVersion);
experimental-genesis 738 mi = m.insert(mi, item);
experimental-genesis 739 }
experimental-genesis 740 }
experimental-genesis 741
experimental-genesis 742
experimental-genesis 743
experimental-genesis 744
experimental-genesis 745
experimental-genesis 746
experimental-genesis 747 template<typename K, typename Pred, typename A>
experimental-genesis 748 unsigned int GetSerializeSize(const std::set<K, Pred, A>& m, int nType, int nVersion)
experimental-genesis 749 {
experimental-genesis 750 unsigned int nSize = GetSizeOfCompactSize(m.size());
experimental-genesis 751 for (typename std::set<K, Pred, A>::const_iterator it = m.begin(); it != m.end(); ++it)
experimental-genesis 752 nSize += GetSerializeSize((*it), nType, nVersion);
experimental-genesis 753 return nSize;
experimental-genesis 754 }
experimental-genesis 755
experimental-genesis 756 template<typename Stream, typename K, typename Pred, typename A>
experimental-genesis 757 void Serialize(Stream& os, const std::set<K, Pred, A>& m, int nType, int nVersion)
experimental-genesis 758 {
experimental-genesis 759 WriteCompactSize(os, m.size());
experimental-genesis 760 for (typename std::set<K, Pred, A>::const_iterator it = m.begin(); it != m.end(); ++it)
experimental-genesis 761 Serialize(os, (*it), nType, nVersion);
experimental-genesis 762 }
experimental-genesis 763
experimental-genesis 764 template<typename Stream, typename K, typename Pred, typename A>
experimental-genesis 765 void Unserialize(Stream& is, std::set<K, Pred, A>& m, int nType, int nVersion)
experimental-genesis 766 {
experimental-genesis 767 m.clear();
experimental-genesis 768 unsigned int nSize = ReadCompactSize(is);
experimental-genesis 769 typename std::set<K, Pred, A>::iterator it = m.begin();
experimental-genesis 770 for (unsigned int i = 0; i < nSize; i++)
experimental-genesis 771 {
experimental-genesis 772 K key;
experimental-genesis 773 Unserialize(is, key, nType, nVersion);
experimental-genesis 774 it = m.insert(it, key);
experimental-genesis 775 }
experimental-genesis 776 }
experimental-genesis 777
experimental-genesis 778
experimental-genesis 779
experimental-genesis 780
experimental-genesis 781
experimental-genesis 782
experimental-genesis 783 class CSerActionGetSerializeSize { };
experimental-genesis 784 class CSerActionSerialize { };
experimental-genesis 785 class CSerActionUnserialize { };
experimental-genesis 786
experimental-genesis 787 template<typename Stream, typename T>
experimental-genesis 788 inline unsigned int SerReadWrite(Stream& s, const T& obj, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
experimental-genesis 789 {
experimental-genesis 790 return ::GetSerializeSize(obj, nType, nVersion);
experimental-genesis 791 }
experimental-genesis 792
experimental-genesis 793 template<typename Stream, typename T>
experimental-genesis 794 inline unsigned int SerReadWrite(Stream& s, const T& obj, int nType, int nVersion, CSerActionSerialize ser_action)
experimental-genesis 795 {
experimental-genesis 796 ::Serialize(s, obj, nType, nVersion);
experimental-genesis 797 return 0;
experimental-genesis 798 }
experimental-genesis 799
experimental-genesis 800 template<typename Stream, typename T>
experimental-genesis 801 inline unsigned int SerReadWrite(Stream& s, T& obj, int nType, int nVersion, CSerActionUnserialize ser_action)
experimental-genesis 802 {
experimental-genesis 803 ::Unserialize(s, obj, nType, nVersion);
experimental-genesis 804 return 0;
experimental-genesis 805 }
experimental-genesis 806
experimental-genesis 807 struct ser_streamplaceholder
experimental-genesis 808 {
experimental-genesis 809 int nType;
experimental-genesis 810 int nVersion;
experimental-genesis 811 };
experimental-genesis 812
experimental-genesis 813
experimental-genesis 814
experimental-genesis 815
experimental-genesis 816
experimental-genesis 817
experimental-genesis 818
experimental-genesis 819
experimental-genesis 820
experimental-genesis 821
experimental-genesis 822
experimental-genesis 823
experimental-genesis 824
experimental-genesis 825 template<typename T>
experimental-genesis 826 struct secure_allocator : public std::allocator<T>
experimental-genesis 827 {
experimental-genesis 828
experimental-genesis 829 typedef std::allocator<T> base;
experimental-genesis 830 typedef typename base::size_type size_type;
experimental-genesis 831 typedef typename base::difference_type difference_type;
experimental-genesis 832 typedef typename base::pointer pointer;
experimental-genesis 833 typedef typename base::const_pointer const_pointer;
experimental-genesis 834 typedef typename base::reference reference;
experimental-genesis 835 typedef typename base::const_reference const_reference;
experimental-genesis 836 typedef typename base::value_type value_type;
experimental-genesis 837 secure_allocator() throw() {}
experimental-genesis 838 secure_allocator(const secure_allocator& a) throw() : base(a) {}
experimental-genesis 839 template <typename U>
experimental-genesis 840 secure_allocator(const secure_allocator<U>& a) throw() : base(a) {}
experimental-genesis 841 ~secure_allocator() throw() {}
experimental-genesis 842 template<typename _Other> struct rebind
experimental-genesis 843 { typedef secure_allocator<_Other> other; };
experimental-genesis 844
experimental-genesis 845 T* allocate(std::size_t n, const void *hint = 0)
experimental-genesis 846 {
experimental-genesis 847 T *p;
experimental-genesis 848 p = std::allocator<T>::allocate(n, hint);
experimental-genesis 849 if (p != NULL)
experimental-genesis 850 mlock(p, sizeof(T) * n);
experimental-genesis 851 return p;
experimental-genesis 852 }
experimental-genesis 853
experimental-genesis 854 void deallocate(T* p, std::size_t n)
experimental-genesis 855 {
experimental-genesis 856 if (p != NULL)
experimental-genesis 857 {
experimental-genesis 858 memset(p, 0, sizeof(T) * n);
experimental-genesis 859 munlock(p, sizeof(T) * n);
experimental-genesis 860 }
experimental-genesis 861 std::allocator<T>::deallocate(p, n);
experimental-genesis 862 }
experimental-genesis 863 };
experimental-genesis 864
experimental-genesis 865
experimental-genesis 866
experimental-genesis 867
experimental-genesis 868
experimental-genesis 869 template<typename T>
experimental-genesis 870 struct zero_after_free_allocator : public std::allocator<T>
experimental-genesis 871 {
experimental-genesis 872
experimental-genesis 873 typedef std::allocator<T> base;
experimental-genesis 874 typedef typename base::size_type size_type;
experimental-genesis 875 typedef typename base::difference_type difference_type;
experimental-genesis 876 typedef typename base::pointer pointer;
experimental-genesis 877 typedef typename base::const_pointer const_pointer;
experimental-genesis 878 typedef typename base::reference reference;
experimental-genesis 879 typedef typename base::const_reference const_reference;
experimental-genesis 880 typedef typename base::value_type value_type;
experimental-genesis 881 zero_after_free_allocator() throw() {}
experimental-genesis 882 zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {}
experimental-genesis 883 template <typename U>
experimental-genesis 884 zero_after_free_allocator(const zero_after_free_allocator<U>& a) throw() : base(a) {}
experimental-genesis 885 ~zero_after_free_allocator() throw() {}
experimental-genesis 886 template<typename _Other> struct rebind
experimental-genesis 887 { typedef zero_after_free_allocator<_Other> other; };
experimental-genesis 888
experimental-genesis 889 void deallocate(T* p, std::size_t n)
experimental-genesis 890 {
experimental-genesis 891 if (p != NULL)
experimental-genesis 892 memset(p, 0, sizeof(T) * n);
experimental-genesis 893 std::allocator<T>::deallocate(p, n);
experimental-genesis 894 }
experimental-genesis 895 };
experimental-genesis 896
experimental-genesis 897
experimental-genesis 898
experimental-genesis 899
experimental-genesis 900
experimental-genesis 901
experimental-genesis 902
experimental-genesis 903
experimental-genesis 904 class CDataStream
experimental-genesis 905 {
experimental-genesis 906 protected:
experimental-genesis 907 typedef std::vector<char, zero_after_free_allocator<char> > vector_type;
experimental-genesis 908 vector_type vch;
experimental-genesis 909 unsigned int nReadPos;
experimental-genesis 910 short state;
experimental-genesis 911 short exceptmask;
experimental-genesis 912 public:
experimental-genesis 913 int nType;
experimental-genesis 914 int nVersion;
experimental-genesis 915
experimental-genesis 916 typedef vector_type::allocator_type allocator_type;
experimental-genesis 917 typedef vector_type::size_type size_type;
experimental-genesis 918 typedef vector_type::difference_type difference_type;
experimental-genesis 919 typedef vector_type::reference reference;
experimental-genesis 920 typedef vector_type::const_reference const_reference;
experimental-genesis 921 typedef vector_type::value_type value_type;
experimental-genesis 922 typedef vector_type::iterator iterator;
experimental-genesis 923 typedef vector_type::const_iterator const_iterator;
experimental-genesis 924 typedef vector_type::reverse_iterator reverse_iterator;
experimental-genesis 925
experimental-genesis 926 explicit CDataStream(int nTypeIn=SER_NETWORK, int nVersionIn=VERSION)
experimental-genesis 927 {
experimental-genesis 928 Init(nTypeIn, nVersionIn);
experimental-genesis 929 }
experimental-genesis 930
experimental-genesis 931 CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(pbegin, pend)
experimental-genesis 932 {
experimental-genesis 933 Init(nTypeIn, nVersionIn);
experimental-genesis 934 }
experimental-genesis 935
experimental-genesis 936 #if !defined(_MSC_VER) || _MSC_VER >= 1300
experimental-genesis 937 CDataStream(const char* pbegin, const char* pend, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(pbegin, pend)
experimental-genesis 938 {
experimental-genesis 939 Init(nTypeIn, nVersionIn);
experimental-genesis 940 }
experimental-genesis 941 #endif
experimental-genesis 942
experimental-genesis 943 CDataStream(const vector_type& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(vchIn.begin(), vchIn.end())
experimental-genesis 944 {
experimental-genesis 945 Init(nTypeIn, nVersionIn);
experimental-genesis 946 }
experimental-genesis 947
experimental-genesis 948 CDataStream(const std::vector<char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(vchIn.begin(), vchIn.end())
experimental-genesis 949 {
experimental-genesis 950 Init(nTypeIn, nVersionIn);
experimental-genesis 951 }
experimental-genesis 952
experimental-genesis 953 CDataStream(const std::vector<unsigned char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch((char*)&vchIn.begin()[0], (char*)&vchIn.end()[0])
experimental-genesis 954 {
experimental-genesis 955 Init(nTypeIn, nVersionIn);
experimental-genesis 956 }
experimental-genesis 957
experimental-genesis 958 void Init(int nTypeIn=SER_NETWORK, int nVersionIn=VERSION)
experimental-genesis 959 {
experimental-genesis 960 nReadPos = 0;
experimental-genesis 961 nType = nTypeIn;
experimental-genesis 962 nVersion = nVersionIn;
experimental-genesis 963 state = 0;
experimental-genesis 964 exceptmask = std::ios::badbit | std::ios::failbit;
experimental-genesis 965 }
experimental-genesis 966
experimental-genesis 967 CDataStream& operator+=(const CDataStream& b)
experimental-genesis 968 {
experimental-genesis 969 vch.insert(vch.end(), b.begin(), b.end());
experimental-genesis 970 return *this;
experimental-genesis 971 }
experimental-genesis 972
experimental-genesis 973 friend CDataStream operator+(const CDataStream& a, const CDataStream& b)
experimental-genesis 974 {
experimental-genesis 975 CDataStream ret = a;
experimental-genesis 976 ret += b;
experimental-genesis 977 return (ret);
experimental-genesis 978 }
experimental-genesis 979
experimental-genesis 980 std::string str() const
experimental-genesis 981 {
experimental-genesis 982 return (std::string(begin(), end()));
experimental-genesis 983 }
experimental-genesis 984
experimental-genesis 985
experimental-genesis 986
experimental-genesis 987
experimental-genesis 988
experimental-genesis 989 const_iterator begin() const { return vch.begin() + nReadPos; }
experimental-genesis 990 iterator begin() { return vch.begin() + nReadPos; }
experimental-genesis 991 const_iterator end() const { return vch.end(); }
experimental-genesis 992 iterator end() { return vch.end(); }
experimental-genesis 993 size_type size() const { return vch.size() - nReadPos; }
experimental-genesis 994 bool empty() const { return vch.size() == nReadPos; }
experimental-genesis 995 void resize(size_type n, value_type c=0) { vch.resize(n + nReadPos, c); }
experimental-genesis 996 void reserve(size_type n) { vch.reserve(n + nReadPos); }
experimental-genesis 997 const_reference operator[](size_type pos) const { return vch[pos + nReadPos]; }
experimental-genesis 998 reference operator[](size_type pos) { return vch[pos + nReadPos]; }
experimental-genesis 999 void clear() { vch.clear(); nReadPos = 0; }
experimental-genesis 1000 iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); }
experimental-genesis 1001 void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); }
experimental-genesis 1002
experimental-genesis 1003 void insert(iterator it, const_iterator first, const_iterator last)
experimental-genesis 1004 {
experimental-genesis 1005 if (it == vch.begin() + nReadPos && last - first <= nReadPos)
experimental-genesis 1006 {
experimental-genesis 1007
experimental-genesis 1008 nReadPos -= (last - first);
experimental-genesis 1009 memcpy(&vch[nReadPos], &first[0], last - first);
experimental-genesis 1010 }
experimental-genesis 1011 else
experimental-genesis 1012 vch.insert(it, first, last);
experimental-genesis 1013 }
experimental-genesis 1014
experimental-genesis 1015 void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
experimental-genesis 1016 {
experimental-genesis 1017 if (it == vch.begin() + nReadPos && last - first <= nReadPos)
experimental-genesis 1018 {
experimental-genesis 1019
experimental-genesis 1020 nReadPos -= (last - first);
experimental-genesis 1021 memcpy(&vch[nReadPos], &first[0], last - first);
experimental-genesis 1022 }
experimental-genesis 1023 else
experimental-genesis 1024 vch.insert(it, first, last);
experimental-genesis 1025 }
experimental-genesis 1026
experimental-genesis 1027 #if !defined(_MSC_VER) || _MSC_VER >= 1300
experimental-genesis 1028 void insert(iterator it, const char* first, const char* last)
experimental-genesis 1029 {
experimental-genesis 1030 if (it == vch.begin() + nReadPos && last - first <= nReadPos)
experimental-genesis 1031 {
experimental-genesis 1032
experimental-genesis 1033 nReadPos -= (last - first);
experimental-genesis 1034 memcpy(&vch[nReadPos], &first[0], last - first);
experimental-genesis 1035 }
experimental-genesis 1036 else
experimental-genesis 1037 vch.insert(it, first, last);
experimental-genesis 1038 }
experimental-genesis 1039 #endif
experimental-genesis 1040
experimental-genesis 1041 iterator erase(iterator it)
experimental-genesis 1042 {
experimental-genesis 1043 if (it == vch.begin() + nReadPos)
experimental-genesis 1044 {
experimental-genesis 1045
experimental-genesis 1046 if (++nReadPos >= vch.size())
experimental-genesis 1047 {
experimental-genesis 1048
experimental-genesis 1049 nReadPos = 0;
experimental-genesis 1050 return vch.erase(vch.begin(), vch.end());
experimental-genesis 1051 }
experimental-genesis 1052 return vch.begin() + nReadPos;
experimental-genesis 1053 }
experimental-genesis 1054 else
experimental-genesis 1055 return vch.erase(it);
experimental-genesis 1056 }
experimental-genesis 1057
experimental-genesis 1058 iterator erase(iterator first, iterator last)
experimental-genesis 1059 {
experimental-genesis 1060 if (first == vch.begin() + nReadPos)
experimental-genesis 1061 {
experimental-genesis 1062
experimental-genesis 1063 if (last == vch.end())
experimental-genesis 1064 {
experimental-genesis 1065 nReadPos = 0;
experimental-genesis 1066 return vch.erase(vch.begin(), vch.end());
experimental-genesis 1067 }
experimental-genesis 1068 else
experimental-genesis 1069 {
experimental-genesis 1070 nReadPos = (last - vch.begin());
experimental-genesis 1071 return last;
experimental-genesis 1072 }
experimental-genesis 1073 }
experimental-genesis 1074 else
experimental-genesis 1075 return vch.erase(first, last);
experimental-genesis 1076 }
experimental-genesis 1077
experimental-genesis 1078 inline void Compact()
experimental-genesis 1079 {
experimental-genesis 1080 vch.erase(vch.begin(), vch.begin() + nReadPos);
experimental-genesis 1081 nReadPos = 0;
experimental-genesis 1082 }
experimental-genesis 1083
experimental-genesis 1084 bool Rewind(size_type n)
experimental-genesis 1085 {
experimental-genesis 1086
experimental-genesis 1087 if (n > nReadPos)
experimental-genesis 1088 return false;
experimental-genesis 1089 nReadPos -= n;
experimental-genesis 1090 return true;
experimental-genesis 1091 }
experimental-genesis 1092
experimental-genesis 1093
experimental-genesis 1094
experimental-genesis 1095
experimental-genesis 1096
experimental-genesis 1097 void setstate(short bits, const char* psz)
experimental-genesis 1098 {
experimental-genesis 1099 state |= bits;
experimental-genesis 1100 if (state & exceptmask)
experimental-genesis 1101 throw std::ios_base::failure(psz);
experimental-genesis 1102 }
experimental-genesis 1103
experimental-genesis 1104 bool eof() const { return size() == 0; }
experimental-genesis 1105 bool fail() const { return state & (std::ios::badbit | std::ios::failbit); }
experimental-genesis 1106 bool good() const { return !eof() && (state == 0); }
experimental-genesis 1107 void clear(short n) { state = n; }
experimental-genesis 1108 short exceptions() { return exceptmask; }
experimental-genesis 1109 short exceptions(short mask) { short prev = exceptmask; exceptmask = mask; setstate(0, "CDataStream"); return prev; }
experimental-genesis 1110 CDataStream* rdbuf() { return this; }
experimental-genesis 1111 int in_avail() { return size(); }
experimental-genesis 1112
experimental-genesis 1113 void SetType(int n) { nType = n; }
experimental-genesis 1114 int GetType() { return nType; }
experimental-genesis 1115 void SetVersion(int n) { nVersion = n; }
experimental-genesis 1116 int GetVersion() { return nVersion; }
experimental-genesis 1117 void ReadVersion() { *this >> nVersion; }
experimental-genesis 1118 void WriteVersion() { *this << nVersion; }
experimental-genesis 1119
experimental-genesis 1120 CDataStream& read(char* pch, int nSize)
experimental-genesis 1121 {
experimental-genesis 1122
experimental-genesis 1123 assert(nSize >= 0);
experimental-genesis 1124 unsigned int nReadPosNext = nReadPos + nSize;
experimental-genesis 1125 if (nReadPosNext >= vch.size())
experimental-genesis 1126 {
experimental-genesis 1127 if (nReadPosNext > vch.size())
experimental-genesis 1128 {
experimental-genesis 1129 setstate(std::ios::failbit, "CDataStream::read() : end of data");
experimental-genesis 1130 memset(pch, 0, nSize);
experimental-genesis 1131 nSize = vch.size() - nReadPos;
experimental-genesis 1132 }
experimental-genesis 1133 memcpy(pch, &vch[nReadPos], nSize);
experimental-genesis 1134 nReadPos = 0;
experimental-genesis 1135 vch.clear();
experimental-genesis 1136 return (*this);
experimental-genesis 1137 }
experimental-genesis 1138 memcpy(pch, &vch[nReadPos], nSize);
experimental-genesis 1139 nReadPos = nReadPosNext;
experimental-genesis 1140 return (*this);
experimental-genesis 1141 }
experimental-genesis 1142
experimental-genesis 1143 CDataStream& ignore(int nSize)
experimental-genesis 1144 {
experimental-genesis 1145
experimental-genesis 1146 assert(nSize >= 0);
experimental-genesis 1147 unsigned int nReadPosNext = nReadPos + nSize;
experimental-genesis 1148 if (nReadPosNext >= vch.size())
experimental-genesis 1149 {
experimental-genesis 1150 if (nReadPosNext > vch.size())
experimental-genesis 1151 {
experimental-genesis 1152 setstate(std::ios::failbit, "CDataStream::ignore() : end of data");
experimental-genesis 1153 nSize = vch.size() - nReadPos;
experimental-genesis 1154 }
experimental-genesis 1155 nReadPos = 0;
experimental-genesis 1156 vch.clear();
experimental-genesis 1157 return (*this);
experimental-genesis 1158 }
experimental-genesis 1159 nReadPos = nReadPosNext;
experimental-genesis 1160 return (*this);
experimental-genesis 1161 }
experimental-genesis 1162
experimental-genesis 1163 CDataStream& write(const char* pch, int nSize)
experimental-genesis 1164 {
experimental-genesis 1165
experimental-genesis 1166 assert(nSize >= 0);
experimental-genesis 1167 vch.insert(vch.end(), pch, pch + nSize);
experimental-genesis 1168 return (*this);
experimental-genesis 1169 }
experimental-genesis 1170
experimental-genesis 1171 template<typename Stream>
experimental-genesis 1172 void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const
experimental-genesis 1173 {
experimental-genesis 1174
experimental-genesis 1175 if (!vch.empty())
experimental-genesis 1176 s.write((char*)&vch[0], vch.size() * sizeof(vch[0]));
experimental-genesis 1177 }
experimental-genesis 1178
experimental-genesis 1179 template<typename T>
experimental-genesis 1180 unsigned int GetSerializeSize(const T& obj)
experimental-genesis 1181 {
experimental-genesis 1182
experimental-genesis 1183 return ::GetSerializeSize(obj, nType, nVersion);
experimental-genesis 1184 }
experimental-genesis 1185
experimental-genesis 1186 template<typename T>
experimental-genesis 1187 CDataStream& operator<<(const T& obj)
experimental-genesis 1188 {
experimental-genesis 1189
experimental-genesis 1190 ::Serialize(*this, obj, nType, nVersion);
experimental-genesis 1191 return (*this);
experimental-genesis 1192 }
experimental-genesis 1193
experimental-genesis 1194 template<typename T>
experimental-genesis 1195 CDataStream& operator>>(T& obj)
experimental-genesis 1196 {
experimental-genesis 1197
experimental-genesis 1198 ::Unserialize(*this, obj, nType, nVersion);
experimental-genesis 1199 return (*this);
experimental-genesis 1200 }
experimental-genesis 1201 };
experimental-genesis 1202
experimental-genesis 1203 #ifdef TESTCDATASTREAM
experimental-genesis 1204
experimental-genesis 1205
experimental-genesis 1206
experimental-genesis 1207
experimental-genesis 1208
experimental-genesis 1209
experimental-genesis 1210
experimental-genesis 1211
experimental-genesis 1212
experimental-genesis 1213
experimental-genesis 1214
experimental-genesis 1215
experimental-genesis 1216
experimental-genesis 1217
experimental-genesis 1218
experimental-genesis 1219
experimental-genesis 1220
experimental-genesis 1221
experimental-genesis 1222
experimental-genesis 1223
experimental-genesis 1224
experimental-genesis 1225
experimental-genesis 1226
experimental-genesis 1227
experimental-genesis 1228
experimental-genesis 1229 #include <iostream>
experimental-genesis 1230 int main(int argc, char *argv[])
experimental-genesis 1231 {
experimental-genesis 1232 vector<unsigned char> vch(0xcc, 250);
experimental-genesis 1233 printf("CDataStream:\n");
experimental-genesis 1234 for (int n = 1000; n <= 4500000; n *= 2)
experimental-genesis 1235 {
experimental-genesis 1236 CDataStream ss;
experimental-genesis 1237 time_t nStart = time(NULL);
experimental-genesis 1238 for (int i = 0; i < n; i++)
experimental-genesis 1239 ss.write((char*)&vch[0], vch.size());
experimental-genesis 1240 printf("n=%-10d %d seconds\n", n, time(NULL) - nStart);
experimental-genesis 1241 }
experimental-genesis 1242 printf("stringstream:\n");
experimental-genesis 1243 for (int n = 1000; n <= 4500000; n *= 2)
experimental-genesis 1244 {
experimental-genesis 1245 stringstream ss;
experimental-genesis 1246 time_t nStart = time(NULL);
experimental-genesis 1247 for (int i = 0; i < n; i++)
experimental-genesis 1248 ss.write((char*)&vch[0], vch.size());
experimental-genesis 1249 printf("n=%-10d %d seconds\n", n, time(NULL) - nStart);
experimental-genesis 1250 }
experimental-genesis 1251 }
experimental-genesis 1252 #endif
experimental-genesis 1253
experimental-genesis 1254
experimental-genesis 1255
experimental-genesis 1256
experimental-genesis 1257
experimental-genesis 1258
experimental-genesis 1259
experimental-genesis 1260
experimental-genesis 1261
experimental-genesis 1262
experimental-genesis 1263
experimental-genesis 1264
experimental-genesis 1265
experimental-genesis 1266
experimental-genesis 1267
experimental-genesis 1268
experimental-genesis 1269 class CAutoFile
experimental-genesis 1270 {
experimental-genesis 1271 protected:
experimental-genesis 1272 FILE* file;
experimental-genesis 1273 short state;
experimental-genesis 1274 short exceptmask;
experimental-genesis 1275 public:
experimental-genesis 1276 int nType;
experimental-genesis 1277 int nVersion;
experimental-genesis 1278
experimental-genesis 1279 typedef FILE element_type;
experimental-genesis 1280
experimental-genesis 1281 CAutoFile(FILE* filenew=NULL, int nTypeIn=SER_DISK, int nVersionIn=VERSION)
experimental-genesis 1282 {
experimental-genesis 1283 file = filenew;
experimental-genesis 1284 nType = nTypeIn;
experimental-genesis 1285 nVersion = nVersionIn;
experimental-genesis 1286 state = 0;
experimental-genesis 1287 exceptmask = std::ios::badbit | std::ios::failbit;
experimental-genesis 1288 }
experimental-genesis 1289
experimental-genesis 1290 ~CAutoFile()
experimental-genesis 1291 {
experimental-genesis 1292 fclose();
experimental-genesis 1293 }
experimental-genesis 1294
experimental-genesis 1295 void fclose()
experimental-genesis 1296 {
experimental-genesis 1297 if (file != NULL && file != stdin && file != stdout && file != stderr)
experimental-genesis 1298 ::fclose(file);
experimental-genesis 1299 file = NULL;
experimental-genesis 1300 }
experimental-genesis 1301
experimental-genesis 1302 FILE* release() { FILE* ret = file; file = NULL; return ret; }
experimental-genesis 1303 operator FILE*() { return file; }
experimental-genesis 1304 FILE* operator->() { return file; }
experimental-genesis 1305 FILE& operator*() { return *file; }
experimental-genesis 1306 FILE** operator&() { return &file; }
experimental-genesis 1307 FILE* operator=(FILE* pnew) { return file = pnew; }
experimental-genesis 1308 bool operator!() { return (file == NULL); }
experimental-genesis 1309
experimental-genesis 1310
experimental-genesis 1311
experimental-genesis 1312
experimental-genesis 1313
experimental-genesis 1314 void setstate(short bits, const char* psz)
experimental-genesis 1315 {
experimental-genesis 1316 state |= bits;
experimental-genesis 1317 if (state & exceptmask)
experimental-genesis 1318 throw std::ios_base::failure(psz);
experimental-genesis 1319 }
experimental-genesis 1320
experimental-genesis 1321 bool fail() const { return state & (std::ios::badbit | std::ios::failbit); }
experimental-genesis 1322 bool good() const { return state == 0; }
experimental-genesis 1323 void clear(short n = 0) { state = n; }
experimental-genesis 1324 short exceptions() { return exceptmask; }
experimental-genesis 1325 short exceptions(short mask) { short prev = exceptmask; exceptmask = mask; setstate(0, "CAutoFile"); return prev; }
experimental-genesis 1326
experimental-genesis 1327 void SetType(int n) { nType = n; }
experimental-genesis 1328 int GetType() { return nType; }
experimental-genesis 1329 void SetVersion(int n) { nVersion = n; }
experimental-genesis 1330 int GetVersion() { return nVersion; }
experimental-genesis 1331 void ReadVersion() { *this >> nVersion; }
experimental-genesis 1332 void WriteVersion() { *this << nVersion; }
experimental-genesis 1333
experimental-genesis 1334 CAutoFile& read(char* pch, int nSize)
experimental-genesis 1335 {
experimental-genesis 1336 if (!file)
experimental-genesis 1337 throw std::ios_base::failure("CAutoFile::read : file handle is NULL");
experimental-genesis 1338 if (fread(pch, 1, nSize, file) != nSize)
experimental-genesis 1339 setstate(std::ios::failbit, feof(file) ? "CAutoFile::read : end of file" : "CAutoFile::read : fread failed");
experimental-genesis 1340 return (*this);
experimental-genesis 1341 }
experimental-genesis 1342
experimental-genesis 1343 CAutoFile& write(const char* pch, int nSize)
experimental-genesis 1344 {
experimental-genesis 1345 if (!file)
experimental-genesis 1346 throw std::ios_base::failure("CAutoFile::write : file handle is NULL");
experimental-genesis 1347 if (fwrite(pch, 1, nSize, file) != nSize)
experimental-genesis 1348 setstate(std::ios::failbit, "CAutoFile::write : write failed");
experimental-genesis 1349 return (*this);
experimental-genesis 1350 }
experimental-genesis 1351
experimental-genesis 1352 template<typename T>
experimental-genesis 1353 unsigned int GetSerializeSize(const T& obj)
experimental-genesis 1354 {
experimental-genesis 1355
experimental-genesis 1356 return ::GetSerializeSize(obj, nType, nVersion);
experimental-genesis 1357 }
experimental-genesis 1358
experimental-genesis 1359 template<typename T>
experimental-genesis 1360 CAutoFile& operator<<(const T& obj)
experimental-genesis 1361 {
experimental-genesis 1362
experimental-genesis 1363 if (!file)
experimental-genesis 1364 throw std::ios_base::failure("CAutoFile::operator<< : file handle is NULL");
experimental-genesis 1365 ::Serialize(*this, obj, nType, nVersion);
experimental-genesis 1366 return (*this);
experimental-genesis 1367 }
experimental-genesis 1368
experimental-genesis 1369 template<typename T>
experimental-genesis 1370 CAutoFile& operator>>(T& obj)
experimental-genesis 1371 {
experimental-genesis 1372
experimental-genesis 1373 if (!file)
experimental-genesis 1374 throw std::ios_base::failure("CAutoFile::operator>> : file handle is NULL");
experimental-genesis 1375 ::Unserialize(*this, obj, nType, nVersion);
experimental-genesis 1376 return (*this);
experimental-genesis 1377 }
experimental-genesis 1378 };
experimental-genesis 1379
experimental-genesis 1380 #endif