[184] | 1 | #pragma once
|
---|
| 2 |
|
---|
[256] | 3 | #include <BoostSerializationSupport.h>
|
---|
| 4 |
|
---|
[184] | 5 | //DataTable.cpp
|
---|
| 6 | class DataTable{
|
---|
[256] | 7 | char *buffer;
|
---|
[184] | 8 | int size;
|
---|
| 9 |
|
---|
[256] | 10 | // XMLシリアライズ用
|
---|
| 11 | private:
|
---|
| 12 | friend class boost::serialization::access;
|
---|
| 13 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
---|
| 14 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
---|
| 15 | {
|
---|
| 16 | std::string _buffer;
|
---|
| 17 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
| 18 | ar & BOOST_SERIALIZATION_NVP( size );
|
---|
| 19 |
|
---|
| 20 | // 読み込み後の処理
|
---|
| 21 | Realloc( size );
|
---|
| 22 | for( int i=0; i<size; i++ )
|
---|
| 23 | {
|
---|
| 24 | if( _buffer[i*3+2] != ',' )
|
---|
| 25 | {
|
---|
| 26 | //エラー
|
---|
| 27 | DebugBreak();
|
---|
| 28 | }
|
---|
| 29 | ULONG_PTR l;
|
---|
| 30 | sscanf( _buffer.c_str() + i*3, "%02x,", &l );
|
---|
| 31 | buffer[i] = (char)l;
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
---|
| 35 | {
|
---|
| 36 | // 保存準備
|
---|
| 37 | char *tempCode = (char *)calloc( (size+1) * 3, 1 );
|
---|
| 38 | for( int i=0; i<size; i++ )
|
---|
| 39 | {
|
---|
| 40 | char temp[32];
|
---|
| 41 | sprintf( temp, "%02x,", (unsigned char)buffer[i] );
|
---|
| 42 | tempCode[i*3] = temp[0];
|
---|
| 43 | tempCode[i*3+1] = temp[1];
|
---|
| 44 | tempCode[i*3+2] = temp[2];
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | std::string _buffer = tempCode;
|
---|
| 48 | free( tempCode );
|
---|
| 49 |
|
---|
| 50 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
| 51 | ar & BOOST_SERIALIZATION_NVP( size );
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[184] | 54 | public:
|
---|
[256] | 55 | DataTable()
|
---|
| 56 | : buffer( (char *)malloc(100) )
|
---|
| 57 | , size( 0 )
|
---|
| 58 | {
|
---|
| 59 | lstrcpy( buffer, "initialized!!!" );
|
---|
| 60 | }
|
---|
| 61 | DataTable( const DataTable &dataTable )
|
---|
| 62 | : buffer( (char *)malloc(100) )
|
---|
| 63 | , size( 0 )
|
---|
| 64 | {
|
---|
| 65 | lstrcpy( buffer, "initialized!!!" );
|
---|
| 66 | AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
|
---|
| 67 | }
|
---|
| 68 | ~DataTable()
|
---|
| 69 | {
|
---|
| 70 | free( buffer );
|
---|
| 71 | }
|
---|
| 72 | void Clear()
|
---|
| 73 | {
|
---|
| 74 | size = 0;
|
---|
| 75 | }
|
---|
[184] | 76 |
|
---|
[256] | 77 | void operator =( const DataTable &dataTable )
|
---|
| 78 | {
|
---|
| 79 | Clear();
|
---|
| 80 | AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void Realloc( int size );
|
---|
| 84 | int AddBinary( const void *buffer, int size );
|
---|
[184] | 85 | int Add( _int64 i64data );
|
---|
| 86 | int Add( int i32data );
|
---|
| 87 | int Add( double dbl );
|
---|
| 88 | int Add( float flt );
|
---|
| 89 | int AddString( const char *str, int length );
|
---|
| 90 | int AddString( const char *str );
|
---|
| 91 |
|
---|
| 92 | const void *GetPtr() const;
|
---|
| 93 | int GetSize() const;
|
---|
| 94 | };
|
---|