iotivity 0.9.0
[platform/upstream/iotivity.git] / build_common / android / compatibility / android_cpp11_compat.cpp
1 #include <sstream>
2 #include "android_cpp11_compat.h"
3
4 namespace OC {
5     template <typename T>
6     void from_string(const std::string& s, T& result) {
7         std::stringstream ss(s);
8         ss >> result;    // TODO handle errors
9     }
10 }
11
12 namespace std {
13
14     int stoi(const string& s)
15     {
16         int ret;
17         int &ref = ret;
18         OC::from_string(s, ref);
19         return ret;
20     }
21
22     double stod(const std::string& s)
23     {
24         double ret;
25         double &ref = ret;
26         OC::from_string(s, ref);
27         return ret;
28     }
29
30     long long stoll(const std::string& s)
31     {
32         long long ret;
33         long long int &ref = ret;
34         OC::from_string(s, ref);
35         return ret;
36     }
37
38     unsigned long long stoull(const std::string& s)
39     {
40         unsigned long long ret;
41         unsigned long long  &ref = ret;
42         OC::from_string(s, ref);
43         return ret;
44     }
45
46     long double stold(const string& s)
47     {
48         long double ret;
49         long double &ref = ret;
50         OC::from_string(s, ref);
51         return ret;
52     }
53
54     std::string to_string(int t) {
55         std::ostringstream os;
56             os << t;
57         return os.str();
58     }
59
60     std::string to_string(double t) {
61         std::ostringstream os;
62             os << t;
63         return os.str();
64     }
65
66     std::string to_string(uint32_t t)
67     {
68         std::ostringstream os;
69             os << t;
70         return os.str();
71     }
72
73 } // std