blob: d0aad7a4dfca24f84cbb2b4018806d88f5882c5a (
plain)
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
|
#include "globalFunctions.h"
#include "../ui/resources.h"
inline
int globalFunctions::round(const double d)
{
return static_cast<int>(d<0?d-.5:d+.5);
}
inline
int globalFunctions::abs(const int d)
{
return(d<0?-d:d);
}
inline
unsigned int globalFunctions::abs(const unsigned int d)
{
return(d<0?-d:d);
}
inline
float globalFunctions::abs(const float d)
{
return(d<0?-d:d);
};
inline
double globalFunctions::abs(const double d)
{
return(d<0?-d:d);
}
string globalFunctions::numberToString(const unsigned int number)
{
char result[100];
sprintf( result, "%u", number);
return string(result);
}
string globalFunctions::numberToString(const int number)
{
char result[100];
sprintf( result, "%d", number);
return string(result);
}
string globalFunctions::numberToString(const float number)
{
char result[100];
sprintf( result, "%f", number);
return string(result);
}
wxString globalFunctions::numberToWxString(const unsigned int number)
{
return wxString::Format(wxT("%u"), number);
}
wxString globalFunctions::numberToWxString(const int number)
{
return wxString::Format(wxT("%i"), number);
}
wxString globalFunctions::numberToWxString(const float number)
{
return wxString::Format(wxT("%f"), number);
}
inline
int globalFunctions::stringToInt(const string& number)
{
return atoi(number.c_str());
}
inline
double globalFunctions::stringToDouble(const string& number)
{
return atof(number.c_str());
}
inline
int globalFunctions::wxStringToInt(const wxString& number)
{
long result = 0;
if (number.ToLong(&result))
return result;
else
throw std::runtime_error("Error when converting number to long");
}
inline
double globalFunctions::wxStringToDouble(const wxString& number)
{
double result = 0;
if (number.ToDouble(&result))
return result;
else
throw std::runtime_error("Error when converting number to double");
}
wxString& globalFunctions::includeNumberSeparator(wxString& number)
{
for (int i = number.size() - 3; i > 0; i-= 3)
number.insert(i, GlobalResources::numberSeparator);
return number;
}
|