当前位置: 首页>>代码示例>>C++>>正文


C++ Program::add_operation方法代码示例

本文整理汇总了C++中Program::add_operation方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::add_operation方法的具体用法?C++ Program::add_operation怎么用?C++ Program::add_operation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Program的用法示例。


在下文中一共展示了Program::add_operation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parseMetaData

bool Simulator::parseMetaData()
{
    string lineBuffer;
    string filePath = configurationData.filePath;
    int hardwareCycleTime;
    bool doneParsing = false;
    Program program;

    const string BEGIN_SIMULATOR_STRING = "S(start)0";
    const string END_SIMULATOR_STRING   = "S(end)0.";
    const string BEGIN_PROGRAM_STRING   = "A(start)0";
    const string END_PROGRAM_STRING     = "A(end)0";

    // Open the file for reading
    ifstream inFile( filePath.c_str() );
    if( inFile.fail() )
    {
        cerr << "Error! Failed to open Meta-Data file." << endl;
        return false;
    }

    // Check first line
    getline( inFile, lineBuffer );
    if( lineBuffer != "Start Program Meta-Data Code:" )
    {
        cerr << "Error! Invalid Meta-Data file." << endl;
        if( inFile.is_open() )
        {
            inFile.close();
        }
        return false;
    }

    // Get each token delimited by semicolons
    while( !doneParsing )
    {
        // Ignore whitespace
        inFile >> std::ws;

        // Get the next operation
        getline( inFile, lineBuffer, ';' );

        // Check if at the end
        doneParsing = lineBuffer.find( END_SIMULATOR_STRING ) != string::npos;

        if( lineBuffer == BEGIN_PROGRAM_STRING )
        {
            program.clear_operations();
            hardwareCycleTime = 0;
            program.add_operation( lineBuffer, 0 );
        }
        else if( lineBuffer == END_PROGRAM_STRING )
        {
            program.add_operation( lineBuffer, 0 );
            programs_.push_back( program );
            programs_.back().prepare();
        }
        else if( ( lineBuffer != BEGIN_SIMULATOR_STRING ) && !doneParsing )
        {
            if( lineBuffer.find( "printer" ) != string::npos )
            {
                hardwareCycleTime = configurationData.printerCycleTime;
            }
            else if( lineBuffer.find( "monitor" ) != string::npos )
            {
                hardwareCycleTime = configurationData.monitorDisplayTime;
            }
            else if( lineBuffer.find( "keyboard" ) != string::npos )
            {
                hardwareCycleTime = configurationData.keyboardCycleTime;
            }
            else if( lineBuffer.find( "run" ) != string::npos )
            {
                hardwareCycleTime = configurationData.processorCycleTime;
            }
            else if( lineBuffer.find( "hard drive" ) != string::npos )
            {
                hardwareCycleTime = configurationData.hardDriveCycleTime;
            }
            else
            {
                cerr << "Error! Invalid Meta-Data file. "
                    << "Could not set operation hardware cycle!" << endl;

                if(inFile.is_open())
                {
                    inFile.close();
                }
                return false;
            }

            program.add_operation( lineBuffer, hardwareCycleTime );
        }

    }

    // Close the file
    if(inFile.is_open())
    {
        inFile.close();
//.........这里部分代码省略.........
开发者ID:matthewjberger,项目名称:cs446Berger,代码行数:101,代码来源:Simulator.cpp


注:本文中的Program::add_operation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。