some unimportant clean-ups ;)
[senf.git] / Utils / 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_SENF_Scheduler_Console_Config_
27 #define IH_SENF_Scheduler_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 #include "../../Utils/DiscardStream.hh"
35
36 ///////////////////////////////ih.p////////////////////////////////////////
37
38 namespace senf {
39 namespace console {
40 namespace detail {
41
42     /** \brief Internal: Executor wrapper implementing restricted execution
43         
44         A RestrictedExecutor will only process commands which a re children of a given node. It does
45         \e not follow any links.
46      */
47     class RestrictedExecutor
48         : boost::noncopyable
49     {
50     public:
51         typedef void result_type;
52
53         ///////////////////////////////////////////////////////////////////////////
54         //\/name Structors and default members
55         ///\{
56
57         RestrictedExecutor(DirectoryNode & root = senf::console::root());
58
59         ///\}
60         ///////////////////////////////////////////////////////////////////////////
61
62         void execute(std::ostream & output, ParseCommandInfo const & command);
63                                         ///< Execute command
64                                         /**< Output will be written to \a output. 
65                                              Same as operator()(). */
66
67         void operator()(std::ostream & output, ParseCommandInfo const & command);
68                                         ///< Execute command
69                                         /**< Output will be written to \a output. 
70                                              Same as execute(). */
71
72         bool complete() const;          ///< \c true, if all nodes have been parsed
73         bool parsed(GenericNode & node) const; ///< \c true. if \a node has been parsed
74         void reset();                   ///< Reset node parse info state
75                                         /**< After a call to reset(), all information about already
76                                              parsed nodes is cleared. Calling parse() will parse the
77                                              complete config file again. */
78
79         DirectoryNode & root() const;
80
81         std::ostream & stream();
82
83         class RestrictGuard;
84
85     protected:
86
87     private:
88         void policyCallback(DirectoryNode & dir, std::string const & item);
89         void insertParsedNode(DirectoryNode & node);
90
91         typedef std::vector<DirectoryNode::weak_ptr> ParsedNodes;
92
93         Executor executor_;
94         ParsedNodes parsedNodes_;
95         DirectoryNode::ptr restrict_;
96         DiscardStream stream_;
97
98         friend class RestrictGuard;
99     };
100
101     /** \brief Internal: Set restricted node of a RestrictedExecutor
102         
103         A RestrictGuard will set the node to which to restrict. It will automatically reset the node
104         in it's destructor.
105      */
106     class RestrictedExecutor::RestrictGuard
107     {
108     public:
109         ///////////////////////////////////////////////////////////////////////////
110         //\/name Structors and default members
111         ///\{
112
113         explicit RestrictGuard(RestrictedExecutor & executor);
114         RestrictGuard(RestrictedExecutor & executor, DirectoryNode & restrict);
115         ~RestrictGuard();
116
117         ///\}
118         ///////////////////////////////////////////////////////////////////////////
119
120     protected:
121
122     private:
123         RestrictedExecutor & executor_;
124
125     };
126
127     /** \brief Internal: ConfigSource base class
128
129         All configuration sources derive from ConfigSource. A ConigSource somehow reads
130         configuration commands and passes them to a RestrictedExecutor.
131       */
132     class ConfigSource
133         : public senf::intrusive_refcount
134     {
135     public:
136         typedef boost::intrusive_ptr<ConfigSource> ptr;
137         virtual ~ConfigSource();
138
139         void parse(RestrictedExecutor & executor);
140
141     protected:
142
143     private:
144         virtual void v_parse(RestrictedExecutor & executor) = 0;
145     };
146
147 }}}
148
149 ///////////////////////////////ih.e////////////////////////////////////////
150 #endif
151
152 \f
153 // Local Variables:
154 // mode: c++
155 // fill-column: 100
156 // comment-column: 40
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"
161 // End: