Changeset 18997
- Timestamp:
- 04/19/18 19:07:33 (7 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Configuration.cc
r18587 r18997 463 463 fPrintUsage(bind(&Configuration::PrintUsage, this)) 464 464 { 465 if (prgname.empty()) 466 return; 467 465 468 po::options_description generic("Generic options"); 466 469 generic.add_options() … … 1256 1259 } 1257 1260 1261 const 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 1258 1307 bool Configuration::DoParse(int argc, const char **argv, const std::function<void()> &PrintHelp) 1259 1308 { … … 1276 1325 1277 1326 return !HasVersion() && !HasPrint() && !HasHelp(); 1327 } 1328 1329 bool 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; 1278 1349 } 1279 1350 -
trunk/FACT++/src/Configuration.h
r14735 r18997 138 138 // Process command line arguments 139 139 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); 140 141 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); 141 143 142 144 bool HasVersion()
Note:
See TracChangeset
for help on using the changeset viewer.