ceb081b5f4beeb5b0b732a50c0e502193c32124c
[senf.git] / Console / Config.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 Config internal header */
25
26 #ifndef IH_Console_Config_
27 #define IH_Console_Config_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include <boost/intrusive_ptr.hpp>
32 #include "Executor.hh"
33 #include "../Utils/intrusive_refcount.hh"
34
35 ///////////////////////////////ih.p////////////////////////////////////////
36
37 namespace senf {
38 namespace console {
39 namespace detail {
40
41     class RestrictedExecutor
42         : boost::noncopyable
43     {
44     public:
45         typedef void result_type;
46
47         ///////////////////////////////////////////////////////////////////////////
48         //\/name Structors and default members
49         ///\{
50
51         RestrictedExecutor(DirectoryNode & root = senf::console::root());
52
53         ///\}
54         ///////////////////////////////////////////////////////////////////////////
55
56         void execute(std::ostream & output, ParseCommandInfo const & command);
57                                         ///< Execute command
58                                         /**< Output will be written to \a output. 
59                                              Same as operator()(). */
60
61         void operator()(std::ostream & output, ParseCommandInfo const & command);
62                                         ///< Execute command
63                                         /**< Output will be written to \a output. 
64                                              Same as execute(). */
65
66         bool complete() const;          ///< \c true, if all nodes have been parsed
67         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
68         void reset();                   ///< Reset node parse info state
69                                         /**< After a call to reset(), all information about already
70                                              parsed nodes is cleared. Calling parse() will parse the
71                                              complete config file again. */
72
73         DirectoryNode & root() const;
74
75         class RestrictGuard;
76
77     protected:
78
79     private:
80         void policyCallback(DirectoryNode & dir, std::string const & item);
81         void insertParsedNode(DirectoryNode & node);
82
83         typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
84
85         Executor executor_;
86         ParsedNodes parsedNodes_;
87         DirectoryNode::ptr restrict_;
88
89         friend class RestrictGuard;
90     };
91
92     class RestrictedExecutor::RestrictGuard
93     {
94     public:
95         ///////////////////////////////////////////////////////////////////////////
96         //\/name Structors and default members
97         ///\{
98
99         explicit RestrictGuard(RestrictedExecutor & executor);
100         RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
101         ~RestrictGuard();
102
103         ///\}
104         ///////////////////////////////////////////////////////////////////////////
105
106     protected:
107
108     private:
109         RestrictedExecutor & executor_;
110
111     };
112
113     /** \brief
114       */
115     class ConfigSource
116         : public senf::intrusive_refcount
117     {
118     public:
119         typedef boost::intrusive_ptr<ConfigSource> ptr;
120         virtual ~ConfigSource();
121
122         void parse(RestrictedExecutor & executor);
123
124     protected:
125
126     private:
127         virtual void v_parse(RestrictedExecutor & executor) = 0;
128     };
129
130 }}}
131
132 ///////////////////////////////ih.e////////////////////////////////////////
133 #endif
134
135 \f
136 // Local Variables:
137 // mode: c++
138 // fill-column: 100
139 // comment-column: 40
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // End: