63#pragma clang diagnostic push
64#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
65#pragma clang diagnostic ignored "-Wc++98-compat"
66#pragma clang diagnostic ignored "-Wc++11-long-long"
67#pragma clang diagnostic ignored "-Wunused-macros"
68#pragma clang diagnostic ignored "-Wreserved-id-macro"
69#pragma clang diagnostic ignored "-Wdeprecated"
70#pragma clang diagnostic ignored "-Wold-style-cast"
73#define _POSIX_SOURCE 200112L
79#ifndef _DARWIN_C_SOURCE
80#define _DARWIN_C_SOURCE 200112L
81#ifndef __DARWIN_C_LEVEL
82#define __DARWIN_C_LEVEL 200112L
92#define DPRINTF(x) printf x
103#define protected_msleep(ms) protected_usleep(1000LL*(ms))
104#define protected_sleep(s) protected_usleep(1000000LL*(s))
107#define __block _xblock
119#define __block __attribute__((__blocks__(byref)))
133# if __cplusplus >= 201103L
134# define NULLPTR nullptr
141# if __cplusplus >= 201103L
142# define OVERRIDE override
149# if __cplusplus >= 201103L
150# define NOEXCEPT noexcept
156#define atoi16(s) static_cast<int16_t>(atoi(s))
157#define atou16(s) static_cast<uint16_t>(atoi(s))
158#define atoi32(s) static_cast<int32_t>(atoi(s))
159#define atou32(s) static_cast<uint32_t>(atoi(s))
160#define atoi64(s) static_cast<int64_t>(atoll(s))
161#define atou64(s) static_cast<uint64_t>(atoll(s))
169#define DOXY_SGC(n, s)
170#define DOXY_ARRAY_G(n)
171#define DOXY_ARRAY_GC(n)
172#define DOXY_VERSION_NEW(n)
178#define PROPERTY_DECLARATION(t, n) protected: t _##n;
179#define PROPERTY_GETTER(t, n) public: DOXY_G(n) t &n () { return _##n ; } DOXY_GC(n) const t &n () const { return _##n ; }
180#define PROPERTY_SETTER(t, n) public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; }
181#define PROPERTY(type, name) PROPERTY_DECLARATION(type,name) PROPERTY_GETTER(type,name) PROPERTY_SETTER(type,name)
183#define BIT_DECLARATION(n) protected: unsigned int _##n : 1;
184#define BIT_GETTER(n) public: DOXY_G(n) unsigned int n () DOXY_GC(n) const { return _##n ; }
185#define BIT_SETTER(n) public: DOXY_S(n) void set_##n (const unsigned int n = true) { _##n = n ; }
186#define BIT_PROPERTY(name) BIT_DECLARATION(name) BIT_GETTER(name) BIT_SETTER(name)
188#define ARRAY_PROPERTY_DECLARATION(t, n, s) protected: t _##n[s];
189#define ARRAY_PROPERTY_GETTER(t, n, s) public: DOXY_ARRAY_G(n) t &n (int e) { return _##n[e] ; } DOXY_ARRAY_GC(n) const t &n (int e) const { return _##n[e] ; } const t* n() const { return _##n; } size_t n##_size() { return s; }
190#define ARRAY_PROPERTY_SETTER(t, n) public: DOXY_S(n) void set_##n (const t &v, int e ) { _##n[e] = v ; }
191#define ARRAY_PROPERTY(type, name, size) ARRAY_PROPERTY_DECLARATION(type,name,size) ARRAY_PROPERTY_GETTER(type,name,size) ARRAY_PROPERTY_SETTER(type,name)
193#define STRING_PROPERTY_DECLARATION(n, s) protected: char _##n[s];
194#define STRING_PROPERTY_GETTER(n, s) public: DOXY_SG(n,s) char* n () { return &(_##n[0]); } DOXY_SGC(n,s) const char* n () const { return &(_##n[0]); }
195#define STRING_PROPERTY_SETTER(n, s) public: DOXY_SS(n,s) void set_##n (const char* n ) { gu_strlcpy(_##n,n,(s)); }
196#define STRING_PROPERTY(name, size) STRING_PROPERTY_DECLARATION(name, size) STRING_PROPERTY_GETTER(name, size) STRING_PROPERTY_SETTER(name, size)
199#define BIT_ARRAY_PROPERTY_DECLARATION(n, s) protected: uint8_t _##n[((s-1)/8)+1];
200#define BIT_ARRAY_PROPERTY_GETTER(n) public: DOXY_BAPG(n) uint8_t n (int b) { return ( (_##n[( b/8) ] & (1 << (b%8) ) ) >> (b%8)); } DOXY_BAPGC(n) const uint8_t n (int b) const { return ( (_##n[(b/8)] & (1 << (b%8))) >>(b%8) ); }
201#define BIT_ARRAY_PROPERTY_SETTER(n) public: DOXY_BAPS(n) void set_##n (int b, const unsigned int v = true ) { ( (v)&1 ? _##n[(b/8)] |= (1 << (b%8)) : _##n[(b/8)] &= ~(1 << (b%8)) ); }
202#define BIT_ARRAY_PROPERTY(name, size) BIT_ARRAY_PROPERTY_DECLARATION(name, size) BIT_ARRAY_PROPERTY_GETTER(name) BIT_ARRAY_PROPERTY_SETTER(name)
204#define CONTROLLED_SETTER(t, n) public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; _##n##_mask = 1;}
205#define CONTROLLED_PROPERTY(type, name) PROPERTY_DECLARATION(type, name) PROPERTY_GETTER(type, name) CONTROLLED_SETTER(type, name)
207#define CONTROLLED_ARRAY_PROPERTY_SETTER(t, n, s) public: DOXY_S(n) void set_##n(const t* n, size_t size) { _##n##_mask = 1; if(size <= s) memcpy(_##n, n, size); else { memcpy(_##n, n, size); printf("WARNING: wb msg array property setter out of bounds");}}
208#define CONTROLLED_ARRAY_PROPERTY(type, name, size) ARRAY_PROPERTY_DECLARATION(type, name, size) ARRAY_PROPERTY_GETTER(type, name,size) CONTROLLED_ARRAY_PROPERTY_SETTER(type, name, size)
210#define CONTROL_BIT(name) DOXY_MASK(n) BIT_DECLARATION(name##_mask) BIT_GETTER(name##_mask) BIT_SETTER(name##_mask)
212#define VERSION_DECLARATION(n) private: int _##n##_version; static int* get_##n##_classVersion() { static int _##n##_classVersion = 0; return &_##n##_classVersion;}
213#define VERSION_PROPERTY_SETTER(t, n) public: DOXY_S(n) void set_##n (const t &n ) { _##n = n; (*get_##n##_classVersion())+=1; _##n##_version = *get_##n##_classVersion();} private: void reset_##n##_version() {(*get_##n##_classVersion())=0;}
214#define VERSION_PROPERTY_GETTER(t, n) public: DOXY_G(n) t &n () {(*get_##n##_classVersion()) = _##n##_version; return _##n ; }
215#define VERSION_PROPERTY_CHECK(n) public: DOXY_VERSION_NEW(n) bool new_##n () {if(_##n##_version > (*get_##n##_classVersion())) return true; return false;}
216#define VERSION_PROPERTY_INITIALIZATION(n) _##n##_version = 0;
217#define VERSIONED_PROPERTY(type, name) PROPERTY_DECLARATION(type,name) VERSION_DECLARATION(name) VERSION_PROPERTY_SETTER(type,name) VERSION_PROPERTY_GETTER(type,name) VERSION_PROPERTY_CHECK(name)
219#define SET_CONTROL_VAL(o,a,v) do { (o).set_##a(v); (o)set_##a##_mask(true); } while (0)
221#define CHECK_ENUM(s,p,v) if (strstr((s), #v)) set_##p(v)
222#define STREAM_ENUM_CASE(s,v) case v: s << #v; break
225#define DEG_OVER_RAD (180.0f / static_cast<float>(M_PI))
226#define RAD_OVER_DEG (static_cast<float>(M_PI) / 180.0f)
227#define DEG_OVER_RAD_10 (DEG_OVER_RAD * 10.0f)
228#define RAD_OVER_DEG_10 (RAD_OVER_DEG / 10.0f)
230#define RAD2DEG(x) ((x) * DEG_OVER_RAD)
231#define DEG2RAD(x) ((x) * RAD_OVER_DEG)
243 #define M_PI 3.14159265358979323846
246#define DEG_OVER_RAD (180.0f / (float)M_PI)
247#define RAD_OVER_DEG ((float)M_PI / 180.0f)
249#define RAD2DEG(x) ((x) * DEG_OVER_RAD)
250#define DEG2RAD(x) ((x) * RAD_OVER_DEG)
255#define PROPERTY_DECLARATION(t, n) t n;
256#define PROPERTY_GETTER(t, n)
257#define PROPERTY_SETTER(t, n)
258#define PROPERTY(type, name) PROPERTY_DECLARATION(type,name)
259#define CONTROLLED_PROPERTY(type, name) PROPERTY_DECLARATION(type, name)
261#define ARRAY_PROPERTY_DECLARATION(t, n, s) t n[s];
262#define ARRAY_PROPERTY_GETTER(t, n)
263#define ARRAY_PROPERTY_SETTER(t, n)
264#define ARRAY_PROPERTY(type, name, size) ARRAY_PROPERTY_DECLARATION(type,name,size)
265#define CONTROLLED_ARRAY_PROPERTY(type, name, size) ARRAY_PROPERTY_DECLARATION(type, name, size)
267#define STRING_PROPERTY_DECLARATION(n, s) char n[s];
268#define STRING_PROPERTY_GETTER(n, s)
269#define STRING_PROPERTY_SETTER(n, s)
270#define STRING_PROPERTY(name, size) STRING_PROPERTY_DECLARATION(name, size)
272#define VERSION_DECLARATION(n) int n##_version = 0; static int* get_##n##_classVersion() { static int n##_classVersion = 0; return &##n##_classVersion;}
273#define VERSION_PROPERTY_SETTER(t, n)
274#define VERSION_PROPERTY_GETTER(t, n)
275#define VERSION_PROPERTY_CHECK(n)
276#define VERSIONED_PROPERTY(type, name) PROPERTY_DECLARATION(type,name) VERSION_DECLARATION(name) VERSION_PROPERTY_SETTER(type,name) VERSION_PROPERTY_GETTER(type,name) VERSION_PROPERTY_CHECK(name)
277#define VERSION_PROPERTY_INITIALIZATION(n) n##_version = 0;
279#define BIT_DECLARATION(n) unsigned n : 1;
282#define BIT_PROPERTY(name) BIT_DECLARATION(name) BIT_GETTER(name) BIT_SETTER(name)
283#define CONTROL_BIT(name) BIT_DECLARATION(name##_mask)
287#include <sys/param.h>
289#if defined(BSD) && (BSD >= 199506)
290#define gu_strlcpy(d,s,n) strlcpy((d),(s),(n))
291#define gu_strlcat(d,s,n) strlcat((d),(s),(n))
293size_t gu_strlcpy(
char *dst,
const char *src,
size_t size);
294size_t gu_strlcat(
char *dst,
const char *src,
size_t size);
397std::string &
gu_trim(std::string &s);
409std::string
gu_ultos(
unsigned long val);
415std::string
gu_dtos(
double val);
449#pragma clang diagnostic pop
std::string gu_ltos(long val)
Convert a long value to a string.
char * gu_strdup(const char *str)
Duplicate a string.
std::string gu_ultos(unsigned long val)
Convert an unsigned long value to a string.
std::string string_by_concatenating_path_components(const std::string &head, const std::string &tail)
Concatenate two path components into a new string.
long long get_utime(void)
Get the current time of day in microseconds.
int int_from_file(const char *fileName)
Load the contents of a given file into an int.
double double_from_file(const char *fileName)
Load the contents of a given file into a double.
std::string & gu_trim(std::string &s)
Trim whitespace characters from both ends of a string.
int dec(void *num)
Decrement a number Used to decrement a enum value without warnings.
std::string string_from_file(const char *fileName)
Load the contents of a given file into a string.
char * new_string_from_file(const char *fileName)
Load the contents of a given file into a string.
std::map< std::string, std::string > read_configuration(const std::string &filename)
Read simple key = value pairs into a c++ map.
size_t gu_strlcat(char *dst, const char *src, size_t size)
char * gu_strtrim(const char *s)
Return a trimmed copy of the current string by removing all leading and trailing whitespace character...
char * concatenate_path(const char *head, const char *tail)
Create a new string by concatenating two path components.
bool file_exists(const char *fileName)
Return whether a file exists.
std::vector< std::string > components_of_string_separated(const std::string &str, char sep='\n', bool trim=false)
Split a string based on the token.
int mipal_err_file(const char *filename)
Set the log file for the current module.
const char * gu_getprogname(void)
get the basename of the current program
int getplayernumber(void)
get player number
std::string gu_dtos(double val)
Convert a double value to a string.
void protected_usleep(long long us)
Protected usleep() – guaranteed to sleep for the given time! param us number of microseconds to sleep...
void mipal_warn(const char *fmt,...)
Print a warning to the file mipal_err_file() has been set for (or stderr if none has been set)
size_t gu_strlcpy(char *dst, const char *src, size_t size)
int inc(void *num)
Increment a number Used to increment an enum value without warnings.