//#pragma warning(disable : 4996) #include #include #include #include #include #include #include #include #include #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include #include #include //boost libraries #include // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする //#define OBJECT_MODULE_IS_NOT_BINARY #pragma warning(push) #pragma warning(disable: 4244 6011 6326) #ifdef OBJECT_MODULE_IS_NOT_BINARY #include #include #else #include #include #endif #include #include #include #include #include #include #include #include #include #pragma warning(pop) #define foreach(v, c) for each (v in c) #include #include void ObjectModule::StaticLink( ObjectModule &objectModule, bool isSll ) { const std::vector relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames ); long dataSectionBaseOffset = dataTable.GetSize(); // メタ情報を結合 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable ); if( !isSll ) { // グローバル ネイティブコードを結合 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset ); objectModule.globalNativeCode.ResetRelationalObjectModuleIndex( relationTable ); globalNativeCode.PutEx( objectModule.globalNativeCode ); // データテーブルを結合 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset ); dataTable.Add( objectModule.dataTable ); } // TODO: basbufがいらなくなったら消す extern char *basbuf; basbuf = this->source.GetBuffer(); } void ObjectModule::Resolve( ResolveErrors &resolveErrors ) { this->meta.Resolve( *this, resolveErrors ); // グローバルネイティブコードを解決(スケジュールを解決する) this->globalNativeCode.Resolve( *this, resolveErrors ); // データテーブルを解決(スケジュールを解決する) this->dataTable.Resolve( *this, resolveErrors ); } const std::vector ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames ) { // 要素 = 古いインデックス、値 = 新しいインデックス std::vector relationTable; // リレーションテーブルを構築 foreach( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames ) { bool isMatch = false; for( int i=0; i(this->relationalObjectModuleNames.size()); i++ ) { if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] ) { isMatch = true; relationTable.push_back( i ); break; } } if( !isMatch ) { // エラー _ASSERT( false ); } } return relationTable; } bool ObjectModule::Read( const std::string &filePath ) { // 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(), std::ios::in | std::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 { 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(), std::ios::out | std::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 ) { 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, 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::WriteString( std::string &str ) 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 ); 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; } BOOST_CLASS_EXPORT_IMPLEMENT( DynamicMethod ); BOOST_CLASS_EXPORT_IMPLEMENT( StaticMethod );