Game Develop Core: CommonTools.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
CommonTools.h
Go to the documentation of this file.
1
6 #ifndef COMMONTOOLS_H
7 #define COMMONTOOLS_H
8 #include <string>
9 #include <vector>
10 #include <sstream>
11 class wxString;
12
13 namespace gd
14 {
15
20 template<typename T>
21 double ToDouble( const T & value )
22 {
23 double d;
24 std::istringstream oss(value);
25 oss >> d;
26 return d;
27 }
28
37 template<typename T>
38 std::string ToString( const T & value )
39 {
40 std::ostringstream oss;
41 oss << value;
42 return oss.str();
43 }
44
54 template<typename T>
55 int ToInt( const T & value )
56 {
57 int i;
58 std::istringstream oss(value);
59 oss >> i;
60 return i;
61 }
62
67 template<typename T>
68 float ToFloat( const T & value )
69 {
70 float f;
71 std::istringstream oss(value);
72 oss >> f;
73 return f;
74 }
75
80 template<>
81 std::string GD_CORE_API ToString( const wxString & value );
82
88 template <typename T>
89 std::vector <T> SplitString( const std::string & str, char separator )
90 {
91 std::istringstream iss( str );
92 std::string token;
93 std::vector <T> array;
94
95 while ( std::getline( iss, token, separator ) )
96 array.push_back( T(token) );
97
98 return array;
99 }
100
101 }
102
103 #endif // COMMONTOOLS_H