Changeset 10296 for trunk/FACT++/src


Ignore:
Timestamp:
04/07/11 10:10:33 (14 years ago)
Author:
tbretz
Message:
Changed some output from cout to cerr to avoid it going to man pages cerated with help2man; added --version option, added possibility to add some text in front of the --help option
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r10230 r10296  
    267267#include <iostream>
    268268
     269#include <boost/bind.hpp>
    269270#include <boost/regex.hpp>
    270271//#include <boost/filesystem.hpp>
     
    442443        ("help-database",       "Print available options retreived from the database.")
    443444        ("help-config",         "Print available configuration file options.")
     445        ("version,V",           "Print version information.")
    444446        ("print-all",           "Print all options as parsed from all the different sources.")
    445447        ("print",               "Print options as parsed from the commandline.")
     
    678680//!
    679681//
    680 void Configuration::SetNameMapper(const boost::function1<std::string, std::string> &func)
     682void Configuration::SetNameMapper(const boost::function<std::string(std::string)> &func)
    681683{
    682684    fNameMapper = func;
     
    686688{
    687689    fNameMapper = bind1st(mem_fun(&Configuration::DefaultMapper), this);
     690}
     691
     692void Configuration::SetPrintUsage(const boost::function<void(void)> &func)
     693{
     694    fPrintUsage = func;
     695}
     696
     697void Configuration::SetPrintUsage()
     698{
     699    fPrintUsage = boost::bind(&Configuration::PrintUsage, this);
    688700}
    689701
     
    803815
    804816    if (getfiles.count("help"))
    805         cout << endl << fOptionsCommandline[kVisible] << endl;
     817    {
     818        fPrintUsage();
     819        cout << fOptionsCommandline[kVisible] << endl;
     820    }
    806821    if (getfiles.count("help-config"))
    807         cout << endl << fOptionsConfigfile[kVisible] << endl;
     822        cout << fOptionsConfigfile[kVisible] << endl;
    808823    if (getfiles.count("help-env"))
    809         cout << endl << fOptionsEnvironment[kVisible] << endl;
     824        cout << fOptionsEnvironment[kVisible] << endl;
    810825    if (getfiles.count("help-database"))
    811         cout << endl << fOptionsDatabase[kVisible] << endl;
     826        cout << fOptionsDatabase[kVisible] << endl;
    812827
    813828    // ------------------------ (4) --------------------------
     
    826841    {
    827842        fDefaultFile = getfiles["default"].as<string>();
    828         cout << "Reading configuration from '" << fDefaultFile << "'." << endl;
     843        cerr << "Reading configuration from '" << fDefaultFile << "'." << endl;
    829844    }
    830845
     
    862877    {
    863878        fPriorityFile = getfiles["config"].as<string>();
    864         cout << "Retrieved option from '" << fPriorityFile << "'." << endl;
     879        cerr << "Retrieved option from '" << fPriorityFile << "'." << endl;
    865880    }
    866881
     
    895910    {
    896911        fDatabase = getdatabase["database"].as<string>();
    897         cout << "Retrieving configuration from '" << fDatabase << "'." << endl;
     912        cerr << "Retrieving configuration from '" << fDatabase << "'." << endl;
    898913    }
    899914
  • trunk/FACT++/src/Configuration.h

    r10220 r10296  
    4545
    4646    /// Pointer to the mapper function for environment variables
    47     boost::function1<std::string, std::string> fNameMapper;
     47    boost::function<std::string(std::string)> fNameMapper;
     48    boost::function<void()>                   fPrintUsage;
    4849
    4950    /// Helper function which return the max of the two arguments in the first argument
     
    5859    /// Print a list of all unkown options within the given vector
    5960    void PrintUnknown(std::vector<std::string> &vec, int steps=1);
     61
     62    virtual void PrintUsage() const { }
    6063
    6164public:
     
    8184    void SetArgumentPositions(const po::positional_options_description &desc);
    8285
    83     void SetNameMapper(const boost::function1<std::string, std::string> &func);
     86    void SetNameMapper(const boost::function<std::string(std::string)> &func);
    8487    void SetNameMapper();
     88
     89    void SetPrintUsage(const boost::function<void(void)> &func);
     90    void SetPrintUsage();
    8591
    8692    void AddEnv(const std::string &conf, const std::string &env)
     
    95101    // Process command line arguments
    96102    const po::variables_map &Parse(int argc, char **argv);
     103
     104    bool HasVersion() const
     105    {
     106        return Has("version");
     107    }
    97108
    98109    bool HasHelp() const
Note: See TracChangeset for help on using the changeset viewer.