Dependents:   communication

Committer:
inst
Date:
Thu Mar 31 04:42:55 2016 +0000
Revision:
0:f398994b70f5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:f398994b70f5 1 #ifndef SIMPLE_MAP_DESERIALIZER_HPP
inst 0:f398994b70f5 2 #define SIMPLE_MAP_DESERIALIZER_HPP
inst 0:f398994b70f5 3
inst 0:f398994b70f5 4 #include <string>
inst 0:f398994b70f5 5 #include <map>
inst 0:f398994b70f5 6 #include <deque>
inst 0:f398994b70f5 7 #include "StringToValue.hpp"
inst 0:f398994b70f5 8
inst 0:f398994b70f5 9 namespace SimpleMapSerialization{
inst 0:f398994b70f5 10 template <class T,class U>
inst 0:f398994b70f5 11 void simpleMapDeSerializer(const std::string &str, char delim,std::map<T,U>& result){
inst 0:f398994b70f5 12 std::deque<std::string> res;
inst 0:f398994b70f5 13 size_t current = 0, found;
inst 0:f398994b70f5 14 while((found = str.find_first_of(delim, current)) != std::string::npos){
inst 0:f398994b70f5 15 res.push_back(std::string(str, current, found - current));
inst 0:f398994b70f5 16 current = found + 1;
inst 0:f398994b70f5 17 }
inst 0:f398994b70f5 18 res.push_back(std::string(str, current, str.size() - current));
inst 0:f398994b70f5 19 for (std::deque<std::string>::iterator it = res.begin(); it != res.end(); it+=2){
inst 0:f398994b70f5 20 T key = ConvertData::stringToValue<T>(*it);
inst 0:f398994b70f5 21 U value = ConvertData::stringToValue<U>(*(it+1));
inst 0:f398994b70f5 22 result[key] = value;
inst 0:f398994b70f5 23 }
inst 0:f398994b70f5 24 }
inst 0:f398994b70f5 25 }
inst 0:f398994b70f5 26
inst 0:f398994b70f5 27 #endif //SIMPLE_MAP_DESERIALIZER_HPP