]>
Dogcows Code - chaz/yoink/blob - src/moof/settings.hh
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
10 #ifndef _MOOF_SETTINGS_HH_
11 #define _MOOF_SETTINGS_HH_
16 #include <boost/algorithm/string.hpp>
18 #include <moof/script.hh>
23 * Load, store, save program settings.
33 settings(int argc
, char* argv
[], const std::string
& path
);
36 void parse_args(int argc
, char* argv
[]);
38 void load_files(const std::string
& path
);
39 void load_files(const std::vector
<std::string
>& path
);
42 * Remove all settings.
46 void save_as(const std::string
& path
);
50 * Get a setting by name.
51 * \param key The name of the setting.
52 * \param value A reference to the variable to store the setting.
53 * \return True if the setting exists, false otherwise.
56 bool get(const std::string
& key
, T
& value
) const;
60 mutable script script_
;
61 std::string userfile_
;
65 bool settings::get(const std::string
& key
, T
& value
) const
67 script::slot top
= script_
[-1];
68 script::slot globals
= script_
.globals();
70 std::vector
<std::string
> fields
;
71 boost::split(fields
, key
, boost::is_any_of("."));
75 std::vector
<std::string
>::iterator it
;
76 for (it
= fields
.begin(); it
!= fields
.end(); ++it
)
84 script_
.clear_stack();
89 bool got
= top
.get(value
);
90 script_
.clear_stack();
97 #endif // _MOOF_SETTINGS_HH_
This page took 0.039654 seconds and 4 git commands to generate.