source: dev/trunk/abdev/BasicCompiler_Common/include/DataTable.h@ 311

Last change on this file since 311 was 279, checked in by dai_9181, 17 years ago

sourceをObjectModuleに入れた

File size: 2.3 KB
Line 
1#pragma once
2
3#include <BoostSerializationSupport.h>
4
5//DataTable.cpp
6class DataTable{
7 char *buffer;
8 int size;
9
10 void Realloc( int size )
11 {
12 this->buffer = (char *)realloc( this->buffer, size + 100 );
13 this->size = size;
14 }
15
16 // XMLシリアライズ用
17private:
18 friend class boost::serialization::access;
19 BOOST_SERIALIZATION_SPLIT_MEMBER();
20 template<class Archive> void load(Archive& ar, const unsigned int version)
21 {
22 std::string _buffer;
23 ar & BOOST_SERIALIZATION_NVP( _buffer );
24 ar & BOOST_SERIALIZATION_NVP( size );
25
26 // 読み込み後の処理
27 Realloc( size );
28 for( int i=0; i<size; i++ )
29 {
30 ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
31 ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
32 ULONG_PTR l = l1 + l2;
33 buffer[i] = static_cast<char>(l);
34 }
35 }
36 template<class Archive> void save(Archive& ar, const unsigned int version) const
37 {
38 // 保存準備
39 char *tempCode = (char *)calloc( (size+1) * 3, 1 );
40 for( int i=0; i<size; i++ )
41 {
42 char temp[32];
43 sprintf( temp, "%02x,", (unsigned char)buffer[i] );
44 tempCode[i*3] = temp[0];
45 tempCode[i*3+1] = temp[1];
46 tempCode[i*3+2] = temp[2];
47 }
48
49 std::string _buffer = tempCode;
50 free( tempCode );
51
52 ar & BOOST_SERIALIZATION_NVP( _buffer );
53 ar & BOOST_SERIALIZATION_NVP( size );
54 }
55
56public:
57 DataTable()
58 : buffer( (char *)malloc(100) )
59 , size( 0 )
60 {
61 lstrcpy( buffer, "initialized!!!" );
62 }
63 DataTable( const DataTable &dataTable )
64 : buffer( (char *)malloc(100) )
65 , size( 0 )
66 {
67 lstrcpy( buffer, "initialized!!!" );
68 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
69 }
70 ~DataTable()
71 {
72 free( buffer );
73 }
74 void Clear()
75 {
76 size = 0;
77 }
78
79 void operator = ( const DataTable &dataTable )
80 {
81 Clear();
82 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
83 }
84
85 int AddBinary( const void *buffer, int size );
86 int Add( _int64 i64data );
87 int Add( int i32data );
88 int Add( double dbl );
89 int Add( float flt );
90 int AddString( const char *str, int length );
91 int AddString( const char *str );
92 void Add( const DataTable &dataTable )
93 {
94 AddBinary( dataTable.GetPtr(), dataTable.GetSize() );
95 }
96
97 const void *GetPtr() const;
98 int GetSize() const;
99};
Note: See TracBrowser for help on using the repository browser.