/* * File: HeterogeneousMap.cc * Author: jgaebler * * Created on February 13, 2014, 9:37 AM */ #include "HeterogeneousMap.h" namespace ubeeme { namespace moversight { /** * @brief Constructor */ HeterogeneousMap::HeterogeneousMap() { } /** * @brief Destructor */ HeterogeneousMap::~HeterogeneousMap() { } /** * @brief Returns the bool element stored under that key. Is no bool element * stored under this key, a new, false one is created, using the * default constructor. * @param key The key identifies the bool element to read. * @return The desired element, or an false instances of the target type, * if no element stored under that key. */ template<> bool HeterogeneousMap::get(const char * key) { if (storage[key].empty()) { bool t = 0; return t; } else { if (storage[key].type() == typeid (bool)) { return boost::any_cast(storage[key]); } else { std::stringstream buf; buf << "bad type, expect type 'bool' for key: " << key; throw ParameterException(buf.str().c_str()); } } } /** * @brief Returns the int element stored under that key. Is no int element * stored under this key, a new, zero one is created, using the * default constructor. * @param key The key identifies the int element to read. * @return The desired element, or a zero instances of the target type, * if no element stored under that key. */ template<> int HeterogeneousMap::get(const char * key) { if (storage[key].empty()) { int t = 0; return t; } else { if (storage[key].type() == typeid (int)) { return boost::any_cast(storage[key]); } else { std::stringstream buf; buf << "bad type, expect type 'int' for key: " << key; throw ParameterException(buf.str().c_str()); } } } /** * @brief Returns the double element stored under that key. Is no double * element stored under this key, a new, zero one is created, using the * default constructor. * @param key The key identifies the double element to read. * @return The desired element, or a zero instances of the target type, * if no element stored under that key. */ template<> double HeterogeneousMap::get(const char * key) { if (storage[key].empty()) { double t = 0; return t; } else { if (storage[key].type() == typeid (double)) { return boost::any_cast(storage[key]); } else { std::stringstream buf; buf << "bad type, expect type 'double' for key: " << key; throw ParameterException(buf.str().c_str()); } } } /** * @brief Returns the float element stored under that key. Is no float element * stored under this key, a new, zero one is created, using the * default constructor. * @param key The key identifies the float element to read. * @return The desired element, or a zero instances of the target type, * if no element stored under that key. */ template<> float HeterogeneousMap::get(const char * key) { if (storage[key].empty()) { float t = 0; return t; } else { if (storage[key].type() == typeid (float)) { return boost::any_cast(storage[key]); } else { std::stringstream buf; buf << "bad type, expect type 'float' for key: " << key; throw ParameterException(buf.str().c_str()); } } } } }