1 | #pragma once
|
---|
2 |
|
---|
3 | #include <BoostSerializationSupport.h>
|
---|
4 |
|
---|
5 | //DataTable.cpp
|
---|
6 | class DataTable
|
---|
7 | {
|
---|
8 | char *buffer;
|
---|
9 | int size;
|
---|
10 |
|
---|
11 | public:
|
---|
12 | // リンカで解決しなければならないスケジュール
|
---|
13 | Schedules schedules;
|
---|
14 |
|
---|
15 | // XMLシリアライズ用
|
---|
16 | private:
|
---|
17 | friend class boost::serialization::access;
|
---|
18 | BOOST_SERIALIZATION_SPLIT_MEMBER();
|
---|
19 | template<class Archive> void load(Archive& ar, const unsigned int version)
|
---|
20 | {
|
---|
21 | std::string _buffer;
|
---|
22 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
23 | ar & BOOST_SERIALIZATION_NVP( size );
|
---|
24 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
---|
25 |
|
---|
26 | // 読み込み後の処理
|
---|
27 | Realloc( size );
|
---|
28 | for( int i=0; i<size; i++ )
|
---|
29 | {
|
---|
30 | ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
|
---|
31 | ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
|
---|
32 | ULONG_PTR l = l1 + l2;
|
---|
33 | buffer[i] = static_cast<char>(l);
|
---|
34 | }
|
---|
35 | }
|
---|
36 | template<class Archive> void save(Archive& ar, const unsigned int version) const
|
---|
37 | {
|
---|
38 | // 保存準備
|
---|
39 | char *tempCode = (char *)calloc( (size+1) * 3, 1 );
|
---|
40 | for( int i=0; i<size; i++ )
|
---|
41 | {
|
---|
42 | char temp[32];
|
---|
43 | sprintf( temp, "%02x,", (unsigned char)buffer[i] );
|
---|
44 | tempCode[i*3] = temp[0];
|
---|
45 | tempCode[i*3+1] = temp[1];
|
---|
46 | tempCode[i*3+2] = temp[2];
|
---|
47 | }
|
---|
48 |
|
---|
49 | std::string _buffer = tempCode;
|
---|
50 | free( tempCode );
|
---|
51 |
|
---|
52 | ar & BOOST_SERIALIZATION_NVP( _buffer );
|
---|
53 | ar & BOOST_SERIALIZATION_NVP( size );
|
---|
54 | ar & BOOST_SERIALIZATION_NVP( schedules );
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | void Realloc( int size )
|
---|
59 | {
|
---|
60 | this->buffer = (char *)realloc( this->buffer, size + 100 );
|
---|
61 | this->size = size;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public:
|
---|
65 | DataTable()
|
---|
66 | : buffer( (char *)malloc(100) )
|
---|
67 | , size( 0 )
|
---|
68 | {
|
---|
69 | lstrcpy( buffer, "initialized!!!" );
|
---|
70 | }
|
---|
71 | DataTable( const DataTable &dataTable )
|
---|
72 | : buffer( (char *)malloc(100) )
|
---|
73 | , size( 0 )
|
---|
74 | {
|
---|
75 | lstrcpy( buffer, "initialized!!!" );
|
---|
76 | AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
|
---|
77 | }
|
---|
78 | ~DataTable()
|
---|
79 | {
|
---|
80 | free( buffer );
|
---|
81 | }
|
---|
82 | void Clear()
|
---|
83 | {
|
---|
84 | size = 0;
|
---|
85 | }
|
---|
86 |
|
---|
87 | void operator = ( const DataTable &dataTable )
|
---|
88 | {
|
---|
89 | Clear();
|
---|
90 | AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
|
---|
91 | }
|
---|
92 |
|
---|
93 | int AddBinary( const void *buffer, int size );
|
---|
94 | int Add( _int64 i64data );
|
---|
95 | int Add( int i32data );
|
---|
96 | int Add( double dbl );
|
---|
97 | int Add( float flt );
|
---|
98 | int AddString( const char *str, int length );
|
---|
99 | int AddString( const char *str );
|
---|
100 | int AddString( const std::string &str );
|
---|
101 | void Add( const DataTable &dataTable )
|
---|
102 | {
|
---|
103 | long baseOffset = GetSize();
|
---|
104 |
|
---|
105 | AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
|
---|
106 |
|
---|
107 | // スケジュールを追加
|
---|
108 | BOOST_FOREACH( const Schedule &schedule, dataTable.schedules )
|
---|
109 | {
|
---|
110 | this->schedules.push_back(
|
---|
111 | Schedule(
|
---|
112 | schedule.GetType(),
|
---|
113 | baseOffset + schedule.GetOffset(),
|
---|
114 | schedule.GetLongPtrValue()
|
---|
115 | )
|
---|
116 | );
|
---|
117 | }
|
---|
118 | }
|
---|
119 | int AddSpace( int size );
|
---|
120 | void AddAlignment( int size );
|
---|
121 |
|
---|
122 | const void *GetPtr() const
|
---|
123 | {
|
---|
124 | return buffer;
|
---|
125 | }
|
---|
126 | int GetSize() const
|
---|
127 | {
|
---|
128 | return size;
|
---|
129 | }
|
---|
130 |
|
---|
131 | long GetLong( int pos ) const
|
---|
132 | {
|
---|
133 | return *(long *)( buffer + pos );
|
---|
134 | }
|
---|
135 | _int64 GetInt64( int pos ) const
|
---|
136 | {
|
---|
137 | return *(_int64 *)( buffer + pos );
|
---|
138 | }
|
---|
139 | void Overwrite( int pos, long newLongValue )
|
---|
140 | {
|
---|
141 | *(long *)( buffer + pos ) = newLongValue;
|
---|
142 | }
|
---|
143 | void OverwriteInt64( int pos, _int64 new64Value )
|
---|
144 | {
|
---|
145 | *(_int64 *)( buffer + pos ) = new64Value;
|
---|
146 | }
|
---|
147 | void OverwriteBinary( int pos, const void *ptr, int size )
|
---|
148 | {
|
---|
149 | memcpy( buffer + pos, ptr, size );
|
---|
150 | }
|
---|
151 |
|
---|
152 | bool MakeConstObjectToProcessStaticBuffer( const CClass &objClass, const Jenga::Common::Strings &initMemberValues, int &dataTableOffset );
|
---|
153 | bool MakeConstObjectToProcessStaticBuffer( const char *expression, Type &resultType, int &dataTableOffset );
|
---|
154 | int MakeConstStringObjectToProcessStaticBuffer( const char *str );
|
---|
155 | bool MakeLiteralArrayBuffer( const char *expression, const Type &baseType, int &dataTableOffset );
|
---|
156 |
|
---|
157 | private:
|
---|
158 | int lastMadeConstObjectDataTableOffset;
|
---|
159 | public:
|
---|
160 | int GetLastMadeConstObjectDataTableOffset()
|
---|
161 | {
|
---|
162 | return lastMadeConstObjectDataTableOffset;
|
---|
163 | }
|
---|
164 |
|
---|
165 | void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
|
---|
166 | };
|
---|