gu_util
Macros | Functions
gu_util.h File Reference
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <sys/param.h>
Include dependency graph for gu_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _POSIX_SOURCE   200112L
 
#define _XOPEN_SOURCE
 
#define DBG(x)
 
#define DPRINTF(x)
 
#define protected_msleep(ms)   protected_usleep(1000LL*(ms))
 
#define protected_sleep(s)   protected_usleep(1000000LL*(s))
 
#define __block   _xblock
 
#define __block   __attribute__((__blocks__(byref)))
 
#define NULLPTR   nullptr
 
#define OVERRIDE   override
 
#define NOEXCEPT   noexcept
 
#define atoi16(s)   static_cast<int16_t>(atoi(s))
 
#define atou16(s)   static_cast<uint16_t>(atoi(s))
 
#define atoi32(s)   static_cast<int32_t>(atoi(s))
 
#define atou32(s)   static_cast<uint32_t>(atoi(s))
 
#define atoi64(s)   static_cast<int64_t>(atoll(s))
 
#define atou64(s)   static_cast<uint64_t>(atoll(s))
 
#define DOXY_MASK(n)   /** Control bit (mask) for _ ##n (Used Internally) */
 
#define DOXY_S(n)   /** property setter for _ ##n (see Protected Attributes below) */
 
#define DOXY_SS(n, s)   /** property setter for _ ##n[s] (see Protected Attributes below) */
 
#define DOXY_G(n)   /** property getter for _ ##n (see Protected Attributes below) @return _ ##n value */
 
#define DOXY_SG(n, s)   /** property getter for _ ##n[s] (see Protected Attributes below) @return _ ##n[s] value */
 
#define DOXY_GC(n)   /** property getter for a constant referance to _ ##n (see Protected Attributes below) @return _ ##n value */
 
#define DOXY_SGC(n, s)   /** property getter for a constant referance to _ ##n[s] (see Protected Attributes below) @return _ ##n[s] value */
 
#define DOXY_ARRAY_G(n)   /** property getter for an element of the array _ ##n (see Protected Attributes below) @param e element index @return _ ##n value */
 
#define DOXY_ARRAY_GC(n)   /** property getter for a constant referance to an element of the array _ ##n (see Protected Attributes below) @param e element index @return _ ##n value */
 
#define DOXY_VERSION_NEW(n)   /** Checks if ##n##'s version number in the current message is greater then the local version number @return true if the version number is greater, false otherwise*/
 
#define DOXY_BAPG(n)   /** property getter for an element of the bit array _ ##n (see Protected Attributes below) @param b element index @return _ ##n value */
 
#define DOXY_BAPGC(n)   /** property getter for a constant referance to an element of the bit array _ ##n (see Protected Attributes below) @param b element index @return _ ##n value */
 
#define DOXY_BAPS(n)   /** property setter for an element of bit array _ ##n (see Protected Attributes below) @param b element index @param v element's value */
 
#define PROPERTY_DECLARATION(t, n)   protected: t _##n;
 
#define PROPERTY_GETTER(t, n)   public: DOXY_G(n) t &n () { return _##n ; } DOXY_GC(n) const t &n () const { return _##n ; }
 
#define PROPERTY_SETTER(t, n)   public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; }
 
#define PROPERTY(type, name)   PROPERTY_DECLARATION(type,name) PROPERTY_GETTER(type,name) PROPERTY_SETTER(type,name)
 
#define BIT_DECLARATION(n)   protected: unsigned int _##n : 1;
 
#define BIT_GETTER(n)   public: DOXY_G(n) unsigned int n () DOXY_GC(n) const { return _##n ; }
 
#define BIT_SETTER(n)   public: DOXY_S(n) void set_##n (const unsigned int n = true) { _##n = n ; }
 
#define BIT_PROPERTY(name)   BIT_DECLARATION(name) BIT_GETTER(name) BIT_SETTER(name)
 
#define ARRAY_PROPERTY_DECLARATION(t, n, s)   protected: t _##n[s];
 
#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; }
 
#define ARRAY_PROPERTY_SETTER(t, n)   public: DOXY_S(n) void set_##n (const t &v, int e ) { _##n[e] = v ; }
 
#define ARRAY_PROPERTY(type, name, size)   ARRAY_PROPERTY_DECLARATION(type,name,size) ARRAY_PROPERTY_GETTER(type,name,size) ARRAY_PROPERTY_SETTER(type,name)
 
#define STRING_PROPERTY_DECLARATION(n, s)   protected: char _##n[s];
 
#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]); }
 
#define STRING_PROPERTY_SETTER(n, s)   public: DOXY_SS(n,s) void set_##n (const char* n ) { gu_strlcpy(_##n,n,(s)); }
 
#define STRING_PROPERTY(name, size)   STRING_PROPERTY_DECLARATION(name, size) STRING_PROPERTY_GETTER(name, size) STRING_PROPERTY_SETTER(name, size)
 
#define BIT_ARRAY_PROPERTY_DECLARATION(n, s)   protected: uint8_t _##n[((s-1)/8)+1];
 
#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) ); }
 
#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)) ); }
 
#define BIT_ARRAY_PROPERTY(name, size)   BIT_ARRAY_PROPERTY_DECLARATION(name, size) BIT_ARRAY_PROPERTY_GETTER(name) BIT_ARRAY_PROPERTY_SETTER(name)
 
#define CONTROLLED_SETTER(t, n)   public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; _##n##_mask = 1;}
 
#define CONTROLLED_PROPERTY(type, name)   PROPERTY_DECLARATION(type, name) PROPERTY_GETTER(type, name) CONTROLLED_SETTER(type, name)
 
#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");}}
 
#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)
 
#define CONTROL_BIT(name)   DOXY_MASK(n) BIT_DECLARATION(name##_mask) BIT_GETTER(name##_mask) BIT_SETTER(name##_mask)
 
#define VERSION_DECLARATION(n)   private: int _##n##_version; static int* get_##n##_classVersion() { static int _##n##_classVersion = 0; return &_##n##_classVersion;}
 
#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;}
 
#define VERSION_PROPERTY_GETTER(t, n)   public: DOXY_G(n) t &n () {(*get_##n##_classVersion()) = _##n##_version; return _##n ; }
 
#define VERSION_PROPERTY_CHECK(n)   public: DOXY_VERSION_NEW(n) bool new_##n () {if(_##n##_version > (*get_##n##_classVersion())) return true; return false;}
 
#define VERSION_PROPERTY_INITIALIZATION(n)   _##n##_version = 0;
 
#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)
 
#define SET_CONTROL_VAL(o, a, v)   do { (o).set_##a(v); (o)set_##a##_mask(true); } while (0)
 
#define CHECK_ENUM(s, p, v)   if (strstr((s), #v)) set_##p(v)
 
#define STREAM_ENUM_CASE(s, v)   case v: s << #v; break
 
#define DEG_OVER_RAD   (180.0f / static_cast<float>(M_PI))
 
#define RAD_OVER_DEG   (static_cast<float>(M_PI) / 180.0f)
 
#define DEG_OVER_RAD_10   (DEG_OVER_RAD * 10.0f)
 
#define RAD_OVER_DEG_10   (RAD_OVER_DEG / 10.0f)
 
#define RAD2DEG(x)   ((x) * DEG_OVER_RAD)
 
#define DEG2RAD(x)   ((x) * RAD_OVER_DEG)
 

Functions

size_t gu_strlcpy (char *dst, const char *src, size_t size)
 
size_t gu_strlcat (char *dst, const char *src, size_t size)
 
bool file_exists (const char *fileName)
 Return whether a file exists. More...
 
char * new_string_from_file (const char *fileName)
 Load the contents of a given file into a string. More...
 
int int_from_file (const char *fileName)
 Load the contents of a given file into an int. More...
 
double double_from_file (const char *fileName)
 Load the contents of a given file into a double. More...
 
char * gu_strdup (const char *str)
 Duplicate a string. More...
 
char * concatenate_path (const char *head, const char *tail)
 Create a new string by concatenating two path components. More...
 
long long get_utime (void)
 Get the current time of day in microseconds. More...
 
void protected_usleep (long long us)
 Protected usleep() – guaranteed to sleep for the given time! param us number of microseconds to sleep. More...
 
char * gu_strtrim (const char *s)
 Return a trimmed copy of the current string by removing all leading and trailing whitespace characters (needs to be free()d) More...
 
int mipal_err_file (const char *filename)
 Set the log file for the current module. More...
 
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) More...
 
const char * gu_getprogname (void)
 get the basename of the current program More...
 
int getplayernumber (void)
 get player number More...
 
std::string string_from_file (const char *fileName)
 Load the contents of a given file into a string. More...
 
std::string string_by_concatenating_path_components (const std::string &head, const std::string &tail)
 Concatenate two path components into a new string. More...
 
std::string & gu_trim (std::string &s)
 Trim whitespace characters from both ends of a string. More...
 
std::string gu_ltos (long val)
 Convert a long value to a string. More...
 
std::string gu_ultos (unsigned long val)
 Convert an unsigned long value to a string. More...
 
std::string gu_dtos (double val)
 Convert a double value to a string. More...
 
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. More...
 
std::map< std::string, std::string > read_configuration (const std::string &filename)
 Read simple key = value pairs into a c++ map. More...
 
int inc (void *num)
 Increment a number Used to increment an enum value without warnings. More...
 
int dec (void *num)
 Decrement a number Used to decrement a enum value without warnings. More...
 

Macro Definition Documentation

◆ __block [1/2]

#define __block   _xblock

Definition at line 119 of file gu_util.h.

◆ __block [2/2]

#define __block   __attribute__((__blocks__(byref)))

Definition at line 119 of file gu_util.h.

◆ _POSIX_SOURCE

#define _POSIX_SOURCE   200112L

Definition at line 73 of file gu_util.h.

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE

Definition at line 76 of file gu_util.h.

◆ ARRAY_PROPERTY

#define ARRAY_PROPERTY (   type,
  name,
  size 
)    ARRAY_PROPERTY_DECLARATION(type,name,size) ARRAY_PROPERTY_GETTER(type,name,size) ARRAY_PROPERTY_SETTER(type,name)

Definition at line 191 of file gu_util.h.

◆ ARRAY_PROPERTY_DECLARATION

#define ARRAY_PROPERTY_DECLARATION (   t,
  n,
 
)    protected: t _##n[s];

Definition at line 188 of file gu_util.h.

◆ ARRAY_PROPERTY_GETTER

#define ARRAY_PROPERTY_GETTER (   t,
  n,
 
)    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; }

Definition at line 189 of file gu_util.h.

◆ ARRAY_PROPERTY_SETTER

#define ARRAY_PROPERTY_SETTER (   t,
 
)    public: DOXY_S(n) void set_##n (const t &v, int e ) { _##n[e] = v ; }

Definition at line 190 of file gu_util.h.

◆ atoi16

#define atoi16 (   s)    static_cast<int16_t>(atoi(s))

Definition at line 156 of file gu_util.h.

◆ atoi32

#define atoi32 (   s)    static_cast<int32_t>(atoi(s))

Definition at line 158 of file gu_util.h.

◆ atoi64

#define atoi64 (   s)    static_cast<int64_t>(atoll(s))

Definition at line 160 of file gu_util.h.

◆ atou16

#define atou16 (   s)    static_cast<uint16_t>(atoi(s))

Definition at line 157 of file gu_util.h.

◆ atou32

#define atou32 (   s)    static_cast<uint32_t>(atoi(s))

Definition at line 159 of file gu_util.h.

◆ atou64

#define atou64 (   s)    static_cast<uint64_t>(atoll(s))

Definition at line 161 of file gu_util.h.

◆ BIT_ARRAY_PROPERTY

#define BIT_ARRAY_PROPERTY (   name,
  size 
)    BIT_ARRAY_PROPERTY_DECLARATION(name, size) BIT_ARRAY_PROPERTY_GETTER(name) BIT_ARRAY_PROPERTY_SETTER(name)

Definition at line 202 of file gu_util.h.

◆ BIT_ARRAY_PROPERTY_DECLARATION

#define BIT_ARRAY_PROPERTY_DECLARATION (   n,
 
)    protected: uint8_t _##n[((s-1)/8)+1];

Definition at line 199 of file gu_util.h.

◆ BIT_ARRAY_PROPERTY_GETTER

#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) ); }

Definition at line 200 of file gu_util.h.

◆ BIT_ARRAY_PROPERTY_SETTER

#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)) ); }

Definition at line 201 of file gu_util.h.

◆ BIT_DECLARATION

#define BIT_DECLARATION (   n)    protected: unsigned int _##n : 1;

Definition at line 183 of file gu_util.h.

◆ BIT_GETTER

#define BIT_GETTER (   n)    public: DOXY_G(n) unsigned int n () DOXY_GC(n) const { return _##n ; }

Definition at line 184 of file gu_util.h.

◆ BIT_PROPERTY

#define BIT_PROPERTY (   name)    BIT_DECLARATION(name) BIT_GETTER(name) BIT_SETTER(name)

Definition at line 186 of file gu_util.h.

◆ BIT_SETTER

#define BIT_SETTER (   n)    public: DOXY_S(n) void set_##n (const unsigned int n = true) { _##n = n ; }

Definition at line 185 of file gu_util.h.

◆ CHECK_ENUM

#define CHECK_ENUM (   s,
  p,
 
)    if (strstr((s), #v)) set_##p(v)

Definition at line 221 of file gu_util.h.

◆ CONTROL_BIT

#define CONTROL_BIT (   name)    DOXY_MASK(n) BIT_DECLARATION(name##_mask) BIT_GETTER(name##_mask) BIT_SETTER(name##_mask)

Definition at line 210 of file gu_util.h.

◆ CONTROLLED_ARRAY_PROPERTY

#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)

Definition at line 208 of file gu_util.h.

◆ CONTROLLED_ARRAY_PROPERTY_SETTER

#define CONTROLLED_ARRAY_PROPERTY_SETTER (   t,
  n,
 
)    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");}}

Definition at line 207 of file gu_util.h.

◆ CONTROLLED_PROPERTY

#define CONTROLLED_PROPERTY (   type,
  name 
)    PROPERTY_DECLARATION(type, name) PROPERTY_GETTER(type, name) CONTROLLED_SETTER(type, name)

Definition at line 205 of file gu_util.h.

◆ CONTROLLED_SETTER

#define CONTROLLED_SETTER (   t,
 
)    public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; _##n##_mask = 1;}

Definition at line 204 of file gu_util.h.

◆ DBG

#define DBG (   x)

Definition at line 96 of file gu_util.h.

◆ DEG2RAD

#define DEG2RAD (   x)    ((x) * RAD_OVER_DEG)

Definition at line 231 of file gu_util.h.

◆ DEG_OVER_RAD

#define DEG_OVER_RAD   (180.0f / static_cast<float>(M_PI))

Definition at line 225 of file gu_util.h.

◆ DEG_OVER_RAD_10

#define DEG_OVER_RAD_10   (DEG_OVER_RAD * 10.0f)

Definition at line 227 of file gu_util.h.

◆ DOXY_ARRAY_G

#define DOXY_ARRAY_G (   n)    /** property getter for an element of the array _ ##n (see Protected Attributes below) @param e element index @return _ ##n value */

Definition at line 170 of file gu_util.h.

◆ DOXY_ARRAY_GC

#define DOXY_ARRAY_GC (   n)    /** property getter for a constant referance to an element of the array _ ##n (see Protected Attributes below) @param e element index @return _ ##n value */

Definition at line 171 of file gu_util.h.

◆ DOXY_BAPG

#define DOXY_BAPG (   n)    /** property getter for an element of the bit array _ ##n (see Protected Attributes below) @param b element index @return _ ##n value */

Definition at line 174 of file gu_util.h.

◆ DOXY_BAPGC

#define DOXY_BAPGC (   n)    /** property getter for a constant referance to an element of the bit array _ ##n (see Protected Attributes below) @param b element index @return _ ##n value */

Definition at line 175 of file gu_util.h.

◆ DOXY_BAPS

#define DOXY_BAPS (   n)    /** property setter for an element of bit array _ ##n (see Protected Attributes below) @param b element index @param v element's value */

Definition at line 176 of file gu_util.h.

◆ DOXY_G

#define DOXY_G (   n)    /** property getter for _ ##n (see Protected Attributes below) @return _ ##n value */

Definition at line 166 of file gu_util.h.

◆ DOXY_GC

#define DOXY_GC (   n)    /** property getter for a constant referance to _ ##n (see Protected Attributes below) @return _ ##n value */

Definition at line 168 of file gu_util.h.

◆ DOXY_MASK

#define DOXY_MASK (   n)    /** Control bit (mask) for _ ##n (Used Internally) */

Definition at line 163 of file gu_util.h.

◆ DOXY_S

#define DOXY_S (   n)    /** property setter for _ ##n (see Protected Attributes below) */

Definition at line 164 of file gu_util.h.

◆ DOXY_SG

#define DOXY_SG (   n,
 
)    /** property getter for _ ##n[s] (see Protected Attributes below) @return _ ##n[s] value */

Definition at line 167 of file gu_util.h.

◆ DOXY_SGC

#define DOXY_SGC (   n,
 
)    /** property getter for a constant referance to _ ##n[s] (see Protected Attributes below) @return _ ##n[s] value */

Definition at line 169 of file gu_util.h.

◆ DOXY_SS

#define DOXY_SS (   n,
 
)    /** property setter for _ ##n[s] (see Protected Attributes below) */

Definition at line 165 of file gu_util.h.

◆ DOXY_VERSION_NEW

#define DOXY_VERSION_NEW (   n)    /** Checks if ##n##'s version number in the current message is greater then the local version number @return true if the version number is greater, false otherwise*/

Definition at line 172 of file gu_util.h.

◆ DPRINTF

#define DPRINTF (   x)

Definition at line 99 of file gu_util.h.

◆ NOEXCEPT

#define NOEXCEPT   noexcept

Definition at line 150 of file gu_util.h.

◆ NULLPTR

#define NULLPTR   nullptr

Definition at line 134 of file gu_util.h.

◆ OVERRIDE

#define OVERRIDE   override

Definition at line 142 of file gu_util.h.

◆ PROPERTY

#define PROPERTY (   type,
  name 
)    PROPERTY_DECLARATION(type,name) PROPERTY_GETTER(type,name) PROPERTY_SETTER(type,name)

Definition at line 181 of file gu_util.h.

◆ PROPERTY_DECLARATION

#define PROPERTY_DECLARATION (   t,
 
)    protected: t _##n;

Definition at line 178 of file gu_util.h.

◆ PROPERTY_GETTER

#define PROPERTY_GETTER (   t,
 
)    public: DOXY_G(n) t &n () { return _##n ; } DOXY_GC(n) const t &n () const { return _##n ; }

Definition at line 179 of file gu_util.h.

◆ PROPERTY_SETTER

#define PROPERTY_SETTER (   t,
 
)    public: DOXY_S(n) void set_##n (const t &n ) { _##n = n ; }

Definition at line 180 of file gu_util.h.

◆ protected_msleep

#define protected_msleep (   ms)    protected_usleep(1000LL*(ms))

Definition at line 103 of file gu_util.h.

◆ protected_sleep

#define protected_sleep (   s)    protected_usleep(1000000LL*(s))

Definition at line 104 of file gu_util.h.

◆ RAD2DEG

#define RAD2DEG (   x)    ((x) * DEG_OVER_RAD)

Definition at line 230 of file gu_util.h.

◆ RAD_OVER_DEG

#define RAD_OVER_DEG   (static_cast<float>(M_PI) / 180.0f)

Definition at line 226 of file gu_util.h.

◆ RAD_OVER_DEG_10

#define RAD_OVER_DEG_10   (RAD_OVER_DEG / 10.0f)

Definition at line 228 of file gu_util.h.

◆ SET_CONTROL_VAL

#define SET_CONTROL_VAL (   o,
  a,
 
)    do { (o).set_##a(v); (o)set_##a##_mask(true); } while (0)

Definition at line 219 of file gu_util.h.

◆ STREAM_ENUM_CASE

#define STREAM_ENUM_CASE (   s,
 
)    case v: s << #v; break

Definition at line 222 of file gu_util.h.

◆ STRING_PROPERTY

#define STRING_PROPERTY (   name,
  size 
)    STRING_PROPERTY_DECLARATION(name, size) STRING_PROPERTY_GETTER(name, size) STRING_PROPERTY_SETTER(name, size)

Definition at line 196 of file gu_util.h.

◆ STRING_PROPERTY_DECLARATION

#define STRING_PROPERTY_DECLARATION (   n,
 
)    protected: char _##n[s];

Definition at line 193 of file gu_util.h.

◆ STRING_PROPERTY_GETTER

#define STRING_PROPERTY_GETTER (   n,
 
)    public: DOXY_SG(n,s) char* n () { return &(_##n[0]); } DOXY_SGC(n,s) const char* n () const { return &(_##n[0]); }

Definition at line 194 of file gu_util.h.

◆ STRING_PROPERTY_SETTER

#define STRING_PROPERTY_SETTER (   n,
 
)    public: DOXY_SS(n,s) void set_##n (const char* n ) { gu_strlcpy(_##n,n,(s)); }

Definition at line 195 of file gu_util.h.

◆ VERSION_DECLARATION

#define VERSION_DECLARATION (   n)    private: int _##n##_version; static int* get_##n##_classVersion() { static int _##n##_classVersion = 0; return &_##n##_classVersion;}

Definition at line 212 of file gu_util.h.

◆ VERSION_PROPERTY_CHECK

#define VERSION_PROPERTY_CHECK (   n)    public: DOXY_VERSION_NEW(n) bool new_##n () {if(_##n##_version > (*get_##n##_classVersion())) return true; return false;}

Definition at line 215 of file gu_util.h.

◆ VERSION_PROPERTY_GETTER

#define VERSION_PROPERTY_GETTER (   t,
 
)    public: DOXY_G(n) t &n () {(*get_##n##_classVersion()) = _##n##_version; return _##n ; }

Definition at line 214 of file gu_util.h.

◆ VERSION_PROPERTY_INITIALIZATION

#define VERSION_PROPERTY_INITIALIZATION (   n)    _##n##_version = 0;

Definition at line 216 of file gu_util.h.

◆ VERSION_PROPERTY_SETTER

#define VERSION_PROPERTY_SETTER (   t,
 
)    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;}

Definition at line 213 of file gu_util.h.

◆ VERSIONED_PROPERTY

#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)

Definition at line 217 of file gu_util.h.

Function Documentation

◆ components_of_string_separated()

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.

Parameters
strThe string to split
sepToken separator character
trimBoolean to specify whether the result should be trimmed
Returns
array of strings split by token

Definition at line 348 of file gu_util.cpp.

References gu_trim().

Referenced by read_configuration().

◆ concatenate_path()

char * concatenate_path ( const char *  head,
const char *  tail 
)

Create a new string by concatenating two path components.

Parameters
headparent directory
tailchild path component
Returns
char * with the concatenated path (needs to be free()d)

Definition at line 125 of file gu_util.cpp.

References gu_strdup(), and string_by_concatenating_path_components().

◆ dec()

int dec ( void *  num)

Decrement a number Used to decrement a enum value without warnings.

Parameters
numA pointer to the number to decrement
Returns
the new value of the number

Definition at line 395 of file gu_util.cpp.

◆ double_from_file()

double double_from_file ( const char *  fileName)

Load the contents of a given file into a double.

Parameters
fileNameName of the file to load
Returns
double with the contents of the file

Definition at line 98 of file gu_util.cpp.

References new_string_from_file().

◆ file_exists()

bool file_exists ( const char *  fileName)

Return whether a file exists.

Parameters
fileNameName of the file to test
Returns
true if the file exists, false otherwise

Definition at line 54 of file gu_util.cpp.

◆ get_utime()

long long get_utime ( void  )

Get the current time of day in microseconds.

Returns
long long with the current time in us (-1LL in case of error)

Definition at line 130 of file gu_util.cpp.

Referenced by protected_usleep().

◆ getplayernumber()

int getplayernumber ( void  )

get player number

Returns
int player number

Definition at line 228 of file gu_util.cpp.

◆ gu_dtos()

std::string gu_dtos ( double  val)

Convert a double value to a string.

Parameters
valValue to convert
Returns
string with contens value

Definition at line 339 of file gu_util.cpp.

◆ gu_getprogname()

const char * gu_getprogname ( void  )

get the basename of the current program

Returns
const char * program name

Definition at line 210 of file gu_util.cpp.

◆ gu_ltos()

std::string gu_ltos ( long  val)

Convert a long value to a string.

Parameters
valValue to convert
Returns
string with contens value

Definition at line 321 of file gu_util.cpp.

◆ gu_strdup()

char * gu_strdup ( const char *  str)

Duplicate a string.

Parameters
stroriginal string
Returns
char * duplicated string (needs to be free()d)

Definition at line 111 of file gu_util.cpp.

Referenced by concatenate_path(), and gu_strtrim().

◆ gu_strlcat()

size_t gu_strlcat ( char *  dst,
const char *  src,
size_t  size 
)

Definition at line 252 of file gu_util.cpp.

◆ gu_strlcpy()

size_t gu_strlcpy ( char *  dst,
const char *  src,
size_t  size 
)

Definition at line 245 of file gu_util.cpp.

◆ gu_strtrim()

char * gu_strtrim ( const char *  s)

Return a trimmed copy of the current string by removing all leading and trailing whitespace characters (needs to be free()d)

Parameters
sthe string to trim
Returns
new string void of leading

Definition at line 150 of file gu_util.cpp.

References gu_strdup(), and gu_trim().

◆ gu_trim()

std::string & gu_trim ( std::string &  s)

Trim whitespace characters from both ends of a string.

This operation is in-place, so the original string gets modified!

Parameters
sthe string to trim (in place)
Returns
reference to s

Definition at line 305 of file gu_util.cpp.

References WHITESPACE.

Referenced by components_of_string_separated(), and gu_strtrim().

◆ gu_ultos()

std::string gu_ultos ( unsigned long  val)

Convert an unsigned long value to a string.

Parameters
valValue to convert
Returns
string with contens value

Definition at line 330 of file gu_util.cpp.

◆ inc()

int inc ( void *  num)

Increment a number Used to increment an enum value without warnings.

Parameters
numA pointer to the number to increment
Returns
the new value of the number

Definition at line 389 of file gu_util.cpp.

◆ int_from_file()

int int_from_file ( const char *  fileName)

Load the contents of a given file into an int.

Parameters
fileNameName of the file to load
Returns
int with the contents of the file

Definition at line 84 of file gu_util.cpp.

References new_string_from_file().

◆ mipal_err_file()

int mipal_err_file ( const char *  filename)

Set the log file for the current module.

Parameters
filenamename of the file to open. If the file contains a slash '/', it will create the directory the file should go in with mode 01777 if non-existent
Returns
-1 in case of errors, 0 in case of success

Definition at line 158 of file gu_util.cpp.

◆ mipal_warn()

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)

Parameters
fmtprintf() style format string

Definition at line 187 of file gu_util.cpp.

Referenced by read_configuration().

◆ new_string_from_file()

char * new_string_from_file ( const char *  fileName)

Load the contents of a given file into a string.

Parameters
fileNameName of the file to load
Returns
string with contens of file

Definition at line 60 of file gu_util.cpp.

Referenced by double_from_file(), int_from_file(), and string_from_file().

◆ protected_usleep()

void protected_usleep ( long long  us)

Protected usleep() – guaranteed to sleep for the given time! param us number of microseconds to sleep.

Definition at line 140 of file gu_util.cpp.

References get_utime().

◆ read_configuration()

std::map< std::string, std::string > read_configuration ( const std::string &  filename)

Read simple key = value pairs into a c++ map.

Parameters
filenamePath to configuration file
Returns
map<string, string> of key/value string pairs

Definition at line 363 of file gu_util.cpp.

References components_of_string_separated(), and mipal_warn().

◆ string_by_concatenating_path_components()

std::string string_by_concatenating_path_components ( const std::string &  head,
const std::string &  tail 
)

Concatenate two path components into a new string.

Parameters
headparent directory
tailchild path component
Returns
string with the concatenated path

Definition at line 280 of file gu_util.cpp.

Referenced by concatenate_path().

◆ string_from_file()

std::string string_from_file ( const char *  fileName)

Load the contents of a given file into a string.

Parameters
fileNameName of the file to load
Returns
string with contens of file

Definition at line 267 of file gu_util.cpp.

References new_string_from_file().