code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -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

View File

@@ -1,23 +1,24 @@
/*
PIP - Platform Independent Primitives
Command-Line Parser
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Command-Line Parser
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/>.
*/
#include "picli.h"
#include "pisysteminfo.h"
@@ -69,14 +70,13 @@
PICLI::PICLI(int argc, char * argv[]) {
needParse = debug_ = true;
_prefix_short = "-";
_prefix_full = "--";
_count_opt = 0;
_count_mand = 0;
_prefix_short = "-";
_prefix_full = "--";
_count_opt = 0;
_count_mand = 0;
for (int i = 0; i < argc; ++i)
_args_raw << argv[i];
if (argc > 0)
PISystemInfo::instance()->execCommand = argv[0];
if (argc > 0) PISystemInfo::instance()->execCommand = argv[0];
}
@@ -89,10 +89,10 @@ void PICLI::parse() {
if (cra.left(2) == _prefix_full) {
last = 0;
full = cra.right(cra.length() - 2);
piForeach (Argument & a, _args) {
piForeach(Argument & a, _args) {
if (a.full_key == full) {
a.found = true;
last = &a;
last = &a;
break;
}
}
@@ -101,11 +101,11 @@ void PICLI::parse() {
last = 0;
for (int j = 1; j < cra.length(); ++j) {
bool found = false;
piForeach (Argument & a, _args) {
piForeach(Argument & a, _args) {
if ((a.short_key != '\0') && (a.short_key == cra[j])) {
a.found = true;
last = &a;
found = true;
last = &a;
found = true;
break;
}
}
@@ -125,7 +125,7 @@ void PICLI::parse() {
}
if (last == 0 ? false : last->has_value) {
last->value = cra;
last = 0;
last = 0;
}
}
}

View File

@@ -3,132 +3,201 @@
* \~\brief
* \~english Command-Line parser
* \~russian Парсер командной строки
*/
*/
/*
PIP - Platform Independent Primitives
Command-Line Parser
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Command-Line Parser
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 PICLI_H
#define PICLI_H
#include "pistringlist.h"
#include "piset.h"
#include "pistringlist.h"
//! \ingroup Core
//! \~\brief
//! \~english Command-Line parser.
//! \~russian Парсер командной строки.
class PIP_EXPORT PICLI
{
class PIP_EXPORT PICLI {
public:
//! \~english Constructs %PICLI from "argc" and "argv" from "int main()" method.
//! \~russian Создает %PICLI из "argc" и "argv" из метода "int main()".
PICLI(int argc, char * argv[]);
//! \~english Add argument with name "name", short key = name first letter and full key = name.
//! \~russian Добавляет аргумент с именем "name", коротким ключом = первой букве имени и полным ключом = имени.
void addArgument(const PIString & name, bool value = false) {_args << Argument(name, name[0], name, value); needParse = true;}
void addArgument(const PIString & name, bool value = false) {
_args << Argument(name, name[0], name, value);
needParse = true;
}
//! \~english Add argument with name "name", short key = "shortKey" and full key = name.
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = имени.
void addArgument(const PIString & name, const PIChar & shortKey, bool value = false) {_args << Argument(name, shortKey, name, value); needParse = true;}
void addArgument(const PIString & name, const PIChar & shortKey, bool value = false) {
_args << Argument(name, shortKey, name, value);
needParse = true;
}
//! \~english Add argument with name "name", short key = "shortKey" and full key = name.
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = имени.
void addArgument(const PIString & name, const char * shortKey, bool value = false) {_args << Argument(name, PIChar(shortKey), name, value); needParse = true;}
void addArgument(const PIString & name, const char * shortKey, bool value = false) {
_args << Argument(name, PIChar(shortKey), name, value);
needParse = true;
}
//! \~english Add argument with name "name", short key = "shortKey" and full key = "fullKey".
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = "fullKey".
void addArgument(const PIString & name, const PIChar & shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, shortKey, fullKey, value); needParse = true;}
void addArgument(const PIString & name, const PIChar & shortKey, const PIString & fullKey, bool value = false) {
_args << Argument(name, shortKey, fullKey, value);
needParse = true;
}
//! \~english Add argument with name "name", short key = "shortKey" and full key = "fullKey".
//! \~russian Добавляет аргумент с именем "name", коротким ключом = "shortKey" и полным ключом = "fullKey".
void addArgument(const PIString & name, const char * shortKey, const PIString & fullKey, bool value = false) {_args << Argument(name, PIChar(shortKey), fullKey, value); needParse = true;}
void addArgument(const PIString & name, const char * shortKey, const PIString & fullKey, bool value = false) {
_args << Argument(name, PIChar(shortKey), fullKey, value);
needParse = true;
}
//! \~english Returns unparsed command-line argument by index "index". Index 0 is program execute command.
//! \~russian Возвращает исходный аргумент командной строки по индексу "index". Индекс 0 это команда вызова программы.
PIString rawArgument(int index) {parse(); return _args_raw[index];}
PIString mandatoryArgument(int index) {parse(); return _args_mand[index];}
PIString optionalArgument(int index) {parse(); return _args_opt[index];}
PIString rawArgument(int index) {
parse();
return _args_raw[index];
}
PIString mandatoryArgument(int index) {
parse();
return _args_mand[index];
}
PIString optionalArgument(int index) {
parse();
return _args_opt[index];
}
//! \~english Returns unparsed command-line arguments.
//! \~russian Возвращает исходные аргументы командной строки.
const PIStringList & rawArguments() {parse(); return _args_raw;}
const PIStringList & mandatoryArguments() {parse(); return _args_mand;}
const PIStringList & optionalArguments() {parse(); return _args_opt;}
const PIStringList & rawArguments() {
parse();
return _args_raw;
}
const PIStringList & mandatoryArguments() {
parse();
return _args_mand;
}
const PIStringList & optionalArguments() {
parse();
return _args_opt;
}
//! \~english Returns program execute command without arguments.
//! \~russian Возвращает команду вызова программы без аргументов.
PIString programCommand() {parse(); return _args_raw.size() > 0 ? _args_raw.front() : PIString();}
PIString programCommand() {
parse();
return _args_raw.size() > 0 ? _args_raw.front() : PIString();
}
//! \~english Returns if argument "name" found.
//! \~russian Возвращает найден ли аргумент "name".
bool hasArgument(const PIString & name) {parse(); piForeach (Argument & i, _args) if (i.name == name && i.found) return true; return false;}
bool hasArgument(const PIString & name) {
parse();
piForeach(Argument & i, _args)
if (i.name == name && i.found) return true;
return false;
}
//! \~english Returns argument "name" value, or empty string if this is no value.
//! \~russian Возвращает значение аргумента "name" или пустую строку, если значения нет.
PIString argumentValue(const PIString & name) {parse(); piForeach (Argument &i, _args) if (i.name == name && i.found) return i.value; return PIString();}
PIString argumentValue(const PIString & name) {
parse();
piForeach(Argument & i, _args)
if (i.name == name && i.found) return i.value;
return PIString();
}
//! \~english Returns short key of argument "name", or empty string if this is no argument.
//! \~russian Возвращает короткий ключ аргумента "name" или пустую строку, если аргумента нет.
PIString argumentShortKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.short_key; return PIString();}
PIString argumentShortKey(const PIString & name) {
piForeach(Argument & i, _args)
if (i.name == name) return i.short_key;
return PIString();
}
//! \~english Returns full key of argument "name", or empty string if this is no argument.
//! \~russian Возвращает полный ключ аргумента "name" или пустую строку, если аргумента нет.
PIString argumentFullKey(const PIString & name) {piForeach (Argument &i, _args) if (i.name == name) return i.full_key; return PIString();}
const PIString & shortKeyPrefix() const {return _prefix_short;}
const PIString & fullKeyPrefix() const {return _prefix_full;}
int mandatoryArgumentsCount() const {return _count_mand;}
int optionalArgumentsCount() const {return _count_opt;}
void setShortKeyPrefix(const PIString & prefix) {_prefix_short = prefix; needParse = true;}
void setFullKeyPrefix(const PIString & prefix) {_prefix_full = prefix; needParse = true;}
void setMandatoryArgumentsCount(const int count) {_count_mand = count; needParse = true;}
void setOptionalArgumentsCount(const int count) {_count_opt = count; needParse = true;}
bool debug() const {return debug_;}
void setDebug(bool debug) {debug_ = debug;}
PIConstChars className() const {return "PICLI";}
PIString name() const {return PIStringAscii("CLI");}
PIString argumentFullKey(const PIString & name) {
piForeach(Argument & i, _args)
if (i.name == name) return i.full_key;
return PIString();
}
const PIString & shortKeyPrefix() const { return _prefix_short; }
const PIString & fullKeyPrefix() const { return _prefix_full; }
int mandatoryArgumentsCount() const { return _count_mand; }
int optionalArgumentsCount() const { return _count_opt; }
void setShortKeyPrefix(const PIString & prefix) {
_prefix_short = prefix;
needParse = true;
}
void setFullKeyPrefix(const PIString & prefix) {
_prefix_full = prefix;
needParse = true;
}
void setMandatoryArgumentsCount(const int count) {
_count_mand = count;
needParse = true;
}
void setOptionalArgumentsCount(const int count) {
_count_opt = count;
needParse = true;
}
bool debug() const { return debug_; }
void setDebug(bool debug) { debug_ = debug; }
PIConstChars className() const { return "PICLI"; }
PIString name() const { return PIStringAscii("CLI"); }
private:
struct Argument {
Argument() {has_value = found = false;}
Argument(const PIString & n, const PIChar & s, const PIString & f, bool v) {name = n; short_key = s; full_key = f; has_value = v; found = false;}
Argument() { has_value = found = false; }
Argument(const PIString & n, const PIChar & s, const PIString & f, bool v) {
name = n;
short_key = s;
full_key = f;
has_value = v;
found = false;
}
PIString name;
PIChar short_key;
PIString full_key;
PIString value;
bool has_value, found;
};
void parse();
PIString _prefix_short, _prefix_full;
PIStringList _args_raw, _args_mand, _args_opt;
PISet<PIString> keys_full, keys_short;
PIVector<Argument> _args;
int _count_mand, _count_opt;
bool needParse, debug_;
};
#endif // PICLI_H

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
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/>.
*/
#include "picollection.h"
@@ -40,37 +40,35 @@
PIStringList PICollection::groups() {
PIStringList sl;
PIVector<PICollection::Group> & cg(_groups());
piForeachC (Group & g, cg)
piForeachC(Group & g, cg)
sl << g.name;
return sl;
}
PIVector<const PIObject * > PICollection::groupElements(const PIString & group) {
PIVector<const PIObject *> PICollection::groupElements(const PIString & group) {
PIVector<PICollection::Group> & cg(_groups());
piForeachC (Group & g, cg)
if (g.name == group)
return g.elements;
return PIVector<const PIObject * >();
piForeachC(Group & g, cg)
if (g.name == group) return g.elements;
return PIVector<const PIObject *>();
}
bool PICollection::addToGroup(const PIString & group, const PIObject * element) {
//piCout << "add to" << group << element;
// piCout << "add to" << group << element;
PIString n = PIStringAscii(element->className());
PIVector<PICollection::Group> & cg(_groups());
piForeach (Group & g, cg)
piForeach(Group & g, cg)
if (g.name == group) {
for (int i = 0; i < g.elements.size_s(); ++i)
if (PIString(g.elements[i]->className()) == n)
return false;
if (PIString(g.elements[i]->className()) == n) return false;
g.elements << element;
//piCout << "new group" << group << ", ok";
// piCout << "new group" << group << ", ok";
return true;
}
_groups() << Group(group);
_groups().back().elements << element;
//piCout << "new group" << group << ", ok";
// piCout << "new group" << group << ", ok";
return true;
}
@@ -83,9 +81,7 @@ PIVector<PICollection::Group> & PICollection::_groups() {
PICollection::CollectionAdder::CollectionAdder(const PIString & group, const PIObject * element, const PIString & name, bool own) {
if (!element) return;
if (name.isNotEmpty())
const_cast<PIObject * >(element)->setName(name);
if (name.isNotEmpty()) const_cast<PIObject *>(element)->setName(name);
bool added = PICollection::addToGroup(group, element);
if (!added && own)
delete element;
if (!added && own) delete element;
}

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english Unique classes collection
* \~russian Коллекция уникальных классов
*/
*/
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
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 PICOLLECTION_H
@@ -87,16 +87,16 @@
#else
# define ADD_TO_COLLECTION(group, object) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, "", false);
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, "", false);
# define ADD_TO_COLLECTION_WITH_NAME(group, object, name) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, #name, false);
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, #name, false);
# define ADD_NEW_TO_COLLECTION(group, class) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), "", true);
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), "", true);
# define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), #name, true);
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), #name, true);
#endif
@@ -104,36 +104,35 @@
//! \~\brief
//! \~english Helper to collect and retrieve classes to groups.
//! \~russian Помощник для создания и получения классов в группы.
class PIP_EXPORT PICollection
{
class PIP_EXPORT PICollection {
friend class __PICollectionInitializer;
public:
PICollection() {;}
PICollection() { ; }
//! \~english Returns all existing groups by their names
//! \~russian Возвращает имена всех групп
static PIStringList groups();
//! \~english Returns all elements of group "group"
//! \~russian Возвращает все элементы группы "group"
static PIVector<const PIObject * > groupElements(const PIString & group);
static PIVector<const PIObject *> groupElements(const PIString & group);
static bool addToGroup(const PIString & group, const PIObject * element);
class PIP_EXPORT CollectionAdder {
public:
CollectionAdder(const PIString & group, const PIObject * element, const PIString & name = PIString(), bool own = false);
};
protected:
struct PIP_EXPORT Group {
Group(const PIString & name_ = PIString()) {name = name_;}
Group(const PIString & name_ = PIString()) { name = name_; }
PIString name;
PIVector<const PIObject * > elements;
PIVector<const PIObject *> elements;
};
static PIVector<Group> & _groups();
};
#endif // PICOLLECTION_H

View File

@@ -1,20 +1,20 @@
/*
PIP - Platform Independent Primitives
Module includes
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
PIP - Platform Independent Primitives
Module includes
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@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/>.
*/
//! \defgroup Core Core
//! \~\brief
@@ -51,12 +51,12 @@
#ifndef PICOREMODULE_H
#define PICOREMODULE_H
#include "picollection.h"
#include "piobject.h"
#include "pitime.h"
#include "picli.h"
#include "pichunkstream.h"
#include "pipropertystorage.h"
#include "picli.h"
#include "picollection.h"
#include "pijson.h"
#include "piobject.h"
#include "pipropertystorage.h"
#include "pitime.h"
#endif // PICOREMODULE_H

View File

@@ -1,35 +1,36 @@
/*
PIP - Platform Independent Primitives
Universal output to console class
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Universal output to console class
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/>.
*/
#include "piincludes_p.h"
#include "picout.h"
#include "pibytearray.h"
#include "pistack.h"
#include "piincludes_p.h"
#include "piobject.h"
#include "pistack.h"
#include "pistring_std.h"
#ifdef HAS_LOCALE
# include <locale>
# include <codecvt>
# include <locale>
#endif
#ifdef WINDOWS
# include <wincon.h>
# include <windows.h>
# include <wingdi.h>
# include <wincon.h>
# define COMMON_LVB_UNDERSCORE 0x8000
#endif
@@ -106,13 +107,13 @@
class NotifierObject: public PIObject {
PIOBJECT(NotifierObject)
public:
NotifierObject() {}
EVENT2(finished, int, id, PIString*, buffer);
EVENT2(finished, int, id, PIString *, buffer);
};
PICout::Notifier::Notifier() {
o = new NotifierObject();
}
@@ -129,12 +130,16 @@ PIObject * PICout::Notifier::object() {
}
using namespace PICoutManipulators;
PIMutex & PICout::__mutex__() {static PIMutex * ret = new PIMutex(); return *ret;}
PIString & PICout::__string__() {static PIString * ret = new PIString(); return *ret;}
PIMutex & PICout::__mutex__() {
static PIMutex * ret = new PIMutex();
return *ret;
}
PIString & PICout::__string__() {
static PIString * ret = new PIString();
return *ret;
}
PICout::OutputDevices PICout::devs = PICout::StdOut;
@@ -149,7 +154,7 @@ PRIVATE_DEFINITION_END(PICout)
#ifdef WINDOWS
void * PICout::__Private__::hOut = 0;
WORD PICout::__Private__::dattr = 0;
WORD PICout::__Private__::dattr = 0;
DWORD PICout::__Private__::smode = 0;
#endif
@@ -164,9 +169,16 @@ PICout::PICout(bool active): fo_(true), cc_(false), fc_(false), act_(active), cn
}
PICout::PICout(const PICout & other): fo_(other.fo_), cc_(true), fc_(false), act_(other.act_), cnb_(other.cnb_), attr_(other.attr_),
id_(other.id_), buffer_(other.buffer_), co_(other.co_) {
}
PICout::PICout(const PICout & other)
: fo_(other.fo_)
, cc_(true)
, fc_(false)
, act_(other.act_)
, cnb_(other.cnb_)
, attr_(other.attr_)
, id_(other.id_)
, buffer_(other.buffer_)
, co_(other.co_) {}
PICout::~PICout() {
@@ -178,12 +190,12 @@ PICout::~PICout() {
PICout::__mutex__().unlock();
}
if (buffer_) {
((NotifierObject*)Notifier::object())->finished(id_, buffer_);
((NotifierObject *)Notifier::object())->finished(id_, buffer_);
}
}
PICout & PICout::operator <<(PICoutAction v) {
PICout & PICout::operator<<(PICoutAction v) {
if (!act_) return *this;
#ifdef WINDOWS
CONSOLE_SCREEN_BUFFER_INFO sbi;
@@ -200,7 +212,7 @@ PICout & PICout::operator <<(PICoutAction v) {
if (isOutputDeviceActive(StdOut)) {
#ifdef WINDOWS
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
coord = sbi.dwCursorPosition;
coord = sbi.dwCursorPosition;
coord.X = piMax<int>(0, int(coord.X) - 1);
SetConsoleCursorPosition(__Private__::hOut, coord);
printf(" ");
@@ -236,8 +248,8 @@ PICout & PICout::operator <<(PICoutAction v) {
if (isOutputDeviceActive(StdOut)) {
#ifdef WINDOWS
GetConsoleScreenBufferInfo(__Private__::hOut, &sbi);
coord = sbi.dwCursorPosition;
int dx = coord.X;
coord = sbi.dwCursorPosition;
int dx = coord.X;
coord.X = 0;
SetConsoleCursorPosition(__Private__::hOut, coord);
if (dx > 0) {
@@ -270,7 +282,7 @@ PICout & PICout::operator <<(PICoutAction v) {
}
PICout & PICout::operator <<(PICoutManipulators::PICoutFormat v) {
PICout & PICout::operator<<(PICoutManipulators::PICoutFormat v) {
switch (v) {
case PICoutManipulators::Bin: cnb_ = 2; break;
case PICoutManipulators::Oct: cnb_ = 8; break;
@@ -282,7 +294,7 @@ PICout & PICout::operator <<(PICoutManipulators::PICoutFormat v) {
}
PICout & PICout::operator <<(PIFlags<PICoutManipulators::PICoutFormat> v) {
PICout & PICout::operator<<(PIFlags<PICoutManipulators::PICoutFormat> v) {
if (v[PICoutManipulators::Bin]) cnb_ = 2;
if (v[PICoutManipulators::Oct]) cnb_ = 8;
if (v[PICoutManipulators::Dec]) cnb_ = 10;
@@ -312,32 +324,35 @@ PICout & PICout::operator <<(PIFlags<PICoutManipulators::PICoutFormat> v) {
return *this;
}
#define PIINTCOUT(v) { \
if (!act_) return *this; \
space(); \
if (cnb_ == 10) {\
if (buffer_) {\
(*buffer_) += PIString::fromNumber(v);\
} else {\
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v);\
}\
} else write(PIString::fromNumber(v, cnb_)); \
return *this; \
#define PIINTCOUT(v) \
{ \
if (!act_) return *this; \
space(); \
if (cnb_ == 10) { \
if (buffer_) { \
(*buffer_) += PIString::fromNumber(v); \
} else { \
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v); \
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v); \
} \
} else \
write(PIString::fromNumber(v, cnb_)); \
return *this; \
}
#define PIFLOATCOUT(v) { \
if (buffer_) {\
(*buffer_) += PIString::fromNumber(v, 'g');\
} else {\
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v);\
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g');\
}\
}\
#define PIFLOATCOUT(v) \
{ \
if (buffer_) { \
(*buffer_) += PIString::fromNumber(v, 'g'); \
} else { \
if (PICout::isOutputDeviceActive(PICout::StdOut)) std::cout << (v); \
if (PICout::isOutputDeviceActive(PICout::Buffer)) PICout::__string__() += PIString::fromNumber(v, 'g'); \
} \
} \
return *this;
PICout & PICout::operator <<(const PIString & v) {
PICout & PICout::operator<<(const PIString & v) {
space();
quote();
write(v);
@@ -345,7 +360,7 @@ PICout & PICout::operator <<(const PIString & v) {
return *this;
}
PICout & PICout::operator <<(const char * v) {
PICout & PICout::operator<<(const char * v) {
if (!act_ || !v) return *this;
if (v[0] == '\0') return *this;
space();
@@ -355,56 +370,71 @@ PICout & PICout::operator <<(const char * v) {
return *this;
}
PICout & PICout::operator <<(bool v) {
PICout & PICout::operator<<(bool v) {
if (!act_) return *this;
space();
if (v) write("true");
else write("false");
if (v)
write("true");
else
write("false");
return *this;
}
PICout & PICout::operator <<(char v) {
PICout & PICout::operator<<(char v) {
if (!act_) return *this;
space();
write(v);
return *this;
}
PICout & PICout::operator <<(uchar v) {PIINTCOUT(ushort(v))}
PICout & PICout::operator<<(uchar v){PIINTCOUT(ushort(v))}
PICout & PICout::operator <<(short int v) {PIINTCOUT(v)}
PICout & PICout::operator<<(short int v){PIINTCOUT(v)}
PICout & PICout::operator <<(ushort v) {PIINTCOUT(v)}
PICout & PICout::operator<<(ushort v){PIINTCOUT(v)}
PICout & PICout::operator <<(int v) {PIINTCOUT(v)}
PICout & PICout::operator<<(int v){PIINTCOUT(v)}
PICout & PICout::operator <<(uint v) {PIINTCOUT(v)}
PICout & PICout::operator<<(uint v){PIINTCOUT(v)}
PICout & PICout::operator <<(long v) {PIINTCOUT(v)}
PICout & PICout::operator<<(long v){PIINTCOUT(v)}
PICout & PICout::operator <<(ulong v) {PIINTCOUT(v)}
PICout & PICout::operator<<(ulong v){PIINTCOUT(v)}
PICout & PICout::operator <<(llong v) {PIINTCOUT(v)}
PICout & PICout::operator<<(llong v){PIINTCOUT(v)}
PICout & PICout::operator <<(ullong v) {PIINTCOUT(v)}
PICout & PICout::operator<<(ullong v){PIINTCOUT(v)}
PICout & PICout::operator <<(float v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
PICout & PICout::operator<<(float v) {
if (!act_) return *this;
space();
PIFLOATCOUT(v)
}
PICout & PICout::operator <<(double v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
PICout & PICout::operator<<(double v) {
if (!act_) return *this;
space();
PIFLOATCOUT(v)
}
PICout & PICout::operator <<(ldouble v) {if (!act_) return *this; space(); PIFLOATCOUT(v)}
PICout & PICout::operator<<(ldouble v) {
if (!act_) return *this;
space();
PIFLOATCOUT(v)
}
PICout & PICout::operator <<(const void * v) {
PICout & PICout::operator<<(const void * v) {
if (!act_) return *this;
space();
write("0x" + PIString::fromNumber(ullong(v), 16));
return *this;
}
PICout & PICout::operator <<(const PIObject * v) {
PICout & PICout::operator<<(const PIObject * v) {
if (!act_) return *this;
space();
if (v == 0) write("PIObject*(0x0)");
if (v == 0)
write("PIObject*(0x0)");
else {
write(v->className());
write("*(0x" + PIString::fromNumber(ullong(v), 16) + ", \"" + v->name() + "\")");
@@ -412,7 +442,7 @@ PICout & PICout::operator <<(const PIObject * v) {
return *this;
}
PICout & PICout::operator <<(PICoutSpecialChar v) {
PICout & PICout::operator<<(PICoutSpecialChar v) {
if (!act_) return *this;
switch (v) {
case Null:
@@ -487,7 +517,6 @@ PICout & PICout::restoreControls() {
}
//! \details
//! \~english
//! If it is not a first output and control \a AddSpaces is set space character is put
@@ -594,9 +623,11 @@ PICout & PICout::write(const PIString & s) {
void PICout::stdoutPIString(const PIString & s) {
#ifdef HAS_LOCALE
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> utf8conv;
std::cout << utf8conv.to_bytes((char16_t*)&(const_cast<PIString&>(s).front()), (char16_t*)&(const_cast<PIString&>(s).front()) + s.size());
std::cout << utf8conv.to_bytes((char16_t *)&(const_cast<PIString &>(s).front()),
(char16_t *)&(const_cast<PIString &>(s).front()) + s.size());
#else
for (PIChar c: s) std::wcout.put(c.toWChar());
for (PIChar c: s)
std::wcout.put(c.toWChar());
#endif
}
@@ -626,7 +657,10 @@ void PICout::applyFormat(PICoutFormat f) {
static int mask_fore = ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
static int mask_back = ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
switch (f) {
case Bin: case Oct: case Dec: case Hex: break;
case Bin:
case Oct:
case Dec:
case Hex: break;
case PICoutManipulators::Bold: attr_ |= FOREGROUND_INTENSITY; break;
case PICoutManipulators::Underline: attr_ |= COMMON_LVB_UNDERSCORE; break;
case PICoutManipulators::Black: attr_ = (attr_ & mask_fore); break;
@@ -651,7 +685,10 @@ void PICout::applyFormat(PICoutFormat f) {
SetConsoleTextAttribute(__Private__::hOut, attr_);
#else
switch (f) {
case Bin: case Oct: case Dec: case Hex: break;
case Bin:
case Oct:
case Dec:
case Hex: break;
case PICoutManipulators::Bold: printf("\e[1m"); break;
case PICoutManipulators::Faint: printf("\e[2m"); break;
case PICoutManipulators::Italic: printf("\e[3m"); break;
@@ -721,6 +758,6 @@ bool PICout::isOutputDeviceActive(PICout::OutputDevice d) {
PICout PICout::withExternalBuffer(PIString * buffer, int id, PIFlags<PICoutManipulators::PICoutControl> controls) {
PICout c(controls);
c.buffer_ = buffer;
c.id_ = id;
c.id_ = id;
return c;
}

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english Universal output to console class
* \~russian Универсальный вывод в консоль
*/
*/
/*
PIP - Platform Independent Primitives
Universal output to console class
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Universal output to console class
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 PICOUT_H
@@ -41,7 +41,9 @@
#else
# define piCout PICout(piDebug)
# define piCoutObj PICout(piDebug && debug()) << (PIStringAscii("[") + className() + (name().isEmpty() ? "]" : PIStringAscii(" \"") + name() + PIStringAscii("\"]")))
# define piCoutObj \
PICout(piDebug && debug()) << (PIStringAscii("[") + className() + \
(name().isEmpty() ? "]" : PIStringAscii(" \"") + name() + PIStringAscii("\"]")))
#endif
@@ -53,76 +55,75 @@ class PIObject;
//! \~russian Пространство имен содержит перечисления для контроля PICout
namespace PICoutManipulators {
//! \~english Enum contains special characters
//! \~russian Перечисление со спецсимволами
enum PICoutSpecialChar {
Null /*! \~english Null-character, '\\0' \~russian Нулевой символ, '\\0' */,
NewLine /*! \~english New line character, '\\n' \~russian Новая строка, '\\n' */,
Tab /*! \~english Tab character, '\\t' \~russian Табуляция, '\\t' */,
Esc /*! \~english Escape character, '\\e' \~russian Esc-символ, '\\e' */,
Quote /*! \~english Quote character, '\"' \~russian Кавычки, '\"' */
};
//! \~english Enum contains special characters
//! \~russian Перечисление со спецсимволами
enum PICoutSpecialChar {
Null /*! \~english Null-character, '\\0' \~russian Нулевой символ, '\\0' */,
NewLine /*! \~english New line character, '\\n' \~russian Новая строка, '\\n' */,
Tab /*! \~english Tab character, '\\t' \~russian Табуляция, '\\t' */,
Esc /*! \~english Escape character, '\\e' \~russian Esc-символ, '\\e' */,
Quote /*! \~english Quote character, '\"' \~russian Кавычки, '\"' */
};
//! \~english Enum contains immediate action
//! \~russian Перечисление с немедленными действиями
enum PICoutAction {
Flush /*! \~english Flush the output \~russian Обновить вывод */,
Backspace /*! \~english Remove last symbol \~russian Удалить последний символ */,
ShowCursor /*! \~english Show cursor \~russian Показать курсор */,
HideCursor /*! \~english Hide cursor \~russian Скрыть курсор */,
ClearLine /*! \~english Clear current line \~russian Очистить текущую строку */,
ClearScreen /*! \~english Clear the screen \~russian Очистить экран */,
SaveContol /*! \~english Save control flags, equivalent to \a saveControl() \~russian Сохранить флаги, аналогично \a saveControl() */,
RestoreControl /*! \~english Restore control flags, equivalent to \a restoreControl() \~russian Восстановить флаги, аналогично \a restoreControl() */
};
//! \~english Enum contains immediate action
//! \~russian Перечисление с немедленными действиями
enum PICoutAction {
Flush /*! \~english Flush the output \~russian Обновить вывод */,
Backspace /*! \~english Remove last symbol \~russian Удалить последний символ */,
ShowCursor /*! \~english Show cursor \~russian Показать курсор */,
HideCursor /*! \~english Hide cursor \~russian Скрыть курсор */,
ClearLine /*! \~english Clear current line \~russian Очистить текущую строку */,
ClearScreen /*! \~english Clear the screen \~russian Очистить экран */,
SaveContol /*! \~english Save control flags, equivalent to \a saveControl() \~russian Сохранить флаги, аналогично \a saveControl() */,
RestoreControl /*! \~english Restore control flags, equivalent to \a restoreControl() \~russian Восстановить флаги, аналогично \a
restoreControl() */
};
//! \~english Enum contains control of PICout
//! \~russian Перечисление с управлением PICout
enum PICoutControl {
AddNone /*! \~english No controls \~russian Без управления */ = 0x0,
AddSpaces /*! \~english Spaces will be appear after each output \~russian Пробел после каждого вывода */ = 0x1,
AddNewLine /*! \~english New line will be appear after all output \~russian Новая строка после завершения вывода */ = 0x2,
AddQuotes /*! \~english Each string will be quoted \~russian Каждая строка в кавычках */ = 0x4,
DefaultControls /*! \~english Default controls \~russian Управление по умолчанию */ = AddSpaces | AddNewLine,
AddAll /*! \~english All controls \~russian Всё управление */ = 0xFF,
NoLock /*! \~english Don`t use mutex for output \~russian Не использовать мьютекс при выводе */ = 0x100,
};
//! \~english Enum contains output format
//! \~russian Перечисление с форматом вывода
enum PICoutFormat {
Bin /*! \~english Binary representation of integers \~russian Двоичное представление для целых чисел */ = 0x01,
Oct /*! \~english Octal representation of integers \~russian Восьмеричное представление для целых чисел */ = 0x02,
Dec /*! \~english Decimal representation of integers \~russian Десятичное представление для целых чисел */ = 0x04,
Hex /*! \~english Hexadecimal representation of integers \~russian Шестнадцатеричное представление для целых чисел */ = 0x08,
Bold /*! \~english Bold \~russian Жирный */ = 0x10,
Faint /*! \~english \~russian */ = 0x20,
Italic /*! \~english \~russian */ = 0x40,
Underline /*! \~english Underline \~russian Подчеркнутый */ = 0x80,
Blink /*! \~english Blink \~russian Мигающий */ = 0x100,
Black /*! \~english Black font \~russian Чёрный */ = 0x400,
Red /*! \~english Red font \~russian Красный */ = 0x800,
Green /*! \~english Green font \~russian Зелёный */ = 0x1000,
Blue /*! \~english Blue font \~russian Синий */ = 0x2000,
Yellow /*! \~english Yellow font \~russian Жёлтый */ = 0x4000,
Magenta /*! \~english Magenta font \~russian Пурпурный */ = 0x8000,
Cyan /*! \~english Cyan font \~russian Голубой */ = 0x10000,
White /*! \~english White font \~russian Белый */ = 0x20000,
BackBlack /*! \~english Black background \~russian Чёрный фон */ = 0x40000,
BackRed /*! \~english Red background \~russian Красный фон */ = 0x80000,
BackGreen /*! \~english Green background \~russian Зелёный фон */ = 0x100000,
BackBlue /*! \~english Blue background \~russian Синий фон */ = 0x200000,
BackYellow /*! \~english Yellow background \~russian Жёлтый фон */ = 0x400000,
BackMagenta /*! \~english Magenta background \~russian Пурпурный фон */ = 0x800000,
BackCyan /*! \~english Cyan background \~russian Голубой фон */ = 0x1000000,
BackWhite /*! \~english White background \~russian Белый фон */ = 0x2000000,
Default /*! \~english Default format \~russian Формат по умолчанию */ = 0x4000000
};
typedef PIFlags<PICoutControl> PICoutControls;
}
//! \~english Enum contains control of PICout
//! \~russian Перечисление с управлением PICout
enum PICoutControl {
AddNone /*! \~english No controls \~russian Без управления */ = 0x0,
AddSpaces /*! \~english Spaces will be appear after each output \~russian Пробел после каждого вывода */ = 0x1,
AddNewLine /*! \~english New line will be appear after all output \~russian Новая строка после завершения вывода */ = 0x2,
AddQuotes /*! \~english Each string will be quoted \~russian Каждая строка в кавычках */ = 0x4,
DefaultControls /*! \~english Default controls \~russian Управление по умолчанию */ = AddSpaces | AddNewLine,
AddAll /*! \~english All controls \~russian Всё управление */ = 0xFF,
NoLock /*! \~english Don`t use mutex for output \~russian Не использовать мьютекс при выводе */ = 0x100,
};
//! \~english Enum contains output format
//! \~russian Перечисление с форматом вывода
enum PICoutFormat {
Bin /*! \~english Binary representation of integers \~russian Двоичное представление для целых чисел */ = 0x01,
Oct /*! \~english Octal representation of integers \~russian Восьмеричное представление для целых чисел */ = 0x02,
Dec /*! \~english Decimal representation of integers \~russian Десятичное представление для целых чисел */ = 0x04,
Hex /*! \~english Hexadecimal representation of integers \~russian Шестнадцатеричное представление для целых чисел */ = 0x08,
Bold /*! \~english Bold \~russian Жирный */ = 0x10,
Faint /*! \~english \~russian */ = 0x20,
Italic /*! \~english \~russian */ = 0x40,
Underline /*! \~english Underline \~russian Подчеркнутый */ = 0x80,
Blink /*! \~english Blink \~russian Мигающий */ = 0x100,
Black /*! \~english Black font \~russian Чёрный */ = 0x400,
Red /*! \~english Red font \~russian Красный */ = 0x800,
Green /*! \~english Green font \~russian Зелёный */ = 0x1000,
Blue /*! \~english Blue font \~russian Синий */ = 0x2000,
Yellow /*! \~english Yellow font \~russian Жёлтый */ = 0x4000,
Magenta /*! \~english Magenta font \~russian Пурпурный */ = 0x8000,
Cyan /*! \~english Cyan font \~russian Голубой */ = 0x10000,
White /*! \~english White font \~russian Белый */ = 0x20000,
BackBlack /*! \~english Black background \~russian Чёрный фон */ = 0x40000,
BackRed /*! \~english Red background \~russian Красный фон */ = 0x80000,
BackGreen /*! \~english Green background \~russian Зелёный фон */ = 0x100000,
BackBlue /*! \~english Blue background \~russian Синий фон */ = 0x200000,
BackYellow /*! \~english Yellow background \~russian Жёлтый фон */ = 0x400000,
BackMagenta /*! \~english Magenta background \~russian Пурпурный фон */ = 0x800000,
BackCyan /*! \~english Cyan background \~russian Голубой фон */ = 0x1000000,
BackWhite /*! \~english White background \~russian Белый фон */ = 0x2000000,
Default /*! \~english Default format \~russian Формат по умолчанию */ = 0x4000000
};
typedef PIFlags<PICoutControl> PICoutControls;
} // namespace PICoutManipulators
//! \ingroup Core
@@ -131,7 +132,6 @@ namespace PICoutManipulators {
//! \~russian Универсальный вывод в консоль.
class PIP_EXPORT PICout {
public:
//! \~english Default constructor with default features (AddSpaces and AddNewLine)
//! \~russian Конструктор по умолчанию (AddSpaces и AddNewLine)
PICout(int controls = PICoutManipulators::DefaultControls);
@@ -154,6 +154,7 @@ public:
//! \~english Object that emit events from %PICout
//! \~russian Объект, который посылает события от %PICout
static PIObject * object();
private:
Notifier();
PIObject * o;
@@ -162,113 +163,123 @@ public:
//! \~english Enum contains output devices of %PICout
//! \~russian Перечисление с устройствами вывода для %PICout
enum OutputDevice {
NoDevices /** \~english %PICout is disabled \~russian %PICout неактивен */ = 0x0,
StdOut /** \~english Standard console output \~russian Стандартный вывод в консоль */ = 0x1,
Buffer /** \~english Internal buffer \~russian Внутренний буфер */ = 0x2,
AllDevices /** \~english All \~russian Все */ = 0xFFFF,
NoDevices /** \~english %PICout is disabled \~russian %PICout неактивен */ = 0x0,
StdOut /** \~english Standard console output \~russian Стандартный вывод в консоль */ = 0x1,
Buffer /** \~english Internal buffer \~russian Внутренний буфер */ = 0x2,
AllDevices /** \~english All \~russian Все */ = 0xFFFF,
};
typedef PIFlags<OutputDevice> OutputDevices;
//! \~english Output operator for strings with <tt>"const char * "</tt> type
//! \~russian Оператор вывода для строк <tt>"const char * "</tt>
PICout & operator <<(const char * v);
PICout & operator<<(const char * v);
//! \~english Output operator for \a PIString
//! \~russian Оператор вывода для \a PIString
PICout & operator <<(const PIString & v);
PICout & operator<<(const PIString & v);
//! \~english Output operator for boolean values
//! \~russian Оператор вывода для логических значений
PICout & operator <<(bool v);
PICout & operator<<(bool v);
//! \~english Output operator for <tt>"char"</tt> values
//! \~russian Оператор вывода для <tt>"char"</tt> значений
PICout & operator <<(char v);
PICout & operator<<(char v);
//! \~english Output operator for <tt>"unsigned char"</tt> values
//! \~russian Оператор вывода для <tt>"unsigned char"</tt> значений
PICout & operator <<(uchar v);
PICout & operator<<(uchar v);
//! \~english Output operator for <tt>"short"</tt> values
//! \~russian Оператор вывода для <tt>"short"</tt> значений
PICout & operator <<(short v);
PICout & operator<<(short v);
//! \~english Output operator for <tt>"unsigned short"</tt> values
//! \~russian Оператор вывода для <tt>"unsigned short"</tt> значений
PICout & operator <<(ushort v);
PICout & operator<<(ushort v);
//! \~english Output operator for <tt>"int"</tt> values
//! \~russian Оператор вывода для <tt>"int"</tt> значений
PICout & operator <<(int v);
PICout & operator<<(int v);
//! \~english Output operator for <tt>"unsigned int"</tt> values
//! \~russian Оператор вывода для <tt>"unsigned int"</tt> значений
PICout & operator <<(uint v);
PICout & operator<<(uint v);
//! \~english Output operator for <tt>"long"</tt> values
//! \~russian Оператор вывода для <tt>"long"</tt> значений
PICout & operator <<(long v);
PICout & operator<<(long v);
//! \~english Output operator for <tt>"unsigned long"</tt> values
//! \~russian Оператор вывода для <tt>"unsigned long"</tt> значений
PICout & operator <<(ulong v);
PICout & operator<<(ulong v);
//! \~english Output operator for <tt>"long long"</tt> values
//! \~russian Оператор вывода для <tt>"long long"</tt> значений
PICout & operator <<(llong v);
PICout & operator<<(llong v);
//! \~english Output operator for <tt>"unsigned long long"</tt> values
//! \~russian Оператор вывода для <tt>"unsigned long long"</tt> значений
PICout & operator <<(ullong v);
PICout & operator<<(ullong v);
//! \~english Output operator for <tt>"float"</tt> values
//! \~russian Оператор вывода для <tt>"float"</tt> значений
PICout & operator <<(float v);
PICout & operator<<(float v);
//! \~english Output operator for <tt>"double"</tt> values
//! \~russian Оператор вывода для <tt>"double"</tt> значений
PICout & operator <<(double v);
PICout & operator<<(double v);
//! \~english Output operator for <tt>"ldouble"</tt> values
//! \~russian Оператор вывода для <tt>"ldouble"</tt> значений
PICout & operator <<(ldouble v);
PICout & operator<<(ldouble v);
//! \~english Output operator for pointers
//! \~russian Оператор вывода для указателей
PICout & operator <<(const void * v);
PICout & operator<<(const void * v);
//! \~english Output operator for PIObject and ancestors
//! \~russian Оператор вывода для PIObject и наследников
PICout & operator <<(const PIObject * v);
PICout & operator<<(const PIObject * v);
//! \~english Output operator for \a PICoutSpecialChar values
//! \~russian Оператор вывода для \a PICoutSpecialChar
PICout & operator <<(PICoutManipulators::PICoutSpecialChar v);
PICout & operator<<(PICoutManipulators::PICoutSpecialChar v);
//! \~english Output operator for \a PIFlags<PICoutFormat> values
//! \~russian Оператор вывода для \a PIFlags<PICoutFormat>
PICout & operator <<(PIFlags<PICoutManipulators::PICoutFormat> v);
PICout & operator<<(PIFlags<PICoutManipulators::PICoutFormat> v);
//! \~english Output operator for \a PICoutFormat values
//! \~russian Оператор вывода для \a PICoutFormat
PICout & operator <<(PICoutManipulators::PICoutFormat v);
PICout & operator<<(PICoutManipulators::PICoutFormat v);
//! \~english Do some action
//! \~russian Делает действие
PICout & operator <<(PICoutManipulators::PICoutAction v);
PICout & operator<<(PICoutManipulators::PICoutAction v);
//! \~english Set control flag "c" is "on" state
//! \~russian Установить флаг "c" в "on" состояние
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {co_.setFlag(c, on); return *this;}
PICout & setControl(PICoutManipulators::PICoutControl c, bool on = true) {
co_.setFlag(c, on);
return *this;
}
//! \~english Set control flags "c"
//! \~russian Установить флаги "c"
PICout & setControls(PICoutManipulators::PICoutControls c) {co_ = c; return *this;}
PICout & setControls(PICoutManipulators::PICoutControls c) {
co_ = c;
return *this;
}
//! \~english Exec \a saveControls() and set control flags to "c"
//! \~russian Иыполнить \a saveControls() и Установить флаги "c"
PICout & saveAndSetControls(PICoutManipulators::PICoutControls c) {saveControls(); co_ = c; return *this;}
PICout & saveAndSetControls(PICoutManipulators::PICoutControls c) {
saveControls();
co_ = c;
return *this;
}
//! \~english Save control flags to internal stack
//! \~russian Сохраняет состояние флагов во внутренний стек
@@ -331,11 +342,11 @@ public:
//! \~english Turn on output device "d". Returns if it was enabled
//! \~russian Включает устройство вывода "d". Возвращает было ли устройство активно
static bool enableOutputDevice(OutputDevice d) {return setOutputDevice(d, true);}
static bool enableOutputDevice(OutputDevice d) { return setOutputDevice(d, true); }
//! \~english Turn off output device "d". Returns if it was enabled
//! \~russian Выключает устройство вывода "d". Возвращает было ли устройство активно
static bool disableOutputDevice(OutputDevice d) {return setOutputDevice(d, false);}
static bool disableOutputDevice(OutputDevice d) { return setOutputDevice(d, false); }
//! \~english Set output to devices to "d"
//! \~russian Устанавливает устройства вывода "d"
@@ -343,7 +354,7 @@ public:
//! \~english Returns current output devices
//! \~russian Возвращает текущие устройства вывода
static OutputDevices currentOutputDevices() {return devs;}
static OutputDevices currentOutputDevices() { return devs; }
//! \~english Returns if output device "d" is active
//! \~russian Возвращает активно ли устройство вывода "d"
@@ -352,7 +363,10 @@ public:
//! \~english Construct with external buffer and ID "id". See \a Notifier for details
//! \~russian Конструктор с внешним буфером и ID "id". Подробнее \a Notifier
static PICout withExternalBuffer(PIString * buffer, int id = 0, PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::AddSpaces | PICoutManipulators::AddNewLine);
static PICout withExternalBuffer(PIString * buffer,
int id = 0,
PIFlags<PICoutManipulators::PICoutControl> controls = PICoutManipulators::AddSpaces |
PICoutManipulators::AddNewLine);
static PIMutex & __mutex__();
static PIString & __string__();

View File

@@ -1,23 +1,24 @@
/*
PIP - Platform Independent Primitives
Global includes
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Global includes
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/>.
*/
#include "piincludes.h"
#include "piincludes_p.h"
#include "pitime.h"
#ifndef QNX
@@ -26,21 +27,21 @@
# include <locale.h>
#endif
#ifdef MAC_OS
//# include <mach/mach_traps.h>
//# include <mach/mach.h>
// # include <mach/mach_traps.h>
// # include <mach/mach.h>
# include <mach/clock.h>
//# include <crt_externs.h>
// # include <crt_externs.h>
#endif
#include <errno.h>
bool piDebug = true;
bool piDebug = true;
double piMountInfoRefreshIntervalMs = 10000.;
lconv * currentLocale =
#ifdef ANDROID
0;
0;
#else
std::localeconv();
std::localeconv();
#endif
#ifdef MAC_OS
@@ -49,9 +50,9 @@ clock_serv_t __pi_mac_clock;
#ifdef WINDOWS
FILETIME __pi_ftjan1970;
long long __pi_perf_freq = -1;
long long __pi_perf_freq = -1;
PINtQueryTimerResolution getTimerResolutionAddr = 0;
PINtSetTimerResolution setTimerResolutionAddr = 0;
PINtSetTimerResolution setTimerResolutionAddr = 0;
#endif
void errorClear() {
@@ -65,8 +66,14 @@ void errorClear() {
PIString errorString() {
#ifdef WINDOWS
char * msg = nullptr;
int err = GetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, NULL);
int err = GetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&msg,
0,
NULL);
PIString ret = PIStringAscii("code ") + PIString::fromNumber(err) + PIStringAscii(" - ");
if (msg) {
ret += PIString::fromSystem(msg).trim();

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english Minimal PIP includes
* \~russian Минимально-необходимые инклюды PIP
*/
*/
/*
PIP - Platform Independent Primitives
Minimal PIP includes
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Minimal PIP includes
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 PIINCLUDES_H
@@ -28,6 +28,7 @@
#include "pibase.h"
#include "piflags.h"
#include <sys/types.h>
#ifdef PIP_STD_IOSTREAM
# include <iostream>
@@ -38,7 +39,8 @@ class PIMutexLocker;
class PIObject;
class PIString;
class PIByteArray;
template <typename P> class PIBinaryStream;
template<typename P>
class PIBinaryStream;
#ifndef MICRO_PIP
class PIInit;
#endif

View File

@@ -1,58 +1,60 @@
/*
PIP - Platform Independent Primitives
Private PIP includes
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
PIP - Platform Independent Primitives
Private PIP includes
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@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 PIINCLUDES_P_H
#define PIINCLUDES_P_H
// clang-format off
#include "picout.h"
#ifdef WINDOWS
# ifdef _WIN32_WINNT
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
# endif
# include <stdarg.h>
# include <windef.h>
# include <winbase.h>
typedef LONG(NTAPI*PINtQueryTimerResolution)(PULONG, PULONG, PULONG);
typedef LONG(NTAPI*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
typedef LONG(NTAPI * PINtQueryTimerResolution)(PULONG, PULONG, PULONG);
typedef LONG(NTAPI * PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
#endif
#ifdef CC_GCC
# include <unistd.h>
#endif
#include <string.h>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <cstdlib>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#ifdef FREERTOS
# ifdef ESP_PLATFORM
# include "freertos/FreeRTOS.h"
# include "freertos/task.h"
# include "freertos/FreeRTOS.h"
# include "freertos/task.h"
# endif
# ifdef ARDUINO_ARCH_STM32
# include <STM32FreeRTOS.h>
# include <STM32FreeRTOS.h>
# endif
#endif
// clang-format on
#endif // PIINCLUDES_P_H

View File

@@ -1,106 +1,105 @@
/*
PIP - Platform Independent Primitives
Initialization
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Initialization
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/>.
*/
#include "piincludes_p.h"
#include "piinit.h"
#include "piincludes_p.h"
#ifndef MICRO_PIP
#include "pitime.h"
#include "pisignals.h"
#include "piobject.h"
#include "pisysteminfo.h"
#include "piresourcesstorage.h"
#include "pidir.h"
#include "piprocess.h"
#ifdef ESP_PLATFORM
# include "esp_system.h"
#endif
#include <codecvt>
#ifdef WINDOWS
# include <winsock2.h>
# include "pidir.h"
# include "piobject.h"
# include "piprocess.h"
# include "piresourcesstorage.h"
# include "pisignals.h"
# include "pisysteminfo.h"
# include "pitime.h"
# ifdef ESP_PLATFORM
# include "esp_system.h"
# endif
# include <codecvt>
# ifdef WINDOWS
# include <winsock2.h>
extern FILETIME __pi_ftjan1970;
extern PINtQueryTimerResolution getTimerResolutionAddr;
extern PINtSetTimerResolution setTimerResolutionAddr;
void __PISetTimerResolution() {
if (setTimerResolutionAddr == NULL || getTimerResolutionAddr == NULL)
return;
if (setTimerResolutionAddr == NULL || getTimerResolutionAddr == NULL) return;
ULONG _max(0), _min(0), _cur(0);
//printf("getTimerResolution ...\n");
// printf("getTimerResolution ...\n");
LONG q = getTimerResolutionAddr(&_max, &_min, &_cur);
//printf("getTimerResolution %d %lu %lu %lu\n", q, _min, _max, _cur);
if (q == 0)
setTimerResolutionAddr(_min, TRUE, &_cur);
//printf("setTimerResolution %lu\n", cur);
// printf("getTimerResolution %d %lu %lu %lu\n", q, _min, _max, _cur);
if (q == 0) setTimerResolutionAddr(_min, TRUE, &_cur);
// printf("setTimerResolution %lu\n", cur);
}
#else
# include <pwd.h>
# include <sys/utsname.h>
# include <pthread.h>
# ifdef BLACKBERRY
# include <signal.h>
# else
# include <csignal>
# include <pthread.h>
# include <pwd.h>
# include <sys/utsname.h>
# ifdef BLACKBERRY
# include <signal.h>
# else
# include <csignal>
# endif
# endif
#endif
#ifdef MAC_OS
# include <mach/mach_traps.h>
# include <mach/mach.h>
# include <mach/clock.h>
# ifdef MAC_OS
# include <mach/clock.h>
# include <mach/mach.h>
# include <mach/mach_traps.h>
extern clock_serv_t __pi_mac_clock;
#endif
#ifdef PIP_ICU
# define U_NOEXCEPT
# include <unicode/uclean.h>
# include <unicode/ucnv.h>
#endif
# endif
# ifdef PIP_ICU
# define U_NOEXCEPT
# include <unicode/uclean.h>
# include <unicode/ucnv.h>
# endif
#ifdef HAS_LOCALE
# ifdef HAS_LOCALE
static locale_t currentLocale_t = 0;
#endif
# endif
PRIVATE_DEFINITION_START(PIInit)
#ifdef WINDOWS
HMODULE ntlib;
ULONG prev_res;
#endif
bool delete_locs;
# ifdef WINDOWS
HMODULE ntlib;
ULONG prev_res;
# endif
bool delete_locs;
PRIVATE_DEFINITION_END(PIInit)
void __sighandler__(PISignals::Signal s) {
//piCout << Hex << int(s);
if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput)
piMSleep(10);
// piCout << Hex << int(s);
if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput) piMSleep(10);
if (s == PISignals::UserDefined1)
dumpApplicationToFile(PIDir::home().path() + PIDir::separator + PIStringAscii("_PIP_DUMP_") + PIString::fromNumber(PIProcess::currentPID()));
dumpApplicationToFile(PIDir::home().path() + PIDir::separator + PIStringAscii("_PIP_DUMP_") +
PIString::fromNumber(PIProcess::currentPID()));
}
PIInit::PIInit() {
file_charset = 0;
file_charset = 0;
PISystemInfo * sinfo = PISystemInfo::instance();
sinfo->execDateTime = PIDateTime::current();
sinfo->execDateTime = PIDateTime::current();
setFileCharset("UTF-8");
#ifndef ANDROID
# ifndef ANDROID
PISignals::setSlot(__sighandler__);
PISignals::grabSignals(PISignals::UserDefined1);
# ifndef WINDOWS
# ifndef WINDOWS
PISignals::grabSignals(PISignals::StopTTYInput | PISignals::StopTTYOutput);
sigset_t ss;
sigemptyset(&ss);
@@ -109,25 +108,25 @@ PIInit::PIInit() {
pthread_sigmask(SIG_BLOCK, &ss, 0);
signal(SIGPIPE, SIG_IGN);
PIStringList ifpathes;
ifpathes << PIStringAscii("/bin/ifconfig") << PIStringAscii("/sbin/ifconfig")
<< PIStringAscii("/usr/bin/ifconfig") << PIStringAscii("/usr/sbin/ifconfig");
piForeachC (PIString & i, ifpathes) {
ifpathes << PIStringAscii("/bin/ifconfig") << PIStringAscii("/sbin/ifconfig") << PIStringAscii("/usr/bin/ifconfig")
<< PIStringAscii("/usr/sbin/ifconfig");
piForeachC(PIString & i, ifpathes) {
if (fileExists(i)) {
sinfo->ifconfigPath = i;
break;
}
}
# else //WINDOWS
# else // WINDOWS
// OS version
DWORD dwVersion = GetVersion();
DWORD dwVersion = GetVersion();
DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
DWORD dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
sinfo->OS_version = PIString::fromNumber(dwMajorVersion) + "." + PIString::fromNumber(dwMinorVersion);
sinfo->OS_version = PIString::fromNumber(dwMajorVersion) + "." + PIString::fromNumber(dwMinorVersion);
// WinSock inint
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
// Timers init
SYSTEMTIME jan1970 = {1970, 1, 4, 1, 0, 0, 0, 0};
SystemTimeToFileTime(&jan1970, &__pi_ftjan1970);
@@ -135,7 +134,7 @@ PIInit::PIInit() {
pf.QuadPart = -1;
if (QueryPerformanceFrequency(&pf) != 0) __pi_perf_freq = pf.QuadPart;
if (__pi_perf_freq == 0) __pi_perf_freq = -1;
// Sleep precision init
PRIVATE->ntlib = LoadLibraryA("ntdll.dll");
if (PRIVATE->ntlib) {
@@ -143,66 +142,65 @@ PIInit::PIInit() {
setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
__PISetTimerResolution();
}
# endif //WINDOWS
# ifdef HAS_LOCALE
//std::cout << "has locale" << std::endl;
# endif // WINDOWS
# ifdef HAS_LOCALE
// std::cout << "has locale" << std::endl;
if (currentLocale_t != 0) {
freelocale(currentLocale_t);
currentLocale_t = 0;
}
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, "C"), 0);
setlocale(LC_CTYPE, "en_US.UTF-8");
//std::ios_base::sync_with_stdio(false);
//std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
//std::wcout.imbue(utf8);
# else //HAS_LOCALE
// std::ios_base::sync_with_stdio(false);
// std::locale utf8( std::locale(), new std::codecvt_utf8<wchar_t> );
// std::wcout.imbue(utf8);
# else // HAS_LOCALE
setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C");
# endif //HAS_LOCALE
#endif //ANDROID
# endif // HAS_LOCALE
# endif // ANDROID
PRIVATE->delete_locs = false;
__syslocname__ = __sysoemname__ = 0;
__utf8name__ = const_cast<char*>("UTF-8");
#ifdef PIP_ICU
__utf8name__ = const_cast<char *>("UTF-8");
# ifdef PIP_ICU
UErrorCode e((UErrorCode)0);
u_init(&e);
# ifdef WINDOWS
# ifdef WINDOWS
PRIVATE->delete_locs = true;
CPINFOEX cpinfo;
int l = 0;
GetCPInfoEx(CP_OEMCP, 0, &cpinfo);
for (l = 0; l < MAX_PATH; ++l)
if (cpinfo.CodePageName[l] == '\0' || cpinfo.CodePageName[l] == ' ')
break;
if (cpinfo.CodePageName[l] == '\0' || cpinfo.CodePageName[l] == ' ') break;
__sysoemname__ = new char[256];
memset(__sysoemname__, 0, 256);
memcpy(__sysoemname__, "ibm-", 4);
memcpy(&(__sysoemname__[4]), cpinfo.CodePageName, l);
# else
# else
/*PIString en(getenv("LANG"));
if (!en.isEmpty())
en = en.mid(en.find(".") + 1);
en = en.mid(en.find(".") + 1);
PIByteArray enba = en.toByteArray();
memcpy(__syslocname__, enba.data(), enba.size_s());*/
# endif
//piCout << __syslocname__;
//piCout << __sysoemname__;
#else //PIP_ICU
# ifdef WINDOWS
__syslocname__ = (char *)CP_ACP;
__sysoemname__ = (char *)CP_OEMCP;
__utf8name__ = (char *)CP_UTF8;
# endif
#endif //PIP_ICU
#ifdef MAC_OS
# endif
// piCout << __syslocname__;
// piCout << __sysoemname__;
# else // PIP_ICU
# ifdef WINDOWS
__syslocname__ = (char *)CP_ACP;
__sysoemname__ = (char *)CP_OEMCP;
__utf8name__ = (char *)CP_UTF8;
# endif
# endif // PIP_ICU
# ifdef MAC_OS
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
#endif
# endif
char cbuff[1024];
memset(cbuff, 0, 1024);
if (gethostname(cbuff, 1023) == 0) {
sinfo->hostname = cbuff;
}
#ifdef WINDOWS
# ifdef WINDOWS
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
sinfo->processorsCount = sysinfo.dwNumberOfProcessors;
@@ -216,57 +214,54 @@ PIInit::PIInit() {
}
int argc_(0);
wchar_t ** argv_ = CommandLineToArgvW(GetCommandLineW(), &argc_);
if (argc_ > 0 && argv_ != 0)
sinfo->execCommand = argv_[0];
if (argc_ > 0 && argv_ != 0) sinfo->execCommand = argv_[0];
LocalFree(argv_);
memset(cbuff, 0, 1024);
ulong unlen = 1023;
if (GetUserNameA(cbuff, &unlen) != 0)
sinfo->user = cbuff;
#else //WINDOWS
if (GetUserNameA(cbuff, &unlen) != 0) sinfo->user = cbuff;
# else // WINDOWS
sinfo->processorsCount = piMaxi(1, int(sysconf(_SC_NPROCESSORS_ONLN)));
passwd * ps = getpwuid(getuid());
passwd * ps = getpwuid(getuid());
if (ps)
sinfo->user = ps->pw_name;
else {
memset(cbuff, 0, 1024);
char * l = getlogin();
if (l)
sinfo->user = l;
if (l) sinfo->user = l;
}
struct utsname uns;
if (uname(&uns) == 0) {
sinfo->OS_version = uns.release;
sinfo->OS_version = uns.release;
sinfo->architecture = uns.machine;
}
#endif //WINDOWS
# endif // WINDOWS
#ifdef ESP_PLATFORM
# ifdef ESP_PLATFORM
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
sinfo->processorsCount = chip_info.cores;
sinfo->architecture = "Xtensa LX6";
//printf("silicon revision %d, ", chip_info.revision);
sinfo->OS_version = esp_get_idf_version();
#endif
sinfo->architecture = "Xtensa LX6";
// printf("silicon revision %d, ", chip_info.revision);
sinfo->OS_version = esp_get_idf_version();
# endif
sinfo->OS_name =
#ifdef WINDOWS
PIStringAscii("Windows");
#elif defined(QNX)
PIStringAscii("QNX");
#elif defined(MAC_OS)
PIStringAscii("MacOS");
#elif defined(ANDROID)
PIStringAscii("Android");
#elif defined(FREE_BSD)
PIStringAscii("FreeBSD");
#elif defined(FREERTOS)
PIStringAscii("FreeRTOS");
#elif defined(MICRO_PIP)
PIStringAscii("MicroPIP");
#else
uns.sysname;
#endif
# ifdef WINDOWS
PIStringAscii("Windows");
# elif defined(QNX)
PIStringAscii("QNX");
# elif defined(MAC_OS)
PIStringAscii("MacOS");
# elif defined(ANDROID)
PIStringAscii("Android");
# elif defined(FREE_BSD)
PIStringAscii("FreeBSD");
# elif defined(FREERTOS)
PIStringAscii("FreeRTOS");
# elif defined(MICRO_PIP)
PIStringAscii("MicroPIP");
# else
uns.sysname;
# endif
}
@@ -274,74 +269,82 @@ PIInit::~PIInit() {
if (file_charset) delete[] file_charset;
file_charset = 0;
PIResourcesStorage::instance()->clear();
#ifdef WINDOWS
# ifdef WINDOWS
WSACleanup();
if (PRIVATE->ntlib) FreeLibrary(PRIVATE->ntlib);
PRIVATE->ntlib = 0;
#endif
#ifdef MAC_OS
# endif
# ifdef MAC_OS
mach_port_deallocate(mach_task_self(), __pi_mac_clock);
#endif
# endif
if (PRIVATE->delete_locs) {
if (__syslocname__) delete __syslocname__;
if (__sysoemname__) delete __sysoemname__;
}
#ifdef PIP_ICU
# ifdef PIP_ICU
u_cleanup();
#endif
# endif
}
bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
switch (o) {
case boICU: return
#ifdef PIP_ICU
true;
#else
false;
#endif
case boUSB: return
#ifdef PIP_USB
true;
#else
false;
#endif
case boCrypt: return
#ifdef PIP_CRYPT
true;
#else
false;
#endif
case boIntrospection: return
#ifdef PIP_INTROSPECTION
true;
#else
false;
#endif
case boFFTW: return
#ifdef PIP_FFTW
true;
#else
false;
#endif
case boCompress: return
#ifdef PIP_COMPRESS
true;
#else
false;
#endif
case boOpenCL: return
#ifdef PIP_OPENCL
true;
#else
false;
#endif
case boCloud: return
#ifdef PIP_CLOUD
true;
#else
false;
#endif
case boICU:
return
# ifdef PIP_ICU
true;
# else
false;
# endif
case boUSB:
return
# ifdef PIP_USB
true;
# else
false;
# endif
case boCrypt:
return
# ifdef PIP_CRYPT
true;
# else
false;
# endif
case boIntrospection:
return
# ifdef PIP_INTROSPECTION
true;
# else
false;
# endif
case boFFTW:
return
# ifdef PIP_FFTW
true;
# else
false;
# endif
case boCompress:
return
# ifdef PIP_COMPRESS
true;
# else
false;
# endif
case boOpenCL:
return
# ifdef PIP_OPENCL
true;
# else
false;
# endif
case boCloud:
return
# ifdef PIP_CLOUD
true;
# else
false;
# endif
default: return false;
}
return false;
@@ -362,7 +365,7 @@ PIStringList PIInit::buildOptions() {
}
void PIInit::setFileCharset(const char *charset) {
void PIInit::setFileCharset(const char * charset) {
if (file_charset) delete file_charset;
file_charset = 0;
if (charset) {
@@ -375,14 +378,12 @@ void PIInit::setFileCharset(const char *charset) {
bool PIInit::fileExists(const PIString & p) {
FILE * f = fopen(p.data(), "r");
if (f == 0)
return false;
if (f == 0) return false;
fclose(f);
return true;
}
int __PIInit_Initializer__::count_(0);
PIInit * __PIInit_Initializer__::__instance__(0);
@@ -390,7 +391,7 @@ PIInit * __PIInit_Initializer__::__instance__(0);
__PIInit_Initializer__::__PIInit_Initializer__() {
count_++;
if (count_ > 1) return;
//piCout << "create PIInit";
// piCout << "create PIInit";
__instance__ = new PIInit();
}
@@ -398,7 +399,7 @@ __PIInit_Initializer__::__PIInit_Initializer__() {
__PIInit_Initializer__::~__PIInit_Initializer__() {
count_--;
if (count_ > 0) return;
//piCout << "delete PIInit";
// piCout << "delete PIInit";
if (__instance__ != 0) {
delete __instance__;
__instance__ = 0;
@@ -406,4 +407,3 @@ __PIInit_Initializer__::~__PIInit_Initializer__() {
}
#endif // MICRO_PIP

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english Library initialization
* \~russian Инициализация библиотеки
*/
*/
/*
PIP - Platform Independent Primitives
Initialization
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Initialization
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 PIINIT_H
@@ -30,7 +30,7 @@
#ifndef MICRO_PIP
#include "piincludes.h"
# include "piincludes.h"
class PIFile;
@@ -51,6 +51,7 @@ static __PIInit_Initializer__ __piinit_initializer__;
class PIP_EXPORT PIInit {
friend class __PIInit_Initializer__;
friend class PIFile;
public:
~PIInit();
@@ -58,16 +59,16 @@ public:
//! \~english Build options which PIP library was built
//! \~russian Опции, с которыми был собран PIP
enum BuildOption {
boICU /*! \~english Unicode support by ICU \~russian Поддержка юникода через ICU */ = 0x01,
boUSB /*! \~english USB support \~russian Поддержка USB */ = 0x02,
boCrypt /*! \~english Crypt support \~russian Поддержка шифрования */ = 0x08,
boIntrospection /*! \~english Introspection \~russian Интроспекция */ = 0x010,
boFFTW /*! \~english FFTW3 support \~russian Поддержка FFTW3 */ = 0x40,
boCompress /*! \~english Zlib compression support \~russian Поддержка сжатия Zlib */ = 0x80,
boOpenCL /*! \~english OpenCL support \~russian Поддержка OpenCL */ = 0x100,
boICU /*! \~english Unicode support by ICU \~russian Поддержка юникода через ICU */ = 0x01,
boUSB /*! \~english USB support \~russian Поддержка USB */ = 0x02,
boCrypt /*! \~english Crypt support \~russian Поддержка шифрования */ = 0x08,
boIntrospection /*! \~english Introspection \~russian Интроспекция */ = 0x010,
boFFTW /*! \~english FFTW3 support \~russian Поддержка FFTW3 */ = 0x40,
boCompress /*! \~english Zlib compression support \~russian Поддержка сжатия Zlib */ = 0x80,
boOpenCL /*! \~english OpenCL support \~russian Поддержка OpenCL */ = 0x100,
boCloud /*! \~english PICloud transport support \~russian Поддержка облачного транспорта PICloud */ = 0x200,
};
static PIInit * instance() {return __PIInit_Initializer__::__instance__;}
static PIInit * instance() { return __PIInit_Initializer__::__instance__; }
//! \ingroup Core
//! \~english Returns if build option was enabled
@@ -78,9 +79,10 @@ public:
//! \~english Returns build options as stringlist
//! \~russian Возвращает опции сборки как список строк
static PIStringList buildOptions();
private:
explicit PIInit();
void setFileCharset(const char *charset);
void setFileCharset(const char * charset);
bool fileExists(const PIString & p);
PRIVATE_DECLARATION(PIP_EXPORT)
char * file_charset;

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english Base types and functions
* \~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 PIMEMORYBLOCK_H
@@ -34,40 +34,53 @@
//! \~russian Вспомогательная структура для сохранения/извлечения произвольного блока данных в/из PIBinaryStream
struct PIMemoryBlock {
public:
//! \~english Constructs data block
//! \~russian Создает блок данных
PIMemoryBlock(void * data_ = 0, int size_ = 0) {
d = data_;
s = size_;
}
//! \~english Constructs data block
//! \~russian Создает блок данных
PIMemoryBlock(void * data_ = 0, int size_ = 0) {d = data_; s = size_;}
PIMemoryBlock(const void * data_, const int size_) {
d = const_cast<void *>(data_);
s = size_;
}
//! \~english Constructs data block
//! \~russian Создает блок данных
PIMemoryBlock(const void * data_, const int size_) {d = const_cast<void * >(data_); s = size_;}
PIMemoryBlock(const PIMemoryBlock & o) {
d = o.d;
s = o.s;
}
PIMemoryBlock(const PIMemoryBlock & o) {d = o.d; s = o.s;}
PIMemoryBlock & operator =(const PIMemoryBlock & o) {d = o.d; s = o.s; return *this;}
PIMemoryBlock & operator=(const PIMemoryBlock & o) {
d = o.d;
s = o.s;
return *this;
}
//! \~english Pointer to data
//! \~russian Указатель на данные
void * data() {return d;}
void * data() { return d; }
//! \~english Pointer to data
//! \~russian Указатель на данные
const void * data() const {return d;}
const void * data() const { return d; }
//! \~english Size of data in bytes
//! \~russian Размер данных в байтах
int size() const {return s;}
int size() const { return s; }
private:
void * d;
int s;
};
//! \~english Returns PIMemoryBlock from pointer to variable "ptr" with type "T"
//! \~russian Возвращает PIMemoryBlock из указателя "ptr" типа "T"
template<typename T>
PIMemoryBlock createMemoryBlock(const T * ptr) {return PIMemoryBlock(ptr, sizeof(T));}
PIMemoryBlock createMemoryBlock(const T * ptr) {
return PIMemoryBlock(ptr, sizeof(T));
}
#endif // PIMEMORYBLOCK_H

View File

@@ -1,29 +1,30 @@
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
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/>.
*/
#include "piobject.h"
#include "pithread.h"
#include "piconditionvar.h"
#include "pithread.h"
#ifndef MICRO_PIP
# include "pisysteminfo.h"
# include "pifile.h"
# include "piiostream.h"
# include "pisysteminfo.h"
#endif
@@ -104,15 +105,14 @@
PIObject::__MetaFunc::__MetaFunc() {
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
types[i] = names[i] = nullptr;
types_id[i] = 0;
types_id[i] = 0;
}
}
int PIObject::__MetaFunc::argumentsCount() const {
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i)
if (!types[i])
return i;
if (!types[i]) return i;
return __PIOBJECT_MAX_ARGS__;
}
@@ -129,9 +129,7 @@ PIString PIObject::__MetaFunc::arguments() const {
PIString PIObject::__MetaFunc::fullFormat() const {
PIString ret = PIStringAscii(type_ret) + " " +
PIStringAscii(scope) + "::" +
PIStringAscii(func_name) +"(";
PIString ret = PIStringAscii(type_ret) + " " + PIStringAscii(scope) + "::" + PIStringAscii(func_name) + "(";
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
if (!types[i]) break;
if (i > 0) ret += ", ";
@@ -143,7 +141,7 @@ PIString PIObject::__MetaFunc::fullFormat() const {
void PIObject::__MetaFunc::__setFuncName(const char * n) {
func_name = n;
func_name = n;
func_name_id = PIStringAscii(n).hash();
}
@@ -151,27 +149,25 @@ void PIObject::__MetaFunc::__setFuncName(const char * n) {
void PIObject::__MetaFunc::__addArgument(const char * t, const char * n) {
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
if (types[i]) continue;
types[i] = t;
names[i] = n;
types[i] = t;
names[i] = n;
types_id[i] = PIObject::simplifyType(t, false).hash();
break;
}
//PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes)
// PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes)
// << "__addArgument" << t << n << PIObject::simplifyType(t) << types_id.back();
}
bool PIObject::__MetaFunc::canConnectTo(const __MetaFunc & dst, int & args_count) const {
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
//piCout << "canConnectTo" << i << types[i] << dst.types[i];
// piCout << "canConnectTo" << i << types[i] << dst.types[i];
args_count = i;
if (!dst.types[i]) break;
if (!types[i]) return false;
if (types_id[i] != dst.types_id[i])
return false;
if (types_id[i] != dst.types_id[i]) return false;
}
return true;
}
@@ -182,13 +178,13 @@ PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__),
mutexObjects().lock();
objects() << this;
mutexObjects().unlock();
//piCout << "new" << this;
// piCout << "new" << this;
}
PIObject::~PIObject() {
in_event_cnt = 0;
//piCout << "delete" << this;
// piCout << "delete" << this;
mutexObjects().lock();
objects().removeAll(this);
mutexObjects().unlock();
@@ -198,19 +194,16 @@ PIObject::~PIObject() {
}
bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple> & vl) {
if (method.isEmpty()) return false;
if (!isPIObject()) {
piCout << "Error: \"execute(" << method << ")\":" << (void*)this << "is not PIObject!";
piCout << "Error: \"execute(" << method << ")\":" << (void *)this << "is not PIObject!";
return false;
}
int ac = 0;
__MetaFunc func;
bool ok = findSuitableMethodV(method, vl.size_s(), ac, func);
if (!ok)
return false;
if (!ok) return false;
callAddrV(func.addrV, toThis(), ac, vl);
return true;
}
@@ -218,18 +211,17 @@ bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple>
bool PIObject::executeQueued(PIObject * performer, const PIString & method, const PIVector<PIVariantSimple> & vl) {
if (!isPIObject()) {
piCout << "Error: \"executeQueued(" << method << ")\": this(" << (void*)this << ") is not PIObject!";
piCout << "Error: \"executeQueued(" << method << ")\": this(" << (void *)this << ") is not PIObject!";
return false;
}
if (!performer->isPIObject()) {
piCout << "Error: \"executeQueued(" << method << ")\": performer(" << (void*)performer << ") is not PIObject!";
piCout << "Error: \"executeQueued(" << method << ")\": performer(" << (void *)performer << ") is not PIObject!";
return false;
}
int ac = 0;
__MetaFunc func;
bool ok = findSuitableMethodV(method, vl.size_s(), ac, func);
if (!ok)
return false;
if (!ok) return false;
performer->postQueuedEvent(__QueuedEvent(func.addrV, toThis(), this, performer, vl));
performer->proc_event_queue = true;
return true;
@@ -262,8 +254,7 @@ bool PIObject::isMethodEHContains(const PIString & name) const {
PIMutexLocker ml(__meta_mutex());
const __MetaData & ehd(__meta_data()[classNameID()]);
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
if (eh.value().func_name_id == search_id)
return true;
if (eh.value().func_name_id == search_id) return true;
}
return false;
}
@@ -274,8 +265,7 @@ PIString PIObject::methodEHArguments(const PIString & name) const {
PIMutexLocker ml(__meta_mutex());
const __MetaData & ehd(__meta_data()[classNameID()]);
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
if (eh.value().func_name_id == search_id)
return eh.value().arguments();
if (eh.value().func_name_id == search_id) return eh.value().arguments();
}
return PIString();
}
@@ -286,8 +276,7 @@ PIString PIObject::methodEHFullFormat(const PIString & name) const {
PIMutexLocker ml(__meta_mutex());
const __MetaData & ehd(__meta_data()[classNameID()]);
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
if (eh.value().func_name_id == search_id)
return eh.value().fullFormat();
if (eh.value().func_name_id == search_id) return eh.value().fullFormat();
}
return PIString();
}
@@ -303,8 +292,7 @@ PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const {
PIVector<__MetaFunc> ret;
const __MetaData & ehd(__meta_data()[classNameID()]);
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
if (eh.value().func_name_id == search_id)
ret << eh.value();
if (eh.value().func_name_id == search_id) ret << eh.value();
}
return ret;
}
@@ -316,25 +304,38 @@ PIObject::__MetaFunc PIObject::methodEH(const void * addr) const {
}
PIObject::Connection PIObject::piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc) {
//piCout << "piConnect ...";
//piCout << "piConnect" << src << (void*)(dest) << sig;
//piCout << "piConnect" << src->className() << "->" << ((PIObject*)dest)->className();
PIObject::Connection PIObject::piConnect(PIObject * src,
const PIString & sig,
PIObject * dest_o,
void * dest,
void * ev_h,
void * e_h,
int args,
const char * loc) {
// piCout << "piConnect ...";
// piCout << "piConnect" << src << (void*)(dest) << sig;
// piCout << "piConnect" << src->className() << "->" << ((PIObject*)dest)->className();
PIMutexLocker _ml(src->mutex_connect);
PIMutexLocker _mld(dest_o->mutex_connect, src != dest_o);
Connection conn(ev_h, e_h, sig, src, dest_o, dest, args);
src->connections << conn;
//piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s() << "...";
//piCout << "addConnector" << dest_o << src;
// piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s() << "...";
// piCout << "addConnector" << dest_o << src;
dest_o->connectors << src;
//piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s();
//piCout << "piConnect ok";
// piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s();
// piCout << "piConnect ok";
return conn;
}
PIObject::Connection PIObject::piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer) {
PIObject::Connection PIObject::piConnectU(PIObject * src,
const PIString & sig,
PIObject * dest_o,
void * dest,
const PIString & hname,
const char * loc,
PIObject * performer) {
if (src == 0 || dest_o == 0 || dest == 0) return Connection();
if (!src->isPIObject()) {
piCout << "[piConnectU] \"" << sig << "\" -> \"" << hname << "\" error: source object is not PIObject! (" << loc << ")";
@@ -356,29 +357,29 @@ PIObject::Connection PIObject::piConnectU(PIObject * src, const PIString & sig,
piCout << "[piConnectU] Error: can`t find handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
return Connection();
}
void * addr_src(0), * addr_dest(0);
void *addr_src(0), *addr_dest(0);
int args(0);
bool que = (performer != 0);
piForeachC (__MetaFunc & fs, m_src) {
piForeachC(__MetaFunc & fs, m_src) {
if (addr_src != 0) break;
piForeachC (__MetaFunc & fd, m_dest) {
piForeachC(__MetaFunc & fd, m_dest) {
if (addr_src != 0) break;
if (fs.canConnectTo(fd, args)) {
addr_src = fs.addr;
addr_src = fs.addr;
addr_dest = que ? fd.addrV : fd.addr;
}
}
}
if (addr_src == 0) {
piCout << "[piConnectU] Error: can`t find suitable pair of event \"" << sig << "\" in class \"" << src->className()
<< "\" and handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
<< "\" and handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
return Connection();
}
Connection conn(addr_dest, addr_src, sig, src, dest_o, dest, args, performer);
src->connections << conn;
if (que) performer->proc_event_queue = true;
dest_o->connectors << src;
//piCout << cc << cq << _ol.size();//"connect" << src << "->" << dest_o << ", dest.connectors.size() =" << dest_o->connectors.size();
// piCout << cc << cq << _ol.size();//"connect" << src << "->" << dest_o << ", dest.connectors.size() =" << dest_o->connectors.size();
return conn;
}
@@ -395,7 +396,7 @@ PIObject::Connection PIObject::piConnectLS(PIObject * src, const PIString & sig,
}
PIMutexLocker ml(__meta_mutex());
PIMutexLocker mls(src->mutex_connect);
//piCout << "locked";
// piCout << "locked";
PIVector<__MetaFunc> m_src = src->findEH(sig);
if (m_src.isEmpty()) {
piCout << "[piConnectLS] Error: can`t find event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
@@ -403,15 +404,16 @@ PIObject::Connection PIObject::piConnectLS(PIObject * src, const PIString & sig,
return Connection();
}
if (m_src.size() != 1) {
piCout << "[piConnectLS] Error: can`t connect overloaded event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
piCout << "[piConnectLS] Error: can`t connect overloaded event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc
<< ")";
delete f;
return Connection();
}
PIObject::Connection conn(0, m_src[0].addr, sig, src);
//piCout << "found";
// piCout << "found";
conn.functor = f;
src->connections << conn;
//piCout << "finished";
// piCout << "finished";
return conn;
}
@@ -468,10 +470,10 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) {
void PIObject::piDisconnectAll() {
PIMutexLocker _ml(mutex_connect);
PIVector<PIObject * > cv = connectors.toVector();
// piCout << "disconnect connectors =" << connectors.size();
piForeach (PIObject * o, cv) {
// piCout << "disconnect"<< src << o;
PIVector<PIObject *> cv = connectors.toVector();
// piCout << "disconnect connectors =" << connectors.size();
piForeach(PIObject * o, cv) {
// piCout << "disconnect"<< src << o;
if (!o || (o == this)) continue;
if (!o->isPIObject()) continue;
#if !defined(ANDROID) && !defined(MAC_OS) && !defined(MICRO_PIP)
@@ -480,7 +482,7 @@ void PIObject::piDisconnectAll() {
PIVector<Connection> & oc(o->connections);
for (int i = 0; i < oc.size_s(); ++i) {
if (oc[i].functor) continue;
//piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);
// piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);
if (oc[i].dest_o == this) {
oc[i].destroy();
oc.remove(i);
@@ -488,8 +490,8 @@ void PIObject::piDisconnectAll() {
}
}
}
// piCout << "disconnect connections =" << connections.size();
piForeachC (PIObject::Connection & c, connections) {
// piCout << "disconnect connections =" << connections.size();
piForeachC(PIObject::Connection & c, connections) {
if (c.functor) continue;
if (!c.dest_o) continue;
if (!c.dest_o->isPIObject()) continue;
@@ -502,15 +504,14 @@ void PIObject::piDisconnectAll() {
void PIObject::updateConnectors() {
//piCout << "*** updateConnectors" << this;
// piCout << "*** updateConnectors" << this;
connectors.clear();
PIMutexLocker _ml(mutexObjects());
piForeach (PIObject * o, objects()) {
piForeach(PIObject * o, objects()) {
if (o == this) continue;
PIVector<Connection> & oc(o->connections);
piForeach (Connection & c, oc)
if (c.dest == this)
connectors << o;
piForeach(Connection & c, oc)
if (c.dest == this) connectors << o;
}
}
@@ -523,8 +524,8 @@ void PIObject::postQueuedEvent(const PIObject::__QueuedEvent & e) {
void * PIObject::toThis() const {
//piCout << ptrOffset() << (void*)this << (void*)((char*)this - ptrOffset());
return (void*)((char*)this - ptrOffset());
// piCout << ptrOffset() << (void*)this << (void*)((char*)this - ptrOffset());
return (void *)((char *)this - ptrOffset());
}
@@ -545,7 +546,7 @@ void PIObject::callQueuedEvents() {
PIVector<__QueuedEvent> qe = events_queue;
events_queue.clear();
mutex_queue.unlock();
piForeachC (__QueuedEvent & e, qe) {
piForeachC(__QueuedEvent & e, qe) {
if (e.dest_o->thread_safe_) e.dest_o->mutex_.lock();
e.dest_o->emitter_ = e.src;
callAddrV(e.slot, e.dest, e.values.size_s(), e.values);
@@ -580,7 +581,7 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
int j = m.argumentsCount();
if (mac < 0 || mac > j) mac = j;
if ((j <= args) && (ac < j)) {
ac = j;
ac = j;
mfi = i;
}
}
@@ -589,13 +590,13 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
return false;
}
ret_args = ac;
ret = ml[mfi];
ret = ml[mfi];
return true;
}
PIVector<PIObject * > & PIObject::objects() {
static PIVector<PIObject * > * ret = new PIVector<PIObject * >();
PIVector<PIObject *> & PIObject::objects() {
static PIVector<PIObject *> * ret = new PIVector<PIObject *>();
return *ret;
}
@@ -609,11 +610,16 @@ PIMutex & PIObject::mutexObjects() {
void PIObject::callAddrV(void * slot, void * obj, int args, const PIVector<PIVariantSimple> & vl) {
args = piMini(args, vl.size_s());
switch (args) {
case 0: ((void(*)(void *))slot)(obj); break;
case 1: ((void(*)(void * , const PIVariantSimple & ))slot)(obj, vl[0]); break;
case 2: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1]); break;
case 3: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1], vl[2]); break;
case 4: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1], vl[2], vl[3]); break;
case 0: ((void (*)(void *))slot)(obj); break;
case 1: ((void (*)(void *, const PIVariantSimple &))slot)(obj, vl[0]); break;
case 2: ((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &))slot)(obj, vl[0], vl[1]); break;
case 3:
((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))slot)(obj, vl[0], vl[1], vl[2]);
break;
case 4:
((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))
slot)(obj, vl[0], vl[1], vl[2], vl[3]);
break;
default: break;
}
}
@@ -625,7 +631,7 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
int white = -1;
for (int i = 0; i < ret.size_s(); ++i) {
bool iw = ret[i] == ' ' || ret[i] == '\t' || ret[i] == '\r' || ret[i] == '\n';
//piCout << i << iw << white;
// piCout << i << iw << white;
if (white < 0) {
if (iw) {
white = i;
@@ -634,9 +640,9 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
} else {
if (!iw) {
ret.replace(white, i - white, " ");
i = white;
i = white;
white = -1;
//piCout << i;
// piCout << i;
}
}
}
@@ -652,11 +658,9 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
ret.replaceAll("> ", '>');
ret.replaceAll("& ", '&');
ret.replaceAll("* ", '*');
if (ret.startsWith("const ") && ret.endsWith("&"))
ret.cutLeft(6).cutRight(1).trim();
if (ret.startsWith("const ") && ret.endsWith("&")) ret.cutLeft(6).cutRight(1).trim();
} else {
if (ret.startsWith("const ") && ret.endsWith("&"))
ret.cutLeft(6).cutRight(1).trim();
if (ret.startsWith("const ") && ret.endsWith("&")) ret.cutLeft(6).cutRight(1).trim();
ret.removeAll(' ').removeAll('\t').removeAll('\r').removeAll('\n');
}
return ret;
@@ -670,49 +674,53 @@ bool PIObject::isPIObject(const PIObject * o) {
void PIObject::dump(const PIString & line_prefix) const {
//printf("dump %s \"%s\"\n", className(), name().data());
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
// printf("dump %s \"%s\"\n", className(), name().data());
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void *)this << ", \"" << name()
<< "\") {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " scope: " << scopeList().join(" -> ");
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
//printf("dump %d properties\n", properties_.size());
// printf("dump %d properties\n", properties_.size());
const char * o_name = "name";
auto it = properties_.makeIterator();
auto it = properties_.makeIterator();
while (it.next()) {
if (it.key() != piHashData((const uchar *)o_name, strlen(o_name)))
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << it.key() << ": " << it.value();
}
//printf("dump %d properties ok\n", properties_.size());
// printf("dump %d properties ok\n", properties_.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
const __MetaData & ehd(__meta_data()[classNameID()]);
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
//printf("dump %d methods\n", ehd.eh_func.size());
// printf("dump %d methods\n", ehd.eh_func.size());
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.value().fullFormat();
}
//printf("dump %d methods ok\n", ehd.eh_func.size());
// printf("dump %d methods ok\n", ehd.eh_func.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
//printf("dump %d connections\n",connections.size());
for (const Connection & c : connections) {
// printf("dump %d connections\n",connections.size());
for (const Connection & c: connections) {
PIObject * dst = c.dest_o;
__MetaFunc ef = methodEH(c.signal);
__MetaFunc ef = methodEH(c.signal);
PIString src(c.event);
if (ef.func_name)
src = PIStringAscii(ef.func_name) + "(" + ef.arguments() + ")";
if (ef.func_name) src = PIStringAscii(ef.func_name) + "(" + ef.arguments() + ")";
if (dst) {
__MetaFunc hf = dst->methodEH(c.slot);
PIString hf_fn;
if (!hf.func_name) hf_fn = "[BROKEN]";
else hf_fn = PIStringAscii(hf.func_name) + "(" + hf.arguments() + ")";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf_fn;
if (!hf.func_name)
hf_fn = "[BROKEN]";
else
hf_fn = PIStringAscii(hf.func_name) + "(" + hf.arguments() + ")";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest
<< ", \"" << dst->name() << "\")::" << hf_fn;
} else {
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << "[lambda]";
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> "
<< "[lambda]";
}
}
//printf("dump %d connections ok\n",connections.size());
// printf("dump %d connections ok\n",connections.size());
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
PICout(PICoutManipulators::AddNewLine) << line_prefix << "}";
}
@@ -721,8 +729,8 @@ void PIObject::dump(const PIString & line_prefix) const {
#ifndef MICRO_PIP
void dumpApplication(bool with_objects) {
PIMutexLocker _ml(PIObject::mutexObjects());
//printf("dump application ...\n");
PIDateTime cd = PIDateTime::current();
// printf("dump application ...\n");
PIDateTime cd = PIDateTime::current();
PISystemInfo * pi = PISystemInfo::instance();
PICout(PICoutManipulators::AddNewLine) << "application {";
PICout(PICoutManipulators::AddNewLine) << " PIP version: " << PIPVersion();
@@ -734,7 +742,8 @@ void dumpApplication(bool with_objects) {
PICout(PICoutManipulators::AddNewLine) << " username: \"" << pi->user << "\"";
PICout(PICoutManipulators::AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
PICout(PICoutManipulators::AddNewLine) << " started: " << pi->execDateTime.toString();
PICout(PICoutManipulators::AddNewLine) << " uptime: " << PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
PICout(PICoutManipulators::AddNewLine) << " uptime: "
<< PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects().size_s();
if (with_objects) {
@@ -743,7 +752,7 @@ void dumpApplication(bool with_objects) {
}
PICout(PICoutManipulators::AddNewLine) << " }";
PICout(PICoutManipulators::AddNewLine) << "}";
//printf("dump application done\n");
// printf("dump application done\n");
}
@@ -774,8 +783,6 @@ void PIObject::__MetaData::addScope(const char * s, uint shash) {
}
void PIObject::Connection::destroy() {
if (functor) delete functor;
functor = nullptr;
@@ -785,9 +792,9 @@ void PIObject::Connection::destroy() {
PIObject::Connection::Connection() {
slot = signal = dest = nullptr;
src_o = dest_o = performer = nullptr;
functor = nullptr;
eventID = 0;
args_count = 0;
functor = nullptr;
eventID = 0;
args_count = 0;
}
@@ -804,11 +811,9 @@ bool PIObject::Connection::disconnect() {
Connection & cc(src_o->connections[i]);
if (cc.eventID == eventID) {
if (dest_o && (cc.dest_o == dest_o)) {
if (cc.slot == slot)
found = true;
if (cc.slot == slot) found = true;
}
if (functor && (cc.functor == functor))
found = true;
if (functor && (cc.functor == functor)) found = true;
}
if (found) {
src_o->connections[i].destroy();
@@ -818,44 +823,43 @@ bool PIObject::Connection::disconnect() {
}
}
if (dest_o) {
if (dest_o->isPIObject())
dest_o->updateConnectors();
if (dest_o->isPIObject()) dest_o->updateConnectors();
}
if (ndm) dest_o->mutex_connect.unlock();
return ret;
}
PRIVATE_DEFINITION_START(PIObject::Deleter)
PIThread thread;
PIConditionVariable cond_var;
PIVector<PIObject*> obj_queue;
PIVector<PIObject *> obj_queue;
PRIVATE_DEFINITION_END(PIObject::Deleter)
PIObject::Deleter::Deleter() {
//piCout << "Deleter start ...";
PRIVATE->thread.setSlot([this](){
PIVector<PIObject*> oq;
// piCout << "Deleter start ...";
PRIVATE->thread.setSlot([this]() {
PIVector<PIObject *> oq;
PRIVATE->thread.lock();
if (PRIVATE->obj_queue.isEmpty()) PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
oq.swap(PRIVATE->obj_queue);
PRIVATE->thread.unlock();
for (PIObject * o : oq) deleteObject(o);
for (PIObject * o: oq)
deleteObject(o);
});
PRIVATE->thread.start();
}
PIObject::Deleter::~Deleter() {
//piCout << "~Deleter ...";
// piCout << "~Deleter ...";
PRIVATE->thread.stop();
PRIVATE->cond_var.notifyAll();
PRIVATE->thread.waitForFinish();
for (PIObject * o : PRIVATE->obj_queue) deleteObject(o);
//piCout << "~Deleter ok";
for (PIObject * o: PRIVATE->obj_queue)
deleteObject(o);
// piCout << "~Deleter ok";
}
@@ -867,24 +871,25 @@ PIObject::Deleter * PIObject::Deleter::instance() {
void PIObject::Deleter::post(PIObject * o) {
if (!o->isPIObject()) return;
//piCout << "[Deleter] post" << o << "...";
// piCout << "[Deleter] post" << o << "...";
PRIVATE->thread.lock();
if (!PRIVATE->obj_queue.contains(o)) {
PRIVATE->obj_queue << o;
PRIVATE->cond_var.notifyAll();
}
PRIVATE->thread.unlock();
//piCout << "[Deleter] post" << o << "done";
// piCout << "[Deleter] post" << o << "done";
}
void PIObject::Deleter::deleteObject(PIObject * o) {
//piCout << "[Deleter] delete" << (uintptr_t)o << "...";
// piCout << "[Deleter] delete" << (uintptr_t)o << "...";
if (o->isPIObject()) {
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
while (o->isInEvent()) piMinSleep();
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
// piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
while (o->isInEvent())
piMinSleep();
// piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
delete o;
}
//piCout << "[Deleter] delete" << (uintptr_t)o << "done";
// piCout << "[Deleter] delete" << (uintptr_t)o << "done";
}

View File

@@ -3,36 +3,36 @@
* \~\brief
* \~english Base object
* \~russian Базовый класс
*/
*/
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
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 PIOBJECT_H
#define PIOBJECT_H
#include "piinit.h"
#include "pimutex.h"
#include "piobject_macros.h"
#include "piqueue.h"
#include "piset.h"
#include "pivariant.h"
#include "pivariantsimple.h"
#include "pimutex.h"
#include "piset.h"
#include "piqueue.h"
#include "piobject_macros.h"
//! \ingroup Core
//! \~\brief
@@ -46,13 +46,14 @@ class PIP_EXPORT PIObject {
#endif
typedef PIObject __PIObject__;
typedef void __Parent__;
public:
NO_COPY_CLASS(PIObject);
//! \~english Contructs %PIObject with name "name"
//! \~russian Создает %PIObject с именем "name"
explicit PIObject(const PIString & name = PIString());
virtual ~PIObject();
//! \ingroup Core
@@ -61,19 +62,24 @@ public:
//! \~russian Вспомогательный класс для получения информации об успешности соединения и возможности его разрыва.
class PIP_EXPORT Connection {
friend class PIObject;
Connection(void * sl, void * si, const PIString & e = PIString(),
PIObject * s_o = nullptr, PIObject * d_o = nullptr,
void * d = nullptr, int ac = 0, PIObject * p = nullptr) {
slot = sl;
signal = si;
event = e;
eventID = e.hash();
src_o = s_o;
dest_o = d_o;
dest = d;
Connection(void * sl,
void * si,
const PIString & e = PIString(),
PIObject * s_o = nullptr,
PIObject * d_o = nullptr,
void * d = nullptr,
int ac = 0,
PIObject * p = nullptr) {
slot = sl;
signal = si;
event = e;
eventID = e.hash();
src_o = s_o;
dest_o = d_o;
dest = d;
args_count = ac;
performer = p;
functor = 0;
performer = p;
functor = 0;
}
void destroy();
void * slot;
@@ -81,31 +87,31 @@ public:
std::function<void()> * functor;
PIString event;
uint eventID;
PIObject * src_o, * dest_o;
PIObject *src_o, *dest_o;
PIObject * performer;
void * dest;
int args_count;
public:
public:
//! \~english Contructs invalid %Connection
//! \~russian Создает недействительный %Connection
Connection();
//! \~english Returns if %Connection is valid
//! \~russian Возвращает успешен ли %Connection
bool isValid() const {return signal;}
bool isValid() const { return signal; }
//! \~english Returns source object
//! \~russian Возвращает объект-источник
PIObject * sourceObject() const {return src_o;}
PIObject * sourceObject() const { return src_o; }
//! \~english Returns destination object or "nullptr" if this is lambda connection
//! \~russian Возвращает объект-приемник или "nullptr" если это соединение на лямбда-функцию
PIObject * destinationObject() const {return dest_o;}
PIObject * destinationObject() const { return dest_o; }
//! \~english Returns performer object or "nullptr" if this is non-queued connection
//! \~russian Возвращает объект-исполнитель или "nullptr" если это соединение не отложенное
PIObject * performerObject() const {return performer;}
PIObject * performerObject() const { return performer; }
//! \~english Disconnect this %Connection, returns if operation successful
//! \~russian Разрывает этот %Connection, возвращает успешен ли разрыв
@@ -116,84 +122,159 @@ private:
uint _signature_;
public:
//! \~english Returns object name
//! \~russian Возвращает имя объекта
PIString name() const {return property("name").toString();}
PIString name() const { return property("name").toString(); }
//! \~english Returns object class name
//! \~russian Возвращает имя класса объекта
virtual const char * className() const {return "PIObject";}
virtual const char * className() const { return "PIObject"; }
virtual uint classNameID() const {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
virtual uint classNameID() const {
static uint ret = PIStringAscii("PIObject").hash();
return ret;
}
static const char * __classNameCC() {return "PIObject";}
static uint __classNameIDS() {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
static const char * __classNameCC() { return "PIObject"; }
static uint __classNameIDS() {
static uint ret = PIStringAscii("PIObject").hash();
return ret;
}
//! \~english Returns parent class name
//! \~russian Возвращает имя родительского класса
virtual const char * parentClassName() const {return "";}
virtual const char * parentClassName() const { return ""; }
//! \~english Return if \a piCoutObj of this object is active
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
bool debug() const {return property("debug").toBool();}
bool debug() const { return property("debug").toBool(); }
//! \~english Set object name
//! \~russian Устанавливает имя объекта
void setName(const PIString & name) {setProperty("name", name);}
void setName(const PIString & name) { setProperty("name", name); }
//! \~english Set object \a piCoutObj active
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
void setDebug(bool debug) {setProperty("debug", debug);}
void setDebug(bool debug) { setProperty("debug", debug); }
//! \~english Returns property with name "name"
//! \~russian Возвращает свойство объекта по имени "name"
PIVariant property(const char * name) const {return properties_.value(piHashData((const uchar *)name, strlen(name)));}
PIVariant property(const char * name) const { return properties_.value(piHashData((const uchar *)name, strlen(name))); }
//! \~english Set property with name "name" to "value". If there is no such property in object it will be added
//! \~russian Устанавливает у объекта свойство по имени "name" в "value". Если такого свойства нет, оно добавляется
void setProperty(const char * name, const PIVariant & value) {properties_[piHashData((const uchar *)name, strlen(name))] = value; propertyChanged(name);}
void setProperty(const char * name, const PIVariant & value) {
properties_[piHashData((const uchar *)name, strlen(name))] = value;
propertyChanged(name);
}
//! \~english Returns if property with name "name" exists
//! \~russian Возвращает присутствует ли свойство по имени "name"
bool isPropertyExists(const char * name) const {return properties_.contains(piHashData((const uchar *)name, strlen(name)));}
void setThreadSafe(bool yes) {thread_safe_ = yes;}
bool isThreadSafe() const {return thread_safe_;}
bool isPropertyExists(const char * name) const { return properties_.contains(piHashData((const uchar *)name, strlen(name))); }
void setThreadSafe(bool yes) { thread_safe_ = yes; }
bool isThreadSafe() const { return thread_safe_; }
bool execute(const PIString & method, const PIVector<PIVariantSimple> & vl);
bool execute(const PIString & method) {return execute(method, PIVector<PIVariantSimple>());}
bool execute(const PIString & method, const PIVariantSimple & v0) {return execute(method, PIVector<PIVariantSimple>() << v0);}
bool execute(const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {return execute(method, PIVector<PIVariantSimple>() << v0 << v1);}
bool execute(const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {return execute(method, PIVector<PIVariantSimple>() << v0 << v1 << v2);}
bool execute(const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) {return execute(method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);}
bool execute(const PIString & method) { return execute(method, PIVector<PIVariantSimple>()); }
bool execute(const PIString & method, const PIVariantSimple & v0) { return execute(method, PIVector<PIVariantSimple>() << v0); }
bool execute(const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {
return execute(method, PIVector<PIVariantSimple>() << v0 << v1);
}
bool execute(const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {
return execute(method, PIVector<PIVariantSimple>() << v0 << v1 << v2);
}
bool execute(const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2,
const PIVariantSimple & v3) {
return execute(method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);
}
bool executeQueued(PIObject * performer, const PIString & method, const PIVector<PIVariantSimple> & vl);
bool executeQueued(PIObject * performer, const PIString & method) {return executeQueued(performer, method, PIVector<PIVariantSimple>());}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0) {return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0);}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1);}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) {return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);}
bool executeQueued(PIObject * performer, const PIString & method) {
return executeQueued(performer, method, PIVector<PIVariantSimple>());
}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0) {
return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0);
}
bool executeQueued(PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {
return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1);
}
bool executeQueued(PIObject * performer,
const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2) {
return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);
}
bool executeQueued(PIObject * performer,
const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2,
const PIVariantSimple & v3) {
return executeQueued(performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);
}
static bool execute(PIObject * o, const PIString & method, const PIVector<PIVariantSimple> & vl) {return o->execute(method, vl);}
static bool execute(PIObject * o, const PIString & method) {return execute(o, method, PIVector<PIVariantSimple>());}
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0) {return execute(o, method, PIVector<PIVariantSimple>() << v0);}
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1);}
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);}
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) {return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);}
static bool execute(PIObject * o, const PIString & method, const PIVector<PIVariantSimple> & vl) { return o->execute(method, vl); }
static bool execute(PIObject * o, const PIString & method) { return execute(o, method, PIVector<PIVariantSimple>()); }
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0) {
return execute(o, method, PIVector<PIVariantSimple>() << v0);
}
static bool execute(PIObject * o, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {
return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1);
}
static bool
execute(PIObject * o, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {
return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);
}
static bool execute(PIObject * o,
const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2,
const PIVariantSimple & v3) {
return execute(o, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);
}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVector<PIVariantSimple> & vl) {return o->executeQueued(performer, method, vl);}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method) {return executeQueued(o, performer, method, PIVector<PIVariantSimple>());}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0) {return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0);}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1);}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) {return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) {return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVector<PIVariantSimple> & vl) {
return o->executeQueued(performer, method, vl);
}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method) {
return executeQueued(o, performer, method, PIVector<PIVariantSimple>());
}
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0) {
return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0);
}
static bool
executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariantSimple & v0, const PIVariantSimple & v1) {
return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1);
}
static bool executeQueued(PIObject * o,
PIObject * performer,
const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2) {
return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2);
}
static bool executeQueued(PIObject * o,
PIObject * performer,
const PIString & method,
const PIVariantSimple & v0,
const PIVariantSimple & v1,
const PIVariantSimple & v2,
const PIVariantSimple & v3) {
return executeQueued(o, performer, method, PIVector<PIVariantSimple>() << v0 << v1 << v2 << v3);
}
void dump(const PIString & line_prefix = PIString()) const;
//! \~english Returns subclass scope of this object (including this class name)
//! \~russian Возвращает цепочку наследования объекта (вместе с классом самого объекта)
PIStringList scopeList() const;
@@ -203,42 +284,50 @@ public:
PIString methodEHArguments(const PIString & name) const;
PIString methodEHFullFormat(const PIString & name) const;
PIString methodEHFromAddr(const void * addr) const;
// / Direct connect
static PIObject::Connection piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
static PIObject::Connection piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0);
static PIObject::Connection
piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
static PIObject::Connection piConnectU(PIObject * src,
const PIString & sig,
PIObject * dest_o,
void * dest,
const PIString & hname,
const char * loc,
PIObject * performer = 0);
static PIObject::Connection piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc);
template <typename PIINPUT, typename... PITYPES>
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,PITYPES...), PIINPUT functor) {
return (std::function<void()>*)(new std::function<void(PITYPES...)>(functor));
template<typename PIINPUT, typename... PITYPES>
static std::function<void()> * __newFunctor(void (*stat_handler)(void *, PITYPES...), PIINPUT functor) {
return (std::function<void()> *)(new std::function<void(PITYPES...)>(functor));
}
//! \~english Disconnect object from all connections with event name "sig", connected to destination object "dest" and handler "ev_h"
//! \~russian Разрывает все соединения от события "sig" к объекту "dest" и обработчику "ev_h"
void piDisconnect(const PIString & sig, PIObject * dest, void * ev_h) {piDisconnect(this, sig, dest, ev_h);}
void piDisconnect(const PIString & sig, PIObject * dest, void * ev_h) { piDisconnect(this, sig, dest, ev_h); }
//! \~english Disconnect object from all connections with event name "sig", connected to destination object "dest"
//! \~russian Разрывает все соединения от события "sig" к объекту "dest"
void piDisconnect(const PIString & sig, PIObject * dest) {piDisconnect(this, sig, dest);}
void piDisconnect(const PIString & sig, PIObject * dest) { piDisconnect(this, sig, dest); }
//! \~english Disconnect object from all connections with event name "sig"
//! \~russian Разрывает все соединения от события "sig"
void piDisconnect(const PIString & sig) {piDisconnect(this, sig);}
void piDisconnect(const PIString & sig) { piDisconnect(this, sig); }
//! \~english Disconnect object "src" from all connections with event name "sig", connected to destination object "dest" and handler "ev_h"
//! \~english Disconnect object "src" from all connections with event name "sig", connected to destination object "dest" and handler
//! "ev_h"
//! \~russian Разрывает все соединения от события "sig" объекта "src" к объекту "dest" и обработчику "ev_h"
static void piDisconnect(PIObject * src, const PIString & sig, PIObject * dest, void * ev_h);
//! \~english Disconnect object "src" from all connections with event name "sig", connected to destination object "dest"
//! \~russian Разрывает все соединения от события "sig" объекта "src" к объекту "dest"
static void piDisconnect(PIObject * src, const PIString & sig, PIObject * dest);
//! \~english Disconnect object "src" from all connections with event name "sig"
//! \~russian Разрывает все соединения от события "sig" объекта "src"
static void piDisconnect(PIObject * src, const PIString & sig);
// / Raise events
static void raiseEvent(PIObject * sender, const uint eventID) {
for (int j = 0; j < sender->connections.size_s(); ++j) {
@@ -255,7 +344,7 @@ public:
i.dest_o->eventBegin();
sender->eventBegin();
i.dest_o->emitter_ = sender;
((void( *)(void * ))i.slot)(i.dest);
((void (*)(void *))i.slot)(i.dest);
sender->eventEnd();
if (i.dest_o->isPIObject()) {
i.dest_o->emitter_ = 0;
@@ -267,14 +356,14 @@ public:
if (!sender->isPIObject()) break;
}
}
template <typename T0>
template<typename T0>
static void raiseEvent(PIObject * sender, const uint eventID, const T0 & v0 = T0()) {
for (int j = 0; j < sender->connections.size_s(); ++j) {
Connection i(sender->connections[j]);
if (i.eventID != eventID) continue;
if (i.functor) {
(*((std::function<void(T0)>*)i.functor))(v0);
(*((std::function<void(T0)> *)i.functor))(v0);
} else {
if (i.performer) {
PIVector<PIVariantSimple> vl;
@@ -286,8 +375,10 @@ public:
i.dest_o->eventBegin();
sender->eventBegin();
i.dest_o->emitter_ = sender;
if (i.args_count == 0) ((void(*)(void *))i.slot)(i.dest);
else ((void(*)(void * , T0))i.slot)(i.dest, v0);
if (i.args_count == 0)
((void (*)(void *))i.slot)(i.dest);
else
((void (*)(void *, T0))i.slot)(i.dest, v0);
sender->eventEnd();
if (i.dest_o->isPIObject()) {
i.dest_o->emitter_ = 0;
@@ -299,13 +390,13 @@ public:
if (!sender->isPIObject()) break;
}
}
template <typename T0, typename T1>
template<typename T0, typename T1>
static void raiseEvent(PIObject * sender, const uint eventID, const T0 & v0 = T0(), const T1 & v1 = T1()) {
for (int j = 0; j < sender->connections.size_s(); ++j) {
Connection i(sender->connections[j]);
if (i.eventID != eventID) continue;
if (i.functor) {
(*((std::function<void(T0, T1)>*)i.functor))(v0, v1);
(*((std::function<void(T0, T1)> *)i.functor))(v0, v1);
} else {
if (i.performer) {
PIVector<PIVariantSimple> vl;
@@ -319,9 +410,9 @@ public:
sender->eventBegin();
i.dest_o->emitter_ = sender;
switch (i.args_count) {
case 0: ((void(*)(void *))i.slot)(i.dest); break;
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
default: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
case 0: ((void (*)(void *))i.slot)(i.dest); break;
case 1: ((void (*)(void *, T0))i.slot)(i.dest, v0); break;
default: ((void (*)(void *, T0, T1))i.slot)(i.dest, v0, v1); break;
}
sender->eventEnd();
if (i.dest_o->isPIObject()) {
@@ -334,13 +425,13 @@ public:
if (!sender->isPIObject()) break;
}
}
template <typename T0, typename T1, typename T2>
template<typename T0, typename T1, typename T2>
static void raiseEvent(PIObject * sender, const uint eventID, const T0 & v0 = T0(), const T1 & v1 = T1(), const T2 & v2 = T2()) {
for (int j = 0; j < sender->connections.size_s(); ++j) {
Connection i(sender->connections[j]);
if (i.eventID != eventID) continue;
if (i.functor) {
(*((std::function<void(T0, T1, T2)>*)i.functor))(v0, v1, v2);
(*((std::function<void(T0, T1, T2)> *)i.functor))(v0, v1, v2);
} else {
if (i.performer) {
PIVector<PIVariantSimple> vl;
@@ -355,10 +446,10 @@ public:
sender->eventBegin();
i.dest_o->emitter_ = sender;
switch (i.args_count) {
case 0: ((void(*)(void *))i.slot)(i.dest); break;
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
default: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
case 0: ((void (*)(void *))i.slot)(i.dest); break;
case 1: ((void (*)(void *, T0))i.slot)(i.dest, v0); break;
case 2: ((void (*)(void *, T0, T1))i.slot)(i.dest, v0, v1); break;
default: ((void (*)(void *, T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
}
sender->eventEnd();
if (i.dest_o->isPIObject()) {
@@ -371,13 +462,18 @@ public:
if (!sender->isPIObject()) break;
}
}
template <typename T0, typename T1, typename T2, typename T3>
static void raiseEvent(PIObject * sender, const uint eventID, const T0 & v0 = T0(), const T1 & v1 = T1(), const T2 & v2 = T2(), const T3 & v3 = T3()) {
template<typename T0, typename T1, typename T2, typename T3>
static void raiseEvent(PIObject * sender,
const uint eventID,
const T0 & v0 = T0(),
const T1 & v1 = T1(),
const T2 & v2 = T2(),
const T3 & v3 = T3()) {
for (int j = 0; j < sender->connections.size_s(); ++j) {
Connection i(sender->connections[j]);
if (i.eventID != eventID) continue;
if (i.functor) {
(*((std::function<void(T0, T1, T2, T3)>*)i.functor))(v0, v1, v2, v3);
(*((std::function<void(T0, T1, T2, T3)> *)i.functor))(v0, v1, v2, v3);
} else {
if (i.performer) {
PIVector<PIVariantSimple> vl;
@@ -393,11 +489,11 @@ public:
sender->eventBegin();
i.dest_o->emitter_ = sender;
switch (i.args_count) {
case 0: ((void(*)(void *))i.slot)(i.dest); break;
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
case 3: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
default: ((void(*)(void * , T0, T1, T2, T3))i.slot)(i.dest, v0, v1, v2, v3); break;
case 0: ((void (*)(void *))i.slot)(i.dest); break;
case 1: ((void (*)(void *, T0))i.slot)(i.dest, v0); break;
case 2: ((void (*)(void *, T0, T1))i.slot)(i.dest, v0, v1); break;
case 3: ((void (*)(void *, T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
default: ((void (*)(void *, T0, T1, T2, T3))i.slot)(i.dest, v0, v1, v2, v3); break;
}
sender->eventEnd();
if (i.dest_o->isPIObject()) {
@@ -410,20 +506,20 @@ public:
if (!sender->isPIObject()) break;
}
}
//! Returns PIObject* with name "name" or 0, if there is no object found
static PIObject * findByName(const PIString & name) {
PIMutexLocker _ml(mutexObjects());
piForeach (PIObject * i, PIObject::objects()) {
piForeach(PIObject * i, PIObject::objects()) {
if (i->name() != name) continue;
return i;
}
return nullptr;
}
//! \~english Returns if this is valid %PIObject (check signature)
//! \~russian Возвращает действительный ли это %PIObject (проверяет подпись)
bool isPIObject() const {return isPIObject(this);}
bool isPIObject() const { return isPIObject(this); }
//! \~english Returns if this is valid %PIObject subclass "T" (check signature and classname)
//! \~russian Возвращает действительный ли это наследник %PIObject типа "T" (проверяет подпись и имя класса)
@@ -435,55 +531,63 @@ public:
}
//! \~english Returns cast to T if this is valid subclass "T" (check by \a isTypeOf()) or "nullptr"
//! \~russian Возвращает преобразование к типу T если это действительный наследник типа "T" (проверяет через \a isTypeOf()), или "nullptr"
//! \~russian Возвращает преобразование к типу T если это действительный наследник типа "T" (проверяет через \a isTypeOf()), или
//! "nullptr"
template<typename T>
T * cast() const {
if (!isTypeOf<T>()) return (T*)nullptr;
return (T*)this;
if (!isTypeOf<T>()) return (T *)nullptr;
return (T *)this;
}
//! \~english Returns if "o" is valid %PIObject (check signature)
//! \~russian Возвращает действительный ли "o" %PIObject (проверяет подпись)
static bool isPIObject(const PIObject * o);
static bool isPIObject(const void * o) {return isPIObject((PIObject*)o);}
static bool isPIObject(const void * o) { return isPIObject((PIObject *)o); }
//! \~english Returns if "o" is valid %PIObject subclass "T" (check signature and classname)
//! \~russian Возвращает действительный ли "o" наследник %PIObject типа "T" (проверяет подпись и имя класса)
template<typename T>
static bool isTypeOf(const PIObject * o) {return o->isTypeOf<T>();}
static bool isTypeOf(const PIObject * o) {
return o->isTypeOf<T>();
}
template<typename T>
static bool isTypeOf(const void * o) {return isTypeOf<T>((PIObject*)o);}
static bool isTypeOf(const void * o) {
return isTypeOf<T>((PIObject *)o);
}
static PIString simplifyType(const char * a, bool readable = true);
struct PIP_EXPORT __MetaFunc {
__MetaFunc();
bool isNull() const {return addr == nullptr;}
bool isNull() const { return addr == nullptr; }
int argumentsCount() const;
PIString arguments() const;
PIString fullFormat() const;
void __setFuncName(const char * n);
void __addArgument(const char * t, const char * n);
bool canConnectTo(const __MetaFunc & dst, int & args_count) const;
void * addr = nullptr;
void * addrV = nullptr;
uint func_name_id = 0;
void * addr = nullptr;
void * addrV = nullptr;
uint func_name_id = 0;
const char * func_name = nullptr;
const char * type_ret = nullptr;
const char * scope = nullptr;
const char * type_ret = nullptr;
const char * scope = nullptr;
const char * types[__PIOBJECT_MAX_ARGS__];
const char * names[__PIOBJECT_MAX_ARGS__];
uint types_id[__PIOBJECT_MAX_ARGS__];
};
struct PIP_EXPORT __MetaData {
__MetaData() {scope_list << "PIObject"; scope_id << PIStringAscii("PIObject").hash();}
__MetaData() {
scope_list << "PIObject";
scope_id << PIStringAscii("PIObject").hash();
}
void addScope(const char * s, uint shash);
PIVector<const char *> scope_list;
PISet<uint> scope_id;
PISet<const void * > eh_set;
PIMap<const void * , __MetaFunc> eh_func;
PISet<const void *> eh_set;
PIMap<const void *, __MetaFunc> eh_func;
};
typedef PIPair<const void * , __MetaFunc> __EHPair;
typedef PIPair<const void *, __MetaFunc> __EHPair;
//! \~english Execute all posted events from CONNECTU_QUEUED connections
//! \~russian Выполнить все отложенные события от CONNECTU_QUEUED соединений
@@ -497,7 +601,10 @@ public:
//! \brief Если было хотя бы одно CONNECTU_QUEUED соединение с исполнителем this, то выполнить события
//! \details Этот метод более оптимален, чем \a callQueuedEvents(), для объектов, которые не были в роли
//! \"performer\" в макросе CONNECTU_QUEUED
bool maybeCallQueuedEvents() {if (proc_event_queue) callQueuedEvents(); return proc_event_queue;}
bool maybeCallQueuedEvents() {
if (proc_event_queue) callQueuedEvents();
return proc_event_queue;
}
//! \~english Mark object to delete
//! \~russian Пометить объект на удаление
@@ -507,19 +614,18 @@ public:
static PIMap<uint, __MetaData> & __meta_data(); // [hash(classname)]=__MetaData
protected:
//! \~english Returns %PIObject* which has raised an event. This value is correct only in definition of some event handler
//! \~russian Возвращает %PIObject* который вызвал это событие. Значение допустимо только из методов обработчиков событий
PIObject * emitter() const {return emitter_;}
PIObject * emitter() const { return emitter_; }
//! \~english Virtual function executes after property with name "name" has been changed
//! \~russian Виртуальная функция, вызывается после изменения любого свойства.
virtual void propertyChanged(const char * name) {}
EVENT1(deleted, PIObject *, o);
//! \events
//! \{
//! \events
//! \{
//! \fn void deleted(PIObject * o)
//! \brief
@@ -533,16 +639,19 @@ protected:
//! Это событие вызывается из деструктора, поэтому используйте
//! только численное значение "o", не надо кастовать его в другие типы!
//! \}
//! \}
private:
struct __QueuedEvent {
__QueuedEvent(void * sl = 0, void * d = 0, PIObject * d_o = 0, PIObject * s = 0, const PIVector<PIVariantSimple> & v = PIVector<PIVariantSimple>()) {
slot = sl;
dest = d;
__QueuedEvent(void * sl = 0,
void * d = 0,
PIObject * d_o = 0,
PIObject * s = 0,
const PIVector<PIVariantSimple> & v = PIVector<PIVariantSimple>()) {
slot = sl;
dest = d;
dest_o = d_o;
src = s;
src = s;
values = v;
}
void * slot;
@@ -558,6 +667,7 @@ private:
~Deleter();
static Deleter * instance();
void post(PIObject * o);
private:
void deleteObject(PIObject * o);
PRIVATE_DECLARATION(PIP_EXPORT)
@@ -570,26 +680,25 @@ private:
void piDisconnectAll();
void postQueuedEvent(const __QueuedEvent & e);
void eventBegin() {in_event_cnt++;}
void eventEnd () {in_event_cnt--;}
bool isInEvent() const {return in_event_cnt > 0;}
void eventBegin() { in_event_cnt++; }
void eventEnd() { in_event_cnt--; }
bool isInEvent() const { return in_event_cnt > 0; }
void * toThis() const;
virtual int ptrOffset() const {return 0;}
static PIVector<PIObject * > & objects();
virtual int ptrOffset() const { return 0; }
static PIVector<PIObject *> & objects();
static PIMutex & mutexObjects();
static void callAddrV(void * slot, void * obj, int args, const PIVector<PIVariantSimple> & vl);
PIVector<Connection> connections;
PIMap<uint, PIVariant> properties_;
PISet<PIObject * > connectors;
PISet<PIObject *> connectors;
PIVector<__QueuedEvent> events_queue;
PIMutex mutex_, mutex_connect, mutex_queue;
PIObject * emitter_;
bool thread_safe_, proc_event_queue;
std::atomic_int in_event_cnt;
};
#ifndef MICRO_PIP

View File

@@ -3,24 +3,24 @@
* \~\brief
* \~english PIObject macros
* \~russian Макросы PIObject
*/
*/
/*
PIP - Platform Independent Primitives
Macros for PIObject
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Macros for PIObject
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 PIOBJECT_MACROS_H
@@ -33,133 +33,141 @@
//! \relatesalso PIObject
//! \~\brief
//! \~english You should use this macro after class declaration to use EVENT and EVENT_HANDLER and correct piCoutObj output
//! \~russian Необходимо использовать этот макрос после объявления класса для использования событийной системы и корректного вывода piCoutObj
#define PIOBJECT(name)
//! \~russian Необходимо использовать этот макрос после объявления класса для использования событийной системы и корректного вывода
//! piCoutObj
# define PIOBJECT(name)
//! \relatesalso PIObject
//! \~\brief
//! \~english You should use this macro after class declaration to use EVENT and EVENT_HANDLER of parent class, and \a scopeList()
//! \~russian
#define PIOBJECT_SUBCLASS(name, parent)
# define PIOBJECT_SUBCLASS(name, parent)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event handler with name \"name\" and return type \"ret\", ret name()
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name()
#define EVENT_HANDLER0(ret, name) ret name()
# define EVENT_HANDLER0(ret, name) ret name()
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event handler with name \"name\" and return type \"ret\", ret name(type0 var0)
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name(type0 var0)
#define EVENT_HANDLER1(ret, name, type0, var0) ret name(type0 var0)
# define EVENT_HANDLER1(ret, name, type0, var0) ret name(type0 var0)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event handler with name \"name\" and return type \"ret\", ret name(type0 var0, type1 var1)
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name(type0 var0, type1 var1)
#define EVENT_HANDLER2(ret, name, type0, var0, type1, var1) ret name(type0 var0, type1 var1)
# define EVENT_HANDLER2(ret, name, type0, var0, type1, var1) ret name(type0 var0, type1 var1)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event handler with name \"name\" and return type \"ret\", ret name(type0 var0, type1 var1, type2 var2)
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name(type0 var0, type1 var1, type2 var2)
#define EVENT_HANDLER3(ret, name, type0, var0, type1, var1, type2, var2) ret name(type0 var0, type1 var1, type2 var2)
# define EVENT_HANDLER3(ret, name, type0, var0, type1, var1, type2, var2) ret name(type0 var0, type1 var1, type2 var2)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event handler with name \"name\" and return type \"ret\", ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name(type0 var0, type1 var1, type2 var2, type3 var3)
#define EVENT_HANDLER4(ret, name, type0, var0, type1, var1, type2, var2, type3, var3) ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \~russian Объявляет обработчик событий с именем \"name\" и возвращаемым типом \"ret\", ret name(type0 var0, type1 var1, type2 var2,
//! type3 var3)
# define EVENT_HANDLER4(ret, name, type0, var0, type1, var1, type2, var2, type3, var3) \
ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \relatesalso PIObject
//! \~\brief
//! \~english Synonym of EVENT_HANDLER0
//! \~russian Аналог EVENT_HANDLER0
#define EVENT_HANDLER EVENT_HANDLER0
# define EVENT_HANDLER EVENT_HANDLER0
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name()
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name()
#define EVENT_VHANDLER0(ret, name) virtual ret name()
# define EVENT_VHANDLER0(ret, name) virtual ret name()
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name(type0 var0)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0)
#define EVENT_VHANDLER1(ret, name, type0, var0) virtual ret name(type0 var0)
# define EVENT_VHANDLER1(ret, name, type0, var0) virtual ret name(type0 var0)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name(type0 var0, type1 var1)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1 var1)
#define EVENT_VHANDLER2(ret, name, type0, var0, type1, var1) virtual ret name(type0 var0, type1 var1)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1
//! var1)
# define EVENT_VHANDLER2(ret, name, type0, var0, type1, var1) virtual ret name(type0 var0, type1 var1)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name(type0 var0, type1 var1, type2 var2)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1 var1, type2 var2)
#define EVENT_VHANDLER3(ret, name, type0, var0, type1, var1, type2, var2) virtual ret name(type0 var0, type1 var1, type2 var2)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1
//! var1, type2 var2)
# define EVENT_VHANDLER3(ret, name, type0, var0, type1, var1, type2, var2) virtual ret name(type0 var0, type1 var1, type2 var2)
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1 var1, type2 var2, type3 var3)
#define EVENT_VHANDLER4(ret, name, type0, var0, type1, var1, type2, var2, type3, var3) virtual ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \~english Declare virtual event handler with name \"name\" and return type \"ret\", virtual ret name(type0 var0, type1 var1, type2 var2,
//! type3 var3)
//! \~russian Объявляет виртуальный обработчик событий с именем \"name\" и возвращаемым типом \"ret\", virtual ret name(type0 var0, type1
//! var1, type2 var2, type3 var3)
# define EVENT_VHANDLER4(ret, name, type0, var0, type1, var1, type2, var2, type3, var3) \
virtual ret name(type0 var0, type1 var1, type2 var2, type3 var3)
//! \relatesalso PIObject
//! \~\brief
//! \~english Synonym of EVENT_VHANDLER0
//! \~russian Аналог EVENT_VHANDLER0
#define EVENT_VHANDLER EVENT_VHANDLER0
# define EVENT_VHANDLER EVENT_VHANDLER0
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event with name \"name\", void name();
//! \~russian Объявляет событие с именем \"name\", void name();
#define EVENT0(name) void name();
# define EVENT0(name) void name();
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event with name \"name\", void name(type0 var0);
//! \~russian Объявляет событие с именем \"name\", void name(type0 var0);
#define EVENT1(name, type0, var0) void name(type0 var0);
# define EVENT1(name, type0, var0) void name(type0 var0);
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event with name \"name\", void name(type0 var0, type1 var1);
//! \~russian Объявляет событие с именем \"name\", void name(type0 var0, type1 var1);
#define EVENT2(name, type0, var0, type1, var1) void name(type0 var0, type1 var1);
# define EVENT2(name, type0, var0, type1, var1) void name(type0 var0, type1 var1);
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event with name \"name\", void name(type0 var0, type1 var1, type2 var2);
//! \~russian Объявляет событие с именем \"name\", void name(type0 var0, type1 var1, type2 var2);
#define EVENT3(name, type0, var0, type1, var1, type2, var2) void name(type0 var0, type1 var1, type2 var2);
# define EVENT3(name, type0, var0, type1, var1, type2, var2) void name(type0 var0, type1 var1, type2 var2);
//! \relatesalso PIObject
//! \~\brief
//! \~english Declare event with name \"name\", void name(type0 var0, type1 var1, type2 var2, type3 var3);
//! \~russian Объявляет событие с именем \"name\", void name(type0 var0, type1 var1, type2 var2, type3 var3);
#define EVENT4(name, type0, var0, type1, var1, type2, var2, type3, var3) void name(type0 var0, type1 var1, type2 var2, type3 var3);
# define EVENT4(name, type0, var0, type1, var1, type2, var2, type3, var3) void name(type0 var0, type1 var1, type2 var2, type3 var3);
//! \relatesalso PIObject
//! \~\brief
//! \~english Synonym of EVENT0
//! \~russian Аналог EVENT0
#define EVENT EVENT0
# define EVENT EVENT0
#define RAISE_EVENT0(src, event)
#define RAISE_EVENT1(src, event, v0)
#define RAISE_EVENT2(src, event, v0, v1)
#define RAISE_EVENT3(src, event, v0, v1, v2)
#define RAISE_EVENT4(src, event, v0, v1, v2, v3)
#define RAISE_EVENT RAISE_EVENT0
# define RAISE_EVENT0(src, event)
# define RAISE_EVENT1(src, event, v0)
# define RAISE_EVENT2(src, event, v0, v1)
# define RAISE_EVENT3(src, event, v0, v1, v2)
# define RAISE_EVENT4(src, event, v0, v1, v2, v3)
# define RAISE_EVENT RAISE_EVENT0
//! \relatesalso PIObject
@@ -173,7 +181,7 @@
//! \~russian
//! \"handler\" может принимать не все аргументы от \"event\".
//! Возвращает \a PIObject::Connection
#define CONNECTU(src, event, dest, handler)
# define CONNECTU(src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
@@ -192,7 +200,7 @@
//! Все типы аргументов должны быть зарегистрированы с помощью макроса \a REGISTER_VARIANT(),
//! однако многие стандартные и PIP типы уже там.
//! Возвращает \a PIObject::Connection
#define CONNECTU_QUEUED(src, event, dest, handler, performer)
# define CONNECTU_QUEUED(src, event, dest, handler, performer)
//! \relatesalso PIObject
//! \~\brief
@@ -207,62 +215,72 @@
//! \"event\" и \"functor\" должны иметь одинаковые аргументы.
//! В случае сложной лямбда-функции оберните её ().
//! Возвращает \a PIObject::Connection
#define CONNECTL(src, event, functor)
# define CONNECTL(src, event, functor)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" с проверкой наличия события и обработчика.
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with
//! check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" с проверкой наличия события и обработчика.
//! \~\details
//! Returns PIObject::Connection
#define CONNECT0(ret, src, event, dest, handler)
# define CONNECT0(ret, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" с проверкой наличия события и обработчика.
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with
//! check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" с проверкой наличия события и обработчика.
//! \~\details
//! Returns PIObject::Connection
#define CONNECT1(ret, type0, src, event, dest, handler)
# define CONNECT1(ret, type0, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" с проверкой наличия события и обработчика.
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with
//! check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" с проверкой наличия события и обработчика.
//! \~\details
//! Returns PIObject::Connection
#define CONNECT2(ret, type0, type1, src, event, dest, handler)
# define CONNECT2(ret, type0, type1, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" с проверкой наличия события и обработчика.
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with
//! check of event and handler exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" с проверкой наличия события и обработчика.
//! \~\details
//! Returns PIObject::Connection
#define CONNECT3(ret, type0, type1, type2, src, event, dest, handler)
# define CONNECT3(ret, type0, type1, type2, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists.
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" с проверкой наличия события и обработчика.
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with
//! check of event and handler exists.
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" с проверкой наличия события и обработчика.
//! \~\details
//! Returns PIObject::Connection
#define CONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
# define CONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
@@ -271,7 +289,7 @@
//! \~\brief
//! \~english Synonym of \a CONNECT0
//! \~russian Аналог \a CONNECT0
#define CONNECT CONNECT0
# define CONNECT CONNECT0
//! \relatesalso PIObject
@@ -279,45 +297,55 @@
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" без проверки наличия события и обработчика.
#define WEAK_CONNECT0(ret, src, event, dest, handler)
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without
//! check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" без проверки наличия события и обработчика.
# define WEAK_CONNECT0(ret, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" без проверки наличия события и обработчика.
#define WEAK_CONNECT1(ret, type0, src, event, dest, handler)
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without
//! check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" без проверки наличия события и обработчика.
# define WEAK_CONNECT1(ret, type0, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" без проверки наличия события и обработчика.
#define WEAK_CONNECT2(ret, type0, type1, src, event, dest, handler)
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without
//! check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" без проверки наличия события и обработчика.
# define WEAK_CONNECT2(ret, type0, type1, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" без проверки наличия события и обработчика.
#define WEAK_CONNECT3(ret, type0, type1, type2, src, event, dest, handler)
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without
//! check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" без проверки наличия события и обработчика.
# define WEAK_CONNECT3(ret, type0, type1, type2, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
//! \~english Use \a CONNECTU() instead
//! \~russian Используйте \a CONNECTU()
//! \~\brief
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта \"dest\" без проверки наличия события и обработчика.
#define WEAK_CONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
//! \~english Connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" without
//! check of event exists
//! \~russian Соединяет событие \"event\" объекта \"src\" к обработчику или событию \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\" без проверки наличия события и обработчика.
# define WEAK_CONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
//! \relatesalso PIObject
//! \deprecated
@@ -326,367 +354,512 @@
//! \~\brief
//! \~english Synonym of \a WEAK_CONNECT0
//! \~russian Аналог \a WEAK_CONNECT0
#define WEAK_CONNECT WEAK_CONNECT0
# define WEAK_CONNECT WEAK_CONNECT0
//! \relatesalso PIObject
//! \~\brief
//! \~english piDisconnect event \"event\" from object \"src\" from event handler \"handler\" with return type \"ret\" from object \"dest\"
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта \"dest\"
#define DISCONNECT0(ret, src, event, dest, handler)
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\"
# define DISCONNECT0(ret, src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
//! \~english piDisconnect event \"event\" from object \"src\" from event handler \"handler\" with return type \"ret\" from object \"dest\"
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта \"dest\"
#define DISCONNECT1(ret, type0, src, event, dest, handler)
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\"
# define DISCONNECT1(ret, type0, src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
//! \~english piDisconnect event \"event\" from object \"src\" from event handler \"handler\" with return type \"ret\" from object \"dest\"
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта \"dest\"
#define DISCONNECT2(ret, type0, type1, src, event, dest, handler)
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\"
# define DISCONNECT2(ret, type0, type1, src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
//! \~english piDisconnect event \"event\" from object \"src\" from event handler \"handler\" with return type \"ret\" from object \"dest\"
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта \"dest\"
#define DISCONNECT3(ret, type0, type1, type2, src, event, dest, handler)
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\"
# define DISCONNECT3(ret, type0, type1, type2, src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
//! \~english piDisconnect event \"event\" from object \"src\" from event handler \"handler\" with return type \"ret\" from object \"dest\"
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта \"dest\"
#define DISCONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
//! \~russian piDisconnect событие \"event\" объекта \"src\" от обработчика или события \"handler\" с возвращаемым типом \"ret\" объекта
//! \"dest\"
# define DISCONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
//! \relatesalso PIObject
//! \~\brief
//! \~english Synonym of \a DISCONNECT0
//! \~russian Аналог \a DISCONNECT0
#define DISCONNECT DISCONNECT0
# define DISCONNECT DISCONNECT0
//! \relatesalso PIObject
//! \~\brief
//! \~english Returns pointer to events handler \"handler\"
//! \~russian Возвращает указатель на обработчик события \"handler\"
#define HANDLER(handler)
# define HANDLER(handler)
#else
#define _PI_STR(x) #x
#define _PI_SSTR(x) _PI_STR(x)
#define LOCATION __FILE__ ":" _PI_SSTR(__LINE__)
#ifdef CC_GCC
# define __PTYPE(t) typename __PIVariantTypeInfo__<t>::PureType
#else
# define __PTYPE(t) __PIVariantTypeInfo__<t>::PureType
#endif
#define __VVALUE(t, v) v.value< __PTYPE(t) >()
#define __PIOBJECT_MAX_ARGS__ 4
# define _PI_STR(x) #x
# define _PI_SSTR(x) _PI_STR(x)
# define LOCATION __FILE__ ":" _PI_SSTR(__LINE__)
# ifdef CC_GCC
# define __PTYPE(t) typename __PIVariantTypeInfo__<t>::PureType
# else
# define __PTYPE(t) __PIVariantTypeInfo__<t>::PureType
# endif
# define __VVALUE(t, v) v.value<__PTYPE(t)>()
# define __PIOBJECT_MAX_ARGS__ 4
#define PIOBJECT(name) \
protected: \
typedef name __PIObject__; \
public: \
static const char * __classNameCC() {return #name;} \
static uint __classNameIDS() {static uint ret = PIStringAscii(#name).hash(); return ret;} \
const char * className() const override {return #name;} \
uint classNameID() const override {static uint ret = PIStringAscii(#name).hash(); return ret;} \
private: \
int ptrOffset() const override {name * o = (name*)100; return int(llong((PIObject*)o) - llong(o));} \
class __BaseInitializer__ { \
public: \
__BaseInitializer__() { \
uint pid = PIObject::__classNameIDS(); \
if (pid == 0) return; \
uint id = __classNameIDS(); \
PIMutexLocker ml(__meta_mutex()); \
if (__meta_data().contains(id)) return; \
__meta_data()[pid]; \
__meta_data()[id]; \
__MetaData & ehp(__meta_data()[pid]); \
__MetaData & eh(__meta_data()[id]); \
eh.eh_set << ehp.eh_set; \
eh.eh_func << ehp.eh_func; \
eh.addScope(__classNameCC(), id); \
} \
}; \
__BaseInitializer__ __base_init__;
# define PIOBJECT(name) \
\
protected: \
typedef name __PIObject__; \
\
public: \
static const char * __classNameCC() { \
return #name; \
} \
static uint __classNameIDS() { \
static uint ret = PIStringAscii(#name).hash(); \
return ret; \
} \
const char * className() const override { \
return #name; \
} \
uint classNameID() const override { \
static uint ret = PIStringAscii(#name).hash(); \
return ret; \
} \
\
private: \
int ptrOffset() const override { \
name * o = (name *)100; \
return int(llong((PIObject *)o) - llong(o)); \
} \
class __BaseInitializer__ { \
public: \
__BaseInitializer__() { \
uint pid = PIObject::__classNameIDS(); \
if (pid == 0) return; \
uint id = __classNameIDS(); \
PIMutexLocker ml(__meta_mutex()); \
if (__meta_data().contains(id)) return; \
__meta_data()[pid]; \
__meta_data()[id]; \
__MetaData & ehp(__meta_data()[pid]); \
__MetaData & eh(__meta_data()[id]); \
eh.eh_set << ehp.eh_set; \
eh.eh_func << ehp.eh_func; \
eh.addScope(__classNameCC(), id); \
} \
}; \
__BaseInitializer__ __base_init__;
#define PIOBJECT_PARENT(name) \
class __ParentInitializer__ { \
public: \
__ParentInitializer__() { \
uint pid = name::__classNameIDS(); \
if (pid == 0) return; \
uint id = __classNameIDS(); \
PIMutexLocker ml(__meta_mutex()); \
__MetaData & eh(__meta_data()[id]); \
if (eh.scope_id.contains(pid)) return; \
__MetaData ehp(__meta_data().value(pid)); \
eh.eh_set << ehp.eh_set; \
eh.eh_func << ehp.eh_func; \
eh.scope_id = ehp.scope_id; \
eh.scope_list = ehp.scope_list; \
eh.addScope(__classNameCC(), id); \
} \
}; \
__ParentInitializer__ __parent_init__; \
public: \
const char * parentClassName() const override {return #name;} \
typedef name __Parent__; \
private:
# define PIOBJECT_PARENT(name) \
class __ParentInitializer__ { \
public: \
__ParentInitializer__() { \
uint pid = name::__classNameIDS(); \
if (pid == 0) return; \
uint id = __classNameIDS(); \
PIMutexLocker ml(__meta_mutex()); \
__MetaData & eh(__meta_data()[id]); \
if (eh.scope_id.contains(pid)) return; \
__MetaData ehp(__meta_data().value(pid)); \
eh.eh_set << ehp.eh_set; \
eh.eh_func << ehp.eh_func; \
eh.scope_id = ehp.scope_id; \
eh.scope_list = ehp.scope_list; \
eh.addScope(__classNameCC(), id); \
} \
}; \
__ParentInitializer__ __parent_init__; \
\
public: \
const char * parentClassName() const override { \
return #name; \
} \
typedef name __Parent__; \
\
private:
#define PIOBJECT_SUBCLASS(name, parent) PIOBJECT(name) PIOBJECT_PARENT(parent)
# define PIOBJECT_SUBCLASS(name, parent) PIOBJECT(name) PIOBJECT_PARENT(parent)
#define __EH_INIT_BASE__(ret, name) \
PIMutexLocker ml(__meta_mutex()); \
__MetaData & eh(__meta_data()[__classNameIDS()]); \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
__MetaFunc & f(eh.eh_func[fp]); \
f.scope = __classNameCC(); \
f.__setFuncName(#name); \
f.addr = fp; \
f.addrV = fpV; \
f.type_ret = #ret;
# define __EH_INIT_BASE__(ret, name) \
PIMutexLocker ml(__meta_mutex()); \
__MetaData & eh(__meta_data()[__classNameIDS()]); \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
__MetaFunc & f(eh.eh_func[fp]); \
f.scope = __classNameCC(); \
f.__setFuncName(#name); \
f.addr = fp; \
f.addrV = fpV; \
f.type_ret = #ret;
#define EH_INIT0(ret, name) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void*)(ret(*)(void*))__stat_eh_##name##__; \
void * fpV = fp; \
__EH_INIT_BASE__(ret, name) \
STATIC_INITIALIZER_END
# define EH_INIT0(ret, name) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void *)(ret(*)(void *))__stat_eh_##name##__; \
void * fpV = fp; \
__EH_INIT_BASE__(ret, name) \
STATIC_INITIALIZER_END
#define EH_INIT1(ret, name, a0, n0) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void*)(ret(*)(void*, a0))__stat_eh_##name##__; \
void * fpV = (void*)(ret(*)(void*, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
STATIC_INITIALIZER_END
# define EH_INIT1(ret, name, a0, n0) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void *)(ret(*)(void *, a0))__stat_eh_##name##__; \
void * fpV = (void *)(ret(*)(void *, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
STATIC_INITIALIZER_END
#define EH_INIT2(ret, name, a0, n0, a1, n1) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void*)(ret(*)(void*, a0, a1))__stat_eh_##name##__; \
void * fpV = (void*)(ret(*)(void*, const PIVariantSimple &, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
STATIC_INITIALIZER_END
# define EH_INIT2(ret, name, a0, n0, a1, n1) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void *)(ret(*)(void *, a0, a1))__stat_eh_##name##__; \
void * fpV = (void *)(ret(*)(void *, const PIVariantSimple &, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
STATIC_INITIALIZER_END
#define EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void*)(ret(*)(void*, a0, a1, a2))__stat_eh_##name##__; \
void * fpV = (void*)(ret(*)(void*, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
f.__addArgument(#a2, #n2); \
STATIC_INITIALIZER_END
# define EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void *)(ret(*)(void *, a0, a1, a2))__stat_eh_##name##__; \
void * fpV = \
(void *)(ret(*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
f.__addArgument(#a2, #n2); \
STATIC_INITIALIZER_END
#define EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void*)(ret(*)(void*, a0, a1, a2, a3))__stat_eh_##name##__; \
void * fpV = (void*)(ret(*)(void*, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
f.__addArgument(#a2, #n2); \
f.__addArgument(#a3, #n3); \
STATIC_INITIALIZER_END
# define EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
STATIC_INITIALIZER_BEGIN \
void * fp = (void *)(ret(*)(void *, a0, a1, a2, a3))__stat_eh_##name##__; \
void * fpV = \
(void *)(ret(*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &)) \
__stat_eh_v_##name##__; \
__EH_INIT_BASE__(ret, name) \
f.__addArgument(#a0, #n0); \
f.__addArgument(#a1, #n1); \
f.__addArgument(#a2, #n2); \
f.__addArgument(#a3, #n3); \
STATIC_INITIALIZER_END
#define EVENT_HANDLER0(ret, name) \
EH_INIT0(ret, name) \
static ret __stat_eh_##name##__(void * __o__) {return ((__PIObject__*)__o__)->name();} \
ret name()
# define EVENT_HANDLER0(ret, name) \
EH_INIT0(ret, name) \
static ret __stat_eh_##name##__(void * __o__) { \
return ((__PIObject__ *)__o__)->name(); \
} \
ret name()
#define EVENT_HANDLER1(ret, name, a0, n0) \
EH_INIT1(ret, name, a0, n0) \
static ret __stat_eh_##name##__(void * __o__, a0 n0) {return ((__PIObject__*)__o__)->name(n0);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
return ((__PIObject__*)__o__)->name(tv0);} \
ret name(a0 n0)
# define EVENT_HANDLER1(ret, name, a0, n0) \
EH_INIT1(ret, name, a0, n0) \
static ret __stat_eh_##name##__(void * __o__, a0 n0) { \
return ((__PIObject__ *)__o__)->name(n0); \
} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
return ((__PIObject__ *)__o__)->name(tv0); \
} \
ret name(a0 n0)
#define EVENT_HANDLER2(ret, name, a0, n0, a1, n1) \
EH_INIT2(ret, name, a0, n0, a1, n1) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1) {return ((__PIObject__*)__o__)->name(n0, n1);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
return ((__PIObject__*)__o__)->name(tv0, tv1);} \
ret name(a0 n0, a1 n1)
# define EVENT_HANDLER2(ret, name, a0, n0, a1, n1) \
EH_INIT2(ret, name, a0, n0, a1, n1) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1) { \
return ((__PIObject__ *)__o__)->name(n0, n1); \
} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
return ((__PIObject__ *)__o__)->name(tv0, tv1); \
} \
ret name(a0 n0, a1 n1)
#define EVENT_HANDLER3(ret, name, a0, n0, a1, n1, a2, n2) \
EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2) {return ((__PIObject__*)__o__)->name(n0, n1, n2);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
__PTYPE(a2) tv2 = __VVALUE(a2, v2); \
return ((__PIObject__*)__o__)->name(tv0, tv1, tv2);} \
ret name(a0 n0, a1 n1, a2 n2)
# define EVENT_HANDLER3(ret, name, a0, n0, a1, n1, a2, n2) \
EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2) { \
return ((__PIObject__ *)__o__)->name(n0, n1, n2); \
} \
static ret __stat_eh_v_##name##__(void * __o__, \
const PIVariantSimple & v0, \
const PIVariantSimple & v1, \
const PIVariantSimple & v2) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
__PTYPE(a2) tv2 = __VVALUE(a2, v2); \
return ((__PIObject__ *)__o__)->name(tv0, tv1, tv2); \
} \
ret name(a0 n0, a1 n1, a2 n2)
#define EVENT_HANDLER4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2, a3 n3) {return ((__PIObject__*)__o__)->name(n0, n1, n2, n3);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
__PTYPE(a2) tv2 = __VVALUE(a2, v2); \
__PTYPE(a3) tv3 = __VVALUE(a3, v3); \
return ((__PIObject__*)__o__)->name(tv0, tv1, tv2, tv3);} \
ret name(a0 n0, a1 n1, a2 n2, a3 n3)
# define EVENT_HANDLER4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2, a3 n3) { \
return ((__PIObject__ *)__o__)->name(n0, n1, n2, n3); \
} \
static ret __stat_eh_v_##name##__(void * __o__, \
const PIVariantSimple & v0, \
const PIVariantSimple & v1, \
const PIVariantSimple & v2, \
const PIVariantSimple & v3) { \
__PTYPE(a0) tv0 = __VVALUE(a0, v0); \
__PTYPE(a1) tv1 = __VVALUE(a1, v1); \
__PTYPE(a2) tv2 = __VVALUE(a2, v2); \
__PTYPE(a3) tv3 = __VVALUE(a3, v3); \
return ((__PIObject__ *)__o__)->name(tv0, tv1, tv2, tv3); \
} \
ret name(a0 n0, a1 n1, a2 n2, a3 n3)
#define EVENT_HANDLER EVENT_HANDLER0
# define EVENT_HANDLER EVENT_HANDLER0
#define EVENT_VHANDLER0(ret, name) \
EH_INIT0(ret, name) \
static ret __stat_eh_##name##__(void * __o__) { \
return ((__PIObject__*)__o__)->name();} \
virtual ret name()
# define EVENT_VHANDLER0(ret, name) \
EH_INIT0(ret, name) \
static ret __stat_eh_##name##__(void * __o__) { \
return ((__PIObject__ *)__o__)->name(); \
} \
virtual ret name()
#define EVENT_VHANDLER1(ret, name, a0, n0) \
EH_INIT1(ret, name, a0, n0) \
static ret __stat_eh_##name##__(void * __o__, a0 n0) { \
return ((__PIObject__*)__o__)->name(n0);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0) { \
return ((__PIObject__*)__o__)->name(__VVALUE(a0, v0));} \
virtual ret name(a0 n0)
# define EVENT_VHANDLER1(ret, name, a0, n0) \
EH_INIT1(ret, name, a0, n0) \
static ret __stat_eh_##name##__(void * __o__, a0 n0) { \
return ((__PIObject__ *)__o__)->name(n0); \
} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0) { \
return ((__PIObject__ *)__o__)->name(__VVALUE(a0, v0)); \
} \
virtual ret name(a0 n0)
#define EVENT_VHANDLER2(ret, name, a0, n0, a1, n1) \
EH_INIT2(ret, name, a0, n0, a1, n1) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1) { \
return ((__PIObject__*)__o__)->name(n0, n1);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1) { \
return ((__PIObject__*)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1));} \
virtual ret name(a0 n0, a1 n1)
# define EVENT_VHANDLER2(ret, name, a0, n0, a1, n1) \
EH_INIT2(ret, name, a0, n0, a1, n1) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1) { \
return ((__PIObject__ *)__o__)->name(n0, n1); \
} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1) { \
return ((__PIObject__ *)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1)); \
} \
virtual ret name(a0 n0, a1 n1)
#define EVENT_VHANDLER3(ret, name, a0, n0, a1, n1, a2, n2) \
EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2) { \
return ((__PIObject__*)__o__)->name(n0, n1, n2);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2) { \
return ((__PIObject__*)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1), __VVALUE(a2, v2));} \
virtual ret name(a0 n0, a1 n1, a2 n2)
# define EVENT_VHANDLER3(ret, name, a0, n0, a1, n1, a2, n2) \
EH_INIT3(ret, name, a0, n0, a1, n1, a2, n2) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2) { \
return ((__PIObject__ *)__o__)->name(n0, n1, n2); \
} \
static ret __stat_eh_v_##name##__(void * __o__, \
const PIVariantSimple & v0, \
const PIVariantSimple & v1, \
const PIVariantSimple & v2) { \
return ((__PIObject__ *)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1), __VVALUE(a2, v2)); \
} \
virtual ret name(a0 n0, a1 n1, a2 n2)
#define EVENT_VHANDLER4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2, a3 n3) { \
return ((__PIObject__*)__o__)->name(n0, n1, n2, n3);} \
static ret __stat_eh_v_##name##__(void * __o__, const PIVariantSimple & v0, const PIVariantSimple & v1, const PIVariantSimple & v2, const PIVariantSimple & v3) { \
return ((__PIObject__*)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1), __VVALUE(a2, v2), __VVALUE(a3, v3));} \
virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)
# define EVENT_VHANDLER4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
EH_INIT4(ret, name, a0, n0, a1, n1, a2, n2, a3, n3) \
static ret __stat_eh_##name##__(void * __o__, a0 n0, a1 n1, a2 n2, a3 n3) { \
return ((__PIObject__ *)__o__)->name(n0, n1, n2, n3); \
} \
static ret __stat_eh_v_##name##__(void * __o__, \
const PIVariantSimple & v0, \
const PIVariantSimple & v1, \
const PIVariantSimple & v2, \
const PIVariantSimple & v3) { \
return ((__PIObject__ *)__o__)->name(__VVALUE(a0, v0), __VVALUE(a1, v1), __VVALUE(a2, v2), __VVALUE(a3, v3)); \
} \
virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)
#define EVENT_VHANDLER EVENT_VHANDLER0
# define EVENT_VHANDLER EVENT_VHANDLER0
#define EVENT0(name) EVENT_HANDLER0(void, name) { \
static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid);}
# define EVENT0(name) \
EVENT_HANDLER0(void, name) { \
static uint eid = PIStringAscii(#name).hash(); \
PIObject::raiseEvent(this, eid); \
}
#define EVENT1(name, a0, n0) EVENT_HANDLER1(void, name, a0, n0) { \
static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0);}
# define EVENT1(name, a0, n0) \
EVENT_HANDLER1(void, name, a0, n0) { \
static uint eid = PIStringAscii(#name).hash(); \
PIObject::raiseEvent(this, eid, n0); \
}
#define EVENT2(name, a0, n0, a1, n1) EVENT_HANDLER2(void, name, a0, n0, a1, n1) { \
static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1);}
# define EVENT2(name, a0, n0, a1, n1) \
EVENT_HANDLER2(void, name, a0, n0, a1, n1) { \
static uint eid = PIStringAscii(#name).hash(); \
PIObject::raiseEvent(this, eid, n0, n1); \
}
#define EVENT3(name, a0, n0, a1, n1, a2, n2) EVENT_HANDLER3(void, name, a0, n0, a1, n1, a2, n2) { \
static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1, n2);}
# define EVENT3(name, a0, n0, a1, n1, a2, n2) \
EVENT_HANDLER3(void, name, a0, n0, a1, n1, a2, n2) { \
static uint eid = PIStringAscii(#name).hash(); \
PIObject::raiseEvent(this, eid, n0, n1, n2); \
}
#define EVENT4(name, a0, n0, a1, n1, a2, n2, a3, n3) EVENT_HANDLER4(void, name, a0, n0, a1, n1, a2, n2, a3, n3) { \
static uint eid = PIStringAscii(#name).hash(); PIObject::raiseEvent(this, eid, n0, n1, n2, n3);}
# define EVENT4(name, a0, n0, a1, n1, a2, n2, a3, n3) \
EVENT_HANDLER4(void, name, a0, n0, a1, n1, a2, n2, a3, n3) { \
static uint eid = PIStringAscii(#name).hash(); \
PIObject::raiseEvent(this, eid, n0, n1, n2, n3); \
}
#define EVENT EVENT0
# define EVENT EVENT0
#define RAISE_EVENT0(src, event) (src)->event();
#define RAISE_EVENT1(src, event, v0) (src)->event(v0);
#define RAISE_EVENT2(src, event, v0, v1) (src)->event(v0, v1);
#define RAISE_EVENT3(src, event, v0, v1, v2) (src)->event(v0, v1, v2);
#define RAISE_EVENT4(src, event, v0, v1, v2, v3) (src)->event(v0, v1, v2, v3);
#define RAISE_EVENT RAISE_EVENT0
# define RAISE_EVENT0(src, event) (src)->event();
# define RAISE_EVENT1(src, event, v0) (src)->event(v0);
# define RAISE_EVENT2(src, event, v0, v1) (src)->event(v0, v1);
# define RAISE_EVENT3(src, event, v0, v1, v2) (src)->event(v0, v1, v2);
# define RAISE_EVENT4(src, event, v0, v1, v2, v3) (src)->event(v0, v1, v2, v3);
# define RAISE_EVENT RAISE_EVENT0
#define CONNECTU(src, event, dest, handler) \
PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION);
# define CONNECTU(src, event, dest, handler) \
PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION);
#define CONNECTU_QUEUED(src, event, dest, handler, performer) \
PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION, performer);
# define CONNECTU_QUEUED(src, event, dest, handler, performer) \
PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION, performer);
#define CONNECTL(src, event, functor) \
PIObject::piConnectLS(src, PIStringAscii(#event), PIObject::__newFunctor(&(src)->__stat_eh_##event##__, functor), LOCATION);
# define CONNECTL(src, event, functor) \
PIObject::piConnectLS(src, PIStringAscii(#event), PIObject::__newFunctor(&(src)->__stat_eh_##event##__, functor), LOCATION);
#define CONNECT0(ret, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__), \
(void*)(void(*)(void*))(&(src)->__stat_eh_##event##__), 0, LOCATION);
# define CONNECT0(ret, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *))(&(dest)->__stat_eh_##handler##__), \
(void *)(void (*)(void *))(&(src)->__stat_eh_##event##__), \
0, \
LOCATION);
#define CONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__), \
(void*)(void(*)(void*, a0))(&(src)->__stat_eh_##event##__), 1, LOCATION);
# define CONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0))(&(dest)->__stat_eh_##handler##__), \
(void *)(void (*)(void *, a0))(&(src)->__stat_eh_##event##__), \
1, \
LOCATION);
#define CONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1))(&(dest)->__stat_eh_##handler##__), \
(void*)(void(*)(void*, a0, a1))(&(src)->__stat_eh_##event##__), 2, LOCATION);
# define CONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1))(&(dest)->__stat_eh_##handler##__), \
(void *)(void (*)(void *, a0, a1))(&(src)->__stat_eh_##event##__), \
2, \
LOCATION);
#define CONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1, a2))(&(dest)->__stat_eh_##handler##__), \
(void*)(void(*)(void*, a0, a1, a2))(&(src)->__stat_eh_##event##__), 3, LOCATION);
# define CONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1, a2))(&(dest)->__stat_eh_##handler##__), \
(void *)(void (*)(void *, a0, a1, a2))(&(src)->__stat_eh_##event##__), \
3, \
LOCATION);
#define CONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__), \
(void*)(void(*)(void*, a0, a1, a2, a3))(&(src)->__stat_eh_##event##__), 4, LOCATION);
# define CONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__), \
(void *)(void (*)(void *, a0, a1, a2, a3))(&(src)->__stat_eh_##event##__), \
4, \
LOCATION);
#define CONNECT CONNECT0
# define CONNECT CONNECT0
#define WEAK_CONNECT0(ret, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__), 0, 0, LOCATION);
# define WEAK_CONNECT0(ret, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *))(&(dest)->__stat_eh_##handler##__), \
0, \
0, \
LOCATION);
#define WEAK_CONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__), 0, 1, LOCATION);
# define WEAK_CONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0))(&(dest)->__stat_eh_##handler##__), \
0, \
1, \
LOCATION);
#define WEAK_CONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1))(&(dest)->__stat_eh_##handler##__), 0, 2, LOCATION);
# define WEAK_CONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1))(&(dest)->__stat_eh_##handler##__), \
0, \
2, \
LOCATION);
#define WEAK_CONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1, a2))(&(dest)->__stat_eh_##handler##__), 0, 3, LOCATION);
# define WEAK_CONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1, a2))(&(dest)->__stat_eh_##handler##__), \
0, \
3, \
LOCATION);
#define WEAK_CONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__), 0, 4, LOCATION);
# define WEAK_CONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piConnect(src, \
PIStringAscii(#event), \
dest, \
dest, \
(void *)(ret(*)(void *, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__), \
0, \
4, \
LOCATION);
#define WEAK_CONNECT WEAK_CONNECT0
# define WEAK_CONNECT WEAK_CONNECT0
#define DISCONNECT0(ret, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__));
# define DISCONNECT0(ret, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void *)(ret(*)(void *))(&(dest)->__stat_eh_##handler##__));
#define DISCONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__));
# define DISCONNECT1(ret, a0, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void *)(ret(*)(void *, a0))(&(dest)->__stat_eh_##handler##__));
#define DISCONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void*)(ret(*)(void*, a0, a1))(&(dest)->__stat_eh_##handler##__));
# define DISCONNECT2(ret, a0, a1, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void *)(ret(*)(void *, a0, a1))(&(dest)->__stat_eh_##handler##__));
#define DISCONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void*)(ret(*)(void*, a0, a1, a2))(&(dest)->__stat_eh_##handler##__));
# define DISCONNECT3(ret, a0, a1, a2, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void *)(ret(*)(void *, a0, a1, a2))(&(dest)->__stat_eh_##handler##__));
#define DISCONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void*)(ret(*)(void*, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__));
# define DISCONNECT4(ret, a0, a1, a2, a3, src, event, dest, handler) \
PIObject::piDisconnect(src, PIStringAscii(#event), dest, (void *)(ret(*)(void *, a0, a1, a2, a3))(&(dest)->__stat_eh_##handler##__));
#define DISCONNECT DISCONNECT0
# define DISCONNECT DISCONNECT0
#define HANDLER(handler) __stat_eh_##handler##__
# define HANDLER(handler) __stat_eh_##handler##__
#define __PIOBJECT_SIGNATURE__ 0xabcdbadc
# define __PIOBJECT_SIGNATURE__ 0xabcdbadc
#endif

View File

@@ -1,33 +1,33 @@
/*
PIP - Platform Independent Primitives
Private PIP wait object
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Private PIP wait object
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/>.
*/
#include "piwaitevent_p.h"
#ifdef WINDOWS
//# ifdef _WIN32_WINNT
//# undef _WIN32_WINNT
//# define _WIN32_WINNT 0x0600
//# endif
// # ifdef _WIN32_WINNT
// # undef _WIN32_WINNT
// # define _WIN32_WINNT 0x0600
// # endif
# include <synchapi.h>
#else
# include <errno.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# include <errno.h>
#endif
#include "pistring.h"
@@ -45,7 +45,8 @@ void PIWaitEvent::create() {
piCout << "Error with CreateEventA:" << errorString();
}
#else
for (int i = 0; i < 3; ++i) memset(&(fds[i]), 0, sizeof(fds[i]));
for (int i = 0; i < 3; ++i)
memset(&(fds[i]), 0, sizeof(fds[i]));
if (::pipe(pipe_fd) < 0) {
piCout << "Error with pipe:" << errorString();
} else {
@@ -80,16 +81,18 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false;
#else
if (fd == -1) return false;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int fd_index = role;
for (int i = 0; i < 3; ++i) FD_ZERO(&(fds[i]));
for (int i = 0; i < 3; ++i)
FD_ZERO(&(fds[i]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
FD_SET(fd, &(fds[CheckExeption]));
if (fd_index != CheckExeption) FD_SET(fd, &(fds[fd_index]));
int sr = ::select(nfds, &(fds[CheckRead]), &(fds[CheckWrite]), &(fds[CheckExeption]), nullptr);
int sr = ::select(nfds, &(fds[CheckRead]), &(fds[CheckWrite]), &(fds[CheckExeption]), nullptr);
int buf = 0;
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0);
//piCout << "wait result" << sr << FD_ISSET(fd, &(fds[CheckExeption])) << FD_ISSET(fd, &(fds[fd_index]));
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
;
// piCout << "wait result" << sr << FD_ISSET(fd, &(fds[CheckExeption])) << FD_ISSET(fd, &(fds[fd_index]));
if (sr == EBADF || sr == EINTR) return false;
if (FD_ISSET(fd, &(fds[CheckExeption]))) return true;
return FD_ISSET(fd, &(fds[fd_index]));
@@ -111,9 +114,10 @@ bool PIWaitEvent::sleep(int us) {
timeval timeout;
timeout.tv_sec = us / 1000000;
timeout.tv_usec = us % 1000000;
int ret = ::select(nfds, &(fds[CheckRead]), nullptr, nullptr, &timeout);
int buf = 0;
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0);
int ret = ::select(nfds, &(fds[CheckRead]), nullptr, nullptr, &timeout);
int buf = 0;
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
;
return ret == 0;
#endif
}

View File

@@ -1,34 +1,36 @@
/*
PIP - Platform Independent Primitives
Private PIP wait object
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
Private PIP wait object
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 PIWAITEVENT_P_H
#define PIWAITEVENT_P_H
#include "pibase.h"
// clang-format off
#ifdef WINDOWS
# include <stdarg.h>
# include <windef.h>
# include <winbase.h>
#else
# include <unistd.h>
# include <sys/select.h>
# include <unistd.h>
#endif
// clang-format on
class PIP_EXPORT PIWaitEvent {
@@ -60,7 +62,6 @@ private:
WriteEnd = 1
};
#endif
};