source: dev/trunk/abdev/BasicCompiler_Common/include/DataTable.h@ 366

Last change on this file since 366 was 355, checked in by dai_9181, 17 years ago

静的領域に初期オブジェクトを配置可能にした

File size: 3.8 KB
Line 
1#pragma once
2
3#include <BoostSerializationSupport.h>
4
5//DataTable.cpp
6class DataTable
7{
8 char *buffer;
9 int size;
10
11public:
12 // リンカで解決しなければならないスケジュール
13 Schedules schedules;
14
15 // XMLシリアライズ用
16private:
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
64public:
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 void Add( const DataTable &dataTable )
101 {
102 long baseOffset = GetSize();
103
104 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
105
106 // スケジュールを追加
107 BOOST_FOREACH( const Schedule &schedule, dataTable.schedules )
108 {
109 this->schedules.push_back(
110 Schedule(
111 schedule.GetType(),
112 baseOffset + schedule.GetOffset(),
113 schedule.GetLongPtrValue()
114 )
115 );
116 }
117 }
118
119 const void *GetPtr() const
120 {
121 return buffer;
122 }
123 int GetSize() const
124 {
125 return size;
126 }
127
128 long GetLong( int pos ) const
129 {
130 return *(long *)( buffer + pos );
131 }
132 _int64 GetInt64( int pos ) const
133 {
134 return *(_int64 *)( buffer + pos );
135 }
136 void Overwrite( int pos, long newLongValue )
137 {
138 *(long *)( buffer + pos ) = newLongValue;
139 }
140 void OverwriteInt64( int pos, _int64 new64Value )
141 {
142 *(_int64 *)( buffer + pos ) = new64Value;
143 }
144
145 bool MakeConstObjectToProcessStaticBuffer( const CClass &objClass, const Jenga::Common::Strings &initMemberValues, int &dataTableOffset );
146 bool MakeConstObjectToProcessStaticBuffer( const char *expression, Type &resultType, int &dataTableOffset );
147 int MakeConstStringObjectToProcessStaticBuffer( const char *str );
148 bool MakeLiteralArrayBuffer( const char *expression, const Type &baseType, int &dataTableOffset );
149
150private:
151 int lastMadeConstObjectDataTableOffset;
152public:
153 int GetLastMadeConstObjectDataTableOffset()
154 {
155 return lastMadeConstObjectDataTableOffset;
156 }
157
158 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
159};
Note: See TracBrowser for help on using the repository browser.