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

Last change on this file since 217 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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