]>
Dogcows Code - chaz/yoink/blob - src/moof/settings.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_SETTINGS_HH_
13 #define _MOOF_SETTINGS_HH_
17 * Load, store, save program settings.
23 #include <boost/algorithm/string.hpp>
25 #include <moof/script.hh>
35 settings(int argc
, char* argv
[], const std::string
& path
);
39 void parse_args(int argc
, char* argv
[]);
41 void load_files(const std::string
& path
);
42 void load_files(const std::vector
<std::string
>& path
);
46 * Remove all settings.
50 void save_as(const std::string
& path
);
55 * Get a setting by name.
56 * \param key The name of the setting.
57 * \param value A reference to the variable to store the setting.
58 * \return True if the setting exists, false otherwise.
61 bool get(const std::string
& key
, T
& value
) const;
66 mutable script script_
;
68 std::string mUserFile
;
73 bool settings::get(const std::string
& key
, T
& value
) const
75 script::slot top
= script_
[-1];
76 script::slot globals
= script_
.globals();
78 std::vector
<std::string
> fields
;
79 boost::split(fields
, key
, boost::is_any_of("."));
83 std::vector
<std::string
>::iterator it
;
84 for (it
= fields
.begin(); it
!= fields
.end(); ++it
)
92 script_
.clear_stack();
97 bool got
= top
.get(value
);
98 script_
.clear_stack();
105 #endif // _MOOF_SETTINGS_HH_
This page took 0.041086 seconds and 4 git commands to generate.