Changeset 11578


Ignore:
Timestamp:
07/24/11 21:20:34 (13 years ago)
Author:
tbretz
Message:
Moved some part of the initialization from main to Configure::DoParse
Location:
trunk/FACT++
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/gui/fact.cc

    r11576 r11578  
    5151    SetupConfiguration(conf);
    5252
    53     po::variables_map vm;
    54     try
    55     {
    56         vm = conf.Parse(argc, argv);
    57     }
    58 #if BOOST_VERSION > 104000
    59     catch (po::multiple_occurrences &e)
    60     {
    61         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     53    if (!conf.DoParse(argc, argv, PrintHelp))
    6254        return -1;
    63     }
    64 #endif
    65     catch (exception& e)
    66     {
    67         cerr << "Program options invalid due to: " << e.what() << endl;
    68         return -1;
    69     }
    70 
    71     if (conf.HasVersion() || conf.HasPrint())
    72         return -1;
    73 
    74     if (conf.HasHelp())
    75     {
    76         PrintHelp();
    77         return -1;
    78     }
    7955
    8056    Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
  • trunk/FACT++/src/Configuration.cc

    r11573 r11578  
    12331233}
    12341234
     1235bool Configuration::DoParse(int argc, const char **argv, const std::function<void()> &PrintHelp)
     1236{
     1237    try
     1238    {
     1239        Parse(argc, argv);
     1240    }
     1241#if BOOST_VERSION > 104000
     1242    catch (po::multiple_occurrences &e)
     1243    {
     1244        cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     1245        return false;
     1246    }
     1247#endif
     1248    catch (exception& e)
     1249    {
     1250        cerr << "Program options invalid due to: " << e.what() << endl;
     1251        return false;
     1252    }
     1253
     1254    if (HasVersion() || HasPrint())
     1255        return false;
     1256
     1257    if (HasHelp())
     1258    {
     1259        if (PrintHelp)
     1260            PrintHelp();
     1261        return false;
     1262    }
     1263
     1264    return true;
     1265}
     1266
    12351267// --------------------------------------------------------------------------
    12361268//
  • trunk/FACT++/src/Configuration.h

    r11483 r11578  
    125125    // Process command line arguments
    126126    const po::variables_map &Parse(int argc, const char **argv);
     127    bool DoParse(int argc, const char **argv, const std::function<void()> &func=std::function<void()>());
    127128
    128129    bool HasVersion()
  • trunk/FACT++/src/biasctrl.cc

    r11577 r11578  
    622622    SetupConfiguration(conf);
    623623
    624     po::variables_map vm;
    625     try
    626     {
    627         vm = conf.Parse(argc, argv);
    628     }
    629 #if BOOST_VERSION > 104000
    630     catch (po::multiple_occurrences &e)
    631     {
    632         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     624    if (!conf.DoParse(argc, argv, PrintHelp))
    633625        return -1;
    634     }
    635 #endif
    636     catch (exception& e)
    637     {
    638         cerr << "Program options invalid due to: " << e.what() << endl;
    639         return -1;
    640     }
    641 
    642     if (conf.HasVersion() || conf.HasPrint())
    643         return -1;
    644 
    645     if (conf.HasHelp())
    646     {
    647         PrintHelp();
    648         return -1;
    649     }
    650626
    651627    //try
  • trunk/FACT++/src/chatclient.cc

    r11574 r11578  
    7979    SetupConfiguration(conf);
    8080
    81     po::variables_map vm;
    82     try
    83     {
    84         vm = conf.Parse(argc, argv);
    85     }
    86 #if BOOST_VERSION > 104000
    87     catch (po::multiple_occurrences &e)
    88     {
    89         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     81    if (!conf.DoParse(argc, argv, PrintHelp))
    9082        return -1;
    91     }
    92 #endif
    93     catch (exception& e)
    94     {
    95         cerr << "Program options invalid due to: " << e.what() << endl;
    96         return -1;
    97     }
    98 
    99     if (conf.HasVersion() || conf.HasPrint())
    100         return -1;
    101 
    102     if (conf.HasHelp())
    103     {
    104         PrintHelp();
    105         return -1;
    106     }
    10783
    10884    Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
  • trunk/FACT++/src/chatserv.cc

    r11574 r11578  
    7979    SetupConfiguration(conf);
    8080
    81     po::variables_map vm;
    82     try
    83     {
    84         vm = conf.Parse(argc, argv);
    85     }
    86 #if BOOST_VERSION > 104000
    87     catch (po::multiple_occurrences &e)
    88     {
    89         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     81    if (!conf.DoParse(argc, argv, PrintHelp))
    9082        return -1;
    91     }
    92 #endif
    93     catch (exception& e)
    94     {
    95         cerr << "Program options invalid due to: " << e.what() << endl;
    96         return -1;
    97     }
    98 
    99     if (conf.HasVersion() || conf.HasPrint())
    100         return -1;
    101 
    102     if (conf.HasHelp())
    103     {
    104         PrintHelp();
    105         return -1;
    106     }
    10783
    10884    Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
  • trunk/FACT++/src/datalogger.cc

    r11577 r11578  
    24682468    SetupConfiguration(conf);
    24692469
    2470     po::variables_map vm;
    2471     try
    2472     {
    2473         vm = conf.Parse(argc, argv);
    2474     }
    2475 #if BOOST_VERSION > 104000
    2476     catch (po::multiple_occurrences &e)
    2477     {
    2478         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     2470    if (!conf.DoParse(argc, argv, PrintHelp))
    24792471        return -1;
    2480     }
    2481 #endif
    2482     catch (exception& e)
    2483     {
    2484         cerr << "Program options invalid due to: " << e.what() << endl;
    2485         return -1;
    2486     }
    2487 
    2488     if (conf.HasVersion() || conf.HasPrint())
    2489         return -1;
    2490 
    2491     if (conf.HasHelp())
    2492     {
    2493         PrintHelp();
    2494         return -1;
    2495     }
    24962472
    24972473//    try
  • trunk/FACT++/src/dimctrl.cc

    r11575 r11578  
    7070    Main::SetupConfiguration(conf);
    7171
    72     po::variables_map vm;
    73     try
    74     {
    75         vm = conf.Parse(argc, argv);
    76     }
    77 #if BOOST_VERSION > 104000
    78     catch (po::multiple_occurrences &e)
    79     {
    80         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     72    if (!conf.DoParse(argc, argv, PrintHelp))
    8173        return -1;
    82     }
    83 #endif
    84     catch (exception& e)
    85     {
    86         cerr << "Program options invalid due to: " << e.what() << endl;
    87         return -1;
    88     }
    89 
    90     if (conf.HasVersion() || conf.HasPrint())
    91         return -1;
    92 
    93     if (conf.HasHelp())
    94     {
    95         PrintHelp();
    96         return -1;
    97     }
    9874
    9975    Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"));
  • trunk/FACT++/src/drivectrl.cc

    r11577 r11578  
    999999    SetupConfiguration(conf);
    10001000
    1001     po::variables_map vm;
    1002     try
    1003     {
    1004         vm = conf.Parse(argc, argv);
    1005     }
    1006 #if BOOST_VERSION > 104000
    1007     catch (po::multiple_occurrences &e)
    1008     {
    1009         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     1001    if (!conf.DoParse(argc, argv, PrintHelp))
    10101002        return -1;
    1011     }
    1012 #endif
    1013     catch (exception& e)
    1014     {
    1015         cerr << "Program options invalid due to: " << e.what() << endl;
    1016         return -1;
    1017     }
    1018 
    1019     if (conf.HasVersion() || conf.HasPrint())
    1020         return -1;
    1021 
    1022     if (conf.HasHelp())
    1023     {
    1024         PrintHelp();
    1025         return -1;
    1026     }
    10271003
    10281004    //try
  • trunk/FACT++/src/fadctrl.cc

    r11577 r11578  
    20692069    SetupConfiguration(conf);
    20702070
    2071     po::variables_map vm;
    2072     try
    2073     {
    2074         vm = conf.Parse(argc, argv);
    2075     }
    2076 #if BOOST_VERSION > 104000
    2077     catch (po::multiple_occurrences &e)
    2078     {
    2079         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     2071    if (!conf.DoParse(argc, argv, PrintHelp))
    20802072        return -1;
    2081     }
    2082 #endif
    2083     catch (exception& e)
    2084     {
    2085         cerr << "Program options invalid due to: " << e.what() << endl;
    2086         return -1;
    2087     }
    2088 
    2089     if (conf.HasVersion() || conf.HasPrint())
    2090         return -1;
    2091 
    2092     if (conf.HasHelp())
    2093     {
    2094         PrintHelp();
    2095         return -1;
    2096     }
    20972073
    20982074//    try
  • trunk/FACT++/src/fitsdump.cc

    r11566 r11578  
    682682    SetupConfiguration(conf);
    683683
    684     po::variables_map vm;
    685     try
    686     {
    687         vm = conf.Parse(argc, argv);
    688     }
    689 #if BOOST_VERSION > 104000
    690     catch (po::multiple_occurrences &e)
    691     {
    692         cerr << "Program options invalid due to: " << e.what() << " of option '" << e.get_option_name() << "'." << endl;
     684    if (!conf.DoParse(argc, argv, PrintHelp))
    693685        return -1;
    694     }
    695 #endif
    696     catch (exception& e)
    697     {
    698         cerr << "Program options invalid due to: " << e.what() << endl;
    699         return -1;
    700     }
    701 
    702     if (conf.HasVersion() || conf.HasPrint())
    703         return -1;
    704 
    705     if (conf.HasHelp())
    706     {
    707         PrintHelp();
    708         return -1;
    709     }
    710686
    711687    FitsDumper loader;
  • trunk/FACT++/src/fitsloader.cc

    r10884 r11578  
    676676    SetupConfiguration(conf);
    677677
    678     po::variables_map vm;
    679     try
    680     {
    681         vm = conf.Parse(argc, argv);
    682     }
    683 #if BOOST_VERSION > 104000
    684     catch (po::multiple_occurrences &e)
    685     {
    686         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     678    if (!conf.DoParse(argc, argv, PrintHelp))
    687679        return -1;
    688     }
    689 #endif
    690     catch (exception& e)
    691     {
    692         cerr << "Program options invalid due to: " << e.what() << endl;
    693         return -1;
    694     }
    695 
    696     if (conf.HasVersion() || conf.HasPrint())
    697         return -1;
    698 
    699     if (conf.HasHelp())
    700     {
    701         PrintHelp();
    702         return -1;
    703     }
    704680
    705681//    if (!conf.Has("console"))
  • trunk/FACT++/src/fscctrl.cc

    r11577 r11578  
    588588    SetupConfiguration(conf);
    589589
    590     po::variables_map vm;
    591     try
    592     {
    593         vm = conf.Parse(argc, argv);
    594     }
    595 #if BOOST_VERSION > 104000
    596     catch (po::multiple_occurrences &e)
    597     {
    598         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     590    if (!conf.DoParse(argc, argv, PrintHelp))
    599591        return -1;
    600     }
    601 #endif
    602     catch (exception& e)
    603     {
    604         cerr << "Program options invalid due to: " << e.what() << endl;
    605         return -1;
    606     }
    607 
    608     if (conf.HasVersion() || conf.HasPrint())
    609         return -1;
    610 
    611     if (conf.HasHelp())
    612     {
    613         PrintHelp();
    614         return -1;
    615     }
    616592
    617593    //try
  • trunk/FACT++/src/ftmctrl.cc

    r11577 r11578  
    24442444    SetupConfiguration(conf);
    24452445
    2446     po::variables_map vm;
    2447     try
    2448     {
    2449         vm = conf.Parse(argc, argv);
    2450     }
    2451 #if BOOST_VERSION > 104000
    2452     catch (po::multiple_occurrences &e)
    2453     {
    2454         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     2446    if (!conf.DoParse(argc, argv, PrintHelp))
    24552447        return -1;
    2456     }
    2457 #endif
    2458     catch (exception& e)
    2459     {
    2460         cerr << "Program options invalid due to: " << e.what() << endl;
    2461         return -1;
    2462     }
    2463 
    2464     if (conf.HasVersion() || conf.HasPrint())
    2465         return -1;
    2466 
    2467     if (conf.HasHelp())
    2468     {
    2469         PrintHelp();
    2470         return -1;
    2471     }
    24722448
    24732449    //try
  • trunk/FACT++/src/mcp.cc

    r11577 r11578  
    478478    Main::SetupConfiguration(conf);
    479479
    480     po::variables_map vm;
    481     try
    482     {
    483         vm = conf.Parse(argc, argv);
    484     }
    485 #if BOOST_VERSION > 104000
    486     catch (po::multiple_occurrences &e)
    487     {
    488         cerr << "Program options invalid due to: " << e.what() << " of '" << e.get_option_name() << "'." << endl;
     480    if (!conf.DoParse(argc, argv, PrintHelp))
    489481        return -1;
    490     }
    491 #endif
    492     catch (exception& e)
    493     {
    494         cerr << "Program options invalid due to: " << e.what() << endl;
    495         return -1;
    496     }
    497 
    498     if (conf.HasVersion() || conf.HasPrint())
    499         return -1;
    500 
    501     if (conf.HasHelp())
    502     {
    503         PrintHelp();
    504         return -1;
    505     }
    506482
    507483    //try
  • trunk/FACT++/src/triggerschedule.cc

    r11268 r11578  
    5858    SetupConfiguration(conf);
    5959
    60     po::variables_map vm;
    61     try
    62     {
    63         vm = conf.Parse(argc, argv);
    64     }
    65 #if BOOST_VERSION > 104000
    66     catch (po::multiple_occurrences &e)
    67     {
    68         cout << "Error: " << e.what() << " of '" << e.get_option_name() << "' option." << endl;
    69         cout << endl;
     60    if (!conf.DoParse(argc, argv, PrintHelp))
    7061        return -1;
    71     }
    72 #endif
    73     catch (std::exception &e)
    74     {
    75         cout << "Error: " << e.what() << endl;
    76         cout << endl;
    77 
    78         return -1;
    79     }
    80 
    81     if (conf.HasVersion() || conf.HasPrint())
    82         return -1;
    83 
    84     if (conf.HasHelp())
    85     {
    86         PrintHelp();
    87         return -1;
    88     }
    8962
    9063    const string dbname = conf.Get<string>("schedule-database-name");
Note: See TracChangeset for help on using the changeset viewer.