00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _Configuration_
00022 #define _Configuration_
00023
00024 #include <cstdlib>
00025 #include <iostream>
00026 #include <vector>
00027 #include "qpid/Exception.h"
00028
00029 namespace qpid {
00030 namespace broker {
00031 class Configuration{
00032
00033 class Option {
00034 const std::string flag;
00035 const std::string name;
00036 const std::string desc;
00037
00038 bool match(const std::string& arg);
00039
00040 protected:
00041 virtual bool needsValue() const = 0;
00042 virtual void setValue(const std::string& value) = 0;
00043
00044 public:
00045 Option(const char flag, const std::string& name, const std::string& desc);
00046 Option(const std::string& name, const std::string& desc);
00047 virtual ~Option();
00048
00049 bool parse(int& i, char** argv, int argc);
00050 void print(std::ostream& out) const;
00051 };
00052
00053 class IntOption : public Option{
00054 const int defaultValue;
00055 int value;
00056 public:
00057 IntOption(char flag, const std::string& name, const std::string& desc, const int value = 0);
00058 IntOption(const std::string& name, const std::string& desc, const int value = 0);
00059 virtual ~IntOption();
00060
00061 int getValue() const;
00062 virtual bool needsValue() const;
00063 virtual void setValue(const std::string& value);
00064 virtual void setValue(int _value) { value = _value; }
00065 };
00066
00067 class LongOption : public Option{
00068 const long defaultValue;
00069 int value;
00070 public:
00071 LongOption(char flag, const std::string& name, const std::string& desc, const long value = 0);
00072 LongOption(const std::string& name, const std::string& desc, const long value = 0);
00073 virtual ~LongOption();
00074
00075 long getValue() const;
00076 virtual bool needsValue() const;
00077 virtual void setValue(const std::string& value);
00078 virtual void setValue(int _value) { value = _value; }
00079 };
00080
00081 class StringOption : public Option{
00082 const std::string defaultValue;
00083 std::string value;
00084 public:
00085 StringOption(char flag, const std::string& name, const std::string& desc, const std::string value = "");
00086 StringOption(const std::string& name, const std::string& desc, const std::string value = "");
00087 virtual ~StringOption();
00088
00089 const std::string& getValue() const;
00090 virtual bool needsValue() const;
00091 virtual void setValue(const std::string& value);
00092 };
00093
00094 class BoolOption : public Option{
00095 const bool defaultValue;
00096 bool value;
00097 public:
00098 BoolOption(char flag, const std::string& name, const std::string& desc, const bool value = 0);
00099 BoolOption(const std::string& name, const std::string& desc, const bool value = 0);
00100 virtual ~BoolOption();
00101
00102 bool getValue() const;
00103 virtual bool needsValue() const;
00104 virtual void setValue(const std::string& value);
00105 virtual void setValue(bool _value) { value = _value; }
00106 };
00107
00108 BoolOption daemon;
00109 BoolOption trace;
00110 IntOption port;
00111 IntOption workerThreads;
00112 IntOption maxConnections;
00113 IntOption connectionBacklog;
00114 StringOption store;
00115 LongOption stagingThreshold;
00116 BoolOption help;
00117 BoolOption version;
00118 char const *programName;
00119
00120 typedef std::vector<Option*>::iterator op_iterator;
00121 std::vector<Option*> options;
00122
00123 public:
00124
00125 struct BadOptionException : public Exception {
00126 template<class T>
00127 BadOptionException(const T& msg) : Exception(msg) {}
00128 };
00129
00130
00131 class ParseException : public Exception {
00132 public:
00133 template <class T>
00134 ParseException(const T& msg) : Exception(msg) {}
00135 };
00136
00137
00138 Configuration();
00139 ~Configuration();
00140
00141 void parse(char const*, int argc, char** argv);
00142
00143 bool isHelp() const;
00144 bool isVersion() const;
00145 bool isDaemon() const;
00146 bool isTrace() const;
00147 int getPort() const;
00148 int getWorkerThreads() const;
00149 int getMaxConnections() const;
00150 int getConnectionBacklog() const;
00151 const std::string& getStore() const;
00152 long getStagingThreshold() const;
00153
00154 void setHelp(bool b) { help.setValue(b); }
00155 void setVersion(bool b) { version.setValue(b); }
00156 void setDaemon(bool b) { daemon.setValue(b); }
00157 void setTrace(bool b) { trace.setValue(b); }
00158 void setPort(int i) { port.setValue(i); }
00159 void setWorkerThreads(int i) { workerThreads.setValue(i); }
00160 void setMaxConnections(int i) { maxConnections.setValue(i); }
00161 void setConnectionBacklog(int i) { connectionBacklog.setValue(i); }
00162 void setStore(const std::string& s) { store.setValue(s); }
00163 void setStagingThreshold(long l) { stagingThreshold.setValue(l); }
00164
00165 void usage();
00166 };
00167 }
00168 }
00169
00170
00171 #endif