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 VALUE_TO_STRING_HPP
inst 0:f398994b70f5 2 #define VALUE_TO_STRING_HPP
inst 0:f398994b70f5 3
inst 0:f398994b70f5 4 #include <string>
inst 0:f398994b70f5 5
inst 0:f398994b70f5 6 namespace ConvertData{
inst 0:f398994b70f5 7 template <class T>
inst 0:f398994b70f5 8 std::string ValueToString(T t){
inst 0:f398994b70f5 9
inst 0:f398994b70f5 10 }
inst 0:f398994b70f5 11
inst 0:f398994b70f5 12 template<>
inst 0:f398994b70f5 13 std::string ValueToString(int i){
inst 0:f398994b70f5 14 char ch[16] = {0};
inst 0:f398994b70f5 15 std::string str;
inst 0:f398994b70f5 16 sprintf(ch,"%d",i);
inst 0:f398994b70f5 17 str = ch;
inst 0:f398994b70f5 18 return str;
inst 0:f398994b70f5 19 }
inst 0:f398994b70f5 20
inst 0:f398994b70f5 21
inst 0:f398994b70f5 22 template<>
inst 0:f398994b70f5 23 std::string ValueToString(long l){
inst 0:f398994b70f5 24 char ch[16] = {0};
inst 0:f398994b70f5 25 std::string str;
inst 0:f398994b70f5 26 sprintf(ch,"%ld",l);
inst 0:f398994b70f5 27 str = ch;
inst 0:f398994b70f5 28 return str;
inst 0:f398994b70f5 29 }
inst 0:f398994b70f5 30
inst 0:f398994b70f5 31 template<>
inst 0:f398994b70f5 32 std::string ValueToString(float f){
inst 0:f398994b70f5 33 char ch[16] = {0};
inst 0:f398994b70f5 34 std::string str;
inst 0:f398994b70f5 35 sprintf(ch,"%f",f);
inst 0:f398994b70f5 36 str = ch;
inst 0:f398994b70f5 37 return str;
inst 0:f398994b70f5 38 }
inst 0:f398994b70f5 39
inst 0:f398994b70f5 40 template<>
inst 0:f398994b70f5 41 std::string ValueToString(double d){
inst 0:f398994b70f5 42 char ch[16] = {0};
inst 0:f398994b70f5 43 std::string str;
inst 0:f398994b70f5 44 sprintf(ch,"%lf",d);
inst 0:f398994b70f5 45 str = ch;
inst 0:f398994b70f5 46 return str;
inst 0:f398994b70f5 47 }
inst 0:f398994b70f5 48
inst 0:f398994b70f5 49 template<>
inst 0:f398994b70f5 50 std::string ValueToString(std::string str){
inst 0:f398994b70f5 51 return str;
inst 0:f398994b70f5 52 }
inst 0:f398994b70f5 53 }
inst 0:f398994b70f5 54
inst 0:f398994b70f5 55 #endif //VALUE_TO_STRING_HPP