diff --git a/CMakeLists.txt b/CMakeLists.txt index 5021eb52d57509410e3e0f08229045ad963f0073..f9284aade45677b87bcfbcc5a9a366b536b40583 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ SET(HDRS_UTILS include/core/utils/loader.hpp include/core/utils/logging.h include/core/utils/make_unique.h - include/core/utils/params_server.hpp + include/core/utils/params_server.h include/core/utils/singleton.h include/core/utils/utils_gtest.h include/core/utils/converter_utils.h @@ -321,6 +321,7 @@ SET(SRCS_MATH ) SET(SRCS_UTILS src/utils/converter_utils.cpp + src/utils/params_server.cpp ) SET(SRCS_CAPTURE diff --git a/hello_wolf/sensor_range_bearing.h b/hello_wolf/sensor_range_bearing.h index e62bfc1a5cd4ff7115cac06f9738204c71017f2b..491efff4f533edc993051482de7d0e84562a790a 100644 --- a/hello_wolf/sensor_range_bearing.h +++ b/hello_wolf/sensor_range_bearing.h @@ -9,7 +9,7 @@ #define HELLO_WOLF_SENSOR_RANGE_BEARING_H_ #include "core/sensor/sensor_base.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { diff --git a/include/core/ceres_wrapper/ceres_manager.h b/include/core/ceres_wrapper/ceres_manager.h index f124325950a06f74642cff38b6d0c053958cab8e..5115c2a1bab9a3430494842147bbc5b0a802e025 100644 --- a/include/core/ceres_wrapper/ceres_manager.h +++ b/include/core/ceres_wrapper/ceres_manager.h @@ -8,7 +8,7 @@ //wolf includes #include "core/solver/solver_manager.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" #include "core/ceres_wrapper/cost_function_wrapper.h" #include "core/ceres_wrapper/local_parametrization_wrapper.h" #include "core/ceres_wrapper/create_numeric_diff_cost_function.h" diff --git a/include/core/common/params_base.h b/include/core/common/params_base.h index 5295bc0ac17f941503a8f28e462962290a9ee82b..80f6516415e28ddce47ab272415604014ffb0a66 100644 --- a/include/core/common/params_base.h +++ b/include/core/common/params_base.h @@ -1,7 +1,7 @@ #ifndef PARAMS_BASE_H_ #define PARAMS_BASE_H_ -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { struct ParamsBase diff --git a/include/core/problem/problem.h b/include/core/problem/problem.h index e1c48e685010cea4ba3311a7b9aa3fc24eef70ed..65f3b604de57df0d48c6e562191bb49f0960261d 100644 --- a/include/core/problem/problem.h +++ b/include/core/problem/problem.h @@ -18,7 +18,7 @@ struct ProcessorParamsBase; #include "core/common/wolf.h" #include "core/frame/frame_base.h" #include "core/state_block/state_block.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" #include "core/sensor/sensor_factory.h" #include "core/processor/processor_factory.h" #include "core/processor/is_motion.h" diff --git a/include/core/processor/processor_motion.h b/include/core/processor/processor_motion.h index 2ac6c8d5949ad07c1529fd06739c0ce80211f243..2b8d4b7b86acc974d01b5864f2093a6d8e871a56 100644 --- a/include/core/processor/processor_motion.h +++ b/include/core/processor/processor_motion.h @@ -13,7 +13,7 @@ #include "core/processor/processor_base.h" #include "core/processor/is_motion.h" #include "core/common/time_stamp.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" // std #include <iomanip> diff --git a/include/core/processor/processor_odom_2d.h b/include/core/processor/processor_odom_2d.h index 6d46ab61a32c1b9573f386c97f1ae671086478c6..b03416837ec1b0a6a86a67ff0cf40fdf820b1370 100644 --- a/include/core/processor/processor_odom_2d.h +++ b/include/core/processor/processor_odom_2d.h @@ -12,7 +12,7 @@ #include "core/capture/capture_odom_2d.h" #include "core/factor/factor_odom_2d.h" #include "core/math/rotations.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { diff --git a/include/core/sensor/sensor_factory.h b/include/core/sensor/sensor_factory.h index 3930176443a22cebb8c9591253af7f58b0a40a2c..daf01499ac759d799517cdd73ab830fb6ccaf4d5 100644 --- a/include/core/sensor/sensor_factory.h +++ b/include/core/sensor/sensor_factory.h @@ -16,7 +16,7 @@ struct ParamsSensorBase; // wolf #include "core/common/factory.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { diff --git a/include/core/sensor/sensor_odom_2d.h b/include/core/sensor/sensor_odom_2d.h index d6a431d3102b0a82a218ee71247552066c1ef8eb..45499f5c56fb342ed8a82b8521e6c2e156d06031 100644 --- a/include/core/sensor/sensor_odom_2d.h +++ b/include/core/sensor/sensor_odom_2d.h @@ -3,7 +3,7 @@ //wolf includes #include "core/sensor/sensor_base.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { diff --git a/include/core/sensor/sensor_odom_3d.h b/include/core/sensor/sensor_odom_3d.h index 67efe1e9af27f8456401c400766dcbf32f44057b..3d08375b4fc30e43f07f201a5653d5e83a258381 100644 --- a/include/core/sensor/sensor_odom_3d.h +++ b/include/core/sensor/sensor_odom_3d.h @@ -10,7 +10,7 @@ //wolf includes #include "core/sensor/sensor_base.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" namespace wolf { diff --git a/include/core/utils/params_server.h b/include/core/utils/params_server.h new file mode 100644 index 0000000000000000000000000000000000000000..e8b473ca26703f17ea932cca4d1e913717108026 --- /dev/null +++ b/include/core/utils/params_server.h @@ -0,0 +1,55 @@ +#ifndef PARAMS_SERVER_H +#define PARAMS_SERVER_H + +#include "core/utils/converter.h" + +#include <map> +#include <exception> + +namespace wolf{ + +class MissingValueException : public std::runtime_error +{ +public: + MissingValueException(std::string _msg) : std::runtime_error(_msg) {} +}; + +class ParamsServer{ + std::map<std::string, std::string> params_; +public: + ParamsServer(); + ParamsServer(std::map<std::string, std::string> _params); + ~ParamsServer(){ + // + } + + void print(); + + + void addParam(std::string _key, std::string _value); + + void addParams(std::map<std::string, std::string> _params); + + // template<typename T> + // T getParam(std::string key, std::string def_value) const { + // if(params_.find(key) != params_.end()){ + // return converter<T>::convert(params_.find(key)->second); + // }else{ + // return converter<T>::convert(def_value); + // } + // } + + template<typename T> + T getParam(std::string _key) const { + if(params_.find(_key) != params_.end()){ + return converter<T>::convert(params_.find(_key)->second); + }else{ + throw MissingValueException("The following key: '" + _key + "' has not been found in the parameters server."); + } + } + +}; + +} + +#endif diff --git a/include/core/utils/params_server.hpp b/include/core/utils/params_server.hpp deleted file mode 100644 index a750eab79f4ee90b39e4e21d1926129897c29d92..0000000000000000000000000000000000000000 --- a/include/core/utils/params_server.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef PARAMS_SERVER_HPP -#define PARAMS_SERVER_HPP - -#include "core/utils/converter.h" -//#include "core/yaml/parser_yaml.hpp" - -#include <vector> -#include <regex> -#include <map> -#include <exception> - -namespace wolf{ - -class MissingValueException : public std::runtime_error -{ -public: - MissingValueException(std::string msg) : std::runtime_error(msg) {} -}; - -class ParamsServer{ - std::map<std::string, std::string> _params; -public: - ParamsServer(){ - _params = std::map<std::string, std::string>(); - } - ParamsServer(std::map<std::string, std::string> params){ - _params = params; - } - ~ParamsServer(){ - // - } - - void print(){ - for(auto it : _params) - std::cout << it.first << "~~" << it.second << std::endl; - } - - - void addParam(std::string key, std::string value){ - _params.insert(std::pair<std::string, std::string>(key, value)); - } - - void addParams(std::map<std::string, std::string> params) - { - _params.insert(params.begin(), params.end()); - } - - // template<typename T> - // T getParam(std::string key, std::string def_value) const { - // if(_params.find(key) != _params.end()){ - // return converter<T>::convert(_params.find(key)->second); - // }else{ - // return converter<T>::convert(def_value); - // } - // } - - template<typename T> - T getParam(std::string key) const { - if(_params.find(key) != _params.end()){ - return converter<T>::convert(_params.find(key)->second); - }else{ - throw MissingValueException("The following key: '" + key + "' has not been found in the parameters server."); - } - } - -}; - -} - -#endif diff --git a/src/problem/problem.cpp b/src/problem/problem.cpp index b35ae1a865bd9c8c90a2e8b08f4330685251b5b5..eb2cb35db83742c81cd08dc197cd9addfa614a56 100644 --- a/src/problem/problem.cpp +++ b/src/problem/problem.cpp @@ -12,7 +12,7 @@ #include "core/processor/processor_factory.h" #include "core/state_block/state_block.h" #include "core/utils/logging.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" #include "core/utils/loader.hpp" #include "core/utils/check_log.hpp" diff --git a/src/utils/params_server.cpp b/src/utils/params_server.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6344466792706c9e499695721f95e781089ec07e --- /dev/null +++ b/src/utils/params_server.cpp @@ -0,0 +1,28 @@ +#include "core/utils/params_server.h" + +using namespace wolf; + +ParamsServer::ParamsServer() +{ + params_ = std::map<std::string, std::string>(); +} +ParamsServer::ParamsServer(std::map<std::string, std::string> _params) +{ + params_ = _params; +} + +void ParamsServer::print() +{ + for (auto it : params_) + std::cout << it.first << "~~" << it.second << std::endl; +} + +void ParamsServer::addParam(std::string _key, std::string _value) +{ + params_.insert(std::pair<std::string, std::string>(_key, _value)); +} + +void ParamsServer::addParams(std::map<std::string, std::string> _params) +{ + params_.insert(_params.begin(), _params.end()); +} diff --git a/test/gtest_param_server.cpp b/test/gtest_param_server.cpp index d816edd6e6c1e348e6408b3f522686b1e737dc87..1f1f468360e1aa5073606f8ea32e7d82cafbc438 100644 --- a/test/gtest_param_server.cpp +++ b/test/gtest_param_server.cpp @@ -2,7 +2,7 @@ #include "core/utils/converter.h" #include "core/common/wolf.h" #include "core/yaml/parser_yaml.h" -#include "core/utils/params_server.hpp" +#include "core/utils/params_server.h" using namespace std; using namespace wolf;