MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
string.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <cstdint>
5 #include <cstdlib>
6 #include <type_traits>
7 #include <exception>
8 
9 // Polyfill needed by Qt when building for Android with GCC
10 #if defined(__ANDROID__) && defined(__GLIBCXX__)
11 
12 namespace std {
13 
14 inline int stoi(const std::string &str)
15 {
16  return atoi(str.c_str());
17 }
18 
19 inline float stof(const std::string &str) {
20  return static_cast<float>(atof(str.c_str()));
21 }
22 
23 } // namespace std
24 
25 #endif
26 
27 namespace mbgl {
28 namespace util {
29 
34 std::string toString(double, bool decimal = false);
35 
36 inline std::string toString(int16_t t) {
37  return toString(static_cast<int32_t>(t));
38 }
39 
40 inline std::string toString(uint16_t t) {
41  return toString(static_cast<uint32_t>(t));
42 }
43 
44 inline std::string toString(int8_t t) {
45  return toString(static_cast<int32_t>(t));
46 }
47 
48 inline std::string toString(uint8_t t) {
49  return toString(static_cast<uint32_t>(t));
50 }
51 
52 template <typename = std::enable_if<!std::is_same_v<uint64_t, unsigned long>>>
53 inline std::string toString(unsigned long t) {
54  return toString(static_cast<uint64_t>(t));
55 }
56 
57 template <typename = std::enable_if<!std::is_same_v<uint64_t, unsigned long long>>>
58 inline std::string toString(unsigned long long t) {
59  return toString(static_cast<uint64_t>(t));
60 }
61 
62 template <typename = std::enable_if<!std::is_same_v<int64_t, long>>>
63 inline std::string toString(long t) {
64  return toString(static_cast<int64_t>(t));
65 }
66 
67 template <typename = std::enable_if<!std::is_same_v<int64_t, long long>>>
68 inline std::string toString(long long t) {
69  return toString(static_cast<int64_t>(t));
70 }
71 
72 inline std::string toString(float t, bool decimal = false) {
73  return toString(static_cast<double>(t), decimal);
74 }
75 
76 inline std::string toString(long double t, bool decimal = false) {
77  return toString(static_cast<double>(t), decimal);
78 }
79 
80 std::string toString(const std::exception_ptr &);
81 
82 template <class T>
83 std::string toString(T) = delete;
84 
85 std::string toHex(uint32_t);
86 std::string toHex(uint64_t);
87 
88 inline float stof(const std::string& str) {
89  return std::stof(str);
90 }
91 
92 } // namespace util
93 } // namespace mbgl
94 
95 // Android's libstdc++ doesn't have std::to_string()
96 #if defined(__ANDROID__) && defined(__GLIBCXX__)
97 
98 namespace std {
99 
100 template <typename T>
101 inline std::string to_string(T value) {
102  return mbgl::util::toString(value);
103 }
104 
105 } // namespace std
106 
107 #endif
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
float stof(const std::string &str)
Definition: string.hpp:88
std::string toHex(uint32_t)
std::string toString(const CanonicalTileID &)
Definition: actor.hpp:15
Definition: tile_id.hpp:256