X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSettings.hh;fp=src%2FMoof%2FSettings.hh;h=0000000000000000000000000000000000000000;hp=192e2a764254ba61a4b476a23c51c989422c1db8;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hpb=299af4f2047e767e5d79501c26444473bda64c64 diff --git a/src/Moof/Settings.hh b/src/Moof/Settings.hh deleted file mode 100644 index 192e2a7..0000000 --- a/src/Moof/Settings.hh +++ /dev/null @@ -1,102 +0,0 @@ - -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** -**] All rights reserved. -* -* vi:ts=4 sw=4 tw=75 -* -* Distributable under the terms and conditions of the 2-clause BSD license; -* see the file COPYING for a complete text of the license. -* -**************************************************************************/ - -#ifndef _MOOF_SETTINGS_HH_ -#define _MOOF_SETTINGS_HH_ - -/** - * @file Settings.hh - * Load, store, save program settings. - */ - -#include -#include - -#include - -#include -#include - - -namespace Mf { - - -class Settings -{ -public: - - Settings(int argc, char* argv[], const std::string& path) - { - mScript.importBaseLibrary(); - importLogFunctions(mScript); - - parseArgs(argc, argv); - loadFromFiles(path); - } - - ~Settings(); - - void parseArgs(int argc, char* argv[]); - - void loadFromFiles(const std::string& path); - void loadFromFiles(const std::vector& path); - - void clear(); // remove all settings - - void saveAs(const std::string& path); - void save() const; - - template - bool get(const std::string& key, T& value) const; - -private: - - mutable Script mScript; - - std::string mUserFile; -}; - - -template -bool Settings::get(const std::string& key, T& value) const -{ - Script::Slot top = mScript[-1]; - Script::Slot globals = mScript.globals(); - - std::vector fields; - boost::split(fields, key, boost::is_any_of(".")); - - globals.pushCopy(); - - std::vector::iterator it; - for (it = fields.begin(); it != fields.end(); ++it) - { - if (top.isTable()) - { - top.pushField(*it); - } - else - { - mScript.clearStack(); - return false; - } - } - - bool got = top.get(value); - mScript.clearStack(); - return got; -} - - -} // namepsace Mf - -#endif // _MOOF_SETTINGS_HH_ -