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