Console: Refactor config file parser into several classes
[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         void add(detail::ConfigSource::ptr source);
67
68         void parse();                   ///< Parse config file
69                                         /**< All nodes already parsed are skipped */
70         void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
71                                         /**< Only nodes which are children of \a restrict are
72                                              parsed.  */
73
74         bool complete() const;          ///< \c true, if all nodes have been parsed
75         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
76         void reset();                   ///< Reset node parse info state
77                                         /**< After a call to reset(), all information about already
78                                              parsed nodes is cleared. Calling parse() will parse the
79                                              complete config file again. */
80
81     protected:
82
83     private:
84         void parseInternal();
85
86         typedef std::vector<detail::ConfigSource::ptr> Sources;
87
88         Sources sources_;
89         detail::RestrictedExecutor executor_;
90     };
91
92 namespace detail {
93     // hrmpf ... Can't place this into Config.ih ...
94
95     class BundleMixin
96     {
97     public:
98         BundleMixin();
99         BundleMixin(DirectoryNode & root);
100
101         void parse();                   ///< Parse config file
102                                         /**< All nodes already parsed are skipped */
103         void parse(DirectoryNode & restrict); ///< Parse config file under \a restrict
104                                         /**< Only nodes which are children of \a restrict are
105                                              parsed.  */
106
107         bool complete() const;          ///< \c true, if all nodes have been parsed
108         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
109         void reset();                   ///< Reset node parse info state
110                                         /**< After a call to reset(), all information about already
111                                              parsed nodes is cleared. Calling parse() will parse the
112                                              complete config file again. */
113
114     protected:
115         void add(ConfigSource::ptr source);
116
117     private:
118         ConfigBundle bundle_;
119     };
120
121 }}}
122
123 ///////////////////////////////hh.e////////////////////////////////////////
124 #include "Config.cci"
125 //#include "Config.ct"
126 //#include "Config.cti"
127 #endif
128
129 \f
130 // Local Variables:
131 // mode: c++
132 // fill-column: 100
133 // comment-column: 40
134 // c-file-style: "senf"
135 // indent-tabs-mode: nil
136 // ispell-local-dictionary: "american"
137 // compile-command: "scons -u test"
138 // End: