cbp2make
Makefile generation tool for Code::Blocks IDE
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
lib
stlconvert.h
Go to the documentation of this file.
1
/*
2
cbp2make : Makefile generation tool for the Code::Blocks IDE
3
Copyright (C) 2010-2013 Mirai Computing (mirai.computing@gmail.com)
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
//------------------------------------------------------------------------------
20
#ifndef STL_CONVERT_H
21
#define STL_CONVERT_H
22
//------------------------------------------------------------------------------
23
#include <cstdio>
24
#include <sstream>
25
//------------------------------------------------------------------------------
26
#include "
stlstrings.h
"
27
//------------------------------------------------------------------------------
28
29
inline
double
IntToFloat
(
const
int
Value)
30
{
31
return
(
double
)Value;
32
}
33
34
inline
bool
IntToBool
(
const
int
Value)
35
{
36
return
(0!=Value);
37
}
38
39
inline
std::string
IntToStr
(
const
int
Value)
40
{
41
std::string result;
42
std::stringstream tmp;
43
tmp<<Value;
44
tmp>>result;
45
return
result;
46
}
47
48
inline
char
IntToChar
(
const
int
Value)
49
{
50
return
(Value & 0xff);
51
}
52
53
inline
int
FloatToInt
(
const
double
Value)
54
{
55
return
(
int
)Value;
56
}
57
58
inline
bool
FloatToBool
(
const
double
Value)
59
{
60
return
(0.0!=Value);
61
}
62
63
inline
std::string
FloatToStr
(
const
double
Value)
64
{
65
std::string result;
66
std::stringstream tmp;
67
tmp<<Value;
68
tmp>>result;
69
return
result;
70
}
71
72
inline
char
FloatToChar
(
const
double
Value)
73
{
74
return
IntToChar
(
FloatToInt
(Value));
75
}
76
77
inline
double
BoolToFloat
(
const
bool
Value)
78
{
79
return
(
double
)Value;
80
}
81
82
inline
int
BoolToInt
(
const
bool
Value)
83
{
84
return
(
int
)Value;
85
}
86
87
inline
std::string
BoolToStr
(
const
bool
Value)
88
{
89
if
(Value)
return
"true"
;
else
return
"false"
;
90
}
91
92
inline
char
BoolToChar
(
const
bool
Value)
93
{
94
if
(Value)
return
'1'
;
else
return
'0'
;
95
}
96
97
inline
double
StrToFloat
(
const
std::string& Value)
98
{
99
double
result;
100
std::stringstream tmp;
101
tmp<<Value;
102
tmp>>result;
103
return
result;
104
}
105
106
inline
int
StrToInt
(
const
std::string& Value)
107
{
108
int
result;
109
std::stringstream tmp;
110
tmp<<Value;
111
tmp>>result;
112
return
result;
113
}
114
115
inline
bool
StrToBool
(
const
std::string& Value)
116
{
117
return
(
UpperCase
(Value).GetString().compare(
"TRUE"
)==0);
118
}
119
120
inline
char
StrToChar
(
const
std::string& Value)
121
{
122
char
result = 0;
123
if
(Value.size()) result = Value[0];
124
return
result;
125
}
126
127
inline
double
CharToFloat
(
const
char
Value)
128
{
129
return
(
double
)Value;
130
}
131
132
inline
int
CharToInt
(
const
char
Value)
133
{
134
return
(
int
)Value;
135
}
136
137
inline
bool
CharToBool
(
const
char
Value)
138
{
139
return
(
'0'
!=Value);
140
}
141
142
inline
std::string
CharToStr
(
const
char
Value)
143
{
144
std::string result;
145
result.resize(1);
146
result[0] = Value;
147
return
result;
148
}
149
150
//------------------------------------------------------------------------------
151
152
inline
CString
IntegerToString
(
const
int
Value)
153
{
154
CString
result;
155
result = (int)Value;
156
return
result;
157
}
158
159
inline
CString
Int64ToString
(
const
long
long
int
Value)
160
{
161
CString
result;
162
result = (
long
long
int)Value;
163
return
result;
164
}
165
166
inline
CString
FloatToString
(
const
double
Value)
167
{
168
CString
result;
169
result = Value;
170
return
result;
171
}
172
173
inline
CString
FloatToString
(
const
double
Value,
const
CString
& Format)
174
{
175
CString
result; result.
SetLength
(
MAX_SHORTSTRING_LENGTH
);
176
sprintf(result.
GetCString
(),Format.
GetCString
(),Value);
177
result.
SetLength
();
178
return
result;
179
}
180
181
inline
CString
BooleanToString
(
const
bool
Value)
182
{
183
if
(Value)
return
CString
(
"true"
);
else
return
CString
(
"false"
);
184
}
185
186
inline
CString
BooleanToYesNoString
(
const
bool
Value)
187
{
188
if
(Value)
return
CString
(
"yes"
);
else
return
CString
(
"no"
);
189
}
190
191
inline
double
StringToFloat
(
const
CString
& Value)
192
{
193
return
Value.
GetFloat
();
194
}
195
196
inline
int
StringToInteger
(
const
CString
& Value)
197
{
198
return
Value.
GetInteger
();
199
}
200
201
inline
bool
StringToBoolean
(
const
CString
& Value)
202
{
203
return
((
CString
(Value)==
"1"
)||(
UpperCase
(Value)==
"TRUE"
)||(
UpperCase
(Value)==
"YES"
));
204
}
205
206
inline
char
StringToChar
(
const
CString
& Value)
207
{
208
return
Value.
GetChar
(0);
209
}
210
211
inline
CString
CharToString
(
const
char
Value)
212
{
213
CString
result;
214
result.
Assign
((
int
)Value);
215
return
result;
216
}
217
218
#endif
219
//------------------------------------------------------------------------------
Generated on Sun Jun 9 2013 10:55:50 for cbp2make by
1.8.4