From 02d1f7f6c881899ce2d0158e0f058eb1a675f5fe Mon Sep 17 00:00:00 2001 From: Michael Ochmann <miko007@me.com> Date: Fri, 10 Mar 2017 11:22:14 +0100 Subject: [PATCH] fixed strage release build bug --- src/Editor.cpp | 4 ++-- src/config/ConfigParser.cpp | 18 +++++++++--------- src/config/ConfigParser.hpp | 10 ++++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Editor.cpp b/src/Editor.cpp index 03864a7..322e647 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -9,7 +9,7 @@ namespace groove { Editor::Editor(std::string filename) : x(0), y(0), buffer(std::make_unique<Buffer>()), mode_(Mode::EDIT), filename(filename), offset(0), voffset(0), - history(History()), inComment(false), config(config::ConfigParser()) { + history(History()), inComment(false) { this->modes.emplace(Mode::INSERT, std::make_unique<modes::Insert>(*this)); this->modes.emplace(Mode::EDIT, std::make_unique<modes::Edit>(*this)); this->modes.emplace(Mode::QUIT, std::make_unique<modes::Quit>(*this)); @@ -17,7 +17,7 @@ namespace groove { this->modes.emplace(Mode::EXIT, std::make_unique<modes::Exit>(*this)); this->lineMode = this->config.get<std::string>("linenumbers") == "relative" ? LineMode::RELATIVE : - this->config.get<std::string>("linenumbers") == "none" ? LineMode::NONE : LineMode::NUMBERS; + (this->config.get<std::string>("linenumbers") == "none" ? LineMode::NONE : LineMode::NUMBERS); this->overlay = newwin(LINES * 0.9, COLS * 0.9, (LINES * 0.1f) / 2.0f, (COLS * 0.1f) / 2.0f); box(this->overlay, 0, 0); diff --git a/src/config/ConfigParser.cpp b/src/config/ConfigParser.cpp index 0bec241..a63a51a 100644 --- a/src/config/ConfigParser.cpp +++ b/src/config/ConfigParser.cpp @@ -32,7 +32,7 @@ namespace groove { std::string value = pair.at(1); std::trim(key); std::trim(value); - this->params.emplace(key, ConfigValue(value)); + this->params->emplace(key, ConfigValue(value)); } } else { @@ -42,30 +42,30 @@ namespace groove { template<> std::string ConfigParser::get<std::string>(const std::string& key) { - if (this->params.find(key) == this->params.end()) + if (this->params->find(key) == this->params->end()) return ""; - return this->params.at(key).strVal; + return this->params->at(key).strVal; } template<> int ConfigParser::get<int>(const std::string& key) { - if (this->params.find(key) == this->params.end()) + if (this->params->find(key) == this->params->end()) return 0; - return this->params.at(key).intVal; + return this->params->at(key).intVal; } template<> float ConfigParser::get<float>(const std::string& key) { - if (this->params.find(key) == this->params.end()) + if (this->params->find(key) == this->params->end()) return 0.0f; - return this->params.at(key).floatVal; + return this->params->at(key).floatVal; } template<> bool ConfigParser::get<bool>(const std::string& key) { - if (this->params.find(key) == this->params.end()) + if (this->params->find(key) == this->params->end()) return false; - return this->params.at(key).boolVal; + return this->params->at(key).boolVal; } } diff --git a/src/config/ConfigParser.hpp b/src/config/ConfigParser.hpp index deabe75..8e8eeee 100644 --- a/src/config/ConfigParser.hpp +++ b/src/config/ConfigParser.hpp @@ -9,6 +9,7 @@ #include <pwd.h> #include <unistd.h> #include <sys/types.h> +#include <memory> namespace std { static inline std::vector<std::string> explode(const std::string &str, char delimiter) { @@ -54,24 +55,25 @@ namespace groove { class ConfigParser { private: - std::unordered_map<std::string, ConfigValue> params; + std::unique_ptr<std::unordered_map<std::string, ConfigValue>> params; std::string filename; void parse(); public: - ConfigParser() { + ConfigParser() : params(std::make_unique<std::unordered_map<std::string, ConfigValue>>()) { this->filename = getenv("HOME"); this->filename += "/.grooverc"; this->parse(); } + ConfigParser(const ConfigParser&) = delete; template <typename T> - T get(const std::string& key) {} + T get(const std::string& key); template<typename T> void set(std::string key, T value) { std::string newValue = std::to_string(value); - this->params.at(key).set(newValue); + this->params->at(key).set(newValue); } };