Changeset 18997 for trunk


Ignore:
Timestamp:
04/19/18 19:07:33 (6 years ago)
Author:
tbretz
Message:
Added some code which allows to read a single file.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r18587 r18997  
    463463fPrintUsage(bind(&Configuration::PrintUsage, this))
    464464{
     465    if (prgname.empty())
     466        return;
     467
    465468    po::options_description generic("Generic options");
    466469    generic.add_options()
     
    12561259}
    12571260
     1261const po::variables_map &Configuration::ParseFile(const string &fname, const bool &checkf)
     1262{
     1263    // ------------------------ (0) --------------------------
     1264    po::options_description opt_configfile;
     1265
     1266    for (int i=0; i<2; i++)
     1267        opt_configfile.add(fOptionsConfigfile[i]);
     1268
     1269    // ------------------------ (1) --------------------------
     1270
     1271    po::variables_map getfiles;
     1272
     1273    // ------------------------ (1) --------------------------
     1274
     1275    ifstream file(fname.c_str());
     1276    // ===> FIXME: Proper handling of missing file or wrong file name
     1277    const po::parsed_options parsed_file =
     1278        po::parse_config_file<char>(file, opt_configfile, !checkf);
     1279
     1280    // ------------------------ (6) --------------------------
     1281    po::store(parsed_file, getfiles);
     1282
     1283    // ------------------------ (13) -------------------------
     1284
     1285    po::variables_map result;
     1286    po::store(parsed_file, result);
     1287    po::notify(result);
     1288
     1289    fVariables = result;
     1290
     1291    // ------------------------ (14) -------------------------
     1292
     1293    const vector<string> unknown = collect_unrecognized(parsed_file.options, po::exclude_positional);
     1294
     1295    fUnknownConfigfile.clear();
     1296    fUnknownConfigfile.insert(fUnknownConfigfile.end(), unknown.begin(), unknown.end());
     1297
     1298    // ------------------------ (15) -------------------------
     1299
     1300    CreateWildcardOptions();
     1301
     1302    // ------------------------ (16) -------------------------
     1303
     1304    return fVariables;
     1305}
     1306
    12581307bool Configuration::DoParse(int argc, const char **argv, const std::function<void()> &PrintHelp)
    12591308{
     
    12761325
    12771326    return !HasVersion() && !HasPrint() && !HasHelp();
     1327}
     1328
     1329bool Configuration::ReadFile(const string &fname, const bool &checkf)
     1330{
     1331    try
     1332    {
     1333        ParseFile(fname, checkf);
     1334    }
     1335#if BOOST_VERSION > 104000
     1336    catch (po::multiple_occurrences &e)
     1337    {
     1338        cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     1339        return false;
     1340    }
     1341#endif
     1342    catch (exception& e)
     1343    {
     1344        cerr << "Program options invalid due to: " << e.what() << endl;
     1345        return false;
     1346    }
     1347
     1348    return true;
    12781349}
    12791350
  • trunk/FACT++/src/Configuration.h

    r14735 r18997  
    138138    // Process command line arguments
    139139    const po::variables_map &Parse(int argc, const char **argv, const std::function<void()> &func=std::function<void()>());
     140    const po::variables_map &ParseFile(const std::string &fname, const bool &checkf);
    140141    bool DoParse(int argc, const char **argv, const std::function<void()> &func=std::function<void()>());
     142    bool ReadFile(const std::string &fname, const bool &checkf=false);
    141143
    142144    bool HasVersion()
Note: See TracChangeset for help on using the changeset viewer.