Line data Source code
1 : /*
2 : * (C) Copyright 2010 Marek Dopiera
3 : *
4 : * This file is part of CoherentDB.
5 : *
6 : * CoherentDB is free software: you can redistribute it and/or modify it
7 : * under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation, either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * CoherentDB is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public
17 : * License along with CoherentDB. If not, see
18 : * http://www.gnu.org/licenses/.
19 : */
20 :
21 : #ifndef CONFIG_H_2944
22 : #define CONFIG_H_2944
23 :
24 : #include <stdint.h>
25 :
26 : #include <utility>
27 : #include <memory>
28 : #include <string>
29 : #include <vector>
30 : #include <map>
31 : #include <set>
32 :
33 : #include <boost/utility.hpp>
34 : #include <boost/smart_ptr.hpp>
35 :
36 : #include <log/log.h>
37 :
38 : namespace coherent {
39 : namespace config {
40 :
41 : std::string get_version_string();
42 : std::string get_build_information();
43 : void print_running_information();
44 :
45 : struct config_exception
46 0 : {
47 : enum
48 : {
49 : NO_LINE = -1
50 : };
51 :
52 : int const line_no;
53 : std::string const descr;
54 :
55 : config_exception(std::string const & descr);
56 : config_exception(int line_no, std::string const & descr);
57 :
58 : std::string to_string();
59 : };
60 :
61 : class ini_config;
62 :
63 : class config_section_base
64 14 : {
65 : protected:
66 : config_section_base(std::string const & sect, ini_config const & conf);
67 : void check_no_others(); //should be called in derived's ctor
68 :
69 : template<typename T>
70 : T get_value(std::string const & name, T const & def);
71 : template<typename T>
72 : T get_value(std::string const & name);
73 : private:
74 : ini_config const & conf;
75 : std::string name;
76 : std::set<std::string> valid_names;
77 : std::set<std::string> present_names;
78 : };
79 :
80 : struct global_config : private boost::noncopyable
81 : {
82 : private:
83 : std::auto_ptr<ini_config> conf;
84 :
85 : public:
86 : global_config(std::string const & file_name) throw(config_exception);
87 :
88 : struct buffer_cache_sect : public config_section_base, private boost::noncopyable
89 7 : {
90 : buffer_cache_sect(ini_config const & conf);
91 :
92 : uint64_t size;
93 : uint16_t syncer_sleep_time;
94 : };
95 :
96 : struct memory_manager_sect : public config_section_base, private boost::noncopyable
97 7 : {
98 : memory_manager_sect(ini_config const& conf);
99 :
100 : uint64_t initialLimitBytes;
101 : uint32_t defaultSessionLimitBytes;
102 : };
103 :
104 : buffer_cache_sect buffer_cache;
105 : memory_manager_sect memory_manager;
106 : ~global_config(); //the dtor needs to be explicit, because gcc tries to
107 : //inline it otherwise and the ini_config dtor is not
108 : //visible
109 : };
110 :
111 : struct scoped_test_enabler
112 : {
113 : scoped_test_enabler(int argc, char const * const * const argv,
114 : log4cxx::LevelPtr def_log_level = log4cxx::Level::getDebug());
115 : ~scoped_test_enabler();
116 : boost::shared_ptr<global_config> get_config();
117 : std::string get_working_dir();
118 : private:
119 : boost::shared_ptr<global_config> config;
120 : std::string working_dir;
121 : };
122 :
123 : } // namespace config
124 : } // namespace coherent
125 :
126 : #endif /* CONFIG_H_2944 */
|