Fix SCons 1.2.0 build failure
[senf.git] / Utils / Console / Config.hh
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 Config public header */
25
26 #ifndef HH_SENF_Scheduler_Console_Config_
27 #define HH_SENF_Scheduler_Console_Config_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include <list>
32 #include "Parse.hh"
33 #include "Executor.hh"
34
35 //#include "Config.mpp"
36 #include "Config.ih"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40 namespace console {
41
42     /** \brief Combine multiple configuration sources
43
44         A ConfigBundle combines several sources and parses them together, in the order they were
45         added. Parse restrictions are applied uniformly to all sources.
46         \code
47         // Add three configuration sources: A system configuration file, a user configuration file
48         // and command line options
49         senf::console::ConfigBundle conf;
50         conf.add( senf::console::FileConfig("/etc/some.conf") );
51         conf.add( senf::console::FileConfig("local.conf") );
52         conf.add( senf::console::OptionsConfig(senf::Daemon::instance().argc(),
53                                                senf::Daemon::instance().argv()) );
54
55         conf.parse();
56         \endcode
57
58         This bundle may also be passed to other code which may use restricted parsing to parse
59         partial information from all configuration sources.
60         
61         \ingroup console_access
62       */
63     class ConfigBundle
64     {
65     public:
66         ///////////////////////////////////////////////////////////////////////////
67         ///\name Structors and default members
68         ///@{
69
70         ConfigBundle();                     ///< root node is set to console::root()
71         ConfigBundle(DirectoryNode & root); ///< Set custom root node
72
73         ///@}
74         ///////////////////////////////////////////////////////////////////////////
75
76         template <class Source>
77         Source & add(boost::intrusive_ptr<Source> source);
78                                         ///< Add configuration source
79        
80         void parse();                   ///< Parse config bundle
81                                         /**< All nodes already parsed are skipped */
82         void parse(DirectoryNode & restrict); ///< Parse config bundle under \a restrict
83                                         /**< Only nodes which are children of \a restrict are
84                                              parsed. */
85
86         bool complete() const;          ///< \c true, if all nodes have been parsed
87         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
88         void reset();                   ///< Reset node parse info state
89                                         /**< After a call to reset(), all information about already
90                                              parsed nodes is cleared. Calling parse() will parse the
91                                              complete config bundle again. */
92
93         DirectoryNode & root() const;
94         void chroot(DirectoryNode & node);
95
96     protected:
97
98     private:
99         void parseInternal();
100
101         typedef std::list<detail::ConfigSource::ptr> Sources;
102
103         Sources sources_;
104         detail::RestrictedExecutor executor_;
105     };
106
107 namespace detail {
108     // hrmpf ... Can't place this into Config.ih ...
109
110     /** \brief Internal: Provide ConfigBundle facade for a single-source config.
111
112         The BundleMixin is used to define supplementary configuration objects for one specific
113         configuration source. A BundleMixin is \e not a ConfigBundle since it has no public \c add()
114         member.
115      */
116     class BundleMixin
117     {
118     public:
119         BundleMixin();
120         BundleMixin(DirectoryNode & root);
121
122         void parse();                   ///< Parse config file
123                                         /**< All nodes already parsed are skipped */
124         void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
125                                         /**< Only nodes which are children of \a restrict are
126                                              parsed.  */
127
128         bool complete() const;          ///< \c true, if all nodes have been parsed
129         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
130         void reset();                   ///< Reset node parse info state
131                                         /**< After a call to reset(), all information about already
132                                              parsed nodes is cleared. Calling parse() will parse the
133                                              complete config file again. */
134
135     protected:
136         template <class Source>
137         Source & add(boost::intrusive_ptr<Source> source);
138         
139     private:
140         ConfigBundle bundle_;
141     };
142
143 }}}
144
145 ///////////////////////////////hh.e////////////////////////////////////////
146 #include "Config.cci"
147 //#include "Config.ct"
148 #include "Config.cti"
149 #endif
150
151 \f
152 // Local Variables:
153 // mode: c++
154 // fill-column: 100
155 // comment-column: 40
156 // c-file-style: "senf"
157 // indent-tabs-mode: nil
158 // ispell-local-dictionary: "american"
159 // compile-command: "scons -u test"
160 // End: