#pragma warning(disable : 4996) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //boost libraries #include // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする //#define OBJECT_MODULE_IS_NOT_BINARY #ifdef OBJECT_MODULE_IS_NOT_BINARY #include #include #else #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include "../common.h" #include "../BasicFixed.h" #include #include using namespace ActiveBasic::Common::Lexical; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void ObjectModule::StaticLink( ObjectModule &objectModule ) { long dataSectionBaseOffset = this->nativeSection.dataTable.GetSize(); int sourceIndexBase = (int)nativeSection.GetSources().size(); // メタ情報を結合 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase ); // グローバル ネイティブコードを結合 objectModule.nativeSection.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset ); objectModule.nativeSection.globalNativeCode.ResetSourceIndexes( sourceIndexBase ); nativeSection.globalNativeCode.PutEx( objectModule.nativeSection.globalNativeCode ); // データテーブルを結合 objectModule.nativeSection.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset ); this->nativeSection.dataTable.Add( objectModule.nativeSection.dataTable ); // ソースコードを結合 BOOST_FOREACH( const BasicSource &source, objectModule.nativeSection.GetSources() ) { this->nativeSection.GetSources().push_back( source ); } // TODO: basbufがいらなくなったら消す extern char *basbuf; basbuf = this->nativeSection.GetSources()[0].GetBuffer(); } bool ObjectModule::Read( const std::string &filePath ) { Jenga::Common::File file( filePath ); Jenga::Common::Binary binary; if( !file.ReadBinary( binary ) ) { return false; } return Load( binary ); } bool ObjectModule::Write( const std::string &filePath ) const { Jenga::Common::File file( filePath ); Jenga::Common::Binary binary; if( !Save( binary ) ) { return false; } return file.WriteBinary( binary ); } bool ObjectModule::Load( const Jenga::Common::Binary &binary ) { bool isSuccessful = false; // 入力アーカイブの作成 try{ std::string str( binary.GetBuffer(), binary.GetSize() ); #ifdef OBJECT_MODULE_IS_NOT_BINARY std::istringstream iss( str ); boost::archive::xml_iarchive ia(iss); #else std::istringstream iss( str, std::ios::in | std::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::Save( Jenga::Common::Binary &binary ) const { // 出力アーカイブの作成 bool isSuccessful = false; try{ #ifdef OBJECT_MODULE_IS_NOT_BINARY std::ostringstream oss; boost::archive::xml_oarchive oa(oss); #else std::ostringstream oss( "", std::ios::out | std::ios::binary ); boost::archive::binary_oarchive oa(oss); #endif // 文字列ストリームに書き出し oa << boost::serialization::make_nvp( RootTagName(), *this ); binary.Put( oss.str().c_str(), static_cast(oss.str().size()) ); 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; }