4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ProgramOptions public header */
31 #ifndef HH_SENF_Scheduler_Console_ProgramOptions_
32 #define HH_SENF_Scheduler_Console_ProgramOptions_ 1
38 //#include "ProgramOptions.mpp"
39 #include "ProgramOptions.ih"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45 /** \brief Console node tree based command line option parser
47 A ProgramOptions instance allows flexible parsing of command line options against the
48 console node tree. If you just want to parse all options, the senf::console::parseOptions()
49 function will do that. ProgramOptions however allows to incrementally parse only a
50 subset of the given command line options.
52 std::vector<std::string> args;
53 senf::console::ProgramOptions cf (argc, argv);
56 .alias('n', "--foo-bar=x")
57 .alias('x', "--xxx", true);
59 // Parse only options under the directory of some object. The object 'ob'
60 // must have been registered somewhere in the node tree
63 // Parse rest of the config file
67 If your application uses multiple configuration sources, use a ConfigBundle and
70 \ingroup console_access
73 : public detail::BundleMixin
76 //-////////////////////////////////////////////////////////////////////////
77 ///\name Structors and default members
80 ProgramOptions(int argc, char const ** argv, DirectoryNode & root = root());
81 ///< Create ProgramOptions parser for given options
82 /**< The given argc/argv values are those passed to main by
83 the operating system. Especially argv[0] is \e not an
84 option and is ignored. */
87 //-////////////////////////////////////////////////////////////////////////
89 template <class Container>
90 ProgramOptions & nonOptions(Container & container);
91 ///< Set container to add non-option arguments to
92 /**< \a container must have a \c clear() and a \c
93 push_back(std::string) member. All non-options are
94 added to \a container. Before parsing the command-line,
95 \a clear() is called. */
96 ProgramOptions & alias(char letter, std::string const & longOpt, bool withArg=false);
97 ///< Set short option alias
98 /**< A short option is always an alias for a long option
99 with or without argument. if \a withArg is \c true, the
100 short option will expect an argument on the command
101 line. This argument will be appended (with an
102 additional '=') to \a longOpt. If \a withArg is \c
103 false (the default), \a longOpt may optional contain an
105 \param[in] letter option letter
106 \param[in] longOpt long option alias
107 \param[in] withArg \c true, if the option should take
111 detail::ProgramOptionsSource & config_;
114 /** \brief Parse command line options
116 The command line options in \a argc / \a argv will be parsed, interpreting all node's
117 relative to \a root as root node.
119 \related ProgramOptions
121 void parseOptions(int argc, char const ** argv, DirectoryNode & root = root());
123 /** \brief ConfigBundle source reading command line options
125 This constructor is used to create a config source parsing the given command line options to
126 add to a ConfigBundle.
128 \related ProgramOptions
130 detail::ProgramOptionsSource::ptr OptionsConfig(int argc, char const ** argv);
133 //-/////////////////////////////////////////////////////////////////////////////////////////////////
134 #include "ProgramOptions.cci"
135 //#include "ProgramOptions.ct"
136 #include "ProgramOptions.cti"
143 // comment-column: 40
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"