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()), 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(*this)); this->modes.emplace(Mode::EDIT, std::make_unique(*this)); this->modes.emplace(Mode::QUIT, std::make_unique(*this)); @@ -17,7 +17,7 @@ namespace groove { this->modes.emplace(Mode::EXIT, std::make_unique(*this)); this->lineMode = this->config.get("linenumbers") == "relative" ? LineMode::RELATIVE : - this->config.get("linenumbers") == "none" ? LineMode::NONE : LineMode::NUMBERS; + (this->config.get("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(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(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(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(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 #include #include +#include namespace std { static inline std::vector explode(const std::string &str, char delimiter) { @@ -54,24 +55,25 @@ namespace groove { class ConfigParser { private: - std::unordered_map params; + std::unique_ptr> params; std::string filename; void parse(); public: - ConfigParser() { + ConfigParser() : params(std::make_unique>()) { this->filename = getenv("HOME"); this->filename += "/.grooverc"; this->parse(); } + ConfigParser(const ConfigParser&) = delete; template - T get(const std::string& key) {} + T get(const std::string& key); template 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); } };