Changeset 13669 for trunk/FACT++


Ignore:
Timestamp:
05/12/12 12:36:50 (13 years ago)
Author:
tbretz
Message:
Added GetWildcardOptions and GetOptions to be able to access all available wildcard options of one kind at once; replaced some iterator defintions with the auto keyword for conevenience
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Configuration.cc

    r13005 r13669  
    13671367
    13681368    size_t max = 0;
    1369     for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1369    for (auto it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
    13701370        if (it->second.length()>max)
    13711371            max = it->second.length();
    13721372
    13731373    cout.setf(ios_base::left);
    1374     for (map<string,string>::const_iterator it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1374    for (auto it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
    13751375        cout << setw(max+1) << it->second << " : " << it->first <<endl;
     1376}
     1377
     1378const vector<string> Configuration::GetWildcardOptions(const std::string &opt) const
     1379{
     1380    vector<string> rc;
     1381
     1382    for (auto it=fWildcardOptions.begin(); it!=fWildcardOptions.end(); it++)
     1383    {
     1384        if (it->second == opt)
     1385            rc.push_back(it->first);
     1386    }
     1387
     1388    return rc;
    13761389}
    13771390
  • trunk/FACT++/src/Configuration.h

    r13005 r13669  
    120120
    121121    const std::map<std::string,std::string> &GetWildcardOptions() const { return fWildcardOptions; }
     122    const std::vector<std::string> GetWildcardOptions(const std::string &opt) const;
     123
     124    template<class T>
     125    const std::map<std::string,T> GetOptions(const std::string &opt)
     126    {
     127        const std::vector<std::string> rc = GetWildcardOptions(opt+'*');
     128
     129        std::map<std::string,T> map;
     130        for (auto it=rc.begin(); it!=rc.end(); it++)
     131            map[it->substr(opt.length())] = Get<T>(*it);
     132
     133        return map;
     134    }
    122135
    123136    std::multimap<std::string, std::string> GetOptions() const;
Note: See TracChangeset for help on using the changeset viewer.