00001 #ifndef QPID_COMMONOPTIONS_H
00002 #define QPID_COMMONOPTIONS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <boost/program_options.hpp>
00026 #include <boost/format.hpp>
00027
00028 namespace qpid {
00029
00031 namespace program_options {
00032
00033 using namespace boost::program_options;
00034
00036 template <class T>
00037 class OptionValue : public typed_value<T> {
00038 public:
00039 OptionValue(T& value, const std::string& arg)
00040 : typed_value<T>(&value), argName(arg) {}
00041 std::string name() const { return argName; }
00042 private:
00043 std::string argName;
00044 };
00045
00056 template<class T>
00057 value_semantic* optValue(T& value, const char* arg) {
00058 std::string val(boost::lexical_cast<std::string>(value));
00059 std::string argName(
00060 val.empty() ? std::string(arg) :
00061 (boost::format("%s (=%s) ") % arg % val).str());
00062 return new OptionValue<T>(value, argName);
00063 }
00064
00069 struct EnvMapper {
00070 EnvMapper(const options_description& o) : opts(o) {}
00071 std::string operator()(const std::string& env);
00072 const options_description& opts;
00073 };
00074
00078 inline value_semantic* optValue(bool& value) { return bool_switch(&value); }
00079
00080 }
00081
00082 namespace po=program_options;
00083
00087 struct CommonOptions {
00088 static const int DEFAULT_PORT;
00089
00090 CommonOptions();
00091
00092 bool trace;
00093 int port;
00094
00096 void addTo(po::options_description&);
00097 };
00098
00099 }
00100
00101 #endif