code format
This commit is contained in:
@@ -11,33 +11,34 @@
|
||||
* \~russian
|
||||
* Этот файл реализует первый слой после системы и объявляет
|
||||
* несколько базовых полезных методов
|
||||
*/
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Base types and functions
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Base types and functions
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIBASE_H
|
||||
#define PIBASE_H
|
||||
|
||||
#include "pip_defs.h"
|
||||
#include "pip_export.h"
|
||||
#include "pip_version.h"
|
||||
#include "piplatform.h"
|
||||
#include "pip_export.h"
|
||||
#include "pip_defs.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
//! \~english
|
||||
@@ -204,184 +205,195 @@
|
||||
//! \~russian Макрос для подавления предупреждения компилятора о неиспользуемой переменной
|
||||
# define NO_UNUSED(x)
|
||||
|
||||
#undef MICRO_PIP
|
||||
#undef FREERTOS
|
||||
#endif //DOXYGEN
|
||||
# undef MICRO_PIP
|
||||
# undef FREERTOS
|
||||
#endif // DOXYGEN
|
||||
|
||||
#ifdef CC_AVR_GCC
|
||||
# include <ArduinoSTL.h>
|
||||
#endif
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_VC
|
||||
# define SHUT_RDWR 2
|
||||
# pragma comment(lib, "Ws2_32.lib")
|
||||
# pragma comment(lib, "Iphlpapi.lib")
|
||||
# pragma comment(lib, "Psapi.lib")
|
||||
# ifdef ARCH_BITS_32
|
||||
# define _X86_
|
||||
# else
|
||||
# define _IA64_
|
||||
# endif
|
||||
# define SHUT_RDWR 2
|
||||
# pragma comment(lib, "Ws2_32.lib")
|
||||
# pragma comment(lib, "Iphlpapi.lib")
|
||||
# pragma comment(lib, "Psapi.lib")
|
||||
# ifdef ARCH_BITS_32
|
||||
# define _X86_
|
||||
# else
|
||||
# define _IA64_
|
||||
# endif
|
||||
# else
|
||||
# define SHUT_RDWR SD_BOTH
|
||||
# define SHUT_RDWR SD_BOTH
|
||||
# endif
|
||||
typedef int socklen_t;
|
||||
extern long long __pi_perf_freq;
|
||||
typedef int socklen_t;
|
||||
extern long long __pi_perf_freq;
|
||||
#endif
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
#ifdef ANDROID
|
||||
///# define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
||||
//inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
|
||||
//inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;}
|
||||
#endif
|
||||
|
||||
#ifdef MAC_OS
|
||||
# define environ (*_NSGetEnviron())
|
||||
typedef long time_t;
|
||||
#endif
|
||||
|
||||
#ifdef LINUX
|
||||
# define environ __environ
|
||||
#endif
|
||||
|
||||
#ifdef FREE_BSD
|
||||
extern char ** environ;
|
||||
#endif
|
||||
|
||||
#ifndef NO_UNUSED
|
||||
# define NO_UNUSED(x) (void)x
|
||||
#endif
|
||||
|
||||
#ifndef assert
|
||||
# define assert(x)
|
||||
# define assertm(exp, msg)
|
||||
#else
|
||||
# define assertm(exp, msg) assert(((void)msg, exp))
|
||||
#endif
|
||||
|
||||
#ifdef MICRO_PIP
|
||||
# define __PIP_TYPENAME__(T) "?"
|
||||
#else
|
||||
# define __PIP_TYPENAME__(T) typeid(T).name()
|
||||
#endif
|
||||
|
||||
#ifdef CC_GCC
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __attribute__((deprecated))
|
||||
# define DEPRECATEDM(msg) __attribute__((deprecated(msg)))
|
||||
# if CC_GCC_VERSION > 0x025F // > 2.95
|
||||
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
# ifdef LINUX
|
||||
# define HAS_LOCALE
|
||||
# endif
|
||||
# ifdef MAC_OS
|
||||
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
|
||||
# pragma GCC diagnostic ignored "-Wc++11-extensions"
|
||||
# endif
|
||||
# endif
|
||||
# ifdef ANDROID
|
||||
# pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
# pragma GCC diagnostic ignored "-Wextra"
|
||||
# pragma GCC diagnostic ignored "-Wc++11-extensions"
|
||||
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
|
||||
//# pragma GCC diagnostic ignored "-Wliteral-suffix"
|
||||
/// # define tcdrain(fd) ioctl(fd, TCSBRK, 1)
|
||||
// inline int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
|
||||
// inline int mbtowc(wchar_t * w, const char * c, size_t) {*w = ((wchar_t * )&c)[0]; return 1;}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CC_VC
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __declspec(deprecated)
|
||||
# define DEPRECATEDM(msg) __declspec(deprecated(msg))
|
||||
# pragma warning(disable: 4018)
|
||||
# pragma warning(disable: 4061)
|
||||
# pragma warning(disable: 4100)
|
||||
# pragma warning(disable: 4239)
|
||||
# pragma warning(disable: 4242)
|
||||
# pragma warning(disable: 4244)
|
||||
# pragma warning(disable: 4251)
|
||||
# pragma warning(disable: 4365)
|
||||
# pragma warning(disable: 4512)
|
||||
# pragma warning(disable: 4668)
|
||||
# pragma warning(disable: 4710)
|
||||
# pragma warning(disable: 4800)
|
||||
# pragma warning(disable: 4820)
|
||||
# pragma warning(disable: 4986)
|
||||
# pragma warning(disable: 4996)
|
||||
# ifdef ARCH_BITS_32
|
||||
typedef long ssize_t;
|
||||
# ifdef MAC_OS
|
||||
# define environ (*_NSGetEnviron())
|
||||
typedef long time_t;
|
||||
# endif
|
||||
|
||||
# ifdef LINUX
|
||||
# define environ __environ
|
||||
# endif
|
||||
|
||||
# ifdef FREE_BSD
|
||||
extern char ** environ;
|
||||
# endif
|
||||
|
||||
# ifndef NO_UNUSED
|
||||
# define NO_UNUSED(x) (void)x
|
||||
# endif
|
||||
|
||||
# ifndef assert
|
||||
# define assert(x)
|
||||
# define assertm(exp, msg)
|
||||
# else
|
||||
typedef long long ssize_t;
|
||||
# define assertm(exp, msg) assert(((void)msg, exp))
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CC_OTHER
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED
|
||||
# define DEPRECATEDM(msg)
|
||||
#endif
|
||||
# ifdef MICRO_PIP
|
||||
# define __PIP_TYPENAME__(T) "?"
|
||||
# else
|
||||
# define __PIP_TYPENAME__(T) typeid(T).name()
|
||||
# endif
|
||||
|
||||
#endif //DOXYGEN
|
||||
# ifdef CC_GCC
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __attribute__((deprecated))
|
||||
# define DEPRECATEDM(msg) __attribute__((deprecated(msg)))
|
||||
# if CC_GCC_VERSION > 0x025F // > 2.95
|
||||
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
||||
# ifdef LINUX
|
||||
# define HAS_LOCALE
|
||||
# endif
|
||||
# ifdef MAC_OS
|
||||
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
|
||||
# pragma GCC diagnostic ignored "-Wc++11-extensions"
|
||||
# endif
|
||||
# endif
|
||||
# ifdef ANDROID
|
||||
# pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
# pragma GCC diagnostic ignored "-Wextra"
|
||||
# pragma GCC diagnostic ignored "-Wc++11-extensions"
|
||||
# pragma GCC diagnostic ignored "-Wundefined-bool-conversion"
|
||||
// # pragma GCC diagnostic ignored "-Wliteral-suffix"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef CC_VC
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED __declspec(deprecated)
|
||||
# define DEPRECATEDM(msg) __declspec(deprecated(msg))
|
||||
# pragma warning(disable: 4018)
|
||||
# pragma warning(disable: 4061)
|
||||
# pragma warning(disable: 4100)
|
||||
# pragma warning(disable: 4239)
|
||||
# pragma warning(disable: 4242)
|
||||
# pragma warning(disable: 4244)
|
||||
# pragma warning(disable: 4251)
|
||||
# pragma warning(disable: 4365)
|
||||
# pragma warning(disable: 4512)
|
||||
# pragma warning(disable: 4668)
|
||||
# pragma warning(disable: 4710)
|
||||
# pragma warning(disable: 4800)
|
||||
# pragma warning(disable: 4820)
|
||||
# pragma warning(disable: 4986)
|
||||
# pragma warning(disable: 4996)
|
||||
# ifdef ARCH_BITS_32
|
||||
typedef long ssize_t;
|
||||
# else
|
||||
typedef long long ssize_t;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef CC_OTHER
|
||||
# undef DEPRECATED
|
||||
# undef DEPRECATEDM
|
||||
# define DEPRECATED
|
||||
# define DEPRECATEDM(msg)
|
||||
# endif
|
||||
|
||||
#endif // DOXYGEN
|
||||
// Private data macros
|
||||
#ifndef DOXYGEN
|
||||
|
||||
#define PRIVATE_DECLARATION(e) \
|
||||
struct __Private__; \
|
||||
friend struct __Private__; \
|
||||
struct e __PrivateInitializer__ { \
|
||||
__PrivateInitializer__(); \
|
||||
__PrivateInitializer__(const __PrivateInitializer__ & o); \
|
||||
~__PrivateInitializer__(); \
|
||||
__PrivateInitializer__ & operator =(const __PrivateInitializer__ & o); \
|
||||
__Private__ * p; \
|
||||
}; \
|
||||
__PrivateInitializer__ __privateinitializer__;
|
||||
# define PRIVATE_DECLARATION(e) \
|
||||
struct __Private__; \
|
||||
friend struct __Private__; \
|
||||
struct e __PrivateInitializer__ { \
|
||||
__PrivateInitializer__(); \
|
||||
__PrivateInitializer__(const __PrivateInitializer__ & o); \
|
||||
~__PrivateInitializer__(); \
|
||||
__PrivateInitializer__ & operator=(const __PrivateInitializer__ & o); \
|
||||
__Private__ * p; \
|
||||
}; \
|
||||
__PrivateInitializer__ __privateinitializer__;
|
||||
|
||||
#define PRIVATE_DEFINITION_START(c) \
|
||||
struct c::__Private__ {
|
||||
# define PRIVATE_DEFINITION_START(c) struct c::__Private__ {
|
||||
# define PRIVATE_DEFINITION_END(c) \
|
||||
} \
|
||||
; \
|
||||
c::__PrivateInitializer__::__PrivateInitializer__() { \
|
||||
p = new c::__Private__(); \
|
||||
} \
|
||||
c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ &) { /*if (p) delete p;*/ \
|
||||
p = new c::__Private__(); \
|
||||
} \
|
||||
c::__PrivateInitializer__::~__PrivateInitializer__() { \
|
||||
delete p; \
|
||||
p = 0; \
|
||||
} \
|
||||
c::__PrivateInitializer__ & c::__PrivateInitializer__::operator=(const c::__PrivateInitializer__ &) { \
|
||||
if (p) delete p; \
|
||||
p = new c::__Private__(); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
#define PRIVATE_DEFINITION_END(c) \
|
||||
}; \
|
||||
c::__PrivateInitializer__::__PrivateInitializer__() {p = new c::__Private__();} \
|
||||
c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ & ) {/*if (p) delete p;*/ p = new c::__Private__();} \
|
||||
c::__PrivateInitializer__::~__PrivateInitializer__() {delete p; p = 0;} \
|
||||
c::__PrivateInitializer__ & c::__PrivateInitializer__::operator =(const c::__PrivateInitializer__ & ) {if (p) delete p; p = new c::__Private__(); return *this;}
|
||||
# define PRIVATE (__privateinitializer__.p)
|
||||
# define PRIVATEWB __privateinitializer__.p
|
||||
|
||||
#define PRIVATE (__privateinitializer__.p)
|
||||
#define PRIVATEWB __privateinitializer__.p
|
||||
#endif // DOXYGEN
|
||||
|
||||
#endif //DOXYGEN
|
||||
|
||||
#define NO_COPY_CLASS(name) \
|
||||
name(const name&) = delete; \
|
||||
name& operator=(const name&) = delete;
|
||||
#define NO_COPY_CLASS(name) \
|
||||
name(const name &) = delete; \
|
||||
name & operator=(const name &) = delete;
|
||||
|
||||
|
||||
#define _PIP_ADD_COUNTER_WS(a, cnt, line) a##cnt##_##line
|
||||
#define _PIP_ADD_COUNTER_WF(a, cnt, line) _PIP_ADD_COUNTER_WS(a, cnt, line)
|
||||
#define _PIP_ADD_COUNTER(a) _PIP_ADD_COUNTER_WF(a, __COUNTER__, __LINE__)
|
||||
#define _PIP_ADD_COUNTER(a) _PIP_ADD_COUNTER_WF(a, __COUNTER__, __LINE__)
|
||||
|
||||
|
||||
#define STATIC_INITIALIZER_BEGIN \
|
||||
class { \
|
||||
class _Initializer_ { \
|
||||
public: \
|
||||
class { \
|
||||
class _Initializer_ { \
|
||||
public: \
|
||||
_Initializer_() {
|
||||
|
||||
#define STATIC_INITIALIZER_END \
|
||||
} \
|
||||
} _initializer_; \
|
||||
} _PIP_ADD_COUNTER(_pip_initializer_);
|
||||
} \
|
||||
} \
|
||||
_initializer_; \
|
||||
} \
|
||||
_PIP_ADD_COUNTER(_pip_initializer_);
|
||||
|
||||
|
||||
//! \~\brief
|
||||
@@ -392,9 +404,9 @@
|
||||
//! \~russian Используется в \a piMinSleep(), \a PIThread, \a PITimer::Pool. По умолчанию равна 1мс.
|
||||
#ifndef PIP_MIN_MSLEEP
|
||||
# ifndef MICRO_PIP
|
||||
# define PIP_MIN_MSLEEP 1.
|
||||
# define PIP_MIN_MSLEEP 1.
|
||||
# else
|
||||
# define PIP_MIN_MSLEEP 10.
|
||||
# define PIP_MIN_MSLEEP 10.
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -402,7 +414,7 @@
|
||||
//! \~\brief
|
||||
//! \~english Macro used for infinite loop
|
||||
//! \~russian Макрос для бесконечного цикла
|
||||
#define FOREVER for (;;)
|
||||
#define FOREVER for (;;)
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Macro used for infinite wait
|
||||
@@ -441,7 +453,12 @@ typedef long double ldouble;
|
||||
//! \~\details
|
||||
//! \~english Example:\n \snippet piincludes.cpp swap
|
||||
//! \~russian Пример:\n \snippet piincludes.cpp swap
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t(std::move(f)); f = std::move(s); s = std::move(t);}
|
||||
template<typename T>
|
||||
inline void piSwap(T & f, T & s) {
|
||||
T t(std::move(f));
|
||||
f = std::move(s);
|
||||
s = std::move(t);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function for swap two values without "="
|
||||
@@ -449,36 +466,38 @@ template<typename T> inline void piSwap(T & f, T & s) {T t(std::move(f)); f = st
|
||||
//! \~\details
|
||||
//! \~english Example:\n \snippet piincludes.cpp swapBinary
|
||||
//! \~russian Пример:\n \snippet piincludes.cpp swapBinary
|
||||
template<typename T> inline void piSwapBinary(T & f, T & s) {
|
||||
if ((size_t*)&f == (size_t*)&s) return;
|
||||
template<typename T>
|
||||
inline void piSwapBinary(T & f, T & s) {
|
||||
if ((size_t *)&f == (size_t *)&s) return;
|
||||
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];
|
||||
((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];
|
||||
((uchar *)(&f))[i] ^= ((uchar *)(&s))[i];
|
||||
((uchar *)(&s))[i] ^= ((uchar *)(&f))[i];
|
||||
((uchar *)(&f))[i] ^= ((uchar *)(&s))[i];
|
||||
}
|
||||
}
|
||||
|
||||
template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
||||
if ((size_t*)f == (size_t*)s) return;
|
||||
template<>
|
||||
inline void piSwapBinary(const void *& f, const void *& s) {
|
||||
if ((size_t *)f == (size_t *)s) return;
|
||||
size_t j = (sizeof(void *) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(void *);
|
||||
size_t i = 0;
|
||||
void * pf = const_cast<void*>(f), * ps = const_cast<void*>(s);
|
||||
void *pf = const_cast<void *>(f), *ps = const_cast<void *>(s);
|
||||
for (i = 0; i < j; ++i) {
|
||||
((size_t*)(&pf))[i] ^= ((size_t*)(&ps))[i];
|
||||
((size_t*)(&ps))[i] ^= ((size_t*)(&pf))[i];
|
||||
((size_t*)(&pf))[i] ^= ((size_t*)(&ps))[i];
|
||||
((size_t *)(&pf))[i] ^= ((size_t *)(&ps))[i];
|
||||
((size_t *)(&ps))[i] ^= ((size_t *)(&pf))[i];
|
||||
((size_t *)(&pf))[i] ^= ((size_t *)(&ps))[i];
|
||||
}
|
||||
for (i = bs; i < bf; ++i) {
|
||||
((uchar*)(&pf))[i] ^= ((uchar*)(&ps))[i];
|
||||
((uchar*)(&ps))[i] ^= ((uchar*)(&pf))[i];
|
||||
((uchar*)(&pf))[i] ^= ((uchar*)(&ps))[i];
|
||||
((uchar *)(&pf))[i] ^= ((uchar *)(&ps))[i];
|
||||
((uchar *)(&ps))[i] ^= ((uchar *)(&pf))[i];
|
||||
((uchar *)(&pf))[i] ^= ((uchar *)(&ps))[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,8 +510,7 @@ template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
||||
//! \~russian Пример:\n \snippet piincludes.cpp compareBinary
|
||||
inline bool piCompareBinary(const void * f, const void * s, size_t size) {
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
if (((const uchar*)f)[i] != ((const uchar*)s)[i])
|
||||
return false;
|
||||
if (((const uchar *)f)[i] != ((const uchar *)s)[i]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -516,7 +534,10 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) {
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp round
|
||||
template<typename T> inline constexpr int piRound(const T & v) {return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));}
|
||||
template<typename T>
|
||||
inline constexpr int piRound(const T & v) {
|
||||
return int(v >= T(0.) ? v + T(0.5) : v - T(0.5));
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return floor of float falue
|
||||
@@ -538,7 +559,10 @@ template<typename T> inline constexpr int piRound(const T & v) {return int(v >=
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp floor
|
||||
template<typename T> inline constexpr int piFloor(const T & v) {return v < T(0) ? int(v) - 1 : int(v);}
|
||||
template<typename T>
|
||||
inline constexpr int piFloor(const T & v) {
|
||||
return v < T(0) ? int(v) - 1 : int(v);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return ceil of float falue
|
||||
@@ -560,7 +584,10 @@ template<typename T> inline constexpr int piFloor(const T & v) {return v < T(0)
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp ceil
|
||||
template<typename T> inline constexpr int piCeil(const T & v) {return v < T(0) ? int(v) : int(v) + 1;}
|
||||
template<typename T>
|
||||
inline constexpr int piCeil(const T & v) {
|
||||
return v < T(0) ? int(v) : int(v) + 1;
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return absolute of numeric falue
|
||||
@@ -590,7 +617,10 @@ template<typename T> inline constexpr int piCeil(const T & v) {return v < T(0) ?
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp abs
|
||||
template<typename T> inline constexpr T piAbs(const T & v) {return (v >= T(0) ? v : -v);}
|
||||
template<typename T>
|
||||
inline constexpr T piAbs(const T & v) {
|
||||
return (v >= T(0) ? v : -v);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return minimum of two values
|
||||
@@ -618,7 +648,10 @@ template<typename T> inline constexpr T piAbs(const T & v) {return (v >= T(0) ?
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp min2
|
||||
template<typename T> inline constexpr T piMin(const T & f, const T & s) {return ((f > s) ? s : f);}
|
||||
template<typename T>
|
||||
inline constexpr T piMin(const T & f, const T & s) {
|
||||
return ((f > s) ? s : f);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return minimum of tree values
|
||||
@@ -646,7 +679,10 @@ template<typename T> inline constexpr T piMin(const T & f, const T & s) {return
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp min3
|
||||
template<typename T> inline constexpr T piMin(const T & f, const T & s, const T & t) {return ((f < s && f < t) ? f : ((s < t) ? s : t));}
|
||||
template<typename T>
|
||||
inline constexpr T piMin(const T & f, const T & s, const T & t) {
|
||||
return ((f < s && f < t) ? f : ((s < t) ? s : t));
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return maximum of two values
|
||||
@@ -674,7 +710,10 @@ template<typename T> inline constexpr T piMin(const T & f, const T & s, const T
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp max2
|
||||
template<typename T> inline constexpr T piMax(const T & f, const T & s) {return ((f < s) ? s : f);}
|
||||
template<typename T>
|
||||
inline constexpr T piMax(const T & f, const T & s) {
|
||||
return ((f < s) ? s : f);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return maximum of tree values
|
||||
@@ -702,7 +741,10 @@ template<typename T> inline constexpr T piMax(const T & f, const T & s) {return
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp max3
|
||||
template<typename T> inline constexpr T piMax(const T & f, const T & s, const T & t) {return ((f > s && f > t) ? f : ((s > t) ? s : t));}
|
||||
template<typename T>
|
||||
inline constexpr T piMax(const T & f, const T & s, const T & t) {
|
||||
return ((f > s && f > t) ? f : ((s > t) ? s : t));
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function return clamped value
|
||||
@@ -732,14 +774,17 @@ template<typename T> inline constexpr T piMax(const T & f, const T & s, const T
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp clamp
|
||||
template<typename T> inline constexpr T piClamp(const T & v, const T & min, const T & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
template<typename T>
|
||||
inline constexpr T piClamp(const T & v, const T & min, const T & max) {
|
||||
return (v > max ? max : (v < min ? min : v));
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Function inverse byte order in memory block ([1..N] -> [N..1])
|
||||
//! \~russian Метод для смены порядка байт в блоке памяти ([1..N] -> [N..1])
|
||||
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]);
|
||||
piSwap<uchar>(((uchar *)data)[size - i - 1], ((uchar *)data)[i]);
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
@@ -768,7 +813,10 @@ inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric
|
||||
//! \~\brief
|
||||
//! \~english Templated function that inverse byte order of value "v"
|
||||
//! \~russian Шаблонный метод, меняющий порядок байт в переменной "v"
|
||||
template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
||||
template<typename T>
|
||||
inline void piLetobe(T * v) {
|
||||
piLetobe(v, sizeof(T));
|
||||
}
|
||||
|
||||
//! \~\brief
|
||||
//! \~english Templated function that returns "v" with inversed byte order
|
||||
@@ -794,14 +842,26 @@ template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
|
||||
//!
|
||||
//! Пример:
|
||||
//! \snippet piincludes.cpp letobe
|
||||
template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;}
|
||||
template<typename T>
|
||||
inline T piLetobe(const T & v) {
|
||||
T tv(v);
|
||||
piLetobe(&tv, sizeof(T));
|
||||
return tv;
|
||||
}
|
||||
|
||||
// specialization
|
||||
template<> inline uint16_t piLetobe(const uint16_t & v) {return (v << 8) | (v >> 8);}
|
||||
template<> inline uint32_t piLetobe(const uint32_t & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
template<> inline float piLetobe(const float & v) {
|
||||
template<>
|
||||
inline uint16_t piLetobe(const uint16_t & v) {
|
||||
return (v << 8) | (v >> 8);
|
||||
}
|
||||
template<>
|
||||
inline uint32_t piLetobe(const uint32_t & v) {
|
||||
return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);
|
||||
}
|
||||
template<>
|
||||
inline float piLetobe(const float & v) {
|
||||
union _pletobe_f {
|
||||
_pletobe_f(const float &f_) {f = f_;}
|
||||
_pletobe_f(const float & f_) { f = f_; }
|
||||
float f;
|
||||
uint32_t v;
|
||||
};
|
||||
@@ -852,68 +912,104 @@ inline uint piHashData(const uchar * data, uint len, uint seed = 0) {
|
||||
}
|
||||
|
||||
|
||||
template<typename T> inline uint piHash(const T & v) {
|
||||
template<typename T>
|
||||
inline uint piHash(const T & v) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<> inline uint piHash(const char & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const uchar & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const short & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const ushort & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const int & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const uint & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const llong & v) {return piHashData((const uchar *)&v, sizeof(v));}
|
||||
template<> inline uint piHash(const ullong & v) {return piHashData((const uchar *)&v, sizeof(v));}
|
||||
template<> inline uint piHash(const float & v) {return (uint)v;}
|
||||
template<> inline uint piHash(const double & v) {return piHashData((const uchar *)&v, sizeof(v));}
|
||||
template<> inline uint piHash(const ldouble & v) {return piHashData((const uchar *)&v, sizeof(v));}
|
||||
template<>
|
||||
inline uint piHash(const char & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const uchar & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const short & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const ushort & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const int & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const uint & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const llong & v) {
|
||||
return piHashData((const uchar *)&v, sizeof(v));
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const ullong & v) {
|
||||
return piHashData((const uchar *)&v, sizeof(v));
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const float & v) {
|
||||
return (uint)v;
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const double & v) {
|
||||
return piHashData((const uchar *)&v, sizeof(v));
|
||||
}
|
||||
template<>
|
||||
inline uint piHash(const ldouble & v) {
|
||||
return piHashData((const uchar *)&v, sizeof(v));
|
||||
}
|
||||
|
||||
template<typename T> inline void piDeleteAll(T & container) {
|
||||
template<typename T>
|
||||
inline void piDeleteAll(T & container) {
|
||||
for (auto i: container)
|
||||
delete i;
|
||||
}
|
||||
template<typename T> inline void piDeleteAllAndClear(T & container) {
|
||||
template<typename T>
|
||||
inline void piDeleteAllAndClear(T & container) {
|
||||
piDeleteAll(container);
|
||||
container.clear();
|
||||
}
|
||||
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piRoundf piRound<float>
|
||||
#define piRoundd piRound<double>
|
||||
#define piComparef piCompare<float>
|
||||
#define piCompared piCompare<double>
|
||||
#define piFloorf piFloor<float>
|
||||
#define piFloord piFloor<double>
|
||||
#define piCeilf piCeil<float>
|
||||
#define piCeild piCeil<double>
|
||||
#define piAbss piAbs<short>
|
||||
#define piAbsi piAbs<int>
|
||||
#define piAbsl piAbs<long>
|
||||
#define piAbsll piAbs<llong>
|
||||
#define piAbsf piAbs<float>
|
||||
#define piAbsd piAbs<double>
|
||||
#define piMins piMin<short>
|
||||
#define piMini piMin<int>
|
||||
#define piMinl piMin<long>
|
||||
#define piMinll piMin<llong>
|
||||
#define piMinf piMin<float>
|
||||
#define piMind piMin<double>
|
||||
#define piMaxs piMax<short>
|
||||
#define piMaxi piMax<int>
|
||||
#define piMaxl piMax<long>
|
||||
#define piMaxll piMax<llong>
|
||||
#define piMaxf piMax<float>
|
||||
#define piMaxd piMax<double>
|
||||
#define piClamps piClamp<short>
|
||||
#define piClampi piClamp<int>
|
||||
#define piClampl piClamp<long>
|
||||
#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 piFloorf piFloor<float>
|
||||
#define piFloord piFloor<double>
|
||||
#define piCeilf piCeil<float>
|
||||
#define piCeild piCeil<double>
|
||||
#define piAbss piAbs<short>
|
||||
#define piAbsi piAbs<int>
|
||||
#define piAbsl piAbs<long>
|
||||
#define piAbsll piAbs<llong>
|
||||
#define piAbsf piAbs<float>
|
||||
#define piAbsd piAbs<double>
|
||||
#define piMins piMin<short>
|
||||
#define piMini piMin<int>
|
||||
#define piMinl piMin<long>
|
||||
#define piMinll piMin<llong>
|
||||
#define piMinf piMin<float>
|
||||
#define piMind piMin<double>
|
||||
#define piMaxs piMax<short>
|
||||
#define piMaxi piMax<int>
|
||||
#define piMaxl piMax<long>
|
||||
#define piMaxll piMax<llong>
|
||||
#define piMaxf piMax<float>
|
||||
#define piMaxd piMax<double>
|
||||
#define piClamps piClamp<short>
|
||||
#define piClampi piClamp<int>
|
||||
#define piClampl piClamp<long>
|
||||
#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>
|
||||
#define piLetobef piLetobe<float>
|
||||
#define piLetobef piLetobe<float>
|
||||
|
||||
|
||||
#endif // PIBASE_H
|
||||
|
||||
Reference in New Issue
Block a user