switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Console / ConfigFile.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief ConfigFile public header */
30
31 #ifndef HH_SENF_Scheduler_Console_ConfigFile_
32 #define HH_SENF_Scheduler_Console_ConfigFile_ 1
33
34 // Custom includes
35 #include "Config.hh"
36
37 //#include "ConfigFile.mpp"
38 #include "ConfigFile.ih"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 namespace senf {
42 namespace console {
43
44     /** \brief Console node tree based config file parser
45
46         A ConfigFile instance allows flexible parsing of a config file against the console node
47         tree. If you just want to parse a file completely, the senf::console::readConfig() function
48         will do that. ConfigFile however allows to incrementally parse only a subdirectory of the
49         complete configuration file.
50         \code
51         senf::console::ConfigFile cf ("/my/config/file")
52
53         // Parse only statements under the directory of some object. The object 'ob'
54         // must have been registered somewhere in the node tree
55         cf.parse(ob.dir);
56
57         // Parse rest of the config file
58         cf.parse();
59         \endcode
60
61         If your application uses multiple configuration sources, use a ConfigBundle and FileConfig
62
63         \ingroup console_access
64       */
65     class ConfigFile
66         : public detail::BundleMixin
67     {
68     public:
69         //-////////////////////////////////////////////////////////////////////////
70         ///\name Structors and default members
71         //\{
72
73         explicit ConfigFile(std::string const & filename, DirectoryNode & root = root());
74                                         ///< Create ConfigFile object for \a filename
75                                         /**< The \a filename configuration file will be parsed using
76                                              parse() calls. All configuration statements will be
77                                              interpreted relative to \a root as root node. */
78
79         //\}
80         //-////////////////////////////////////////////////////////////////////////
81
82         void ignoreMissing();           ///< Call to ignore missing files
83
84     private:
85         detail::ConfigFileSource & self_;
86     };
87
88     /** \brief Read configuration file
89
90         The configuration file \a filename will be loaded, interpreting all node's relative to \a
91         root as root node.
92
93         This function uses a local ConfigFile object to perform the parsing.
94
95         \related ConfigFile
96      */
97     void parseFile(std::string const & filename, DirectoryNode & root = root());
98
99     /** \brief ConfigBundle source reading a configuration file
100
101         This constructor is used to create a config source parsing the given configuration file to
102         add to a ConfigBundle.
103
104         \related ConfigFile
105      */
106     detail::ConfigFileSource::ptr FileConfig(std::string const & filename);
107
108 }}
109
110 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 #include "ConfigFile.cci"
112 //#include "ConfigFile.ct"
113 //#include "ConfigFile.cti"
114 #endif
115
116 \f
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
120 // comment-column: 40
121 // c-file-style: "senf"
122 // indent-tabs-mode: nil
123 // ispell-local-dictionary: "american"
124 // compile-command: "scons -u test"
125 // End: