source: dev/trunk/abdev/BasicCompiler_Common/src/DataTable.cpp@ 192

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