31 #ifndef USERSETTINGS_H_ 32 #define USERSETTINGS_H_ 49 static UserSettings&
get(
const std::string &path = std::string()) {
51 auto res = find_if(storages.begin(), storages.end(),
53 {
return obj.identifier.compare(path) == 0;});
54 if (storages.end() == res) {
58 res = find_if(storages.begin(), storages.end(),
60 {
return obj.identifier.compare(path) == 0;});
61 if (storages.end() == res) {
63 res = storages.begin();
90 template<
typename T,
typename U>
91 bool insert(
const T &
obj,
const std::string &key,
const U &value) {
93 auto result = data.find(fullKey);
96 std::string valStr = ss.str();
97 bool newRec = result == data.end();
98 bool update = !newRec && (valStr.compare(result->second) != 0);
100 if (newRec || update) {
101 data[fullKey] = valStr;
115 template<
typename T,
typename U>
116 bool find(
const T &
obj,
const std::string &key, U &value) {
118 if (result != data.end()) {
119 std::stringstream ss (result->second);
134 UserSettings(
const std::string &path = std::string()) : wasChanged(false),
135 identifier(path), path(path) {
137 this->path = std::string(getenv(
"HOME")) +
"/.xmipp.settings";
149 std::stringstream ss;
150 ss <<
typeid(
obj).name() << key;
161 std::map<std::string, std::string> data;
173 std::string identifier;
175 static std::list<UserSettings> storages;
const std::string getFullName(const T &obj, const std::string &key)
bool insert(const T &obj, const std::string &key, const U &value)
UserSettings(UserSettings &&)=default
UserSettings(const std::string &path=std::string())
bool find(const T &obj, const std::string &key, U &value)