Console: Refactor config file parser into several classes
[senf.git] / Console / Config.cci
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 inline non-template implementation */
25
26 #include "Config.ih"
27
28 // Custom includes
29 #include "../Utils/membind.hh"
30
31 #define prefix_ inline
32 ///////////////////////////////cci.p///////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::console::ConfigBundle
36
37 prefix_ senf::console::ConfigBundle::ConfigBundle()
38 {}
39
40 prefix_ senf::console::ConfigBundle::ConfigBundle(DirectoryNode & root)
41     : executor_ (root)
42 {}
43
44 prefix_ void senf::console::ConfigBundle::add(detail::ConfigSource::ptr source)
45 {
46     sources_.push_back(source);
47 }
48
49 prefix_ bool senf::console::ConfigBundle::complete()
50     const
51 {
52     return executor_.complete();
53 }
54
55 prefix_ bool senf::console::ConfigBundle::parsed(GenericNode & node)
56     const
57 {
58     return executor_.parsed(node);
59 }
60
61 prefix_ void senf::console::ConfigBundle::reset()
62 {
63     executor_.reset();
64 }
65
66 ///////////////////////////////////////////////////////////////////////////
67 // senf::console::detail::RestrictedExecutor
68
69 prefix_ bool senf::console::detail::RestrictedExecutor::complete()
70     const
71 {
72     return parsedNodes_.size() == 1 
73         && ! parsedNodes_[0].expired() 
74         && *parsedNodes_[0].lock() == executor_.chroot();
75 }
76
77 prefix_ void senf::console::detail::RestrictedExecutor::reset()
78 {
79     parsedNodes_.clear();
80 }
81
82 prefix_ senf::console::DirectoryNode & senf::console::detail::RestrictedExecutor::root()
83     const
84 {
85     return executor_.chroot();
86 }
87
88 ///////////////////////////////////////////////////////////////////////////
89 // senf::console::detail::ConfigSource
90
91 prefix_ void senf::console::detail::ConfigSource::parse(RestrictedExecutor & executor)
92 {
93     v_parse(executor);
94 }
95
96 ///////////////////////////////////////////////////////////////////////////
97 // senf::console::detail::BundleMixin
98
99 prefix_ senf::console::detail::BundleMixin::BundleMixin()
100 {}
101
102 prefix_ senf::console::detail::BundleMixin::BundleMixin(DirectoryNode & root)
103     : bundle_ (root)
104 {}
105
106 prefix_ void senf::console::detail::BundleMixin::parse()
107 {
108     bundle_.parse();
109 }
110
111 prefix_ void senf::console::detail::BundleMixin::parse(DirectoryNode & restrict)
112 {
113     bundle_.parse(restrict);
114 }
115
116 prefix_ bool senf::console::detail::BundleMixin::complete()
117     const
118 {
119     return bundle_.complete();
120 }
121
122 prefix_ bool senf::console::detail::BundleMixin::parsed(GenericNode & node)
123     const
124 {
125     return bundle_.parsed(node);
126 }
127
128 prefix_ void senf::console::detail::BundleMixin::reset()
129 {
130     bundle_.reset();
131 }
132
133 prefix_ void senf::console::detail::BundleMixin::add(ConfigSource::ptr source)
134 {
135     bundle_.add(source);
136 }
137
138 ///////////////////////////////cci.e///////////////////////////////////////
139 #undef prefix_
140
141 \f
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // End: