source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/include/DataTable.h@ 591

Last change on this file since 591 was 591, checked in by dai_9181, 16 years ago

DataTable::AddWStringメソッドを追加。

File size: 3.4 KB
Line 
1#pragma once
2
3//DataTable.cpp
4class DataTable
5{
6 char *buffer;
7 int size;
8
9public:
10 // リンカで解決しなければならないスケジュール
11 Schedules schedules;
12
13 // XMLシリアライズ用
14private:
15 friend class boost::serialization::access;
16 BOOST_SERIALIZATION_SPLIT_MEMBER();
17 template<class Archive> void load(Archive& ar, const unsigned int version)
18 {
19 std::string _buffer;
20 ar & BOOST_SERIALIZATION_NVP( _buffer );
21 ar & BOOST_SERIALIZATION_NVP( size );
22 ar & BOOST_SERIALIZATION_NVP( schedules );
23
24 // 読み込み後の処理
25 Realloc( size );
26 for( int i=0; i<size; i++ )
27 {
28 ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
29 ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
30 ULONG_PTR l = l1 + l2;
31 buffer[i] = static_cast<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 ar & BOOST_SERIALIZATION_NVP( schedules );
53 }
54
55
56 void Realloc( int size )
57 {
58 this->buffer = (char *)realloc( this->buffer, size + 100 );
59 this->size = size;
60 }
61
62public:
63 DataTable()
64 : buffer( (char *)malloc(100) )
65 , size( 0 )
66 {
67 lstrcpy( buffer, "initialized!!!" );
68 }
69 DataTable( const DataTable &dataTable )
70 : buffer( (char *)malloc(100) )
71 , size( 0 )
72 {
73 lstrcpy( buffer, "initialized!!!" );
74 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
75 }
76 ~DataTable()
77 {
78 free( buffer );
79 }
80 void Clear()
81 {
82 size = 0;
83 }
84
85 void operator = ( const DataTable &dataTable )
86 {
87 Clear();
88 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
89 }
90
91 int AddBinary( const void *buffer, int size );
92 int Add( _int64 i64data );
93 int Add( int i32data );
94 int Add( double dbl );
95 int Add( float flt );
96 int AddString( const char *str );
97 int AddString( const std::string &str );
98 int AddWString( const std::wstring &wstr );
99 void Add( const DataTable &dataTable )
100 {
101 long baseOffset = GetSize();
102
103 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
104
105 // スケジュールを追加
106 BOOST_FOREACH( const Schedule &schedule, dataTable.schedules )
107 {
108 this->schedules.push_back(
109 Schedule(
110 schedule.GetType(),
111 baseOffset + schedule.GetOffset(),
112 schedule.GetLongPtrValue()
113 )
114 );
115 }
116 }
117 int AddSpace( int size );
118 void AddAlignment( int size );
119
120 const void *GetPtr() const
121 {
122 return buffer;
123 }
124 int GetSize() const
125 {
126 return size;
127 }
128
129 long GetLong( int pos ) const
130 {
131 return *(long *)( buffer + pos );
132 }
133 _int64 GetInt64( int pos ) const
134 {
135 return *(_int64 *)( buffer + pos );
136 }
137 void Overwrite( int pos, long newLongValue )
138 {
139 *(long *)( buffer + pos ) = newLongValue;
140 }
141 void OverwriteInt64( int pos, _int64 new64Value )
142 {
143 *(_int64 *)( buffer + pos ) = new64Value;
144 }
145 void OverwriteBinary( int pos, const void *ptr, int size )
146 {
147 memcpy( buffer + pos, ptr, size );
148 }
149
150 void ResetDataSectionBaseOffset( long dataSectionBaseOffset );
151};
Note: See TracBrowser for help on using the repository browser.