Game Develop C++ Platform: CommonTools.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
CommonTools.h
Go to the documentation of this file.
1
5 #ifndef STDALGO_H_INCLUDED
6 #define STDALGO_H_INCLUDED
7 #include <string>
8 #include <sstream>
9 #include <vector>
10 #include <cmath>
11 #if defined(GD_IDE_ONLY)
12 class wxString;
13 #endif
14
24 template<typename T>
25 int ToInt( const T & value )
26 {
27 int i;
28 std::istringstream oss(value);
29 oss >> i;
30 return i;
31 }
32
37 template<typename T>
38 float ToFloat( const T & value )
39 {
40 float f;
41 std::istringstream oss(value);
42 oss >> f;
43 return f;
44 }
45
50 template<typename T>
51 double ToDouble( const T & value )
52 {
53 double d;
54 std::istringstream oss(value);
55 oss >> d;
56 return d;
57 }
58
63 template<typename T>
64 std::string ToString( const T & value )
65 {
66 std::ostringstream oss;
67 oss << value;
68 return oss.str();
69 }
70
71 #if defined(GD_IDE_ONLY)
72
76 template<>
77 std::string GD_API ToString( const wxString & value );
78 #endif
79
85 template <typename T>
86 std::vector <T> SplitString( const std::string & str, char separator )
87 {
88 std::istringstream iss( str );
89 std::string token;
90 std::vector <T> array;
91
92 while ( std::getline( iss, token, separator ) )
93 array.push_back( T(token) );
94
95 return array;
96 }
97
109 struct StringEmpty
110 {
111 bool operator ()(const std::string & a) const
112 {
113 return a.empty();
114 }
115 };
116
117 #ifdef __GNUC__
118
122 inline int GDRound(float x)
123 {
124 return round(x);
125 }
126 #else
127
131 inline double GDRound( double d )
132 {
133 return ( d >= 0 ? floor(d+0.5) : ceil(d-0.5) );
134 }
135 #endif
136
137 #endif // STDALGO_H_INCLUDED
138