git-svn-id: svn://db.shs.com.ru/pip@464 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-24 10:44:46 +00:00
parent 929c0869cc
commit 882b30f493
155 changed files with 226 additions and 191 deletions

View File

@@ -6,7 +6,7 @@
/*
PIP - Platform Independent Primitives
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
Copyright (C) 2016 Ivan Pelipenko peri4ko@yandex.ru
Copyright (C) 2017 Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -185,8 +185,8 @@
#define PIOBJECT(name) \
protected: \
typedef name __PIObject__; \
static const PIString __classNameS() {return PIStringAscii(#name);} \
public: \
static const PIString __classNameS() {return PIStringAscii(#name);} \
virtual const char * className() const {return #name;} \
private:
@@ -197,11 +197,11 @@
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()]); \
if (__eh_data().contains(__classNameS())) return; \
__eh_data()[pn]; \
__eh_data()[__classNameS()]; \
__EHData & ehp(__eh_data()[pn]); \
__EHData & eh(__eh_data()[__classNameS()]); \
eh.eh_set << ehp.eh_set; \
eh.eh_func << ehp.eh_func; \
} \
@@ -219,7 +219,7 @@
public: \
__##name##0_Initializer__() { \
PIMutexLocker ml(__eh_mutex()); \
__EHData & eh(__eh_data[__classNameS()]); \
__EHData & eh(__eh_data()[__classNameS()]); \
void * fp = (void*)(ret(*)(void*))__stat_eh_##name##__; \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
@@ -237,7 +237,7 @@
public: \
__##name##1##n0##_Initializer__() { \
PIMutexLocker ml(__eh_mutex()); \
__EHData & eh(__eh_data[__classNameS()]); \
__EHData & eh(__eh_data()[__classNameS()]); \
void * fp = (void*)(ret(*)(void*, a0))__stat_eh_##name##__; \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
@@ -257,7 +257,7 @@
public: \
__##name##2##n0##n1##_Initializer__() { \
PIMutexLocker ml(__eh_mutex()); \
__EHData & eh(__eh_data[__classNameS()]); \
__EHData & eh(__eh_data()[__classNameS()]); \
void * fp = (void*)(ret(*)(void*, a0, a1))__stat_eh_##name##__; \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
@@ -277,7 +277,7 @@
public: \
__##name##3##n0##n1##n2##_Initializer__() { \
PIMutexLocker ml(__eh_mutex()); \
__EHData & eh(__eh_data[__classNameS()]); \
__EHData & eh(__eh_data()[__classNameS()]); \
void * fp = (void*)(ret(*)(void*, a0, a1, a2))__stat_eh_##name##__; \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
@@ -297,7 +297,7 @@
public: \
__##name##4##n0##n1##n2##n3##_Initializer__() { \
PIMutexLocker ml(__eh_mutex()); \
__EHData & eh(__eh_data[__classNameS()]); \
__EHData & eh(__eh_data()[__classNameS()]); \
void * fp = (void*)(ret(*)(void*, a0, a1, a2, a3))__stat_eh_##name##__; \
if (eh.eh_set[fp]) return; \
eh.eh_set << fp; \
@@ -660,7 +660,7 @@ public:
//! Returns PIObject* with name "name" or 0, if there is no object found
static PIObject * findByName(const PIString & name) {
piForeach (PIObject * i, PIObject::objects) {
piForeach (PIObject * i, PIObject::objects()) {
if (i->name() != name) continue;
return i;
}
@@ -668,15 +668,29 @@ public:
}
bool isPIObject() const {return isPIObject(this);}
template<typename T>
bool isTypeOf() const {
if (!this) return false;
if (!isPIObject()) return false;
return (PIStringAscii(className()) == T::__classNameS());
}
template<typename T>
T * cast() const {
if (!isTypeOf<T>()) return (T*)0;
return (T*)this;
}
bool execute(const PIString & method);
static bool isPIObject(const PIObject * o) {return o->_signature_ == __PIOBJECT_SIGNATURE__;}
static bool isPIObject(const PIObject * o);
static bool isPIObject(const void * o) {return isPIObject((PIObject*)o);}
template<typename 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 execute(PIObject * o, const PIString & method) {return o->execute(method);}
static bool execute(void * o, const PIString & method) {return ((PIObject*)o)->execute(method);}
static PIString simplifyType(const char * a);
static PIMutex & __eh_mutex();
struct __EHFunc {
__EHFunc(): addr(0) {;}
bool isNull() const {return addr == 0;}
@@ -694,7 +708,8 @@ public:
PIMap<const void * , __EHFunc> eh_func;
};
typedef PIPair<const void * , __EHFunc> __EHPair;
static PIMap<PIString, __EHData> __eh_data;
static PIMutex & __eh_mutex();
static PIMap<PIString, __EHData> & __eh_data();
protected:
@@ -745,7 +760,7 @@ private:
typedef PIPair<PIString, PIVariant> Property;
PIMap<PIString, PIVariant> properties_;
static PIVector<PIObject * > objects;
static PIVector<PIObject * > & objects();
PISet<PIObject * > connectors;
PIMutex mutex_, mutex_connect;