27 #define ERR_ASSERT "ASSERT FAILED: %s"
28 #define ERR_EXCEPTION "EXCEPTION CAUGHT: %s"
55 std::istream&
safeGetline(std::istream& is, std::string& t);
62 float HeadDiff (
float from,
float to);
69 float RpmToAngle (
float angle,
float rpm,
float s);
74 {
return std::isnan(v) ? T(0) : v; }
82 std::string
str_n (
const char* s,
size_t max);
85 #define STR_N(s) str_n(s,sizeof(s))
88 std::vector<std::string>
str_tokenize (
const std::string& s,
89 const std::string& tokens,
90 bool bSkipEmpty =
true);
97 size_t p = std::string::npos;
101 StrTokens (
const std::string& _s,
const std::string& _sep) :
s(_s),
sep(_sep) {}
105 std::string
next(
const std::string& _sep) {
sep = _sep;
return next(); }
109 bool finished ()
const {
return p != std::string::npos &&
p >=
s.length(); }
113 std::pair<std::string,std::string>
str_split (
const std::string& s,
114 const std::string& tokens);
122 #if defined(__clang__) || defined(__GNUC__)
123 #define XPPLANES_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1)))
125 #define XPPLANES_FMTARGS(FMT)
139 const char*
LogGetString (
const char* szFile,
int ln,
const char* szFunc,
logLevelTy lvl,
const char* szMsg, va_list args );
151 #define LOG_MSG(lvl,...) { \
152 if (lvl >= glob.logLvl) \
153 {LogMsg(__FILE__, __LINE__, __func__, lvl, __VA_ARGS__);} \
159 #define THROW_ERROR(...) \
160 throw XPMP2::XPMP2Error(__FILE__, __LINE__, __func__, __VA_ARGS__);
164 #define LOG_ASSERT(cond) \
166 THROW_ERROR(ERR_ASSERT,#cond); \
175 inline int strerror_s(
char *buf,
size_t bufsz,
int errnum )
176 {
return strerror_r(errnum, buf, bufsz); }
178 inline int strerror_s(
char *buf,
size_t bufsz,
int errnum )
179 { strerror_r(errnum, buf, bufsz);
return 0; }
186 #define SET_THREAD_NAME(sName) SetThreadDescription(GetCurrentThread(), L##sName)
188 #define SET_THREAD_NAME(sName) pthread_setname_np(sName)
190 #define SET_THREAD_NAME(sName) pthread_setname_np(pthread_self(),sName)
193 #define SET_THREAD_NAME(sName)
constexpr double FT_per_HPA
ft altitude diff per hPa change
Definition: Constants.h:31
constexpr double HPA_STANDARD
Definition: Constants.h:26
#define XPPLANES_FMTARGS(FMT)
To apply printf-style warnings to our functions.
Definition: Utilities.h:125
float HeadDiff(float from, float to)
Return shortest turn from one heading to the other.
Definition: Utilities.cpp:75
float RpmToAngle(float angle, float rpm, float s)
Rotation: Computes new rotation angle based on current + revolution in a (small) amount of time.
Definition: Utilities.cpp:85
const char * LogGetString(const char *szFile, int ln, const char *szFunc, logLevelTy lvl, const char *szMsg, va_list args)
Returns ptr to static buffer filled with formatted log string.
Definition: Utilities.cpp:180
float GetMiscNetwTime()
Get synched network time from X-Plane (sim/network/misc/network_time_sec) as used in Log....
Definition: Utilities.cpp:28
void LogMsg(const char *szFile, int ln, const char *szFunc, logLevelTy lvl, const char *szMsg,...) XPPLANES_FMTARGS(5)
Log Text to log file.
Definition: Utilities.cpp:224
std::string GetPluginName(XPLMPluginID who)
Return a plugin's name.
Definition: Utilities.cpp:51
std::vector< std::string > str_tokenize(const std::string &s, const std::string &tokens, bool bSkipEmpty=true)
separates string into tokens
Definition: Utilities.cpp:113
std::istream & safeGetline(std::istream &is, std::string &t)
Read a text line, handling both Windows (CRLF) and Unix (LF) ending.
Definition: Utilities.cpp:62
double WeatherAltCorr_ft(double pressureAlt_ft, double hPa)
Compute geometric altitude [ft] from pressure altitude and current weather in a very simplistic manne...
Definition: Utilities.h:58
T NZ(T v)
Replace NAN with 0.0.
Definition: Utilities.h:73
std::pair< std::string, std::string > str_split(const std::string &s, const std::string &tokens)
Split the string at the first of the tokens and return the two pieces.
Definition: Utilities.cpp:155
std::string str_n(const char *s, size_t max)
Copy at most n chars from location, or less if zero-terminated.
Definition: Utilities.cpp:104
logLevelTy
Logging level.
Definition: Utilities.h:129
@ logDEBUG
Debug, highest level of detail.
Definition: Utilities.h:130
@ logINFO
regular info messages
Definition: Utilities.h:131
@ logWARN
warnings, i.e. unexpected, but uncritical events, maybe leading to unwanted display,...
Definition: Utilities.h:132
@ logFATAL
fatal is shortly before a crash
Definition: Utilities.h:134
@ logERR
errors mean, aircraft can potentially not be displayed
Definition: Utilities.h:133
@ logMSG
will always be output, no matter what has been configured, cannot be suppressed
Definition: Utilities.h:135
bool CheckEverySoOften(float &_lastCheck, float _interval, float _now)
Convenience function to check on something at most every x seconds.
Definition: Utilities.cpp:40
Class to extract tokens from a string.
Definition: Utilities.h:93
std::string next(const std::string &_sep)
(re)sets the separators, then returns the next token
Definition: Utilities.h:105
StrTokens(const std::string &_s, const std::string &_sep)
Constructor: Pass in the string to separate and the separators.
Definition: Utilities.h:101
bool finished() const
have all tokens been returned?
Definition: Utilities.h:109
const std::string & s
reference to the string to search
Definition: Utilities.h:95
size_t p
points to last separator found
Definition: Utilities.h:97
std::string sep
separators
Definition: Utilities.h:96
int count() const
returns how many finds have been returned so far
Definition: Utilities.h:107
std::string next()
returns the next token, can be the empty string if two tokens follow immediately, or if finished()
Definition: Utilities.cpp:136
int num
counts the findings
Definition: Utilities.h:98