Index: trunk/ab5.0/jenga/include/common/Binaly.h
===================================================================
--- trunk/ab5.0/jenga/include/common/Binaly.h	(revision 524)
+++ 	(revision )
@@ -1,170 +1,0 @@
-#pragma once
-
-#include <string>
-#include <vector>
-
-#include <memory.h>
-#include <windows.h>
-
-#define JENGA_SERIALIZER(param) ( isRead?(binaly.Read(param)):(binaly << param) );
-
-class MemoryBlock
-{
-	int base;
-	int size;
-public:
-	MemoryBlock( int base, int size )
-		: base( base )
-		, size( size )
-	{
-	}
-	int GetBase() const
-	{
-		return base;
-	}
-	int GetSize() const
-	{
-		return size;
-	}
-};
-class Binaly
-{
-	static const int alignment = 1024 * 1024;
-
-	unsigned char *pBuffer;
-	int size;
-	int maxSize;
-
-	std::vector<MemoryBlock> memoryBlocks;
-	int indexOfMemoryBlocks;
-
-	// 初期化
-	void Initialize()
-	{
-		maxSize = alignment;
-		pBuffer = (unsigned char *)calloc( maxSize, 1 );
-		size = 0;
-
-		memoryBlocks.clear();
-		indexOfMemoryBlocks = 0;
-	}
-
-	// メモリ領域の再確保
-	void Allocator( int newSize )
-	{
-		size = newSize;
-
-		if( maxSize > newSize )
-		{
-			// 確保済みメモリのサイズがあまっているとき
-			return;
-		}
-
-		while( maxSize <= newSize )
-		{
-			maxSize += alignment;
-		}
-		pBuffer = (unsigned char *)realloc( pBuffer, maxSize );
-	}
-	void AddMemorySize( int plusSize )
-	{
-		Allocator( size + plusSize );
-	}
-	void ReadMemoryCheck( int readSize )
-	{
-		if( (int)memoryBlocks.size() < indexOfMemoryBlocks )
-		{
-			throw "bad memory access";
-		}
-
-		if( memoryBlocks[indexOfMemoryBlocks].GetSize() != readSize )
-		{
-			throw "bad memory access";
-		}
-	}
-
-public:
-	Binaly( const Binaly &binaly )
-	{
-		Initialize();
-	}
-	Binaly( const unsigned char *pNewBuffer, int size )
-	{
-		Initialize();
-	}
-	Binaly()
-	{
-		Initialize();
-	}
-	~Binaly()
-	{
-		free( pBuffer );
-	}
-
-	void Clear()
-	{
-		free( pBuffer );
-		Initialize();
-	}
-
-	void Add( const unsigned char *pBufferOfBlock, int sizeOfBlock )
-	{
-		int base = this->size;
-		AddMemorySize( sizeOfBlock );
-		memcpy( pBuffer + base, pBufferOfBlock, sizeOfBlock );
-
-		memoryBlocks.push_back( MemoryBlock( base, sizeOfBlock ) );
-	}
-	void operator<< ( int i )
-	{
-		Add( (const unsigned char *)&i, sizeof(int) );
-	}
-	void operator<< ( double dbl )
-	{
-		Add( (const unsigned char *)&dbl, sizeof(double) );
-	}
-	void operator<< ( bool b )
-	{
-		Add( (const unsigned char *)&b, sizeof(bool) );
-	}
-	void operator<< ( const std::string &str )
-	{
-		Add( (const unsigned char *)str.c_str(), (int)str.size() );
-	}
-	void operator<< ( const char *lpszStr )
-	{
-		Add( (const unsigned char *)lpszStr, lstrlen(lpszStr) );
-	}
-
-	int GetNextSizeToReading()
-	{
-		return memoryBlocks[indexOfMemoryBlocks].GetSize();
-	}
-	void Read( unsigned char *pBuffer, int readSize )
-	{
-		ReadMemoryCheck( readSize );
-
-		memcpy(
-			pBuffer,
-			this->pBuffer + memoryBlocks[indexOfMemoryBlocks].GetBase(),
-			memoryBlocks[indexOfMemoryBlocks].GetSize()
-		);
-
-		indexOfMemoryBlocks++;
-	}
-	void Read( int &i )
-	{
-		Read( (unsigned char *)&i, sizeof(int) );
-	}
-	void Read( bool &b )
-	{
-		Read( (unsigned char *)&b, sizeof(bool) );
-	}
-	void Read( std::string &str )
-	{
-		str = std::string(
-			(const char *)pBuffer + memoryBlocks[indexOfMemoryBlocks].GetBase(),
-			memoryBlocks[indexOfMemoryBlocks].GetSize()
-		);
-	}
-};
Index: trunk/ab5.0/jenga/include/common/Binary.h
===================================================================
--- trunk/ab5.0/jenga/include/common/Binary.h	(revision 529)
+++ trunk/ab5.0/jenga/include/common/Binary.h	(revision 529)
@@ -0,0 +1,166 @@
+#pragma once
+
+namespace Jenga{ namespace Common{
+
+
+class Binary
+{
+	int allocateSize;
+	char *buffer;
+	int size;
+
+	// XMLシリアライズ用
+private:
+	friend class boost::serialization::access;
+	BOOST_SERIALIZATION_SPLIT_MEMBER();
+	template<class Archive> void load(Archive& ar, const unsigned int version)
+	{
+		std::string _buffer;
+		ar & BOOST_SERIALIZATION_NVP( _buffer );
+		ar & BOOST_SERIALIZATION_NVP( size );
+
+		// 読み込み後の処理
+		Realloc( size );
+		for( int i=0; i<size; i++ )
+		{
+			ULONG_PTR l1 = ( ( _buffer[i*3] >= 'a' ) ? ( _buffer[i*3] - 'a' + 0x0a ) : ( _buffer[i*3] - '0' ) ) * 0x10;
+			ULONG_PTR l2 = ( _buffer[i*3+1] >= 'a' ) ? ( _buffer[i*3+1] - 'a' + 0x0a ) : ( _buffer[i*3+1] - '0' );
+			ULONG_PTR l = l1 + l2;
+			buffer[i] = static_cast<char>(l);
+		}
+	}
+	template<class Archive> void save(Archive& ar, const unsigned int version) const
+	{
+		// 保存準備
+		char *tempCode = (char *)calloc( (size+1) * 3, 1 );
+		for( int i=0; i<size; i++ )
+		{
+			char temp[32];
+			sprintf( temp, "%02x,", (unsigned char)buffer[i] );
+			tempCode[i*3] = temp[0];
+			tempCode[i*3+1] = temp[1];
+			tempCode[i*3+2] = temp[2];
+		}
+
+		std::string _buffer = tempCode;
+		free( tempCode );
+
+		ar & BOOST_SERIALIZATION_NVP( _buffer );
+		ar & BOOST_SERIALIZATION_NVP( size );
+	}
+
+	void Realloc( int newSize )
+	{
+		if( allocateSize < newSize + 8192 )
+		{
+			while( allocateSize < newSize + 8192 )
+			{
+				allocateSize += 8192;
+			}
+			buffer = (char *)realloc( buffer, allocateSize );
+
+			// 再確保した部分を0で埋める
+			memset( buffer + size, 0, allocateSize - size );
+		}
+	}
+
+public:
+	Binary()
+		: allocateSize( 8192 )
+		, buffer( (char *)malloc( allocateSize ) )
+		, size( 0 )
+	{
+	}
+	Binary( const char *buffer, int size )
+		: allocateSize( 8192 )
+		, buffer( (char *)malloc( allocateSize ) )
+		, size( 0 )
+	{
+		Put( buffer, size );
+	}
+	~Binary()
+	{
+		free( buffer );
+	}
+
+	void Clear()
+	{
+		size = 0;
+	}
+
+	const char *GetBuffer() const
+	{
+		return buffer;
+	}
+	int GetSize() const
+	{
+		return size;
+	}
+	void Resize( int newSize )
+	{
+		Realloc( newSize );
+		size = newSize;
+	}
+
+	long GetLong( int pos ) const
+	{
+		return *(long *)( buffer + pos );
+	}
+
+	void Overwrite( int pos, const char *buffer, int size )
+	{
+		memcpy( this->buffer + pos, buffer, size );
+	}
+	void Overwrite( int pos, char c )
+	{
+		buffer[pos] = c;
+	}
+	void Overwrite( int pos, long newLongValue )
+	{
+		*(long *)( buffer + pos ) = newLongValue;
+	}
+	void Overwrite( int pos, _int64 newInt64Value )
+	{
+		*(_int64 *)( buffer + pos ) = newInt64Value;
+	}
+
+	void Put( const char *buffer, int size )
+	{
+		Realloc( this->size + size );
+
+		memcpy( this->buffer + this->size, buffer, size );
+		this->size += size;
+	}
+	void Put( double dbl )
+	{
+		Put( (const char *)(&dbl), sizeof(double) );
+	}
+	void Put( float flt )
+	{
+		Put( (const char *)(&flt), sizeof(float) );
+	}
+	void Put( _int64 i64data )
+	{
+		Put( (const char *)(&i64data), sizeof(_int64) );
+	}
+	void Put( long l )
+	{
+		Realloc( size + sizeof(long) );
+		*((long *)(buffer+size))=l;
+		size += sizeof(long);
+	}
+	void Put( short s )
+	{
+		Realloc( size + sizeof(short) );
+		*((short *)(buffer+size))=s;
+		size += sizeof(short);
+	}
+	void Put( char c )
+	{
+		Realloc( size + 1 );
+		buffer[size++] = c;
+	}
+};
+
+
+}}
