[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 |
|
---|
[256] | 10 | void DataTable::Realloc( int size )
|
---|
| 11 | {
|
---|
| 12 | this->buffer = (char *)realloc( this->buffer, size + 100 );
|
---|
| 13 | this->size = size;
|
---|
[184] | 14 | }
|
---|
| 15 |
|
---|
[256] | 16 | int DataTable::AddBinary( const void *buffer, int size ){
|
---|
[184] | 17 | int retSize = this->size;
|
---|
| 18 |
|
---|
[256] | 19 | Realloc( this->size + size );
|
---|
| 20 | memcpy( (char *)this->buffer + retSize, buffer, size );
|
---|
[184] | 21 |
|
---|
| 22 | return retSize;
|
---|
| 23 | }
|
---|
| 24 | int DataTable::Add( _int64 i64data ){
|
---|
| 25 | int retSize = size;
|
---|
| 26 | AddBinary( &i64data, sizeof( _int64 ) );
|
---|
| 27 | return retSize;
|
---|
| 28 | }
|
---|
| 29 | int DataTable::Add( int i32data ){
|
---|
| 30 | int retSize = size;
|
---|
| 31 | AddBinary( &i32data, sizeof( int ) );
|
---|
| 32 | return retSize;
|
---|
| 33 | }
|
---|
| 34 | int DataTable::Add( double dbl ){
|
---|
| 35 | int retSize = size;
|
---|
| 36 | AddBinary( &dbl, sizeof( double ) );
|
---|
| 37 | return retSize;
|
---|
| 38 | }
|
---|
| 39 | int DataTable::Add( float flt ){
|
---|
| 40 | int retSize = size;
|
---|
| 41 | AddBinary( &flt, sizeof( float ) );
|
---|
| 42 | return retSize;
|
---|
| 43 | }
|
---|
| 44 | int DataTable::AddString( const char *str, int length ){
|
---|
| 45 | int retSize = size;
|
---|
| 46 |
|
---|
| 47 | if( Smoothie::IsUnicode() ){
|
---|
| 48 | //Shift-JIS → Unicode
|
---|
| 49 | int size = MultiByteToWideChar(
|
---|
| 50 | CP_ACP,
|
---|
| 51 | 0,
|
---|
| 52 | str, length + 1,
|
---|
| 53 | NULL, 0 ) * 2;
|
---|
| 54 |
|
---|
| 55 | LPWSTR pwstr = (LPWSTR)malloc( size );
|
---|
| 56 |
|
---|
| 57 | MultiByteToWideChar(
|
---|
| 58 | CP_ACP,
|
---|
| 59 | 0,
|
---|
| 60 | str, length + 1,
|
---|
| 61 | pwstr, length + 1 );
|
---|
| 62 |
|
---|
| 63 | AddBinary( pwstr, size );
|
---|
| 64 |
|
---|
| 65 | free( pwstr );
|
---|
| 66 | }
|
---|
| 67 | else{
|
---|
| 68 | AddBinary( str, length + 1 );
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | return retSize;
|
---|
| 72 | }
|
---|
| 73 | int DataTable::AddString( const char *str ){
|
---|
| 74 | int retSize = size;
|
---|
| 75 | AddString( str, lstrlen( str ) );
|
---|
| 76 | return retSize;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | const void *DataTable::GetPtr() const
|
---|
| 80 | {
|
---|
[256] | 81 | return buffer;
|
---|
[184] | 82 | }
|
---|
| 83 | int DataTable::GetSize() const
|
---|
| 84 | {
|
---|
| 85 | return size;
|
---|
| 86 | }
|
---|