]>
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/Log.hh>
26 #include <Moof/Script.hh>
36 Settings(int argc
, char* argv
[], const std::string
& path
)
38 mScript
.importBaseLibrary();
39 importLogFunctions(mScript
);
41 parseArgs(argc
, argv
);
47 void parseArgs(int argc
, char* argv
[]);
49 void loadFromFiles(const std::string
& path
);
50 void loadFromFiles(const std::vector
<std::string
>& path
);
52 void clear(); // remove all settings
54 void saveAs(const std::string
& path
);
58 bool get(const std::string
& key
, T
& value
) const;
62 mutable Script mScript
;
64 std::string mUserFile
;
69 bool Settings::get(const std::string
& key
, T
& value
) const
71 Script::Slot top
= mScript
[-1];
72 Script::Slot globals
= mScript
.globals();
74 std::vector
<std::string
> fields
;
75 boost::split(fields
, key
, boost::is_any_of("."));
79 std::vector
<std::string
>::iterator it
;
80 for (it
= fields
.begin(); it
!= fields
.end(); ++it
)
93 bool got
= top
.get(value
);
101 #endif // _MOOF_SETTINGS_HH_
This page took 0.039661 seconds and 4 git commands to generate.