XPPlanes
X-Plane plugin to display additional planes based on network data
|
Miscellaneous utility functions, including logging. More...
Go to the source code of this file.
Classes | |
class | StrTokens |
Class to extract tokens from a string. More... | |
Macros | |
#define | ERR_ASSERT "ASSERT FAILED: %s" |
#define | ERR_EXCEPTION "EXCEPTION CAUGHT: %s" |
#define | STR_N(s) str_n(s,sizeof(s)) |
Simplify using str_n() with char arrays. More... | |
#define | XPPLANES_FMTARGS(FMT) |
To apply printf-style warnings to our functions. More... | |
#define | LOG_MSG(lvl, ...) |
Log a message if lvl is greater or equal currently defined log level. More... | |
#define | THROW_ERROR(...) throw XPMP2::XPMP2Error(__FILE__, __LINE__, __func__, __VA_ARGS__); |
Throws an exception using XPMP2Error. More... | |
#define | LOG_ASSERT(cond) |
Throw in an assert-style (logging takes place in XPMP2Error constructor) More... | |
#define | SET_THREAD_NAME(sName) |
Enumerations | |
enum | logLevelTy : int { logDEBUG = 0 , logINFO , logWARN , logERR , logFATAL , logMSG } |
Logging level. More... | |
Functions | |
float | GetMiscNetwTime () |
Get synched network time from X-Plane (sim/network/misc/network_time_sec) as used in Log.txt. More... | |
bool | CheckEverySoOften (float &_lastCheck, float _interval, float _now) |
Convenience function to check on something at most every x seconds. More... | |
bool | CheckEverySoOften (float &_lastCheck, float _interval) |
Convenience function to check on something at most every x seconds. More... | |
std::string | GetPluginName (XPLMPluginID who) |
Return a plugin's name. More... | |
std::istream & | safeGetline (std::istream &is, std::string &t) |
Read a text line, handling both Windows (CRLF) and Unix (LF) ending. More... | |
double | WeatherAltCorr_ft (double pressureAlt_ft, double hPa) |
Compute geometric altitude [ft] from pressure altitude and current weather in a very simplistic manner good enough for the first 3,000ft. More... | |
float | HeadDiff (float from, float to) |
Return shortest turn from one heading to the other. More... | |
float | RpmToAngle (float angle, float rpm, float s) |
Rotation: Computes new rotation angle based on current + revolution in a (small) amount of time. More... | |
template<typename T > | |
T | NZ (T v) |
Replace NAN with 0.0. More... | |
std::string | str_n (const char *s, size_t max) |
Copy at most n chars from location, or less if zero-terminated. More... | |
std::vector< std::string > | str_tokenize (const std::string &s, const std::string &tokens, bool bSkipEmpty=true) |
separates string into tokens More... | |
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. More... | |
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. More... | |
void | LogMsg (const char *szFile, int ln, const char *szFunc, logLevelTy lvl, const char *szMsg,...) XPPLANES_FMTARGS(5) |
Log Text to log file. More... | |
Miscellaneous utility functions, including logging.
#define ERR_ASSERT "ASSERT FAILED: %s" |
#define ERR_EXCEPTION "EXCEPTION CAUGHT: %s" |
#define LOG_ASSERT | ( | cond | ) |
Throw in an assert-style (logging takes place in XPMP2Error constructor)
#define LOG_MSG | ( | lvl, | |
... | |||
) |
Log a message if lvl is greater or equal currently defined log level.
#define SET_THREAD_NAME | ( | sName | ) |
#define THROW_ERROR | ( | ... | ) | throw XPMP2::XPMP2Error(__FILE__, __LINE__, __func__, __VA_ARGS__); |
Throws an exception using XPMP2Error.
#define XPPLANES_FMTARGS | ( | FMT | ) |
To apply printf-style warnings to our functions.
enum logLevelTy : int |
Logging level.
|
inline |
Convenience function to check on something at most every x seconds.
_lastCheck | Provide a float which holds the time of last check (init with 0.0f ) |
_interval | [seconds] How often to perform the check? |
true
if more than _interval
time has passed since _lastCheck
bool CheckEverySoOften | ( | float & | _lastCheck, |
float | _interval, | ||
float | _now | ||
) |
Convenience function to check on something at most every x seconds.
_lastCheck | Provide a float which holds the time of last check (init with 0.0f ) |
_interval | [seconds] How often to perform the check? |
_now | Current time, possibly from a call to GetTotalRunningTime() |
true
if more than _interval
time has passed since _lastCheck
float GetMiscNetwTime | ( | ) |
Get synched network time from X-Plane (sim/network/misc/network_time_sec) as used in Log.txt.
std::string GetPluginName | ( | XPLMPluginID | who | ) |
Return a plugin's name.
float HeadDiff | ( | float | from, |
float | to | ||
) |
Return shortest turn from one heading to the other.
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.
void LogMsg | ( | const char * | szFile, |
int | ln, | ||
const char * | szFunc, | ||
logLevelTy | lvl, | ||
const char * | szMsg, | ||
... | |||
) |
Log Text to log file.
|
inline |
Replace NAN with 0.0.
float RpmToAngle | ( | float | angle, |
float | rpm, | ||
float | s | ||
) |
Rotation: Computes new rotation angle based on current + revolution in a (small) amount of time.
angle | Last rotation angle as basis |
rpm | Rotation speed in revolutions per minute |
s | Timeframe to consider in seconds |
std::istream& safeGetline | ( | std::istream & | is, |
std::string & | t | ||
) |
Read a text line, handling both Windows (CRLF) and Unix (LF) ending.
Code makes use of the fact that in both cases LF is the terminal character. So we read from file until LF (without widening!). In case of CRLF files there then is a trailing CR, which we just remove.
std::string str_n | ( | const char * | s, |
size_t | max | ||
) |
Copy at most n
chars from location, or less if zero-terminated.
Unlike std::string(char*, n) this will not copy null chars
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.
std::vector<std::string> str_tokenize | ( | const std::string & | s, |
const std::string & | tokens, | ||
bool | bSkipEmpty = true |
||
) |
separates string into tokens
|
inline |
Compute geometric altitude [ft] from pressure altitude and current weather in a very simplistic manner good enough for the first 3,000ft.