Commit a1ebbce1 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

- In ElementaryUtils : refactoring.
parent 206aadd7
......@@ -85,6 +85,8 @@ public:
*/
std::string toString() const;
GenericType & operator=(const GenericType & rhs);
private:
std::stringstream m_stream; ///< stream to store serialized simple type
......
......@@ -33,12 +33,16 @@ public:
bool isAvailable(const std::string &parameterName) const;
const GenericType& get(const std::string &key) const;
const GenericType& getLastAvailable() const; /// Care ! Use it after isAvailable to ensure that the iterator is in the map range.
const GenericType& getLastAvailable() const; /// Care ! Use it after isAvailable() to ensure that the iterator is in the map range.
size_t size() const;
void clear();
GenericType operator()(const std::string &key) const;
virtual std::string toString() const;
private:
// <key, value>
std::map<std::string, GenericType> m_parameters;
......
......@@ -115,4 +115,12 @@ size_t GenericType::toSize_t() const {
return sizeT;
}
GenericType& ElemUtils::GenericType::operator =(const GenericType& rhs) {
// clear current stream then copy it from other object
m_stream.clear();
m_stream << rhs.m_stream.str();
return *this;
}
} // namespace ElemUtils
......@@ -26,7 +26,6 @@ void Parameters::add(const std::string& key, const GenericType& value) {
void Parameters::add(const Parameters& parameters) {
for (size_t i = 0; i != parameters.size(); i++) {
//TODO add key/value
}
......@@ -42,7 +41,8 @@ const GenericType& Parameters::get(const std::string& key) const {
return getLastAvailable();
} else {
throw std::runtime_error(
Formatter() << "(Parameters::get) Missing parameter name = "
Formatter()
<< "(Parameters::modify) Cannot found parameter name = "
<< key);
}
}
......@@ -60,4 +60,31 @@ void Parameters::clear() {
m_parameters.clear();
}
GenericType ElemUtils::Parameters::operator ()(const std::string& key) const {
std::map<std::string, GenericType>::const_iterator it;
it = m_parameters.find(key);
if (it == m_parameters.end()) {
throw std::runtime_error(
Formatter()
<< "(Parameters::modify) Cannot found parameter name = "
<< key);
}
return (it->second);
}
std::string ElemUtils::Parameters::toString() const {
Formatter formatter;
std::map<std::string, GenericType>::const_iterator it;
for (it = m_parameters.begin(); it != m_parameters.end(); it++) {
formatter << (it->first) << " = " << (it->second).toString() << '\n';
}
return formatter.str();
}
} // namespace ElemUtils
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment