StringToValue.hpp@0:f398994b70f5, 2016-03-31 (annotated)
- Committer:
- inst
- Date:
- Thu Mar 31 04:42:55 2016 +0000
- Revision:
- 0:f398994b70f5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
inst | 0:f398994b70f5 | 1 | #ifndef STRING_TO_VALUE_HPP |
inst | 0:f398994b70f5 | 2 | #define STRING_TO_VALUE_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 | T stringToValue(std::string str) |
inst | 0:f398994b70f5 | 9 | { |
inst | 0:f398994b70f5 | 10 | T result; |
inst | 0:f398994b70f5 | 11 | return result; |
inst | 0:f398994b70f5 | 12 | } |
inst | 0:f398994b70f5 | 13 | template<> |
inst | 0:f398994b70f5 | 14 | std::string stringToValue(std::string str) |
inst | 0:f398994b70f5 | 15 | { |
inst | 0:f398994b70f5 | 16 | return str; |
inst | 0:f398994b70f5 | 17 | } |
inst | 0:f398994b70f5 | 18 | |
inst | 0:f398994b70f5 | 19 | template<> |
inst | 0:f398994b70f5 | 20 | int stringToValue(std::string str) |
inst | 0:f398994b70f5 | 21 | { |
inst | 0:f398994b70f5 | 22 | return atoi(str.c_str()); |
inst | 0:f398994b70f5 | 23 | } |
inst | 0:f398994b70f5 | 24 | long convert(std::string str) |
inst | 0:f398994b70f5 | 25 | { |
inst | 0:f398994b70f5 | 26 | return atol(str.c_str()); |
inst | 0:f398994b70f5 | 27 | } |
inst | 0:f398994b70f5 | 28 | template<> |
inst | 0:f398994b70f5 | 29 | float stringToValue(std::string str) |
inst | 0:f398994b70f5 | 30 | { |
inst | 0:f398994b70f5 | 31 | return atof(str.c_str()); |
inst | 0:f398994b70f5 | 32 | } |
inst | 0:f398994b70f5 | 33 | } |
inst | 0:f398994b70f5 | 34 | |
inst | 0:f398994b70f5 | 35 | #endif //STRING_TO_VALUE_HPP |