コード例 #1
0
// helper function
void PrintCounters(CounterList& counterList, const string& strGenerationName, const std::string& outputFile)
{
    const unsigned int nLineBreak = 5;
    unsigned int curItem = 0;

    bool shouldWriteToFile = !outputFile.empty();
    std::ofstream fout;

    if (shouldWriteToFile)
    {
        fout.open(outputFile.c_str());

        if (!fout.is_open())
        {
            cout << "Unable to open " << outputFile << std::endl;
            return;
        }
    }
    else
    {
        cout << "The list of valid counters for " << strGenerationName << " based graphics cards:\n";
    }

    for (CounterList::iterator it = counterList.begin(); it != counterList.end(); ++it)
    {

        if (shouldWriteToFile)
        {
            fout << *it << std::endl;
        }
        else
        {
            cout << *it;

            if (*it != counterList.back())
            {
                cout << ", ";
            }

            // line break
            if (curItem && (curItem + 1) % nLineBreak == 0)
            {
                cout << endl;
                curItem = 0;
            }
            else
            {
                curItem++;
            }
        }
    }

    if (shouldWriteToFile)
    {
        fout.close();
        cout << "Counters written to " << outputFile << std::endl;
    }
    else
    {
        cout << endl << endl;
    }
}