BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
bst Namespace Reference

Namespaces

 clck
 
 filesystem
 
 fs_int
 Internal inline functions used only in this file.
 
 geo
 
 layout
 
 math
 
 string
 
 template_tools
 
 time
 

Classes

class  BoosterSeatException
 
class  ConsecutiveValuesFilter
 A simple counting filter that allows for some noise. More...
 
class  IStopwatch
 
class  ITimer
 Interface for a timer class. More...
 
class  Pressure
 
class  Process
 A class to handle linux process calls. More...
 
struct  raii_char_str
 
class  RollingAverage
 Moving average calculator. More...
 
class  SoftwareStopwatch
 A manually controlled stopwatch that does not use the system clock. More...
 
class  SoftwareTimer
 A software timer class for manual control. More...
 
class  Stopwatch
 A simple stopwatch class. Basic start (resume), stop (pause), and reset functionality. More...
 
class  Time
 The generic time class for BoosterSeat. Uses UTC time. More...
 
class  Timer
 A simple timer class for timing events. More...
 

Enumerations

enum class  ErrorNumber {
  UNSPECIFIED = 0 , FS_PATH_DOES_NOT_EXIST = 1 , FS_PATH_ALREADY_EXISTS = 2 , FS_PATH_NOT_REGULAR_FILE = 3 ,
  FS_PATH_NOT_DIRECTORY = 4 , FS_FILE_NOT_VALID = 5 , FS_NO_WRITE_PERMISSIONS = 6 , FS_NO_READ_PERMISSIONS = 7 ,
  FS_INVALID_SIZE_UNIT = 8 , TIME_INVALID_TIMEZONE = 9 , GEO_INVALID_LATITUDE = 10 , GEO_INVALID_LONGITUDE = 11 ,
  TIME_INVALID_TIME = 12 , PROCESS_NOT_COMPLETE = 13 , PROCESS_TIMEOUT = 14 , NOT_YET_IMPLEMENTED
}
 

Functions

bool containsPrefix (const std::string &str, const std::string &prefix)
 Checks if a string contains a prefix. More...
 
bool containsSubstring (const std::string &str, const std::string &sub)
 Checks if a string contains a substring. More...
 
bool containsSuffix (const std::string &str, const std::string &suffix)
 Checks if a string contains a suffix. More...
 
double doubleToPrecisionTwo (double)
 Rounds a double to two decimal places. For example: 1.2345 -> 1.23. More...
 
uint32_t getUnixTime ()
 Get the current Unix time. More...
 
bool isApproxEqual (double a, double b, double epsilon)
 Just a simple function to compare two doubles by a given epsilon. More...
 
bool isApproxEqualPercent (const double a, const double b, const double percent)
 
double randomDouble (double min, double max)
 Generates a random double within the given range. More...
 
std::string randomHexString (size_t length)
 Generates a random hex string of the given length. More...
 
std::string rndTs (double d, int precision)
 
void sleep (int32_t milliseconds)
 

Variables

constexpr double D2R = PI / 180.0
 Factor to convert degrees to radians. More...
 
constexpr double HALF_PI = PI / 2.0
 Half of pi. More...
 
constexpr double K_GRAVITY = 9.80665
 Standard gravity constant. More...
 
constexpr int K_PIPE_READ = 0
 
constexpr int K_PIPE_WRITE = 1
 
constexpr int kPrecision = 6
 
constexpr double PI = 3.14159265358979323846
 The mathematical constant pi. More...
 
constexpr double R2D = 180.0 / PI
 Factor to convert radians to degrees. More...
 
constexpr double THREE_PI_HALVES = 3.0 * HALF_PI
 Three halves of pi. More...
 
constexpr double TWO_PI = 2.0 * PI
 Two times pi. More...
 

Enumeration Type Documentation

◆ ErrorNumber

enum bst::ErrorNumber
strong
Enumerator
UNSPECIFIED 

Default value, just for backwards compatibility. Should not be used in new code.

FS_PATH_DOES_NOT_EXIST 

Path does not exist when it should. Includes path in message.

FS_PATH_ALREADY_EXISTS 

Path already exists when it should not. Includes path in message.

FS_PATH_NOT_REGULAR_FILE 

Path is not a regular file. Includes path in message.

FS_PATH_NOT_DIRECTORY 

Path is not a directory. Includes path in message.

FS_FILE_NOT_VALID 

File is not valid. Includes if/ofstream error code in message.

Format: "Stream errno:<errorno> | <path>"

FS_NO_WRITE_PERMISSIONS 

Throw if write permissions are required but do not exist.

FS_NO_READ_PERMISSIONS 

Throw if read permissions are required but do not exist.

FS_INVALID_SIZE_UNIT 

Thrown if an invalid size unit is used.

TIME_INVALID_TIMEZONE 

Thrown if an invalid time zone is used.

GEO_INVALID_LATITUDE 

Latitude is out of range/invalid.

GEO_INVALID_LONGITUDE 

Longitude is out of range/invalid.

TIME_INVALID_TIME 

Invalid time.

PROCESS_NOT_COMPLETE 

Part of bst::Process, thrown if the process is not yet complete yet a method is called that requires the process to be complete. Call waitToComplete first.

PROCESS_TIMEOUT 

Part of bst::Process, thrown if the process times out.

NOT_YET_IMPLEMENTED 

Throws if a feature is not yet implemented.

Function Documentation

◆ getUnixTime()

uint32_t bst::getUnixTime ( )

Get the current Unix time.

Returns
The current Unix time in seconds (seconds since epoch)

References bst::clck::now().

Here is the call graph for this function:

◆ doubleToPrecisionTwo()

double bst::doubleToPrecisionTwo ( double  d)

Rounds a double to two decimal places. For example: 1.2345 -> 1.23.

Parameters
doubleThe double to round.
Returns
double The rounded double.

◆ isApproxEqual()

bool bst::isApproxEqual ( double  a,
double  b,
double  epsilon 
)
inline

Just a simple function to compare two doubles by a given epsilon.

Todo:
needs to be tested.
Parameters
a- The first double.
b- The second double.
epsilon- The maximum difference between the two doubles.
Returns
true - The two doubles are equal.
false - The two doubles are not equal.

Referenced by isApproxEqualPercent().

Here is the caller graph for this function:

◆ isApproxEqualPercent()

bool bst::isApproxEqualPercent ( const double  a,
const double  b,
const double  percent 
)
inline
Todo:
needs to be tested.
Parameters
a
b
percent- value between 0.0 and 1.0
Returns
true
false

References isApproxEqual().

Referenced by validateSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rndTs()

std::string bst::rndTs ( double  d,
int  precision 
)
inline

◆ randomHexString()

std::string bst::randomHexString ( size_t  length)

Generates a random hex string of the given length.

Parameters
length- The length of the string to generate.
Returns
std::string - The generated string.

Referenced by main(), and TEST().

Here is the caller graph for this function:

◆ randomDouble()

double bst::randomDouble ( double  min,
double  max 
)

Generates a random double within the given range.

Parameters
min- The minimum value of the range.
max- The maximum value of the range.
Returns
double - The generated random double.

Referenced by TEST().

Here is the caller graph for this function:

◆ sleep()

void bst::sleep ( int32_t  milliseconds)
inline

Referenced by main(), TEST(), and bst::Process::waitToComplete().

Here is the caller graph for this function:

◆ containsSubstring()

bool bst::containsSubstring ( const std::string &  str,
const std::string &  sub 
)
inline

Checks if a string contains a substring.

Parameters
str- The string to check
sub- The substring to check for
Returns
true - If the string contains the substring
false - If the string does not contain the substring

◆ containsPrefix()

bool bst::containsPrefix ( const std::string &  str,
const std::string &  prefix 
)
inline

Checks if a string contains a prefix.

Parameters
str- The string to check
prefix- The prefix to check for
Returns
true - If the string contains the prefix
false - If the string does not contain the prefix

◆ containsSuffix()

bool bst::containsSuffix ( const std::string &  str,
const std::string &  suffix 
)
inline

Checks if a string contains a suffix.

Parameters
str- The string to check
suffix- The suffix to check for
Returns
true - If the string contains the suffix
false - If the string does not contain the suffix

Variable Documentation

◆ kPrecision

constexpr int bst::kPrecision = 6
inlineconstexpr

◆ K_PIPE_READ

constexpr int bst::K_PIPE_READ = 0
inlineconstexpr

◆ K_PIPE_WRITE

constexpr int bst::K_PIPE_WRITE = 1
inlineconstexpr

◆ PI

constexpr double bst::PI = 3.14159265358979323846
inlineconstexpr

The mathematical constant pi.

◆ HALF_PI

constexpr double bst::HALF_PI = PI / 2.0
inlineconstexpr

Half of pi.

◆ THREE_PI_HALVES

constexpr double bst::THREE_PI_HALVES = 3.0 * HALF_PI
inlineconstexpr

Three halves of pi.

◆ TWO_PI

constexpr double bst::TWO_PI = 2.0 * PI
inlineconstexpr

Two times pi.

◆ D2R

constexpr double bst::D2R = PI / 180.0
inlineconstexpr

Factor to convert degrees to radians.

◆ R2D

constexpr double bst::R2D = 180.0 / PI
inlineconstexpr

Factor to convert radians to degrees.

◆ K_GRAVITY

constexpr double bst::K_GRAVITY = 9.80665
inlineconstexpr

Standard gravity constant.