Merge branch 'master' of https://git.shs.tools/SHS/pip
This commit is contained in:
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(pip)
|
||||
set(pip_MAJOR 2)
|
||||
set(pip_MINOR 31)
|
||||
set(pip_REVISION 1)
|
||||
set(pip_MINOR 32)
|
||||
set(pip_REVISION 0)
|
||||
set(pip_SUFFIX )
|
||||
set(pip_COMPANY SHS)
|
||||
set(pip_DOMAIN org.SHS)
|
||||
|
||||
@@ -143,50 +143,6 @@ bool PIObject::executeQueued(PIObject * performer, const PIString & method, cons
|
||||
}
|
||||
|
||||
|
||||
void PIObject::piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h) {
|
||||
PIObject * o = findByName(src);
|
||||
if (o == 0) {
|
||||
piCout << "[PIObject] Can`t find object with name \"" << src << "\"!";
|
||||
return;
|
||||
}
|
||||
PIMutexLocker _ml(o->mutex_connect);
|
||||
PIMutexLocker _mld(((PIObject*)dest)->mutex_connect, ((PIObject*)dest) != o);
|
||||
o->connections << __Connection(ev_h, 0, sig, (PIObject*)dest, dest);
|
||||
((PIObject*)dest)->connectors << o;
|
||||
}
|
||||
|
||||
|
||||
void PIObject::piConnect(PIObject * src, const PIString & sig, const PIString & dest, void * ev_h) {
|
||||
PIObject * o = findByName(dest);
|
||||
if (o == 0) {
|
||||
piCout << "[PIObject] Can`t find object with name \"" << dest << "\"!";
|
||||
return;
|
||||
}
|
||||
PIMutexLocker _ml(src->mutex_connect);
|
||||
PIMutexLocker _mld(o->mutex_connect, src != o);
|
||||
src->connections << __Connection(ev_h, 0, sig, o, o);
|
||||
((PIObject*)o)->connectors << src;
|
||||
}
|
||||
|
||||
|
||||
void PIObject::piConnect(const PIString & src, const PIString & sig, const PIString & dest, void * ev_h) {
|
||||
PIObject * s = findByName(src);
|
||||
if (s == 0) {
|
||||
piCout << "[PIObject] Can`t find object with name \"" << src << "\"!";
|
||||
return;
|
||||
}
|
||||
PIObject * d = findByName(dest);
|
||||
if (d == 0) {
|
||||
piCout << "[PIObject] Can`t find object with name \"" << dest << "\"!";
|
||||
return;
|
||||
}
|
||||
PIMutexLocker _ml(s->mutex_connect);
|
||||
PIMutexLocker _mld(d->mutex_connect, s != d);
|
||||
s->connections << __Connection(ev_h, 0, sig, d, d);
|
||||
d->connectors << s;
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIObject::scopeList() const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
return __meta_data()[classNameID()].scope_list;
|
||||
@@ -258,31 +214,33 @@ PIObject::__MetaFunc PIObject::methodEH(const void * addr) const {
|
||||
}
|
||||
|
||||
|
||||
void PIObject::piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc) {
|
||||
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);
|
||||
|
||||
src->connections << __Connection(ev_h, e_h, sig, dest_o, dest, args);
|
||||
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;
|
||||
dest_o->connectors << src;
|
||||
//piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s();
|
||||
//piCout << "piConnect ok";
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
bool 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 false;
|
||||
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 << ")";
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
if (!dest_o->isPIObject()) {
|
||||
piCout << "[piConnectU] \"" << sig << "\" -> \"" << hname << "\" error: destination object is not PIObject! (" << loc << ")";
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
PIMutexLocker mls(src->mutex_connect);
|
||||
@@ -290,11 +248,11 @@ bool PIObject::piConnectU(PIObject * src, const PIString & sig, PIObject * dest_
|
||||
PIVector<__MetaFunc> m_src = src->findEH(sig), m_dest = dest_o->findEH(hname);
|
||||
if (m_src.isEmpty()) {
|
||||
piCout << "[piConnectU] Error: can`t find event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
if (m_dest.isEmpty()) {
|
||||
piCout << "[piConnectU] Error: can`t find handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
void * addr_src(0), * addr_dest(0);
|
||||
int args(0);
|
||||
@@ -313,25 +271,26 @@ bool PIObject::piConnectU(PIObject * src, const PIString & sig, PIObject * dest_
|
||||
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 << ")";
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
src->connections << PIObject::__Connection(addr_dest, addr_src, sig, dest_o, dest, args, performer);
|
||||
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();
|
||||
return true;
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc) {
|
||||
PIObject::Connection PIObject::piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc) {
|
||||
if (src == 0) {
|
||||
delete f;
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
if (!src->isPIObject()) {
|
||||
piCout << "[piConnectLS] \"" << sig << "\" -> [lambda] error: source object is not PIObject! (" << loc << ")";
|
||||
delete f;
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
PIMutexLocker mls(src->mutex_connect);
|
||||
@@ -340,19 +299,19 @@ bool PIObject::piConnectLS(PIObject * src, const PIString & sig, std::function<v
|
||||
if (m_src.isEmpty()) {
|
||||
piCout << "[piConnectLS] Error: can`t find event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
delete f;
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
if (m_src.size() != 1) {
|
||||
piCout << "[piConnectLS] Error: can`t connect overloaded event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
delete f;
|
||||
return false;
|
||||
return Connection();
|
||||
}
|
||||
PIObject::__Connection conn(0, m_src[0].addr, sig);
|
||||
PIObject::Connection conn(0, m_src[0].addr, sig, src);
|
||||
//piCout << "found";
|
||||
conn.functor = f;
|
||||
src->connections << conn;
|
||||
//piCout << "finished";
|
||||
return true;
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,7 +319,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des
|
||||
PIMutexLocker _ml(src->mutex_connect);
|
||||
PIMutexLocker _mld(dest->mutex_connect, src != dest);
|
||||
for (int i = 0; i < src->connections.size_s(); ++i) {
|
||||
__Connection & cc(src->connections[i]);
|
||||
Connection & cc(src->connections[i]);
|
||||
if (cc.event == sig && cc.dest_o == dest && cc.slot == ev_h) {
|
||||
src->connections[i].destroy();
|
||||
src->connections.remove(i);
|
||||
@@ -375,7 +334,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des
|
||||
PIMutexLocker _ml(src->mutex_connect);
|
||||
PIMutexLocker _mld(dest->mutex_connect, src != dest);
|
||||
for (int i = 0; i < src->connections.size_s(); ++i) {
|
||||
__Connection & cc(src->connections[i]);
|
||||
Connection & cc(src->connections[i]);
|
||||
if (cc.event == sig && cc.dest_o == dest) {
|
||||
src->connections[i].destroy();
|
||||
src->connections.remove(i);
|
||||
@@ -389,7 +348,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig, PIObject * des
|
||||
void PIObject::piDisconnect(PIObject * src, const PIString & sig) {
|
||||
PIMutexLocker _ml(src->mutex_connect);
|
||||
for (int i = 0; i < src->connections.size_s(); ++i) {
|
||||
__Connection & cc(src->connections[i]);
|
||||
Connection & cc(src->connections[i]);
|
||||
if (cc.event == sig) {
|
||||
PIObject * dest = cc.dest_o;
|
||||
src->connections[i].destroy();
|
||||
@@ -417,7 +376,7 @@ void PIObject::piDisconnectAll() {
|
||||
#if !defined(ANDROID) && !defined(MAC_OS) && !defined(FREERTOS)
|
||||
PIMutexLocker _mld(o->mutex_connect, this != o);
|
||||
#endif
|
||||
PIVector<__Connection> & oc(o->connections);
|
||||
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);
|
||||
@@ -429,7 +388,7 @@ void PIObject::piDisconnectAll() {
|
||||
}
|
||||
}
|
||||
// piCout << "disconnect connections =" << connections.size();
|
||||
piForeachC (PIObject::__Connection & c, connections) {
|
||||
piForeachC (PIObject::Connection & c, connections) {
|
||||
if (c.functor) continue;
|
||||
if (!c.dest_o) continue;
|
||||
if (!c.dest_o->isPIObject()) continue;
|
||||
@@ -447,8 +406,8 @@ void PIObject::updateConnectors() {
|
||||
PIMutexLocker _ml(mutexObjects());
|
||||
piForeach (PIObject * o, objects()) {
|
||||
if (o == this) continue;
|
||||
PIVector<__Connection> & oc(o->connections);
|
||||
piForeach (__Connection & c, oc)
|
||||
PIVector<Connection> & oc(o->connections);
|
||||
piForeach (Connection & c, oc)
|
||||
if (c.dest == this)
|
||||
connectors << o;
|
||||
}
|
||||
@@ -609,7 +568,7 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||
//printf("dump %d connections\n",connections.size());
|
||||
piForeachC (__Connection & c, connections) {
|
||||
piForeachC (Connection & c, connections) {
|
||||
PIObject * dst = c.dest_o;
|
||||
__MetaFunc ef = methodEH(c.signal);
|
||||
PIString src(c.event);
|
||||
@@ -682,12 +641,58 @@ void PIObject::__MetaData::addScope(const PIString & s, uint shash) {
|
||||
}
|
||||
|
||||
|
||||
void PIObject::__Connection::destroy() {
|
||||
|
||||
|
||||
void PIObject::Connection::destroy() {
|
||||
if (functor) delete functor;
|
||||
functor = nullptr;
|
||||
}
|
||||
|
||||
|
||||
PIObject::Connection::Connection() {
|
||||
slot = signal = dest = nullptr;
|
||||
src_o = dest_o = performer = nullptr;
|
||||
functor = nullptr;
|
||||
eventID = 0;
|
||||
args_count = 0;
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::Connection::disconnect() {
|
||||
if (!isValid() || !src_o) return false;
|
||||
if (!src_o->isPIObject()) return false;
|
||||
bool ndm = dest_o && (src_o != dest_o), ret = false, found = false;
|
||||
if (dest_o) {
|
||||
if (!dest_o->isPIObject()) ndm = false;
|
||||
}
|
||||
PIMutexLocker _ml(src_o->mutex_connect);
|
||||
if (ndm) dest_o->mutex_connect.lock();
|
||||
for (int i = 0; i < src_o->connections.size_s(); ++i) {
|
||||
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 (functor && (cc.functor == functor))
|
||||
found = true;
|
||||
}
|
||||
if (found) {
|
||||
src_o->connections[i].destroy();
|
||||
src_o->connections.remove(i);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dest_o) {
|
||||
if (dest_o->isPIObject())
|
||||
dest_o->updateConnectors();
|
||||
}
|
||||
if (ndm) dest_o->mutex_connect.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIObject::Deleter)
|
||||
|
||||
@@ -50,6 +50,54 @@ public:
|
||||
|
||||
virtual ~PIObject();
|
||||
|
||||
//! Helper class for obtain info about if connection successful and disconnect single connection
|
||||
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;
|
||||
args_count = ac;
|
||||
performer = p;
|
||||
functor = 0;
|
||||
}
|
||||
void destroy();
|
||||
void * slot;
|
||||
void * signal;
|
||||
std::function<void()> * functor;
|
||||
PIString event;
|
||||
uint eventID;
|
||||
PIObject * src_o, * dest_o;
|
||||
PIObject * performer;
|
||||
void * dest;
|
||||
int args_count;
|
||||
public:
|
||||
|
||||
//! Contructs invalid %Connection
|
||||
Connection();
|
||||
|
||||
//! Returns if %Connection is valid
|
||||
bool isValid() const {return signal;}
|
||||
|
||||
//! Returns source object
|
||||
PIObject * sourceObject() const {return src_o;}
|
||||
|
||||
//! Returns destination object or nullptr if this is lambda connection
|
||||
PIObject * destinationObject() const {return dest_o;}
|
||||
|
||||
//! Returns performer object or nullptr if this is non-queued connection
|
||||
PIObject * performerObject() const {return performer;}
|
||||
|
||||
//! Disconnect this %Connection, returns if operation successful
|
||||
bool disconnect();
|
||||
};
|
||||
|
||||
private:
|
||||
uint _signature_;
|
||||
|
||||
@@ -141,21 +189,29 @@ public:
|
||||
PIString methodEHFromAddr(const void * addr) const;
|
||||
|
||||
// / Direct connect
|
||||
static void piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
|
||||
static bool piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0);
|
||||
static bool piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc);
|
||||
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 INPUT, typename... TYPES>
|
||||
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,TYPES...), INPUT functor) {
|
||||
return (std::function<void()>*)(new std::function<void(TYPES...)>(functor));
|
||||
}
|
||||
|
||||
// / Through names and mixed
|
||||
static void piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h);
|
||||
static void piConnect(PIObject * src, const PIString & sig, const PIString & dest, void * ev_h);
|
||||
static void piConnect(const PIString & src, const PIString & sig, const PIString & dest, void * ev_h);
|
||||
|
||||
//! Disconnect object from all connections with event name "sig", connected to destination object "dest" and handler "ev_h"
|
||||
void piDisconnect(const PIString & sig, PIObject * dest, void * ev_h) {piDisconnect(this, sig, dest, ev_h);}
|
||||
|
||||
//! Disconnect object from all connections with event name "sig", connected to destination object "dest"
|
||||
void piDisconnect(const PIString & sig, PIObject * dest) {piDisconnect(this, sig, dest);}
|
||||
|
||||
//! Disconnect object from all connections with event name "sig"
|
||||
void piDisconnect(const PIString & sig) {piDisconnect(this, sig);}
|
||||
|
||||
|
||||
//! Disconnect object "src" from all connections with event name "sig", connected to destination object "dest" and handler "ev_h"
|
||||
static void piDisconnect(PIObject * src, const PIString & sig, PIObject * dest, void * ev_h);
|
||||
|
||||
//! Disconnect object "src" from all connections with event name "sig", connected to destination object "dest"
|
||||
static void piDisconnect(PIObject * src, const PIString & sig, PIObject * dest);
|
||||
|
||||
//! Disconnect object "src" from all connections with event name "sig"
|
||||
@@ -164,7 +220,7 @@ public:
|
||||
// / Raise events
|
||||
static void raiseEvent(PIObject * sender, const uint eventID) {
|
||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||
__Connection i(sender->connections[j]);
|
||||
Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
if (i.functor) {
|
||||
(*(i.functor))();
|
||||
@@ -193,7 +249,7 @@ public:
|
||||
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]);
|
||||
Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0)>*)i.functor))(v0);
|
||||
@@ -224,7 +280,7 @@ public:
|
||||
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]);
|
||||
Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0, T1)>*)i.functor))(v0, v1);
|
||||
@@ -259,7 +315,7 @@ public:
|
||||
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]);
|
||||
Connection i(sender->connections[j]);
|
||||
if (i.eventID != eventID) continue;
|
||||
if (i.functor) {
|
||||
(*((std::function<void(T0, T1, T2)>*)i.functor))(v0, v1, v2);
|
||||
@@ -296,7 +352,7 @@ public:
|
||||
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]);
|
||||
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);
|
||||
@@ -425,30 +481,6 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
struct __Connection {
|
||||
__Connection(void * sl = 0, void * si = 0, const PIString & e = PIString(), PIObject * d_o = 0, void * d = 0, int ac = 0, PIObject * p = 0) {
|
||||
slot = sl;
|
||||
signal = si;
|
||||
event = e;
|
||||
eventID = e.hash();
|
||||
dest_o = d_o;
|
||||
dest = d;
|
||||
args_count = ac;
|
||||
performer = p;
|
||||
functor = 0;
|
||||
}
|
||||
void destroy();
|
||||
void * slot;
|
||||
void * signal;
|
||||
std::function<void()> * functor;
|
||||
PIString event;
|
||||
uint eventID;
|
||||
PIObject * dest_o;
|
||||
PIObject * performer;
|
||||
void * dest;
|
||||
int args_count;
|
||||
};
|
||||
|
||||
struct __QueuedEvent {
|
||||
__QueuedEvent(void * sl = 0, void * d = 0, PIObject * d_o = 0, PIObject * s = 0, const PIVector<PIVariantSimple> & v = PIVector<PIVariantSimple>()) {
|
||||
slot = sl;
|
||||
@@ -499,7 +531,7 @@ private:
|
||||
static void callAddrV(void * slot, void * obj, int args, const PIVector<PIVariantSimple> & vl);
|
||||
|
||||
|
||||
PIVector<__Connection> connections;
|
||||
PIVector<Connection> connections;
|
||||
PIMap<uint, PIPair<PIString, PIVariant> > properties_;
|
||||
PISet<PIObject * > connectors;
|
||||
PIVector<__QueuedEvent> events_queue;
|
||||
|
||||
@@ -102,28 +102,36 @@
|
||||
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\". \"Event\" and \"handler\" must has equal argument lists.
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECTU(src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\".
|
||||
/// Event handler will be executed by \"performer\". \"Event\" and \"handler\" must has equal argument lists.
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECTU_QUEUED(src, event, dest, handler, performer)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to lambda-expression \"functor\". \"Event\" and \"functor\" must has equal argument lists.
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECTL(src, event, functor)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECT0(ret, src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECT1(ret, type0, src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECT2(ret, type0, type1, src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECT3(ret, type0, type1, type2, src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||
/// \relatesalso PIObject @brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists.
|
||||
/// Returns PIObject::Connection
|
||||
#define CONNECT4(ret, type0, type1, type2, type3, src, event, dest, handler)
|
||||
|
||||
/// \relatesalso PIObject @brief CONNECT is synonym of CONNECT0
|
||||
|
||||
@@ -554,7 +554,7 @@ void PIThread::__thread_func_once__() {
|
||||
void PIThread::runOnce(PIObject * object, const char * handler, const PIString & name) {
|
||||
PIThread * t = new PIThread();
|
||||
t->setName(name);
|
||||
if (!PIObject::piConnectU(t, PIStringAscii("started"), object, object, PIStringAscii(handler), "PIThread::runOnce")) {
|
||||
if (!PIObject::piConnectU(t, PIStringAscii("started"), object, object, PIStringAscii(handler), "PIThread::runOnce").isValid()) {
|
||||
delete t;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,54 +1,73 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "pimathmatrix.h"
|
||||
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrix<double> matrix, double val, int num) {
|
||||
bool b = true;
|
||||
template<typename Type>
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrix<Type> matrix, Type val, int num) {
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.element(i, j) != val) {
|
||||
b = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, identity) {
|
||||
TEST(PIMathMatrix_Test, constructor1) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 5.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, constructor2) {
|
||||
PIVector<double> vector(2, 5.0);
|
||||
PIMathMatrix<PIVector<double>> matrix(3, 3, vector);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, vector, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, constructor3) {
|
||||
PIVector2D<double> vector(2, 2, 5.0);
|
||||
PIMathMatrix<double> matrix(vector);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 5.0, 2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, identity1) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(i != j) {
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix[i][i] != 1.0){
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, identity2) {
|
||||
auto matrix = PIMathMatrix<double>::identity(4, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 4; j++) {
|
||||
if(matrix.element(i,j) != (i == j ? 1. : 0.))
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, element) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
if(i != j){
|
||||
if(matrix[i][j] != 0.0){
|
||||
ASSERT_TRUE(false);
|
||||
if(matrix.element(i,j) != (i == j ? 1. : 0.))
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(matrix.element(i,i) != 1.0) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixRow) {
|
||||
@@ -57,10 +76,10 @@ TEST(PIMathMatrix_Test, matrixRow) {
|
||||
auto matrix = PIMathMatrix<double>::matrixRow(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixCol) {
|
||||
@@ -69,10 +88,10 @@ TEST(PIMathMatrix_Test, matrixCol) {
|
||||
auto matrix = PIMathMatrix<double>::matrixCol(vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 3.0) {
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, setCol) {
|
||||
@@ -83,10 +102,10 @@ TEST(PIMathMatrix_Test, setCol) {
|
||||
matrix.setCol(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[i][0] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, setRow) {
|
||||
@@ -97,10 +116,10 @@ TEST(PIMathMatrix_Test, setRow) {
|
||||
matrix.setRow(0, vector);
|
||||
for(uint i = 0; i < vector.size(); i++) {
|
||||
if(matrix[0][i] != 10.0) {
|
||||
ASSERT_TRUE(false);
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, swapCols) {
|
||||
@@ -137,407 +156,3 @@ TEST(PIMathMatrix_Test, swapCols) {
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, swapRows) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathVector<double> vector;
|
||||
uint i1 = 0; uint i2 = 1;
|
||||
double a1[3], a2[3], a3[3];
|
||||
double b1[3], b2[3], b3[3];
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
a1[i] = matrix1.element(0, i);
|
||||
a2[i] = matrix1.element(1, i);
|
||||
a3[i] = matrix1.element(2, i);
|
||||
}
|
||||
matrix1.swapRows(i1, i2);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
b1[i] = matrix1.element(0, i);
|
||||
b2[i] = matrix1.element(1, i);
|
||||
b3[i] = matrix1.element(2, i);
|
||||
}
|
||||
ASSERT_TRUE((memcmp(a1, b2, sizeof(b1)) == 0) && (memcmp(a2, b1, sizeof(b1)) == 0) && (memcmp(a3, b3, sizeof(b1)) == 0));
|
||||
}
|
||||
TEST(PIMathMatrix_Test, fill) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
matrix.fill(7.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix, 7.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 1.0);
|
||||
ASSERT_TRUE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isSquareFalse) {
|
||||
PIMathMatrix<double> matrix(2, 4, 1.0);
|
||||
ASSERT_FALSE(matrix.isSquare());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityTrue) {
|
||||
auto matrix = PIMathMatrix<double>::identity(3, 3);
|
||||
ASSERT_TRUE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isIdentityFalse) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isIdentity());
|
||||
}
|
||||
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
ASSERT_TRUE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isNullFalse) {
|
||||
PIMathMatrix<double> matrix(3, 3, 5.0);
|
||||
ASSERT_FALSE(matrix.isNull());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidTrue) {
|
||||
PIMathMatrix<double> matrix(3, 3, 1.62);
|
||||
ASSERT_TRUE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, isValidFalse) {
|
||||
PIMathMatrix<double> matrix;
|
||||
ASSERT_FALSE(matrix.isValid());
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 5.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 7.12);
|
||||
matrix1 = matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.12, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_EqualTrue) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_EqualFalse) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 == matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualTrue) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 665.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_TRUE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Not_EqualFalse) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 2.0);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.0);
|
||||
matrix1.element(0, 0) = 5.1;
|
||||
matrix1.element(0, 1) = 1.21;
|
||||
matrix1.element(1, 1) = 0.671;
|
||||
matrix1.element(1, 0) = 2.623;
|
||||
matrix2.element(0, 0) = 5.1;
|
||||
matrix2.element(0, 1) = 1.21;
|
||||
matrix2.element(1, 1) = 0.671;
|
||||
matrix2.element(1, 0) = 2.623;
|
||||
ASSERT_FALSE(matrix1 != matrix2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition_Aassignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 1.0);
|
||||
matrix1 += matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 7.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 6.72);
|
||||
matrix1 -= matrix2;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, -5.72, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 *= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 13.44, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Division_Assignment) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
matrix1 /= 2.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1, 3.36, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Addition) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 8.28);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 + matrix2, 15.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Subtraction) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 - matrix2, 1.0, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, operator_Multiplication) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1*4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 26.88, 3));
|
||||
}
|
||||
TEST(PIMathMatrix_Test, operator_Division) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 6.72);
|
||||
PIMathMatrix<double> matrix2(3, 3, 5.0);
|
||||
matrix2 = matrix1/4.0;
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix2, 1.68, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, determinantIfSquare) {
|
||||
double d;
|
||||
double i = 59.0;
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d = matrix.determinant();
|
||||
ASSERT_DOUBLE_EQ(d, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, trace) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double t;
|
||||
double i = 9.0;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
t = matrix.trace();
|
||||
ASSERT_DOUBLE_EQ(t, i);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, toUpperTriangular) {
|
||||
PIMathMatrix<double> matrix(3, 3, 0.0);
|
||||
double d1, d2 = 1;
|
||||
int i;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix.setCol(2, vector);
|
||||
d1 = matrix.determinant();
|
||||
matrix.toUpperTriangular();
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
d2 = d2 * matrix.element(i, i);
|
||||
}
|
||||
ASSERT_DOUBLE_EQ(d1, d2);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, invert) {
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix2.invert();
|
||||
d2 = matrix2.determinant();
|
||||
matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, inverted) {
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix2(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix3(3, 3, 0.0);
|
||||
PIMathMatrix<double> matrix4(3, 3, 0.0);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1;
|
||||
matrix1 = matrix2.invert();
|
||||
d2 = matrix1.determinant();
|
||||
matrix3 = matrix4.invert();
|
||||
ASSERT_TRUE((matrix3 == matrix4) && (round((1/d1)*10000)/10000 == round(d2*10000)/10000));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, transposed) {
|
||||
PIMathMatrix<double> origMatr;
|
||||
double d1, d2;
|
||||
PIMathMatrix<double> matrix1;
|
||||
PIMathMatrix<double> matrix2;
|
||||
PIMathMatrix<double> matrix3;
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(3, 3.0);
|
||||
vector[0] = 3.0;
|
||||
vector[1] = 6.0;
|
||||
vector[2] = 8.0;
|
||||
matrix1 = origMatr.identity(3, 3);
|
||||
matrix1.setCol(0, vector);
|
||||
vector[0] = 2.0;
|
||||
vector[1] = 1.0;
|
||||
vector[2] = 4.0;
|
||||
matrix1.setCol(1, vector);
|
||||
vector[0] = 6.0;
|
||||
vector[1] = 2.0;
|
||||
vector[2] = 5.0;
|
||||
matrix1.setCol(2, vector);
|
||||
d1 = matrix1.determinant();
|
||||
matrix2 = matrix1.transposed();
|
||||
d2 = matrix2.determinant();
|
||||
matrix3 = matrix2.transposed();
|
||||
ASSERT_TRUE((d1 == d2) && (matrix1 == matrix3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathMatrix<double> matrix2(2, 2, 2.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(matrix1 * matrix2, 7.5, 2));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, matrixAndVectorMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((matrix1 * vector)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, vectorAndMatrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(2, 2, 1.5);
|
||||
PIMathVector<double> vector;
|
||||
vector.resize(2, 2.5);
|
||||
for(uint i = 0; i < 2; i++) {
|
||||
if((vector * matrix1)[i] != 7.5) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, valAndMatrixMultiplication) {
|
||||
PIMathMatrix<double> matrix1(3, 3, 1.5);
|
||||
ASSERT_TRUE(cmpSquareMatrixWithValue(25.0*matrix1, 37.5, 3));
|
||||
}
|
||||
|
||||
TEST(PIMathMatrix_Test, hermitian) {
|
||||
complex<double> val;
|
||||
complex<double> res;
|
||||
val.imag(1.0);
|
||||
val.real(1.0);
|
||||
PIMathMatrix<complex<double>> matrix(3, 3, val);
|
||||
res.imag(-1.0);
|
||||
res.real(1.0);
|
||||
auto matr = hermitian(matrix);
|
||||
for(uint i = 0; i < 3; i++) {
|
||||
for(uint j = 0; j < 3; j++) {
|
||||
if(matr.element(i, j) != res) {
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(true);
|
||||
}
|
||||
|
||||
@@ -5,15 +5,14 @@ const uint rows = 3;
|
||||
const uint cols = 3;
|
||||
|
||||
bool cmpSquareMatrixWithValue(PIMathMatrixT<rows, cols, double> matrix, double val, int num) {
|
||||
bool b = true;
|
||||
for(int i = 0; i < num; i++) {
|
||||
for(int j = 0; j < num; j++) {
|
||||
if(matrix.at(i, j) != val) {
|
||||
b = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return b;
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(PIMathMatrixT_Test, identity) {
|
||||
|
||||
Reference in New Issue
Block a user