Index: trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp
===================================================================
--- trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp	(revision 395)
+++ trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp	(revision 404)
@@ -1,13 +1,45 @@
-#include "stdafx.h"
-
+#include <string>
+#include <vector>
+#include <fstream>
+
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <commctrl.h>
+#include <time.h>
+#include <limits.h>
+#include <shlobj.h>
+
+//boost libraries
+#include <boost/foreach.hpp>
+
+#include <jenga/include/common/String.h>
+
+#include "../common.h"
+
+
+// ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
+//#define OBJECT_MODULE_IS_NOT_BINARY
+
+
+#ifdef OBJECT_MODULE_IS_NOT_BINARY
+#include <boost/archive/xml_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#else
+#include <boost/archive/binary_oarchive.hpp>
+#include <boost/archive/binary_iarchive.hpp>
+#endif
+#include <boost/serialization/string.hpp>
+#include <boost/serialization/access.hpp>
+#include <boost/serialization/level.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/serialization/map.hpp>
+#include <boost/serialization/version.hpp>
+#include <boost/serialization/is_abstract.hpp>
+
+#include <BoostSerializationSupport.h>
+#include <Hashmap.h>
 #include <Compiler.h>
-
-enum ObjectModuleDataType
-{
-	ObjectModuleDataTypeXml,
-	ObjectModuleDataTypeText,
-	ObjectModuleDataTypeBinaly,
-};
-const ObjectModuleDataType objectModuleDataType = ObjectModuleDataTypeBinaly;
 
 
@@ -42,64 +74,133 @@
 bool ObjectModule::Read( const std::string &filePath )
 {
-	switch( objectModuleDataType )
-	{
-	case ObjectModuleDataTypeXml:
-		return ReadXml( filePath );
-	case ObjectModuleDataTypeText:
-		return ReadText( filePath );
-	case ObjectModuleDataTypeBinaly:
-		return ReadBinaryFile( filePath );
-	default:
-		Jenga::Throw( "" );
-		break;
-	}
-	return false;
+	// XMLとして読み込む
+	bool isSuccessful = false;
+
+	try{
+#ifdef OBJECT_MODULE_IS_NOT_BINARY
+		std::ifstream ifs( filePath.c_str() );
+		boost::archive::xml_iarchive ia(ifs);
+#else
+		std::ifstream ifs( filePath.c_str(), ios::in | ios::binary );
+		boost::archive::binary_iarchive ia(ifs);
+#endif
+
+		// ファイルから読込
+		ia >> boost::serialization::make_nvp( RootTagName(), *this );
+
+		isSuccessful = true;
+	}
+	catch( boost::archive::archive_exception e )
+	{
+		MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
+	}
+	catch(...){
+		MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
+	}
+
+	if( !isSuccessful )
+	{
+		return false;
+	}
+
+	return true;
 }
 bool ObjectModule::Write( const std::string &filePath ) const
 {
-	switch( objectModuleDataType )
-	{
-	case ObjectModuleDataTypeXml:
-		return WriteXml( filePath );
-	case ObjectModuleDataTypeText:
-		return WriteText( filePath );
-	case ObjectModuleDataTypeBinaly:
-		return WriteBinaryFile( filePath );
-	default:
-		Jenga::Throw( "" );
-		break;
-	}
-	return false;
+	bool isSuccessful = false;
+
+	try{
+#ifdef OBJECT_MODULE_IS_NOT_BINARY
+		std::ofstream ofs( filePath.c_str() );
+		boost::archive::xml_oarchive oa(ofs);
+#else
+		std::ofstream ofs( filePath.c_str(), ios::out | ios::binary );
+		boost::archive::binary_oarchive oa(ofs);
+#endif
+
+		// ファイルに書き出し
+		oa << boost::serialization::make_nvp( RootTagName(), *this );
+
+		isSuccessful = true;
+	}
+	catch( boost::archive::archive_exception e )
+	{
+		MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
+	}
+	catch(...){
+		MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
+	}
+
+	if( !isSuccessful )
+	{
+		return false;
+	}
+
+	return true;
 }
 bool ObjectModule::ReadString( const std::string &str )
 {
-	switch( objectModuleDataType )
-	{
-	case ObjectModuleDataTypeXml:
-		return ReadXmlString( str );
-	case ObjectModuleDataTypeText:
-		return ReadTextString( str );
-	case ObjectModuleDataTypeBinaly:
-		return ReadBinaryString( str );
-	default:
-		Jenga::Throw( "" );
-		break;
-	}
-	return false;
+	bool isSuccessful = false;
+
+	// 入力アーカイブの作成
+
+	try{
+#ifdef OBJECT_MODULE_IS_NOT_BINARY
+		std::istringstream iss( str );
+		boost::archive::xml_iarchive ia(iss);
+#else
+		std::istringstream iss( str, ios::in | ios::binary );
+		boost::archive::binary_iarchive ia(iss);
+#endif
+
+		// 文字列ストリームから読込
+		ia >> boost::serialization::make_nvp( RootTagName(), *this );
+
+		isSuccessful = true;
+	}
+	catch( boost::archive::archive_exception e )
+	{
+		MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
+	}
+	catch(...){
+		MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
+	}
+
+	if( !isSuccessful )
+	{
+		return false;
+	}
+
+	return true;
 }
 bool ObjectModule::WriteString( std::string &str ) const
 {
-	switch( objectModuleDataType )
-	{
-	case ObjectModuleDataTypeXml:
-		return WriteXmlString( str );
-	case ObjectModuleDataTypeText:
-		return WriteTextString( str );
-	case ObjectModuleDataTypeBinaly:
-		return WriteBinaryString( str );
-	default:
-		Jenga::Throw( "" );
-		break;
-	}
-	return false;
-}
+	// 出力アーカイブの作成
+
+	bool isSuccessful = false;
+	try{
+#ifdef OBJECT_MODULE_IS_NOT_BINARY
+		std::ostringstream oss;
+		boost::archive::xml_oarchive oa(oss);
+#else
+		std::ostringstream oss( "", ios::out | ios::binary );
+		boost::archive::binary_oarchive oa(oss);
+#endif
+
+		// 文字列ストリームに書き出し
+		oa << boost::serialization::make_nvp( RootTagName(), *this );
+
+		str = oss.str();
+
+		isSuccessful = true;
+	}
+	catch( boost::archive::archive_exception e )
+	{
+		MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
+	}
+	catch(...){
+		MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
+	}
+
+	return isSuccessful;
+}
