00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef IH_SENF_Scheduler_Console_ProgramOptions_
00027 #define IH_SENF_Scheduler_Console_ProgramOptions_ 1
00028
00029
00030 #include <boost/scoped_ptr.hpp>
00031 #include "Parse.hh"
00032
00033
00034
00035 namespace senf {
00036 namespace console {
00037 namespace detail {
00038
00039 #ifndef DOXYGEN
00040
00041 class ProgramOptionsSource : public ConfigSource
00042 {
00043 public:
00044 typedef boost::intrusive_ptr<ProgramOptionsSource> ptr;
00045
00046 static ptr create(int argc, char const ** argv);
00047
00048 template <class Container>
00049 ProgramOptionsSource & nonOptions(Container & container);
00050 ProgramOptionsSource & alias(char letter, std::string const & longOpt, bool withArg=false);
00051
00052 private:
00053 ProgramOptionsSource(int argc, char const ** argv);
00054
00055 virtual void v_parse(RestrictedExecutor & executor);
00056
00057 void parseLongOption(std::string const & arg, RestrictedExecutor & executor);
00058 void parseNonOption(std::string const & arg, RestrictedExecutor & executor);
00059
00060 struct NonOptionContainer
00061 {
00062 virtual ~NonOptionContainer();
00063 virtual void clear() = 0;
00064 virtual void push_back(std::string const & value) = 0;
00065 };
00066
00067 template <class Container>
00068 struct NonOptionContainerImpl
00069 : public NonOptionContainer
00070 {
00071 NonOptionContainerImpl(Container & c);
00072
00073 void clear();
00074 void push_back(std::string const & value);
00075
00076 Container & c_;
00077 };
00078
00079 struct ShortOption
00080 {
00081 ShortOption(bool withArg, std::string const & longOpt);
00082 bool withArg;
00083 std::string longOpt;
00084 };
00085
00086 typedef std::map<char, ShortOption> ShortOptions;
00087
00088 int argc_;
00089 char const ** argv_;
00090 CommandParser parser_;
00091 ShortOptions shortOptions_;
00092 boost::scoped_ptr<NonOptionContainer> nonOptions_;
00093 };
00094
00095 #endif
00096
00097 }}}
00098
00099
00100 #endif
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111