81a94ef669aa9a886270c8ebbee7ba24bada7c9b
[senf.git] / 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_Console_Config_
27 #define HH_Console_Config_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include "Parse.hh"
32 #include "Executor.hh"
33
34 //#include "Config.mpp"
35 #include "Config.ih"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace console {
40
41     /** \brief
42       */
43     class ConfigBundle
44     {
45     public:
46         ///////////////////////////////////////////////////////////////////////////
47         // Types
48
49         ///////////////////////////////////////////////////////////////////////////
50         ///\name Structors and default members
51         ///@{
52
53         ConfigBundle();
54         ConfigBundle(DirectoryNode & root);
55
56         // default default constructor
57         // default copy constructor
58         // default copy assignment
59         // default destructor
60
61         // no conversion constructors
62
63         ///@}
64         ///////////////////////////////////////////////////////////////////////////
65
66         template <class Source>
67         Source & add(boost::intrusive_ptr<Source> source);
68
69         void parse();                   ///< Parse config file
70                                         /**< All nodes already parsed are skipped */
71         void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
72                                         /**< Only nodes which are children of \a restrict are
73                                              parsed.  */
74
75         bool complete() const;          ///< \c true, if all nodes have been parsed
76         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
77         void reset();                   ///< Reset node parse info state
78                                         /**< After a call to reset(), all information about already
79                                              parsed nodes is cleared. Calling parse() will parse the
80                                              complete config file again. */
81
82     protected:
83
84     private:
85         void parseInternal();
86
87         typedef std::vector<detail::ConfigSource::ptr> Sources;
88
89         Sources sources_;
90         detail::RestrictedExecutor executor_;
91     };
92
93 namespace detail {
94     // hrmpf ... Can't place this into Config.ih ...
95
96     class BundleMixin
97     {
98     public:
99         BundleMixin();
100         BundleMixin(DirectoryNode & root);
101
102         void parse();                   ///< Parse config file
103                                         /**< All nodes already parsed are skipped */
104         void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
105                                         /**< Only nodes which are children of \a restrict are
106                                              parsed.  */
107
108         bool complete() const;          ///< \c true, if all nodes have been parsed
109         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
110         void reset();                   ///< Reset node parse info state
111                                         /**< After a call to reset(), all information about already
112                                              parsed nodes is cleared. Calling parse() will parse the
113                                              complete config file again. */
114
115     protected:
116         template <class Source>
117         Source & add(boost::intrusive_ptr<Source> source);
118         
119     private:
120         ConfigBundle bundle_;
121     };
122
123 }}}
124
125 ///////////////////////////////hh.e////////////////////////////////////////
126 #include "Config.cci"
127 //#include "Config.ct"
128 #include "Config.cti"
129 #endif
130
131 \f
132 // Local Variables:
133 // mode: c++
134 // fill-column: 100
135 // comment-column: 40
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // End: