Ignore:
Timestamp:
May 10, 2008, 3:09:26 PM (16 years ago)
Author:
dai_9181
Message:

[585][586]をリバース。NativeCodeクラスとMetaクラスは依存関係があるので分離しない方針とする。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/abdev/BasicCompiler_Common/src/ObjectModule.cpp

    r585 r587  
    9696void ObjectModule::StaticLink( ObjectModule &objectModule )
    9797{
    98     long dataSectionBaseOffset = this->nativeSection.dataTable.GetSize();
    99     int sourceIndexBase = (int)nativeSection.GetSources().size();
     98    long dataSectionBaseOffset = dataTable.GetSize();
     99    int sourceIndexBase = (int)sources.size();
    100100
    101101    // メタ情報を結合
     
    103103
    104104    // グローバル ネイティブコードを結合
    105     objectModule.nativeSection.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
    106     objectModule.nativeSection.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
    107     nativeSection.globalNativeCode.PutEx( objectModule.nativeSection.globalNativeCode );
     105    objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
     106    objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
     107    globalNativeCode.PutEx( objectModule.globalNativeCode );
    108108
    109109    // データテーブルを結合
    110     objectModule.nativeSection.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
    111     this->nativeSection.dataTable.Add( objectModule.nativeSection.dataTable );
     110    objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
     111    dataTable.Add( objectModule.dataTable );
    112112
    113113    // ソースコードを結合
    114     BOOST_FOREACH( const BasicSource &source, objectModule.nativeSection.GetSources() )
    115     {
    116         this->nativeSection.GetSources().push_back( source );
     114    BOOST_FOREACH( const BasicSource &source, objectModule.sources )
     115    {
     116        this->sources.push_back( source );
    117117    }
    118118
    119119    // TODO: basbufがいらなくなったら消す
    120120    extern char *basbuf;
    121     basbuf = this->nativeSection.GetSources()[0].GetBuffer();
     121    basbuf = this->sources[0].GetBuffer();
    122122}
    123123
    124124bool ObjectModule::Read( const std::string &filePath )
    125125{
    126     Jenga::Common::File file( filePath );
    127 
    128     Jenga::Common::Binary binary;
    129     if( !file.ReadBinary( binary ) )
     126    // XMLとして読み込む
     127    bool isSuccessful = false;
     128
     129    try{
     130#ifdef OBJECT_MODULE_IS_NOT_BINARY
     131        std::ifstream ifs( filePath.c_str() );
     132        boost::archive::xml_iarchive ia(ifs);
     133#else
     134        std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
     135        boost::archive::binary_iarchive ia(ifs);
     136#endif
     137
     138        // ファイルから読込
     139        ia >> boost::serialization::make_nvp( RootTagName(), *this );
     140
     141        isSuccessful = true;
     142    }
     143    catch( boost::archive::archive_exception e )
     144    {
     145        MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
     146    }
     147    catch(...){
     148        MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
     149    }
     150
     151    if( !isSuccessful )
    130152    {
    131153        return false;
    132154    }
    133155
    134     return Load( binary );
     156    return true;
    135157}
    136158bool ObjectModule::Write( const std::string &filePath ) const
    137159{
    138     Jenga::Common::File file( filePath );
    139 
    140     Jenga::Common::Binary binary;
    141     if( !Save( binary ) )
     160    bool isSuccessful = false;
     161
     162    try{
     163#ifdef OBJECT_MODULE_IS_NOT_BINARY
     164        std::ofstream ofs( filePath.c_str() );
     165        boost::archive::xml_oarchive oa(ofs);
     166#else
     167        std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
     168        boost::archive::binary_oarchive oa(ofs);
     169#endif
     170
     171        // ファイルに書き出し
     172        oa << boost::serialization::make_nvp( RootTagName(), *this );
     173
     174        isSuccessful = true;
     175    }
     176    catch( boost::archive::archive_exception e )
     177    {
     178        MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
     179    }
     180    catch(...){
     181        MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
     182    }
     183
     184    if( !isSuccessful )
    142185    {
    143186        return false;
    144187    }
    145188
    146     return file.WriteBinary( binary );
    147 }
    148 bool ObjectModule::Load( const Jenga::Common::Binary &binary )
     189    return true;
     190}
     191bool ObjectModule::ReadString( const std::string &str )
    149192{
    150193    bool isSuccessful = false;
     
    153196
    154197    try{
    155         std::string str( binary.GetBuffer(), binary.GetSize() );
    156 
    157198#ifdef OBJECT_MODULE_IS_NOT_BINARY
    158199        std::istringstream iss( str );
     
    183224    return true;
    184225}
    185 bool ObjectModule::Save( Jenga::Common::Binary &binary ) const
     226bool ObjectModule::WriteString( std::string &str ) const
    186227{
    187228    // 出力アーカイブの作成
     
    200241        oa << boost::serialization::make_nvp( RootTagName(), *this );
    201242
    202         binary.Put( oss.str().c_str(), static_cast<int>(oss.str().size()) );
     243        str = oss.str();
    203244
    204245        isSuccessful = true;
Note: See TracChangeset for help on using the changeset viewer.