eedda90418302dc0384be9d6d455cd754ce15aec
[senf.git] / senf / Utils / Console / ConfigFile.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 ConfigFile public header */
25
26 #ifndef HH_SENF_Scheduler_Console_ConfigFile_
27 #define HH_SENF_Scheduler_Console_ConfigFile_ 1
28
29 // Custom includes
30 #include "Config.hh"
31
32 //#include "ConfigFile.mpp"
33 #include "ConfigFile.ih"
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35
36 namespace senf {
37 namespace console {
38
39     /** \brief Console node tree based config file parser
40
41         A ConfigFile instance allows flexible parsing of a config file against the console node
42         tree. If you just want to parse a file completely, the senf::console::readConfig() function
43         will do that. ConfigFile however allows to incrementally parse only a subdirectory of the
44         complete configuration file.
45         \code
46         senf::console::ConfigFile cf ("/my/config/file")
47
48         // Parse only statements under the directory of some object. The object 'ob'
49         // must have been registered somewhere in the node tree
50         cf.parse(ob.dir);
51
52         // Parse rest of the config file
53         cf.parse();
54         \endcode
55
56         If your application uses multiple configuration sources, use a ConfigBundle and FileConfig
57
58         \ingroup console_access
59       */
60     class ConfigFile
61         : public detail::BundleMixin
62     {
63     public:
64         //-////////////////////////////////////////////////////////////////////////
65         ///\name Structors and default members
66         //\{
67
68         explicit ConfigFile(std::string const & filename, DirectoryNode & root = root());
69                                         ///< Create ConfigFile object for \a filename
70                                         /**< The \a filename configuration file will be parsed using
71                                              parse() calls. All configuration statements will be
72                                              interpreted relative to \a root as root node. */
73
74         //\}
75         //-////////////////////////////////////////////////////////////////////////
76
77         void ignoreMissing();           ///< Call to ignore missing files
78
79     private:
80         detail::ConfigFileSource & self_;
81     };
82
83     /** \brief Read configuration file
84
85         The configuration file \a filename will be loaded, interpreting all node's relative to \a
86         root as root node.
87
88         This function uses a local ConfigFile object to perform the parsing.
89
90         \related ConfigFile
91      */
92     void parseFile(std::string const & filename, DirectoryNode & root = root());
93
94     /** \brief ConfigBundle source reading a configuration file
95
96         This constructor is used to create a config source parsing the given configuration file to
97         add to a ConfigBundle.
98
99         \related ConfigFile
100      */
101     detail::ConfigFileSource::ptr FileConfig(std::string const & filename);
102
103 }}
104
105 //-/////////////////////////////////////////////////////////////////////////////////////////////////
106 #include "ConfigFile.cci"
107 //#include "ConfigFile.ct"
108 //#include "ConfigFile.cti"
109 #endif
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // fill-column: 100
115 // comment-column: 40
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"
120 // End: