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