diff --git a/src_main/console/piscreentypes.h b/src_main/console/piscreentypes.h index 94c297e3..c6473e4f 100644 --- a/src_main/console/piscreentypes.h +++ b/src_main/console/piscreentypes.h @@ -143,9 +143,12 @@ namespace PIScreenTypes { } -inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.symbol << v.format.raw_format; return s;} +//inline PIByteArray & operator <<(PIByteArray & s, const PIScreenTypes::Cell & v) {s << v.symbol << v.format.raw_format; return s;} -inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.symbol >> v.format.raw_format; return s;} +//inline PIByteArray & operator >>(PIByteArray & s, PIScreenTypes::Cell & v) {s >> v.symbol >> v.format.raw_format; return s;} + +__PICONTAINERS_SIMPLE_TYPE__(PIScreenTypes::Cell) +__PIBYTEARRAY_SIMPLE_TYPE__(PIScreenTypes::Cell) #endif // PISCREENTYPES_H diff --git a/src_main/core/pibytearray.h b/src_main/core/pibytearray.h index 1723daaf..d69a26d4 100755 --- a/src_main/core/pibytearray.h +++ b/src_main/core/pibytearray.h @@ -23,18 +23,22 @@ #ifndef PIBYTEARRAY_H #define PIBYTEARRAY_H -#ifdef DOXYGEN -//! This macro allow stream template operators for write and read any type from byte array. Use it with attention! -# define PIP_BYTEARRAY_STREAM_ANY_TYPE -#endif - - #include "pichar.h" #include "pibitarray.h" #include "pimap.h" __PICONTAINERS_SIMPLE_TYPE__(PIChar) +#define __PIBYTEARRAY_SIMPLE_TYPE__(T) \ +template<> \ +inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ +template<> \ +inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +template<> \ +inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ +template<> \ +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v.resize(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} + class PIString; class PIByteArray; @@ -258,22 +262,31 @@ inline PIByteArray & operator >>(PIByteArray & s, PIMap & v) { return s; } -#ifdef PIP_BYTEARRAY_STREAM_ANY_TYPE template -inline PIByteArray & operator <<(PIByteArray & s, const T & v) {PBA_OPERATOR_TO return s;} -#endif - -#ifdef PIP_BYTEARRAY_STREAM_ANY_TYPE +inline PIByteArray & operator <<(PIByteArray & s, const T & ) {piCout << "[PIByteArray] Warning: using undeclared operator < -inline PIByteArray & operator >>(PIByteArray & s, T & v) {assert(s.size() >= sizeof(v)); PBA_OPERATOR_FROM return s;} -#endif +inline PIByteArray & operator >>(PIByteArray & s, T & ) {piCout << "[PIByteArray] Warning: using undeclared operator >>!"; return s;} -#undef PBA_OPERATOR_FROM - //! \relatesalso PIByteArray \brief Byte arrays compare operator inline bool operator ==(PIByteArray & f, PIByteArray & s) {if (f.size_s() != s.size_s()) return false; for (int i = 0; i < f.size_s(); ++i) if (f[i] != s[i]) return false; return true;} //! \relatesalso PIByteArray \brief Byte arrays compare operator inline bool operator !=(PIByteArray & f, PIByteArray & s) {if (f.size_s() != s.size_s()) return true; for (int i = 0; i < f.size_s(); ++i) if (f[i] != s[i]) return true; return false;} +__PIBYTEARRAY_SIMPLE_TYPE__(bool) +__PIBYTEARRAY_SIMPLE_TYPE__(char) +//__PIBYTEARRAY_SIMPLE_TYPE__(uchar) +__PIBYTEARRAY_SIMPLE_TYPE__(short) +__PIBYTEARRAY_SIMPLE_TYPE__(ushort) +__PIBYTEARRAY_SIMPLE_TYPE__(int) +__PIBYTEARRAY_SIMPLE_TYPE__(uint) +__PIBYTEARRAY_SIMPLE_TYPE__(long) +__PIBYTEARRAY_SIMPLE_TYPE__(ulong) +__PIBYTEARRAY_SIMPLE_TYPE__(llong) +__PIBYTEARRAY_SIMPLE_TYPE__(ullong) +__PIBYTEARRAY_SIMPLE_TYPE__(float) +__PIBYTEARRAY_SIMPLE_TYPE__(double) +__PIBYTEARRAY_SIMPLE_TYPE__(ldouble) +__PIBYTEARRAY_SIMPLE_TYPE__(PIChar) + #endif // PIBYTEARRAY_H diff --git a/src_main/core/piobject.cpp b/src_main/core/piobject.cpp index cf47486c..59756bf6 100755 --- a/src_main/core/piobject.cpp +++ b/src_main/core/piobject.cpp @@ -142,10 +142,16 @@ PIStringList PIObject::events() { } */ -PIStringList PIObject::methodsEH() { - PIMutexLocker ml(__eh_mutex()); +PIStringList PIObject::scopeList() const { + PIMutexLocker ml(__meta_mutex()); + return __meta_data()[className()].scope_list; +} + + +PIStringList PIObject::methodsEH() const { + PIMutexLocker ml(__meta_mutex()); PIStringList ret; - __EHData & ehd(__eh_data()[className()]); + __MetaData & ehd(__meta_data()[className()]); piForeachC (__EHPair & eh, ehd.eh_func) ret << eh.second.fullFormat(); return ret; @@ -153,8 +159,8 @@ PIStringList PIObject::methodsEH() { bool PIObject::isMethodEHContains(const PIString & name) const { - PIMutexLocker ml(__eh_mutex()); - __EHData & ehd(__eh_data()[className()]); + PIMutexLocker ml(__meta_mutex()); + __MetaData & ehd(__meta_data()[className()]); piForeachC (__EHPair & eh, ehd.eh_func) if (eh.second.func_name == name) return true; @@ -163,8 +169,8 @@ bool PIObject::isMethodEHContains(const PIString & name) const { PIString PIObject::methodEHArguments(const PIString & name) const { - PIMutexLocker ml(__eh_mutex()); - __EHData & ehd(__eh_data()[className()]); + PIMutexLocker ml(__meta_mutex()); + __MetaData & ehd(__meta_data()[className()]); piForeachC (__EHPair & eh, ehd.eh_func) if (eh.second.func_name == name) return eh.second.arguments(); @@ -173,8 +179,8 @@ PIString PIObject::methodEHArguments(const PIString & name) const { PIString PIObject::methodEHFullFormat(const PIString & name) const { - PIMutexLocker ml(__eh_mutex()); - __EHData & ehd(__eh_data()[className()]); + PIMutexLocker ml(__meta_mutex()); + __MetaData & ehd(__meta_data()[className()]); piForeachC (__EHPair & eh, ehd.eh_func) if (eh.second.func_name == name) return eh.second.fullFormat(); @@ -189,7 +195,7 @@ PIString PIObject::methodEHFromAddr(const void * addr) const { PIVector PIObject::findEH(const PIString & name) const { PIVector<__EHFunc> ret; - __EHData & ehd(__eh_data()[className()]); + __MetaData & ehd(__meta_data()[className()]); piForeachC (__EHPair & eh, ehd.eh_func) if (eh.second.func_name == name) ret << eh.second; @@ -198,8 +204,8 @@ PIVector PIObject::findEH(const PIString & name) const { PIObject::__EHFunc PIObject::methodEH(const void * addr) const { - PIMutexLocker ml(__eh_mutex()); - return __eh_data()[className()].eh_func.value(addr); + PIMutexLocker ml(__meta_mutex()); + return __meta_data()[className()].eh_func.value(addr); } @@ -229,7 +235,7 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des piCout << "[piConnectU] \"" << ename << "\" -> \"" << hname << "\" error: destination object is not PIObject! (" << loc << ")"; return false; } - PIMutexLocker ml(__eh_mutex()); + PIMutexLocker ml(__meta_mutex()); PIMutexLocker mls(src->mutex_connect); PIMutexLocker mld(dest_o->mutex_connect, src != dest_o); PIVector<__EHFunc> m_src = src->findEH(ename), m_dest = dest_o->findEH(hname); @@ -348,14 +354,14 @@ void PIObject::updateConnectors() { } -PIMutex & PIObject::__eh_mutex() { +PIMutex & PIObject::__meta_mutex() { static PIMutex ret; return ret; } -PIMap & PIObject::__eh_data() { - static PIMap ret; +PIMap & PIObject::__meta_data() { + static PIMap ret; return ret; } @@ -427,7 +433,7 @@ void PIObject::dump(const PIString & line_prefix) const { //printf("dump %d properties ok\n", properties_.size()); PICout(PICoutManipulators::AddNewLine) << line_prefix << " }"; PICout(PICoutManipulators::AddNewLine) << line_prefix << " methodsEH {"; - __EHData & ehd(__eh_data()[className()]); + __MetaData & ehd(__meta_data()[className()]); PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s(); //printf("dump %d methods\n", ehd.eh_func.size()); piForeachC (__EHPair & eh, ehd.eh_func) { diff --git a/src_main/core/piobject.h b/src_main/core/piobject.h index ec98e8c5..cc12b112 100755 --- a/src_main/core/piobject.h +++ b/src_main/core/piobject.h @@ -37,7 +37,7 @@ /// \relatesalso PIObject \brief you should use this macro after class declaration to use EVENT and EVENT_HANDLER and correct piCoutObj output #define PIOBJECT(name) -/// \relatesalso PIObject \brief you should use this macro after class declaration to use EVENT and EVENT_HANDLER of parent class +/// \relatesalso PIObject \brief you should use this macro after class declaration to use EVENT and EVENT_HANDLER of parent class, and \a scopeList() #define PIOBJECT_SUBCLASS(name, parent) @@ -196,19 +196,22 @@ __##name##_ParentInitializer__() { \ PIString pn(name::__classNameS()); \ if (pn.isEmpty()) return; \ - PIMutexLocker ml(__eh_mutex()); \ - if (__eh_data().contains(__classNameS())) return; \ - __eh_data()[pn]; \ - __eh_data()[__classNameS()]; \ - __EHData & ehp(__eh_data()[pn]); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + if (__meta_data().contains(__classNameS())) return; \ + __meta_data()[pn]; \ + __meta_data()[__classNameS()]; \ + __MetaData & ehp(__meta_data()[pn]); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ eh.eh_set << ehp.eh_set; \ eh.eh_func << ehp.eh_func; \ + eh.scope_list = ehp.scope_list; \ + eh.addScope(__classNameS()); \ } \ }; \ __##name##_ParentInitializer__ __##name##_parent_init__; \ public: \ - virtual const char * superClassName() const {return #name;} \ + virtual const char * parentClassName() const {return #name;} \ + typedef name __Parent__; \ private: #define PIOBJECT_SUBCLASS(name, parent) PIOBJECT(name) PIOBJECT_PARENT(parent) @@ -218,8 +221,8 @@ class __##name##0_Initializer__ { \ public: \ __##name##0_Initializer__() { \ - PIMutexLocker ml(__eh_mutex()); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ void * fp = (void*)(ret(*)(void*))__stat_eh_##name##__; \ if (eh.eh_set[fp]) return; \ eh.eh_set << fp; \ @@ -236,8 +239,8 @@ class __##name##1##n0##_Initializer__ { \ public: \ __##name##1##n0##_Initializer__() { \ - PIMutexLocker ml(__eh_mutex()); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ void * fp = (void*)(ret(*)(void*, a0))__stat_eh_##name##__; \ if (eh.eh_set[fp]) return; \ eh.eh_set << fp; \ @@ -256,8 +259,8 @@ class __##name##2##n0##n1##_Initializer__ { \ public: \ __##name##2##n0##n1##_Initializer__() { \ - PIMutexLocker ml(__eh_mutex()); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ void * fp = (void*)(ret(*)(void*, a0, a1))__stat_eh_##name##__; \ if (eh.eh_set[fp]) return; \ eh.eh_set << fp; \ @@ -276,8 +279,8 @@ class __##name##3##n0##n1##n2##_Initializer__ { \ public: \ __##name##3##n0##n1##n2##_Initializer__() { \ - PIMutexLocker ml(__eh_mutex()); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ void * fp = (void*)(ret(*)(void*, a0, a1, a2))__stat_eh_##name##__; \ if (eh.eh_set[fp]) return; \ eh.eh_set << fp; \ @@ -296,8 +299,8 @@ class __##name##4##n0##n1##n2##n3##_Initializer__ { \ public: \ __##name##4##n0##n1##n2##n3##_Initializer__() { \ - PIMutexLocker ml(__eh_mutex()); \ - __EHData & eh(__eh_data()[__classNameS()]); \ + PIMutexLocker ml(__meta_mutex()); \ + __MetaData & eh(__meta_data()[__classNameS()]); \ void * fp = (void*)(ret(*)(void*, a0, a1, a2, a3))__stat_eh_##name##__; \ if (eh.eh_set[fp]) return; \ eh.eh_set << fp; \ @@ -419,6 +422,7 @@ class PIP_EXPORT PIObject friend class PIObjectManager; friend void dumpApplication(); typedef PIObject __PIObject__; + typedef void __Parent__; public: //! Contructs PIObject with name "name" @@ -440,10 +444,13 @@ public: //! Returns object class name virtual const char * className() const {return "PIObject";} + + static const PIString __classNameS() {return PIStringAscii("PIObject");} - //! Returns object superclass name - virtual const char * superClassName() const {return "";} - + //! Returns parent object class name + virtual const char * parentClassName() const {return "";} + + //! Return if debug of this object is active bool debug() const {return property(PIStringAscii("debug")).toBool();} @@ -479,7 +486,8 @@ public: void dump(const PIString & line_prefix = PIString()) const; - PIStringList methodsEH(); + PIStringList scopeList() const; + PIStringList methodsEH() const; bool isMethodEHContains(const PIString & name) const; PIString methodEHArguments(const PIString & name) const; PIString methodEHFullFormat(const PIString & name) const; @@ -672,7 +680,7 @@ public: bool isTypeOf() const { if (!this) return false; if (!isPIObject()) return false; - return (PIStringAscii(className()) == T::__classNameS()); + return scopeList().contains(T::__classNameS()); } template T * cast() const { @@ -692,24 +700,28 @@ public: static PIString simplifyType(const char * a); struct __EHFunc { - __EHFunc(): addr(0) {;} + __EHFunc(): addr(0), addrV(0) {;} bool isNull() const {return addr == 0;} PIString arguments() const; PIString fullFormat() const; void * addr; + void * addrV; PIString func_name; PIString type_ret; PIString scope; PIStringList types; PIStringList names; }; - struct __EHData { + struct __MetaData { + __MetaData() {scope_list << PIStringAscii("PIObject");} + void addScope(const PIString & s) {if (!scope_list.contains(s)) scope_list << s;} + PIStringList scope_list; PISet eh_set; PIMap eh_func; }; typedef PIPair __EHPair; - static PIMutex & __eh_mutex(); - static PIMap & __eh_data(); + static PIMutex & __meta_mutex(); + static PIMap & __meta_data(); // [classname]=__MetaData protected: @@ -720,8 +732,6 @@ protected: virtual void propertyChanged(const PIString & name) {} - static const PIString __classNameS() {return PIStringAscii("PIObject");} - EVENT(deleted) //! \events diff --git a/src_main/io/piiodevice.h b/src_main/io/piiodevice.h index 1dc30bba..760e9f54 100755 --- a/src_main/io/piiodevice.h +++ b/src_main/io/piiodevice.h @@ -237,7 +237,7 @@ public: EVENT_HANDLER(bool, open) {if (!init_) init(); opened_ = openDevice(); if (opened_) opened(); return opened_;} EVENT_HANDLER1(bool, open, const PIString &, _path) {setPath(_path); if (!init_) init(); opened_ = openDevice(); if (opened_) opened(); return opened_;} - EVENT_HANDLER1(bool, open, const DeviceMode &, _mode) {mode_ = _mode; if (!init_) init(); opened_ = openDevice(); if (opened_) opened(); return opened_;} + bool open(const DeviceMode & _mode) {mode_ = _mode; if (!init_) init(); opened_ = openDevice(); if (opened_) opened(); return opened_;} EVENT_HANDLER2(bool, open, const PIString &, _path, const DeviceMode &, _mode) {setPath(_path); mode_ = _mode; if (!init_) init(); opened_ = openDevice(); if (opened_) opened(); return opened_;} EVENT_HANDLER(bool, close) {opened_ = !closeDevice(); if (!opened_) closed(); return !opened_;} diff --git a/src_main/math/pimathcomplex.h b/src_main/math/pimathcomplex.h index e6370711..4fc33dc5 100644 --- a/src_main/math/pimathcomplex.h +++ b/src_main/math/pimathcomplex.h @@ -27,6 +27,10 @@ __PICONTAINERS_SIMPLE_TYPE__(complexi) __PICONTAINERS_SIMPLE_TYPE__(complexf) __PICONTAINERS_SIMPLE_TYPE__(complexd) __PICONTAINERS_SIMPLE_TYPE__(complexld) +__PIBYTEARRAY_SIMPLE_TYPE__(complexi) +__PIBYTEARRAY_SIMPLE_TYPE__(complexf) +__PIBYTEARRAY_SIMPLE_TYPE__(complexd) +__PIBYTEARRAY_SIMPLE_TYPE__(complexld) inline complexd sign(const complexd & x) {return complexd(sign(x.real()), sign(x.imag()));} diff --git a/src_main/piversion.h b/src_main/piversion.h index 47468749..4d0485c6 100644 --- a/src_main/piversion.h +++ b/src_main/piversion.h @@ -5,6 +5,6 @@ #define PIP_VERSION_MAJOR 1 #define PIP_VERSION_MINOR 0 #define PIP_VERSION_REVISION 0 -#define PIP_VERSION_SUFFIX "_beta2" +#define PIP_VERSION_SUFFIX "_rc1" #endif // PIVERSION_H diff --git a/src_main/thread/pithread.h b/src_main/thread/pithread.h index 141c1fbb..ee24f1f6 100755 --- a/src_main/thread/pithread.h +++ b/src_main/thread/pithread.h @@ -60,8 +60,8 @@ public: EVENT_HANDLER0(bool, start) {return start(-1);} EVENT_HANDLER1(bool, start, int, timer_delay); - EVENT_HANDLER1(bool, start, ThreadFunc, func) {ret_func = func; return start(-1);} - EVENT_HANDLER2(bool, start, ThreadFunc, func, int, timer_delay) {ret_func = func; return start(timer_delay);} + bool start(ThreadFunc func) {ret_func = func; return start(-1);} + bool start(ThreadFunc func, int timer_delay) {ret_func = func; return start(timer_delay);} EVENT_HANDLER0(bool, startOnce); EVENT_HANDLER1(bool, startOnce, ThreadFunc, func) {ret_func = func; return startOnce();} EVENT_HANDLER0(void, stop) {stop(false);} @@ -119,12 +119,6 @@ public: * * \return \c false if thread already started or can`t start thread */ - /** \fn bool start(ThreadFunc func, int timer_delay = -1) - * \brief Start thread - * \details Overloaded function. Set external function "func" before start - * - * \return \c false if thread already started or can`t start thread */ - /** \fn bool startOnce() * \brief Start thread without internal loop * \details Start execution of \a run() once. Thread also exec diff --git a/src_main/thread/pitimer.h b/src_main/thread/pitimer.h index 5895320e..6d2bea4f 100755 --- a/src_main/thread/pitimer.h +++ b/src_main/thread/pitimer.h @@ -115,13 +115,13 @@ public: bool isStopped() const {return !imp->running_;} EVENT_HANDLER0(bool, start) {return imp->start();} - EVENT_HANDLER1(bool, start, int, interval_ms_i) {setInterval(double(interval_ms_i)); return imp->start(double(interval_ms_i));} EVENT_HANDLER1(bool, start, double, interval_ms_d) {setInterval(interval_ms_d); return imp->start(interval_ms_d);} + bool start(int interval_ms_i) {setInterval(double(interval_ms_i)); return imp->start(double(interval_ms_i));} EVENT_HANDLER0(bool, restart) {imp->stop(); return imp->start();} - EVENT_HANDLER1(void, startDeferred, double, delay_ms) {imp->startDeferred(delay_ms);} - EVENT_HANDLER2(void, startDeferred, double, interval_ms, double, delay_ms) {imp->startDeferred(interval_ms, delay_ms);} - EVENT_HANDLER1(void, startDeferred, PIDateTime, start_datetime) {startDeferred(imp->interval_, start_datetime);} - EVENT_HANDLER2(void, startDeferred, double, interval_ms, PIDateTime, start_datetime) {imp->startDeferred(interval_ms, start_datetime);} + void startDeferred(double delay_ms) {imp->startDeferred(delay_ms);} + void startDeferred(double interval_ms, double delay_ms) {imp->startDeferred(interval_ms, delay_ms);} + void startDeferred(PIDateTime start_datetime) {startDeferred(imp->interval_, start_datetime);} + void startDeferred(double interval_ms, PIDateTime start_datetime) {imp->startDeferred(interval_ms, start_datetime);} EVENT_HANDLER0(bool, stop) {return imp->stop();} bool waitForFinish() {return waitForFinish(-1);}