Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
common Namespace Reference

Namespace of common utility classes and methods. More...

Namespaces

namespace  ptreesupport
 ptree operator support

Classes

class  UniqueKey
 Set of unique keys. More...
class  FlagBlocker
 Flips a flag for the lifetime of the class object. More...
class  Resetter
 Sets a variable for the lifetime of the class object. More...
class  ContainerAdapterExtension
 stl container adapter extension for accessing the underlying container. More...
struct  Interval
 An interval describes the area between two numbers. It is understood to contain the near one and exlude the far. More...

Enumerations

enum class  TextColor {
  black = 0 , dark_blue = 1 , dark_green = 2 , light_blue = 3 ,
  dark_red = 4 , magenta = 5 , orange = 6 , light_gray = 7 ,
  gray = 8 , blue = 9 , green = 10 , cyan = 11 ,
  red = 12 , pink = 13 , yellow = 14 , white = 15 ,
  reset = light_gray
}
enum class  BackgroundColor {
  black = 0 , dark_blue = 1 , dark_green = 2 , light_blue = 3 ,
  dark_red = 4 , magenta = 5 , orange = 6 , light_gray = 7 ,
  gray = 8 , blue = 9 , green = 10 , cyan = 11 ,
  red = 12 , pink = 13 , yellow = 14 , white = 15 ,
  reset = black
}

Functions

template<typename T>
constexpr T Square (T val) noexcept
 This is usefull because it saves a temp.
template<typename T>
constexpr T Cube (T val) noexcept
template<int Y, typename T>
constexpr T pow (T val) noexcept
 power function with templated integer exponent.
template<typename T>
constexpr bool Equals (T a, T b, T epsilon) noexcept
 Tests equality in the sense |a-b| < epsilon.
template<typename T>
constexpr auto Sign (T val) noexcept -> decltype(T{}/T{})
constexpr int Factorial (int n)
template<typename T1, typename T2>
T1 Clip (T1 &val, const T2 &min, const T2 &max) noexcept
 Clips a val to a specified range.
template<class T>
constexpr const T & Clamp (const T &v, const T &lo, const T &hi) noexcept
 Clips a val to a specified range.
template<typename T1, typename T2>
T1 Wrap (const T1 &val, const T2 &min, const T2 &max) noexcept
 Wraps a val to a specified range as if max would be actually min.
template<class T>
Round (T value, int toDigit) noexcept
 Rounding of floating point number to a certain digit aftzer the point.
template<typename Valtype>
Valtype DealDenormalizedNumbers (Valtype val)
 Make too small numbers zero.
template<typename Valtype>
constexpr Valtype FirstPearl (int cntPearls, Valtype distPearls) noexcept
 Center an equidistant row of elements (pearls).
char to_uppercase (unsigned char c)
char to_lowercase (unsigned char c)
std::string quoted (const std::string &str)
 Construct a quoted string.
std::string StripApostrophes (const std::string &str)
 Removes the outmost apostrophes (''' and '"') from a string. Does nothing if the string isn't properly enclosed with apostrophes.
std::string StripReservedCharacters (const std::string &str)
 Removes characters that might not be allowed for file names.
std::string Indent (int indent)
 Needed since for unknown reason, the straightforward implementation std::string{ indent, ' ' } does not work.
template<typename Valtype>
Valtype AttenuateValue (Valtype value, Valtype dattenuation) noexcept
 Attenuates value by the factor dattenuation.
template<typename Valtype>
constexpr Valtype Collision (Valtype m1, Valtype m2, Valtype v1, Valtype v2, Valtype k)
 Calculates the impulse change of body 1 in a collision event.
void TranslateEscapeCharacters (std::string &string)
std::string utf8_to_string (const std::string &utf8str, const std::locale &loc=std::locale(""))
 convert multibyte character string (UTF-8) to ANSI string.
template<typename Valtype>
constexpr bool Intersecting (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool IntersectingClosed (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool IntersectingOpen (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool Touching (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr Interval< Valtype > Intersection (const Interval< Valtype > &intersected, const Interval< Valtype > &with) noexcept
template<class Valtype, class EvalFuncType>
void Sample (const common::Interval< Valtype > range, const EvalFuncType Evaluate)
 Samples an evaluating function inside an interval.
template<typename Target, typename Source>
Target narrow_cast (Source v)
 Safe cast for casting numeric values.
template<typename Target, typename Source>
std::unique_ptr< Target > dynamic_unique_cast (std::unique_ptr< Source > &&source)
std::ostream & operator<< (std::ostream &stream, TextColor color)
std::ostream & operator<< (std::ostream &stream, BackgroundColor color)
std::ostream & rendl (std::ostream &stream)
void StreamInHead (std::istream &is, const std::string &head)
Mathematical Operators for Interval
template<typename Valtype>
void operator+= (Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator+ (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator+ (const Interval< Valtype > &i1, Valtype l) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator+ (Valtype l, const Interval< Valtype > &i1) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator+ (const Interval< Valtype > &i1) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator- (const Interval< Valtype > &i1, Valtype l) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator- (Valtype l, const Interval< Valtype > &i1) noexcept
 Interval operator.
template<typename Valtype>
constexpr Interval< Valtype > operator- (const Interval< Valtype > &i1) noexcept
 Interval operator.
template<typename Valtype, typename Valtype2>
constexpr auto operator* (const Interval< Valtype > &i1, Valtype2 scalar) noexcept -> Interval< decltype(Valtype{} *Valtype2{})>
 Interval operator.
template<typename Valtype, typename Valtype2>
constexpr auto operator* (Valtype scalar, const Interval< Valtype2 > &i1) noexcept -> Interval< decltype(Valtype{} *Valtype2{})>
 Interval operator.
template<typename Valtype, typename Valtype2>
constexpr Interval< Valtype > & operator*= (Interval< Valtype > &i1, Valtype2 scalar) noexcept
 Interval operator.
template<typename Valtype, typename Valtype2>
constexpr auto operator/ (const Interval< Valtype > &i1, Valtype2 scalar) noexcept -> Interval< decltype(Valtype{}/Valtype2{})>
 Interval operator.
template<typename Valtype, typename Valtype2>
constexpr Interval< Valtype > & operator/= (Interval< Valtype > &i1, Valtype2 scalar) noexcept
 Interval operator.
template<typename Valtype>
constexpr bool operator< (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool operator> (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool SmallerClosed (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool SmallerOpen (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool GreaterClosed (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool GreaterOpen (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
template<typename Valtype>
constexpr bool operator== (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
 Interval operator.
template<typename Valtype>
constexpr bool operator!= (const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
 Interval operator.
Streaming functions for Interval

Streams data out and in.

template<typename Valtype>
std::ostream & operator<< (std::ostream &os, const common::Interval< Valtype > &i)
 Streams Interval data out.
template<typename Valtype>
std::istream & operator>> (std::istream &is, common::Interval< Valtype > &i)
 Streams Interval data in.

Detailed Description

Namespace of common utility classes and methods.

Function Documentation

◆ AttenuateValue()

template<typename Valtype>
Valtype common::AttenuateValue ( Valtype value,
Valtype dattenuation )
inlinenoexcept

Attenuates value by the factor dattenuation.

Handles sign and zeroes the result for dattenuation > 1

◆ Clamp()

template<class T>
const T & common::Clamp ( const T & v,
const T & lo,
const T & hi )
constexprnoexcept

Clips a val to a specified range.

Use std::clamp instead.

◆ Clip()

template<typename T1, typename T2>
T1 common::Clip ( T1 & val,
const T2 & min,
const T2 & max )
inlinenoexcept

Clips a val to a specified range.

Parameters
valReferenceValue to clip.
minlower clip range.
maxupper clip range.
Returns
the clipped value.

◆ Collision()

template<typename Valtype>
Valtype common::Collision ( Valtype m1,
Valtype m2,
Valtype v1,
Valtype v2,
Valtype k )
constexpr

Calculates the impulse change of body 1 in a collision event.

Parameters
m1Mass of body 1
m2Mass of body 2
v1Velocity of body 1
v2Velocity of body 2
kcollision module. 0: inelastic ciollision; 1: elastic collision.
Returns
Chnage of impulse of body1 (body2 would be the negative of this value)

◆ Cube()

template<typename T>
T common::Cube ( T val)
inlineconstexprnoexcept
Returns
val risen to the third power.
Deprecated
use std::pow(val,3) or pow<3>(val) instead

◆ DealDenormalizedNumbers()

template<typename Valtype>
Valtype common::DealDenormalizedNumbers ( Valtype val)
inline

Make too small numbers zero.

Deals with subnormal numbers.

◆ Factorial()

int common::Factorial ( int n)
inlineconstexpr
Returns
n!

◆ FirstPearl()

template<typename Valtype>
Valtype common::FirstPearl ( int cntPearls,
Valtype distPearls )
inlineconstexprnoexcept

Center an equidistant row of elements (pearls).

Parameters
cntPearlsNumber of elements.
distPearlsdistance between elements.
Returns
The position of the 'leftmost' element.

◆ GreaterClosed()

template<typename Valtype>
bool common::GreaterClosed ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is lesser than any point in i1, including borders.

◆ GreaterOpen()

template<typename Valtype>
bool common::GreaterOpen ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is lesser than any point in i1, excluding borders.

◆ Intersecting()

template<typename Valtype>
bool common::Intersecting ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if the two intervals have a section in common, including Near() and excluding Far().

◆ IntersectingClosed()

template<typename Valtype>
bool common::IntersectingClosed ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if the two intervals have a section in common, including borders.

◆ IntersectingOpen()

template<typename Valtype>
bool common::IntersectingOpen ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if the two intervals have a section in common, excluding borders.

◆ Intersection()

template<typename Valtype>
Interval< Valtype > common::Intersection ( const Interval< Valtype > & intersected,
const Interval< Valtype > & with )
constexprnoexcept
Returns
The common section as an Interval with the same normal state as i1. If the two intervals do not intersect, the result will be {0,0}.
Parameters
intersectedInterval that is interseced; governs the normal state of the result.
withInterval to intersect with.

◆ narrow_cast()

template<typename Target, typename Source>
Target common::narrow_cast ( Source v)
inline

Safe cast for casting numeric values.

Exceptions
std::runtime_errorif the value would be to big to fit into a smaller type.

◆ operator<()

template<typename Valtype>
bool common::operator< ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is greater than any point in i1.

◆ operator>()

template<typename Valtype>
bool common::operator> ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is lesser than any point in i1.

◆ Round()

template<class T>
T common::Round ( T value,
int toDigit )
inlinenoexcept

Rounding of floating point number to a certain digit aftzer the point.

Parameters
valueInput value to round
toDigitOrdinal number of the digit to round to. 0 would round to integral number.
Returns
The rounded number.

◆ Sample()

template<class Valtype, class EvalFuncType>
void common::Sample ( const common::Interval< Valtype > range,
const EvalFuncType Evaluate )

Samples an evaluating function inside an interval.

Template Parameters
EvalFuncTypecan be function pointer, functor or lambda: Valtype(*)( Valtype ). It returns the distance for the next sample.
Parameters
rangeinterval to sample
Evaluateevaluation function

◆ Sign()

template<typename T>
auto common::Sign ( T val) ->decltype(T{}/T{})
inlineconstexprnoexcept
Returns
+1 if val > 0, -1 if val < 0, 0 if val == 0.

◆ SmallerClosed()

template<typename Valtype>
bool common::SmallerClosed ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is greater than any point in i1, including borders.

◆ SmallerOpen()

template<typename Valtype>
bool common::SmallerOpen ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept
Returns
true if every point in i2 is lesser than any point in i1, excluding borders.

◆ Square()

template<typename T>
T common::Square ( T val)
inlineconstexprnoexcept

This is usefull because it saves a temp.

Parameters
valValue to be squared.
Returns
the square of val.
Deprecated
use std::pow(val,2) or pow<2>(val) instead

◆ Touching()

template<typename Valtype>
bool common::Touching ( const Interval< Valtype > & i1,
const Interval< Valtype > & i2 )
inlineconstexprnoexcept

Two intervals touch, if the distance between them is insignificant (with respect to std::numeric_limits<Valtype>::epsilon()). Intersecting intervals always touch.

Returns
true if the two intervals have a section in common or are at least adjacent.

◆ Wrap()

template<typename T1, typename T2>
T1 common::Wrap ( const T1 & val,
const T2 & min,
const T2 & max )
inlinenoexcept

Wraps a val to a specified range as if max would be actually min.

Parameters
valReferenceValue to wrap.
minlower wrap range.
maxupper wrap range.
Returns
the wrapped value.