Ignore:
Timestamp:
Feb 11, 2008, 12:06:15 PM (16 years ago)
Author:
dai_9181
Message:

メンバ情報を保持するようにした

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/src/DataTable.cpp

    r370 r387  
    6565    return retSize;
    6666}
    67 int DataTable::AddString( const char *str ){
    68     int retSize = size;
    69     AddString( str, lstrlen( str ) );
    70     return retSize;
     67int DataTable::AddString( const char *str )
     68{
     69    return AddString( str, lstrlen( str ) );
     70}
     71int DataTable::AddString( const std::string &str )
     72{
     73    return AddString( str.c_str(), static_cast<int>(str.length()) );
     74}
     75int DataTable::AddSpace( int size )
     76{
     77    int retSize = this->size;
     78    Realloc( this->size + size );
     79    return retSize;
     80}
     81void DataTable::AddAlignment( int size )
     82{
     83    if( this->size % size == 0 )
     84    {
     85        // 既に境界のとき
     86        return;
     87    }
     88    Realloc( this->size + ( size - (int)(this->size%size) ) );
    7189}
    7290
     
    262280    RemoveStringBracket( buffer );
    263281
    264     void *binary = malloc( 1 );
    265     int num = 0;
    266 
     282    Jenga::Common::Strings parameters;
     283    SplitParameter( buffer, parameters );
     284
     285    // アラインメント
     286    AddAlignment( tempBaseType.GetSize() );
     287
     288    // データテーブルに空間を確保
     289    dataTableOffset = AddSpace( static_cast<int>(tempBaseType.GetSize() * parameters.size()) );
     290
     291    bool isSuccessful = true;
    267292    int i = 0;
    268     bool isSuccessful = true;
    269     while( buffer[i] ){
    270         char temporary[1024];
    271 
    272         i = GetOneParameter( buffer, i, temporary );
    273         if( buffer[i] == ',' ){
    274             i++;
    275         }
    276 
    277         Type resultType;
    278         _int64 i64data;
    279         if( !StaticCalculation( true, temporary, tempBaseType.GetBasicType(), &i64data, resultType ) ){
    280             isSuccessful = false;
    281             break;
    282         }
    283         if( !resultType.IsWhole() ){
    284             // TODO: 実数に未対応
    285             SetError();
    286             isSuccessful = false;
    287             break;
    288         }
    289 
    290         binary = realloc( binary, ( num + 1 ) * tempBaseType.GetSize() );
    291         memcpy( (char *)binary + (num * tempBaseType.GetSize()), &i64data, tempBaseType.GetSize() );
    292         num++;
     293    BOOST_FOREACH( const std::string &paramStr, parameters )
     294    {
     295        if( paramStr[0] == '\"' )
     296        {
     297            // 文字列
     298            std::string tempParamStr = paramStr;
     299            if( !RemoveStringQuotes( tempParamStr ) )
     300            {
     301                SetError();
     302            }
     303
     304            // 文字列を追加
     305            _int64 strOffset = this->AddString( tempParamStr );
     306
     307            // ポインタ値を上書き
     308            int tempOffset = dataTableOffset + i * tempBaseType.GetSize();
     309            this->OverwriteBinary( tempOffset, &strOffset, tempBaseType.GetSize() );
     310
     311            // DataTableスケジュール
     312            this->schedules.push_back( Schedule( Schedule::DataTable, tempOffset  ) );
     313        }
     314        else
     315        {
     316            // 数値
     317            Type resultType;
     318            _int64 i64data;
     319            if( !StaticCalculation( true, paramStr.c_str(), tempBaseType.GetBasicType(), &i64data, resultType ) ){
     320                isSuccessful = false;
     321                break;
     322            }
     323            if( !resultType.IsWhole() ){
     324                // TODO: 実数に未対応
     325                SetError();
     326                isSuccessful = false;
     327                break;
     328            }
     329
     330            // 上書き
     331            this->OverwriteBinary( dataTableOffset + i * tempBaseType.GetSize(), &i64data, tempBaseType.GetSize() );
     332        }
     333
     334        i++;
    293335    }
    294336
    295337    free( buffer );
    296 
    297     dataTableOffset = this->AddBinary( binary, num * tempBaseType.GetSize() );
    298 
    299     free( binary );
    300338
    301339    return isSuccessful;
Note: See TracChangeset for help on using the changeset viewer.