15.04.2014 - Version 0.3.8_beta, last version of 0.3.8 branch. Too much added and fixed...
This commit is contained in:
75
piincludes.h
75
piincludes.h
@@ -27,7 +27,7 @@
|
||||
#define PIINCLUDES_H
|
||||
|
||||
//! Version of PIP in hex - 0x##(Major)##(Minor)##(Revision)
|
||||
#define PIP_VERSION 0x000307
|
||||
#define PIP_VERSION 0x000308
|
||||
|
||||
//! Major value of PIP version
|
||||
#define PIP_VERSION_MAJOR (PIP_VERSION & 0xFF0000) >> 16
|
||||
@@ -39,7 +39,7 @@
|
||||
#define PIP_VERSION_REVISION PIP_VERSION & 0xFF
|
||||
|
||||
//! Suffix of PIP version
|
||||
#define PIP_VERSION_SUFFIX ""
|
||||
#define PIP_VERSION_SUFFIX "_beta"
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
@@ -269,6 +269,9 @@ extern PIMonitor piMonitor;
|
||||
//! Macro used for infinite wait
|
||||
#define FOREVER_WAIT FOREVER msleep(1);
|
||||
|
||||
//! Macro used for infinite wait
|
||||
#define WAIT_FOREVER FOREVER msleep(1);
|
||||
|
||||
typedef long long llong;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short int ushort;
|
||||
@@ -303,6 +306,23 @@ typedef std::basic_string<wchar_t> wstring;
|
||||
* \details Example:\n \snippet piincludes.cpp swap */
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
|
||||
|
||||
/*! \brief Templated function for swap two values without "="
|
||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||
template<typename T> inline void piSwapBinary(T & f, T & s) {
|
||||
static size_t j = (sizeof(T) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(T);
|
||||
size_t i = 0;
|
||||
for (i = 0; i < j; ++i) {
|
||||
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
||||
((size_t*)(&s))[i] ^= ((size_t*)(&f))[i];
|
||||
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
||||
}
|
||||
for (i = bs; i < bf; ++i) {
|
||||
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
|
||||
((uchar*)(&s))[i] ^= ((uchar*)(&f))[i];
|
||||
((uchar*)(&f))[i] ^= ((uchar*)(&s))[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*! \brief Templated function return round of float falue
|
||||
* \details Round is the nearest integer value \n
|
||||
* There are some macros:
|
||||
@@ -413,6 +433,44 @@ template<typename T> inline T piMax(const T & f, const T & s, const T & t) {retu
|
||||
* \snippet piincludes.cpp clamp */
|
||||
template<typename T> inline T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
|
||||
/// Function inverse byte order in memory block
|
||||
inline void piLetobe(void * data, int size) {
|
||||
for (int i = 0; i < size / 2; i++)
|
||||
piSwap<uchar>(((uchar*)data)[size - i - 1], ((uchar*)data)[i]);
|
||||
}
|
||||
|
||||
/// \brief Templated function that inverse byte order of value "v"
|
||||
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
||||
|
||||
/*! \brief Templated function that returns "v" with inversed byte order
|
||||
* \details This function used to convert values between little and big endian \n
|
||||
* There are some macros:
|
||||
* - \c piLetobes for "ushort"
|
||||
* - \c piLetobei for "uint"
|
||||
* - \c piLetobel for "ulong"
|
||||
* - \c piLetobell for "ullong"
|
||||
*
|
||||
* Example:
|
||||
* \snippet piincludes.cpp letobe */
|
||||
template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;}
|
||||
|
||||
// specialization
|
||||
template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
__attribute__((deprecated)) inline ushort letobe_s(const ushort & v) {return (v << 8) | (v >> 8);}
|
||||
__attribute__((deprecated)) inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
/// \deprecated \brief Use \a piLetobe() instead of this function
|
||||
ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
|
||||
/// \deprecated \brief Use \a piLetobe() instead of this function
|
||||
uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
|
||||
#endif
|
||||
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piFloorf piFloor<float>
|
||||
@@ -443,6 +501,10 @@ template<typename T> inline T piClamp(const T & v, const T & min, const T & max)
|
||||
#define piClampll piClamp<llong>
|
||||
#define piClampf piClamp<float>
|
||||
#define piClampd piClamp<double>
|
||||
#define piLetobes piLetobe<ushort>
|
||||
#define piLetobei piLetobe<uint>
|
||||
#define piLetobel piLetobe<ulong>
|
||||
#define piLetobell piLetobe<ullong>
|
||||
|
||||
extern bool isPIInit;
|
||||
|
||||
@@ -472,13 +534,6 @@ inline int random() {return rand();}
|
||||
inline double round(const double & v) {return floor(v + 0.5);}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
inline uint letobe_i(uint v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
//inline ullong letobe_ll(ullong v) {return (v >> 56) | ((v >> 40) & 0xFF00L) | ((v >> 24) & 0xFF0000L) | ((v >> 8) & 0xFF000000L) | ((v << 8) & 0xFF00000000L) | ((v << 24) & 0xFF0000000000L) | ((v << 40) & 0xFF000000000000L) | ((v << 56) & 0xFF00000000000000L);}
|
||||
inline void letobe_s(ushort * v) {*v = letobe_s(*v);}
|
||||
inline void letobe_i(uint * v) {*v = letobe_i(*v);}
|
||||
//inline void letobe_ll(ullong * v) {*v = letobe_ll(*v);}
|
||||
inline bool atob(const string & str) {return str == "1" ? true : false;}
|
||||
inline string btos(const bool num) {return num ? "0" : "1";}
|
||||
inline string itos(const int num) {
|
||||
@@ -755,7 +810,7 @@ public:
|
||||
PICout operator <<(const string & v) {space(); quote(); std::cout << v; quote(); return *this;}
|
||||
|
||||
//! Output operator for boolean values
|
||||
PICout operator <<(const bool v) {space(); std::cout << v; return *this;}
|
||||
PICout operator <<(const bool v) {space(); std::cout << (v ? "true" : "false"); return *this;}
|
||||
|
||||
//! Output operator for <tt>"char"</tt> values
|
||||
PICout operator <<(const char v) {space(); std::cout << v; return *this;}
|
||||
|
||||
Reference in New Issue
Block a user