[60] | 1 | #include "common.h"
|
---|
| 2 |
|
---|
| 3 | DataTable dataTable;
|
---|
| 4 |
|
---|
| 5 | DataTable::DataTable(){
|
---|
| 6 | pdata = malloc( 1 );
|
---|
| 7 | size = 0;
|
---|
| 8 | }
|
---|
| 9 | DataTable::~DataTable(){
|
---|
| 10 | free( pdata );
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | void DataTable::Init(){
|
---|
| 14 | free( pdata );
|
---|
| 15 |
|
---|
| 16 | pdata = malloc( 1 );
|
---|
| 17 | size = 0;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | int 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 | }
|
---|
| 29 | int DataTable::Add( _int64 i64data ){
|
---|
| 30 | int retSize = size;
|
---|
| 31 | AddBinary( &i64data, sizeof( _int64 ) );
|
---|
| 32 | return retSize;
|
---|
| 33 | }
|
---|
| 34 | int DataTable::Add( int i32data ){
|
---|
| 35 | int retSize = size;
|
---|
| 36 | AddBinary( &i32data, sizeof( int ) );
|
---|
| 37 | return retSize;
|
---|
| 38 | }
|
---|
| 39 | int DataTable::Add( double dbl ){
|
---|
| 40 | int retSize = size;
|
---|
| 41 | AddBinary( &dbl, sizeof( double ) );
|
---|
| 42 | return retSize;
|
---|
| 43 | }
|
---|
| 44 | int DataTable::Add( float flt ){
|
---|
| 45 | int retSize = size;
|
---|
| 46 | AddBinary( &flt, sizeof( float ) );
|
---|
| 47 | return retSize;
|
---|
| 48 | }
|
---|
| 49 | int 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 | }
|
---|
| 78 | int DataTable::AddString( const char *str ){
|
---|
| 79 | int retSize = size;
|
---|
| 80 | AddString( str, lstrlen( str ) );
|
---|
| 81 | return retSize;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | const void *DataTable::GetPtr() const
|
---|
| 85 | {
|
---|
| 86 | return pdata;
|
---|
| 87 | }
|
---|
| 88 | int DataTable::GetSize() const
|
---|
| 89 | {
|
---|
| 90 | return size;
|
---|
| 91 | }
|
---|