class Settings
{
public:
- Settings() :
- globals_(script_.getGlobalTable()),
- top_(script_[-1])
+
+ Settings()
{
- importLogScript(script_);
+ mScript.importBaseLibrary();
+ importLogFunctions(mScript);
}
- // get global instance
- static Settings& getInstance();
+ ~Settings();
void parseArgs(int argc, char* argv[]);
- void loadFromFile(const std::string& filePath);
- void loadFromFiles(const std::vector<std::string>& filePaths);
+ void loadFromFiles(const std::string& path);
+ void loadFromFiles(const std::vector<std::string>& path);
+
+ void clear(); // remove all settings
+
+ void saveAs(const std::string& path);
+ void save() const;
template <typename T>
- bool get(const std::string& key, T& value);
+ bool get(const std::string& key, T& value) const;
private:
- Script script_;
- Script::Value globals_, top_;
+
+ mutable Script mScript;
+
+ std::string mUserFile;
};
template <typename T>
-bool Settings::get(const std::string& key, T& value)
+bool Settings::get(const std::string& key, T& value) const
{
+ Script::Slot top = mScript[-1];
+ Script::Slot globals = mScript.getGlobalTable();
+
std::vector<std::string> fields;
boost::split(fields, key, boost::is_any_of("."));
- globals_.pushCopy();
+ globals.pushCopy();
std::vector<std::string>::iterator it;
for (it = fields.begin(); it != fields.end(); ++it)
{
- if (top_.isTable())
+ if (top.isTable())
{
- top_.pushField(*it);
+ top.pushField(*it);
}
else
{
- script_.clear();
+ mScript.clear();
return false;
}
}
- bool got = top_.get(value);
- script_.clear();
+ bool got = top.get(value);
+ mScript.clear();
return got;
}
+extern Settings settings;
+
+
} // namepsace Mf
#endif // _MOOF_SETTINGS_HH_