XPPlanes
X-Plane plugin to display additional planes based on network data
Macros | Functions | Variables
Utilities.cpp File Reference

Miscellaneous utility functions, including logging. More...

#include "XPPlanes.h"

Macros

#define PATH_DELIM_STD   '/'
 

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...
 
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...
 
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...
 
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)
 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 *szPath, 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 *szPath, int ln, const char *szFunc, logLevelTy lvl, const char *szMsg,...)
 Log Text to log file. More...
 

Variables

const char * LOG_LEVEL []
 

Detailed Description

Miscellaneous utility functions, including logging.

Author
Birger Hoppe

Macro Definition Documentation

◆ PATH_DELIM_STD

#define PATH_DELIM_STD   '/'

Function Documentation

◆ CheckEverySoOften()

bool CheckEverySoOften ( float &  _lastCheck,
float  _interval,
float  _now 
)

Convenience function to check on something at most every x seconds.

Parameters
_lastCheckProvide a float which holds the time of last check (init with 0.0f)
_interval[seconds] How often to perform the check?
_nowCurrent time, possibly from a call to GetTotalRunningTime()
Returns
true if more than _interval time has passed since _lastCheck

◆ GetMiscNetwTime()

float GetMiscNetwTime ( )

Get synched network time from X-Plane (sim/network/misc/network_time_sec) as used in Log.txt.

◆ GetPluginName()

std::string GetPluginName ( XPLMPluginID  who)

Return a plugin's name.

◆ HeadDiff()

float HeadDiff ( float  from,
float  to 
)

Return shortest turn from one heading to the other.

◆ LogGetString()

const char* LogGetString ( const char *  szPath,
int  ln,
const char *  szFunc,
logLevelTy  lvl,
const char *  szMsg,
va_list  args 
)

Returns ptr to static buffer filled with formatted log string.

◆ LogMsg()

void LogMsg ( const char *  szPath,
int  ln,
const char *  szFunc,
logLevelTy  lvl,
const char *  szMsg,
  ... 
)

Log Text to log file.

◆ RpmToAngle()

float RpmToAngle ( float  angle,
float  rpm,
float  s 
)

Rotation: Computes new rotation angle based on current + revolution in a (small) amount of time.

Parameters
angleLast rotation angle as basis
rpmRotation speed in revolutions per minute
sTimeframe to consider in seconds
Returns
new rotation angle, normalized to [0.0; 360.0)

◆ safeGetline()

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.

◆ str_n()

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

◆ str_split()

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.

◆ str_tokenize()

std::vector<std::string> str_tokenize ( const std::string &  s,
const std::string &  tokens,
bool  bSkipEmpty 
)

separates string into tokens

Variable Documentation

◆ LOG_LEVEL

const char* LOG_LEVEL[]
Initial value:
= {
"DEBUG", "INFO ", "WARN ", "ERROR", "FATAL", "MSG "
}