nis-util  1.0.D108
lib/configuration.h
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef LIB_CONFIGURATION_H
00020 #define LIB_CONFIGURATION_H
00021 
00022 #include <boost/shared_ptr.hpp>
00023 #include <lib/rcstring.h>
00024 #include <lib/configuration/section.h>
00025 #include <lib/input.h>
00026 
00040 class configuration
00041 {
00042 public:
00043     typedef boost::shared_ptr<configuration> pointer;
00044 
00045     typedef configuration_section::level_t level_t;
00046 
00060     rcstring get_string(const rcstring &section_name, const rcstring &item_name)
00061         const;
00062 
00077     long get_long(const rcstring &section_name, const rcstring &item_name)
00078         const;
00079 
00094     bool get_bool(const rcstring &section_name, const rcstring &item_name)
00095         const;
00096 
00102     static configuration &get_singleton(void);
00103 
00118     void load_command_line_file(const rcstring &filename);
00119 
00138     void set_command_line_string(const source_location &locn,
00139         const rcstring &section_name, const rcstring &item_name,
00140         const rcstring &value);
00141 
00160     void set_command_line_long(const source_location &locn,
00161         const rcstring &section_name, const rcstring &item_name,
00162         long value);
00163 
00182     void set_command_line_bool(const source_location &locn,
00183         const rcstring &section_name, const rcstring &item_name,
00184         bool value);
00185 
00202     void set_command_line_bool(const source_location &locn,
00203         const rcstring &item_name, bool value);
00204 
00219     void set_builtin_string(const rcstring &section_name,
00220         const rcstring &item_name, const rcstring &value);
00221 
00236     void set_builtin_long(const rcstring &section_name,
00237         const rcstring &item_name, long value);
00238 
00253     void set_builtin_bool(const rcstring &section_name,
00254         const rcstring &item_name, bool value);
00255 
00260     void print(void) const;
00261 
00262 private:
00266     virtual ~configuration();
00267 
00268 private:
00273     configuration();
00274 
00280     void load(void);
00281 
00294     void parse(level_t level, const input::pointer &src);
00295 
00296     typedef std::map<rcstring, configuration_section::pointer> sections_t;
00297 
00304     sections_t sections;
00305 
00311     static configuration *singleton;
00312 
00327     void set(const rcstring &section_name,
00328         const configuration_item::pointer &item);
00329 
00334     static rcstring canonical_name(const rcstring &name);
00335 
00343     configuration(const configuration &rhs);
00344 
00352     configuration &operator=(const configuration &rhs);
00353 };
00354 
00358 #define cfg configuration::get_singleton()
00359 
00360 // vim: set ts=8 sw=4 et :
00361 #endif // LIB_CONFIGURATION_H