PIP 5.5.3
Platform-Independent Primitives
Classes | Functions | Variables
pibase.h File Reference

Base types and functions. More...

#include "pibase_macros.h"
#include "pimemoryblock.h"
#include "pip_export.h"
#include <string.h>
#include <ArduinoSTL.h>
#include <atomic>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <limits>

Classes

class  PIScopeExitCall
 Class for executing a function upon scope exit. More...
 
struct  PINonTriviallyCopyable
 Inherit from this class to make your class non-trivially copyable. More...
 

Functions

template<typename T >
void piSwap (T &f, T &s)
 Templated function for swap two values. More...
 
template<typename T >
void piSwapBinary (T &f, T &s)
 Templated function for swap two values without "=". More...
 
bool piCompareBinary (const void *f, const void *s, size_t size)
 Function for compare two values without "==" by raw content. More...
 
template<typename T >
constexpr int piRound (const T &v)
 Templated function return round of float falue. More...
 
template<typename T >
constexpr int piFloor (const T &v)
 Templated function return floor of float falue. More...
 
template<typename T >
constexpr int piCeil (const T &v)
 Templated function return ceil of float falue. More...
 
template<typename T >
constexpr T piAbs (const T &v)
 Templated function return absolute of numeric falue. More...
 
template<typename T , typename... Args>
constexpr T piMin (const T &f, const T &s, const Args &... args)
 Templated function return minimum of several values. More...
 
template<typename T , typename... Args>
constexpr T piMax (const T &f, const T &s, const Args &... args)
 Templated function return maximum of several values. More...
 
template<typename T >
constexpr T piClamp (const T &v, const T &min, const T &max)
 Templated function return clamped value. More...
 
template<typename T >
bool piCompare (const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon())
 Function for compare two numeric values with epsilon. More...
 
void piChangeEndianBinary (void *data, size_t size)
 Function inverse byte order in memory block ([1..N] -> [N..1])
 
void piChangeEndianBinary (PIMemoryBlock mem_blk)
 Function inverse byte order in memory block ([1..N] -> [N..1])
 
template<typename T >
void piChangeEndian (T &v)
 Templated function that inverse byte order of value "v".
 
template<typename T >
piChangedEndian (const T &v)
 Templated function that returns value "v" with inversed byte order.
 
uint piHashData (const uchar *data, uint len, uint seed=0)
 Generic hash function, implements murmur3/32 algorithm.
 
void piZeroMemory (void *ptr, size_t size)
 Zero "size" bytes by address "ptr".
 
template<typename T >
void piZeroMemory (T &v)
 Zero variable "v" memory.
 
template<typename T >
void piDeleteAll (const T &container)
 Call delete on each "container" element.
 
template<typename T >
void piDeleteAll (std::initializer_list< T > container)
 Call delete on each element of C++11 initializer list.
 
template<typename T >
void piDeleteAllAndClear (T &container)
 Call delete on each "container" element and clear container.
 
template<typename T >
bool piDeleteSafety (T *&pointer)
 Call delete if "pointer" is not null and set it to null. Returns if deleted.
 

Variables

bool piDebug
 Global variable enabling output to piCout, default is true.
 
double piMountInfoRefreshIntervalMs
 Global variable that set minimum real update interval for function PIInit::mountInfo(), default is 10000 ms.
 

Detailed Description

Base types and functions.

This file implements first layer above the system and declares some basic useful functions

Function Documentation

◆ piSwap()

template<typename T >
void piSwap ( T &  f,
T &  s 
)
inline

Templated function for swap two values.

Example:

int v1 = 1, v2 = 2;
piCout << v1 << v2; // 1 2
piSwap<int>(v1, v2);
piCout << v1 << v2; // 2 1
#define piCout
Macro used for conditional (piDebug) output to PICout(StdOut)
Definition: picout.h:35

◆ piSwapBinary()

template<typename T >
void piSwapBinary ( T &  f,
T &  s 
)
inline

Templated function for swap two values without "=".

Example:

◆ piCompareBinary()

bool piCompareBinary ( const void *  f,
const void *  s,
size_t  size 
)
inline

Function for compare two values without "==" by raw content.

Example:

◆ piRound()

template<typename T >
constexpr int piRound ( const T &  v)
inlineconstexpr

Templated function return round of float falue.

Round is the nearest integer value
There are some macros:

  • piRoundf for "float"
  • piRoundd for "double"

Example:

piCout << piRoundf(0.6f) << piRoundd(0.2); // 1 0
piCout << piRoundf(-0.6f) << piRoundd(-0.2); // -1 0

◆ piFloor()

template<typename T >
constexpr int piFloor ( const T &  v)
inlineconstexpr

Templated function return floor of float falue.

Floor is the largest integer that is not greater than "v"
There are some macros:

  • piFloorf for "float"
  • piFloord for "double"

Example:

piCout << piFloorf(0.6f) << piFloorf(0.2); // 0 0
piCout << piFloorf(-0.6f) << piFloorf(-0.2f); // -1 -1

◆ piCeil()

template<typename T >
constexpr int piCeil ( const T &  v)
inlineconstexpr

Templated function return ceil of float falue.

Ceil is the smallest integer that is not less than "v"
There are some macros:

  • piCeilf for "float"
  • piCeild for "double"

Example:

piCout << piCeilf(0.6f) << piCeilf(0.2); // 1 1
piCout << piCeilf(-0.6f) << piCeilf(-0.2f); // 0 0

◆ piAbs()

template<typename T >
constexpr T piAbs ( const T &  v)
inlineconstexpr

Templated function return absolute of numeric falue.

Absolute is the positive or equal 0 value
There are some macros:

  • piAbss for "short"
  • piAbsi for "int"
  • piAbsl for "long"
  • piAbsll for "llong"
  • piAbsf for "float"
  • piAbsd for "double"

Example:

piCout << piAbsi(5) << piAbsi(-11); // 5 11
piCout << piAbsf(-0.6f) << piAbsf(-0.2f); // 0.6 0.2

◆ piMin()

template<typename T , typename... Args>
constexpr T piMin ( const T &  f,
const T &  s,
const Args &...  args 
)
constexpr

Templated function return minimum of several values.

There are some macros:

  • piMins for "short"
  • piMini for "int"
  • piMinl for "long"
  • piMinll for "llong"
  • piMinf for "float"
  • piMind for "double"

Example:

piCout << piMini(5, 1); // 1
piCout << piMinf(-0.6f, -0.2f); // -0.6

◆ piMax()

template<typename T , typename... Args>
constexpr T piMax ( const T &  f,
const T &  s,
const Args &...  args 
)
constexpr

Templated function return maximum of several values.

There are some macros:

  • piMaxs for "short"
  • piMaxi for "int"
  • piMaxl for "long"
  • piMaxll for "llong"
  • piMaxf for "float"
  • piMaxd for "double"

Example:

piCout << piMaxi(5, 1); // 5
piCout << piMaxf(-0.6f, -0.2f); // -0.2

◆ piClamp()

template<typename T >
constexpr T piClamp ( const T &  v,
const T &  min,
const T &  max 
)
inlineconstexpr

Templated function return clamped value.

Clamped is the not greater than "max" and not lesser than "min" value
There are some macros:

  • piClamps for "short"
  • piClampi for "int"
  • piClampl for "long"
  • piClampll for "llong"
  • piClampf for "float"
  • piClampd for "double"

Example:

piCout << piClampf(-5, -3, 2); // -3
piCout << piClampf(1, -3, 2); // 1
piCout << piClampf(5, -3, 2); // 2

◆ piCompare()

template<typename T >
bool piCompare ( const T &  a,
const T &  b,
const T &  epsilon = std::numeric_limits<T>::epsilon() 
)
inline

Function for compare two numeric values with epsilon.

There are some macros:

  • piComparef for "float"
  • piCompared for "double"

Example: