1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #ifndef _CONVERT_H_ |
---|
6 | #define _CONVERT_H_ |
---|
7 | |
---|
8 | #include "nonstd.h" |
---|
9 | #include "nonstd_math.h" |
---|
10 | #include "nonstd_stl.h" |
---|
11 | #include <stdint.h> |
---|
12 | #include <cmath> |
---|
13 | |
---|
14 | #ifdef LINUX |
---|
15 | #define UINT64_FORMAT "%llu" //we want to avoid this and ambiguous "long long", but gcc does not seem to support I64u (yet?) |
---|
16 | #else |
---|
17 | #define UINT64_FORMAT "%I64u" |
---|
18 | #endif |
---|
19 | |
---|
20 | struct Convert |
---|
21 | { |
---|
22 | public: |
---|
23 | static int toInt(string s); |
---|
24 | static float toFloat(string s); |
---|
25 | static string toLowerCase(string s); |
---|
26 | static string toUpperCase(string s); |
---|
27 | static char toLowerCase(char c); |
---|
28 | static char toUpperCase(char c); |
---|
29 | template<class T> static string _toString(const T& value); |
---|
30 | static string toString(unsigned int v); |
---|
31 | static string toString(int v); |
---|
32 | static string toString(short v); |
---|
33 | static string toString(float v); |
---|
34 | static string toString(double v); |
---|
35 | static string zeroPad(string s, int l) { while ((int)s.length() < l) s = string("0") + s; return s; } |
---|
36 | static uint32_t hexToInt(const string& col); |
---|
37 | |
---|
38 | static double toRadians(double angle) { return angle * M_PI / 180; } |
---|
39 | static double toDegrees(double angle) { return angle / M_PI * 180; } |
---|
40 | static double atan_2(double y, double x) { if (x == 0 && y == 0) return 0; else return atan2(y, x); } //needed by borland 5/6 only? |
---|
41 | |
---|
42 | static double odleglosc_sq(double x1, double y1, double x2, double y2) //odleglosc do kwadratu, wystarczy do porownywania |
---|
43 | { |
---|
44 | double dx = x2 - x1, dy = y2 - y1; |
---|
45 | return dx * dx + dy * dy; |
---|
46 | } |
---|
47 | |
---|
48 | static double odleglosc(double x1, double y1, double x2, double y2) { return sqrt(odleglosc_sq(x1, y1, x2, y2)); } |
---|
49 | |
---|
50 | //static float odleglosc(int x1,int y1,int x2,int y2) {float dx=x1-x2; float dy=y1-y2; return sqrt(dx*dx+dy*dy);} |
---|
51 | //static float odleglosc(float x1,float y1,float x2,float y2) {return sqrt(odleglosc_sq(x1,y1,x2,y2));} |
---|
52 | //static float odleglosc_sq(float x1,float y1,float x2,float y2) {float dx=x1-x2; float dy=y1-y2; return dx*dx+dy*dy;} |
---|
53 | |
---|
54 | static struct tm localtime(const time_t &timep);//jak ::localtime ale zwraca strukture zamiast wskaznika, ref w parametrze dla wygodnego wywolywania |
---|
55 | static string asctime(const struct tm &tm);//jak ::asctime ale thread safe i bez glupiego \n na koncu, ref w parametrze dla wygodnego wywolywania |
---|
56 | |
---|
57 | static std::wstring strTOwstr(const char *s) |
---|
58 | { |
---|
59 | string str(s); |
---|
60 | return std::wstring(str.begin(), str.end()); |
---|
61 | } |
---|
62 | |
---|
63 | static string wstrTOstr(const wchar_t *s) |
---|
64 | { |
---|
65 | wstring str(s); |
---|
66 | return string(str.begin(), str.end()); |
---|
67 | } |
---|
68 | |
---|
69 | static string wstrToUtf8(const wchar_t *str); |
---|
70 | #ifdef _WIN32 |
---|
71 | static wstring utf8ToUtf16(const char *str); |
---|
72 | #endif |
---|
73 | }; |
---|
74 | |
---|
75 | #endif |
---|