File: stlconvert.h

package info (click to toggle)
cbp2make 147%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,072 kB
  • sloc: cpp: 13,020; makefile: 12; sh: 3
file content (219 lines) | stat: -rw-r--r-- 4,572 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/*
    cbp2make : Makefile generation tool for the Code::Blocks IDE
    Copyright (C) 2010-2013 Mirai Computing (mirai.computing@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

//------------------------------------------------------------------------------
#ifndef STL_CONVERT_H
#define STL_CONVERT_H
//------------------------------------------------------------------------------
#include <cstdio>
#include <sstream>
//------------------------------------------------------------------------------
#include "stlstrings.h"
//------------------------------------------------------------------------------

inline double IntToFloat(const int Value)
{
 return (double)Value;
}

inline bool IntToBool(const int Value)
{
 return (0!=Value);
}

inline std::string IntToStr(const int Value)
{
 std::string result;
 std::stringstream tmp;
 tmp<<Value;
 tmp>>result;
 return result;
}

inline char IntToChar(const int Value)
{
 return (Value & 0xff);
}

inline int FloatToInt(const double Value)
{
 return (int)Value;
}

inline bool FloatToBool(const double Value)
{
 return (0.0!=Value);
}

inline std::string FloatToStr(const double Value)
{
 std::string result;
 std::stringstream tmp;
 tmp<<Value;
 tmp>>result;
 return result;
}

inline char FloatToChar(const double Value)
{
 return IntToChar(FloatToInt(Value));
}

inline double BoolToFloat(const bool Value)
{
 return (double)Value;
}

inline int BoolToInt(const bool Value)
{
 return (int)Value;
}

inline std::string BoolToStr(const bool Value)
{
 if (Value) return "true"; else return "false";
}

inline char BoolToChar(const bool Value)
{
 if (Value) return '1'; else return '0';
}

inline double StrToFloat(const std::string& Value)
{
 double result;
 std::stringstream tmp;
 tmp<<Value;
 tmp>>result;
 return result;
}

inline int StrToInt(const std::string& Value)
{
 int result;
 std::stringstream tmp;
 tmp<<Value;
 tmp>>result;
 return result;
}

inline bool StrToBool(const std::string& Value)
{
 return (UpperCase(Value).GetString().compare("TRUE")==0);
}

inline char StrToChar(const std::string& Value)
{
 char result = 0;
 if (Value.size()) result = Value[0];
 return result;
}

inline double CharToFloat(const char Value)
{
 return (double)Value;
}

inline int CharToInt(const char Value)
{
 return (int)Value;
}

inline bool CharToBool(const char Value)
{
 return ('0'!=Value);
}

inline std::string CharToStr(const char Value)
{
 std::string result;
 result.resize(1);
 result[0] = Value;
 return result;
}

//------------------------------------------------------------------------------

inline CString IntegerToString(const int Value)
{
 CString result;
 result = (int)Value;
 return result;
}

inline CString Int64ToString(const long long int Value)
{
 CString result;
 result = (long long int)Value;
 return result;
}

inline CString FloatToString(const double Value)
{
 CString result;
 result = Value;
 return result;
}

inline CString FloatToString(const double Value, const CString& Format)
{
 CString result; result.SetLength(MAX_SHORTSTRING_LENGTH);
 sprintf(result.GetCString(),Format.GetCString(),Value);
 result.SetLength();
 return result;
}

inline CString BooleanToString(const bool Value)
{
 if (Value) return CString("true"); else return CString("false");
}

inline CString BooleanToYesNoString(const bool Value)
{
 if (Value) return CString("yes"); else return CString("no");
}

inline double StringToFloat(const CString& Value)
{
 return Value.GetFloat();
}

inline int StringToInteger(const CString& Value)
{
 return Value.GetInteger();
}

inline bool StringToBoolean(const CString& Value)
{
 return ((CString(Value)=="1")||(UpperCase(Value)=="TRUE")||(UpperCase(Value)=="YES"));
}

inline char StringToChar(const CString& Value)
{
 return Value.GetChar(0);
}

inline CString CharToString(const char Value)
{
 CString result;
 result.Assign((int)Value);
 return result;
}

#endif
//------------------------------------------------------------------------------