source: dev/BasicCompiler_Common/DataTable.cpp@ 85

Last change on this file since 85 was 60, checked in by dai_9181, 18 years ago

バージョンをβ13にした

File size: 1.6 KB
Line 
1#include "common.h"
2
3DataTable dataTable;
4
5DataTable::DataTable(){
6 pdata = malloc( 1 );
7 size = 0;
8}
9DataTable::~DataTable(){
10 free( pdata );
11}
12
13void DataTable::Init(){
14 free( pdata );
15
16 pdata = malloc( 1 );
17 size = 0;
18}
19
20int DataTable::AddBinary( const void *pdata, int size ){
21 int retSize = this->size;
22
23 this->pdata = realloc( this->pdata, this->size + size );
24 memcpy( (char *)this->pdata + this->size, pdata, size );
25 this->size += size;
26
27 return retSize;
28}
29int DataTable::Add( _int64 i64data ){
30 int retSize = size;
31 AddBinary( &i64data, sizeof( _int64 ) );
32 return retSize;
33}
34int DataTable::Add( int i32data ){
35 int retSize = size;
36 AddBinary( &i32data, sizeof( int ) );
37 return retSize;
38}
39int DataTable::Add( double dbl ){
40 int retSize = size;
41 AddBinary( &dbl, sizeof( double ) );
42 return retSize;
43}
44int DataTable::Add( float flt ){
45 int retSize = size;
46 AddBinary( &flt, sizeof( float ) );
47 return retSize;
48}
49int DataTable::AddString( const char *str, int length ){
50 int retSize = size;
51
52 if( isUnicode ){
53 //Shift-JIS → Unicode
54 int size = MultiByteToWideChar(
55 CP_ACP,
56 0,
57 str, length + 1,
58 NULL, 0 ) * 2;
59
60 LPWSTR pwstr = (LPWSTR)malloc( size );
61
62 MultiByteToWideChar(
63 CP_ACP,
64 0,
65 str, length + 1,
66 pwstr, length + 1 );
67
68 AddBinary( pwstr, size );
69
70 free( pwstr );
71 }
72 else{
73 AddBinary( str, length + 1 );
74 }
75
76 return retSize;
77}
78int DataTable::AddString( const char *str ){
79 int retSize = size;
80 AddString( str, lstrlen( str ) );
81 return retSize;
82}
83
84const void *DataTable::GetPtr() const
85{
86 return pdata;
87}
88int DataTable::GetSize() const
89{
90 return size;
91}
Note: See TracBrowser for help on using the repository browser.