source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/DataTable.cpp@ 589

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

DataTableGeneratorクラスを追加。

File size: 2.1 KB
Line 
1#include "stdafx.h"
2
3int DataTable::AddBinary( const void *buffer, int size ){
4 int retSize = this->size;
5
6 Realloc( this->size + size );
7 memcpy( (char *)this->buffer + retSize, buffer, size );
8
9 return retSize;
10}
11int DataTable::Add( _int64 i64data ){
12 int retSize = size;
13 AddBinary( &i64data, sizeof( _int64 ) );
14 return retSize;
15}
16int DataTable::Add( int i32data ){
17 int retSize = size;
18 AddBinary( &i32data, sizeof( int ) );
19 return retSize;
20}
21int DataTable::Add( double dbl ){
22 int retSize = size;
23 AddBinary( &dbl, sizeof( double ) );
24 return retSize;
25}
26int DataTable::Add( float flt ){
27 int retSize = size;
28 AddBinary( &flt, sizeof( float ) );
29 return retSize;
30}
31int DataTable::AddString( const char *str, int length ){
32 int retSize = size;
33
34 if( compiler.IsUnicode() ){
35 //Shift-JIS → Unicode
36 int size = MultiByteToWideChar(
37 CP_ACP,
38 0,
39 str, length + 1,
40 NULL, 0 ) * 2;
41
42 LPWSTR pwstr = (LPWSTR)malloc( size );
43
44 MultiByteToWideChar(
45 CP_ACP,
46 0,
47 str, length + 1,
48 pwstr, length + 1 );
49
50 AddBinary( pwstr, size );
51
52 free( pwstr );
53 }
54 else{
55 AddBinary( str, length + 1 );
56 }
57
58 return retSize;
59}
60int DataTable::AddString( const char *str )
61{
62 return AddString( str, lstrlen( str ) );
63}
64int DataTable::AddString( const std::string &str )
65{
66 return AddString( str.c_str(), static_cast<int>(str.length()) );
67}
68int DataTable::AddSpace( int size )
69{
70 int retSize = this->size;
71 Realloc( this->size + size );
72 return retSize;
73}
74void DataTable::AddAlignment( int size )
75{
76 if( this->size % size == 0 )
77 {
78 // 既に境界のとき
79 return;
80 }
81 Realloc( this->size + ( size - (int)(this->size%size) ) );
82}
83
84void DataTable::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
85{
86 BOOST_FOREACH( const Schedule &schedule, schedules )
87 {
88 if( schedule.GetType() == Schedule::DataTable )
89 {
90#ifdef _WIN64
91 OverwriteInt64(
92 schedule.GetOffset(),
93 GetInt64( schedule.GetOffset() ) + dataSectionBaseOffset
94 );
95#else
96 Overwrite(
97 schedule.GetOffset(),
98 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
99 );
100#endif
101 }
102 }
103}
Note: See TracBrowser for help on using the repository browser.