[184] | 1 | #include <jenga/include/smoothie/Smoothie.h>
|
---|
| 2 |
|
---|
| 3 | #include <DataTable.h>
|
---|
| 4 |
|
---|
| 5 | #include <memory.h>
|
---|
| 6 | #include <stdlib.h>
|
---|
| 7 |
|
---|
| 8 | DataTable::DataTable(){
|
---|
| 9 | pdata = malloc( 1 );
|
---|
| 10 | size = 0;
|
---|
| 11 | }
|
---|
| 12 | DataTable::~DataTable(){
|
---|
| 13 | free( pdata );
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | void DataTable::Init(){
|
---|
| 17 | free( pdata );
|
---|
| 18 |
|
---|
| 19 | pdata = malloc( 1 );
|
---|
| 20 | size = 0;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | int 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 | }
|
---|
| 32 | int DataTable::Add( _int64 i64data ){
|
---|
| 33 | int retSize = size;
|
---|
| 34 | AddBinary( &i64data, sizeof( _int64 ) );
|
---|
| 35 | return retSize;
|
---|
| 36 | }
|
---|
| 37 | int DataTable::Add( int i32data ){
|
---|
| 38 | int retSize = size;
|
---|
| 39 | AddBinary( &i32data, sizeof( int ) );
|
---|
| 40 | return retSize;
|
---|
| 41 | }
|
---|
| 42 | int DataTable::Add( double dbl ){
|
---|
| 43 | int retSize = size;
|
---|
| 44 | AddBinary( &dbl, sizeof( double ) );
|
---|
| 45 | return retSize;
|
---|
| 46 | }
|
---|
| 47 | int DataTable::Add( float flt ){
|
---|
| 48 | int retSize = size;
|
---|
| 49 | AddBinary( &flt, sizeof( float ) );
|
---|
| 50 | return retSize;
|
---|
| 51 | }
|
---|
| 52 | int 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 | }
|
---|
| 81 | int DataTable::AddString( const char *str ){
|
---|
| 82 | int retSize = size;
|
---|
| 83 | AddString( str, lstrlen( str ) );
|
---|
| 84 | return retSize;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | const void *DataTable::GetPtr() const
|
---|
| 88 | {
|
---|
| 89 | return pdata;
|
---|
| 90 | }
|
---|
| 91 | int DataTable::GetSize() const
|
---|
| 92 | {
|
---|
| 93 | return size;
|
---|
| 94 | }
|
---|