forked from OTAcademy/RME
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.h
More file actions
122 lines (103 loc) · 3.46 KB
/
common.h
File metadata and controls
122 lines (103 loc) · 3.46 KB
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
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor 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.
//
// Remere's Map Editor 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 RME_COMMONS_H_
#define RME_COMMONS_H_
#include "main.h"
#include "position.h"
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <iomanip>
#include <string>
#include "mt_rand.h"
//
inline bool testFlags(size_t flags, size_t test) {
return (flags & test) != 0;
}
int32_t uniform_random(int32_t minNumber, int32_t maxNumber);
int32_t uniform_random(int32_t maxNumber);
// Function-like convertions between float, int and doubles
std::string i2s(int i);
std::string f2s(double i);
int s2i(std::string s);
double s2f(std::string s);
wxString i2ws(int i);
wxString f2ws(double i);
int ws2i(wxString s);
double ws2f(wxString s);
double frand();
// replaces all instances of sought in str with replacement
void replaceString(std::string& str, const std::string sought, const std::string replacement);
// Removes all characters in t from source (from either start or beginning of the string)
void trim_right(std::string& source, const std::string& t);
void trim_left(std::string& source, const std::string& t);
// Converts the argument to lower/uppercase
void to_lower_str(std::string& source);
void to_upper_str(std::string& source);
std::string as_lower_str(const std::string& other);
std::string as_upper_str(const std::string& other);
// isFalseString returns true if the string is either "0", "false", "no", "not" or blank
// isTrueString returns the opposite value of isFalseString
bool isFalseString(std::string& str);
bool isTrueString(std::string& str);
// Generates a random number between low and high using the mersenne twister
int random(int high);
int random(int low, int high);
// Unicode conversions
std::wstring string2wstring(const std::string& utf8string);
std::string wstring2string(const std::wstring& widestring);
// Gets position values from ClipBoard
bool posFromClipboard(Position& position, const int mapWidth = MAP_MAX_WIDTH, const int mapHeight = MAP_MAX_HEIGHT);
// Returns 'yes' if the defined value is true or 'no' if it is false.
wxString b2yn(bool v);
wxColor colorFromEightBit(int color);
// Standard math functions
template <class T>
inline T abs(T t) {
return (t < 0 ? -t : t);
}
template <class T, class U>
inline T min(T t, U u) {
return (t < u ? t : u);
}
template <class T, class U>
T max(T t, U u) {
return (t > u ? t : u);
}
template <class T, class U, class V>
inline T min(T t, U u, V v) {
int min = t;
if (u < min) {
min = u;
}
if (v < min) {
min = v;
}
return min;
}
template <class T, class U, class V>
inline T max(T t, U u, V v) {
int max = t;
if (u > max) {
max = u;
}
if (v > max) {
max = v;
}
return max;
}
#endif