From 72c5952a96f5bab01aef02f373a96a2a12f750bb Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 19 Apr 2017 18:28:18 +0200 Subject: Change INI file parser library. Much simpler but also a bit limitated. Could be change easily in futur if needed Change-Id: I06f03f093c9206007e3d0c1e86a35d60111be5f8 Signed-off-by: Romain Forlot --- CAN-binder/low-can-binding/utils/config-parser.cpp | 31 ++++++---------------- CAN-binder/low-can-binding/utils/config-parser.hpp | 5 ++-- 2 files changed, 10 insertions(+), 26 deletions(-) (limited to 'CAN-binder/low-can-binding/utils') diff --git a/CAN-binder/low-can-binding/utils/config-parser.cpp b/CAN-binder/low-can-binding/utils/config-parser.cpp index cb344be..dd500d3 100644 --- a/CAN-binder/low-can-binding/utils/config-parser.cpp +++ b/CAN-binder/low-can-binding/utils/config-parser.cpp @@ -21,25 +21,18 @@ namespace utils { - /// @brief constructor using a POSIX file handle as input. - /// - /// @param conf_file - a POSIX file handle to the INI configuration file - config_parser_t::config_parser_t(int conf_file) - : config_content_(fdopen(conf_file, "r")) - { - ::close(conf_file); - } - /// @brief constructor using path to file config_parser_t::config_parser_t(std::string conf_file) - : config_content_{INIReader(conf_file)} - {} + : config_content_{} + { + config_content_.read_file(conf_file); + } /// @brief read the conf_file_ and parse it into an INIReader object /// to search into later. bool config_parser_t::check_conf() { - if (config_content_.ParseError() < 0) + if (config_content_.size() <= 0) { ERROR(binder_interface, "read_conf: Can't load the INI config file."); return false; @@ -58,18 +51,10 @@ namespace utils { std::vector devices_name; - std::set sections = config_content_.GetSections(); - for(const auto& sectionsIt : sections) + std::map bus_mapping = config_content_.get_keys("CANbus-mapping"); + for(const auto& busIt : bus_mapping ) { - if(sectionsIt == "CANbus-mapping") - { - std::set fields = config_content_.GetFields(sectionsIt); - for(const auto& fieldsIt : fields) - { - std::string val = config_content_.Get(sectionsIt, fieldsIt, "INVALID"); - devices_name.push_back(val); - } - } + devices_name.push_back(busIt.second); } return devices_name; diff --git a/CAN-binder/low-can-binding/utils/config-parser.hpp b/CAN-binder/low-can-binding/utils/config-parser.hpp index 2d50485..a181d9e 100644 --- a/CAN-binder/low-can-binding/utils/config-parser.hpp +++ b/CAN-binder/low-can-binding/utils/config-parser.hpp @@ -24,7 +24,7 @@ #include #include -#include "INIReader.h" +#include "ini-config.hpp" namespace utils { @@ -33,10 +33,9 @@ namespace utils class config_parser_t { private: - INIReader config_content_; /*!< config_content_ - Parsed content of INI file.*/ + ini_config config_content_; /*!< config_content_ - Parsed content of INI file.*/ public: - config_parser_t(int conf_file); config_parser_t(std::string conf_file); bool check_conf(); -- cgit 1.2.3-korg