29c2ebf8cf5a83993e01673b63663bb858e1c911
[senf.git] / senf / Utils / Console / ProgramOptions.ih
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief ProgramOptions internal header */
25
26 #ifndef IH_SENF_Scheduler_Console_ProgramOptions_
27 #define IH_SENF_Scheduler_Console_ProgramOptions_ 1
28
29 // Custom includes
30 #include <boost/scoped_ptr.hpp>
31 #include "Parse.hh"
32
33 ///////////////////////////////ih.p////////////////////////////////////////
34
35 namespace senf {
36 namespace console {
37 namespace detail {
38
39 #ifndef DOXYGEN
40
41     class ProgramOptionsSource : public ConfigSource
42     {
43     public:
44         typedef boost::intrusive_ptr<ProgramOptionsSource> ptr;
45
46         static ptr create(int argc, char const ** argv);
47
48         template <class Container>
49         ProgramOptionsSource & nonOptions(Container & container);
50         ProgramOptionsSource & alias(char letter, std::string const & longOpt, bool withArg=false);
51
52     private:
53         ProgramOptionsSource(int argc, char const ** argv);
54
55         virtual void v_parse(RestrictedExecutor & executor);
56
57         void parseLongOption(std::string const & arg, RestrictedExecutor & executor);
58         void parseNonOption(std::string const & arg, RestrictedExecutor & executor);
59
60         struct NonOptionContainer
61         {
62             virtual ~NonOptionContainer();
63             virtual void clear() = 0;
64             virtual void push_back(std::string const & value) = 0;
65         };
66
67         template <class Container>
68         struct NonOptionContainerImpl
69             : public NonOptionContainer
70         {
71             NonOptionContainerImpl(Container & c);
72
73             void clear();
74             void push_back(std::string const & value);
75
76             Container & c_;
77         };
78
79         struct ShortOption
80         {
81             ShortOption(bool withArg, std::string const & longOpt);
82             bool withArg;
83             std::string longOpt;
84         };
85
86         typedef std::map<char, ShortOption> ShortOptions;
87
88         int argc_;
89         char const ** argv_;
90         CommandParser parser_;
91         ShortOptions shortOptions_;
92         boost::scoped_ptr<NonOptionContainer> nonOptions_;
93     };
94
95 #endif
96
97 }}}
98
99 ///////////////////////////////ih.e////////////////////////////////////////
100 #endif
101
102 \f
103 // Local Variables:
104 // mode: c++
105 // fill-column: 100
106 // comment-column: 40
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // End: