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