diff --git a/main.cpp b/main.cpp index f8b632a4..03ff81e9 100644 --- a/main.cpp +++ b/main.cpp @@ -40,9 +40,10 @@ public: }; int main(int argc, char *argv[]) { - PIThread t; - PIObject * o = (PIObject*)&t; - piCout << (o->cast()); + PIVariant v; + A a = v.value(); +// v = PIVariant::fromValue(a); + // PIDiagnostics d; // piCout << d.receiveBytesPerSec(); diff --git a/src_main/containers/pideque.h b/src_main/containers/pideque.h index 176560e6..72f87e1c 100755 --- a/src_main/containers/pideque.h +++ b/src_main/containers/pideque.h @@ -35,32 +35,32 @@ template class PIDeque { public: - PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { + inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW() //printf("new vector 1 %p (%s) ... !{\n", this, typeid(T).name()); //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - PIDeque(const PIDeque & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { + inline PIDeque(const PIDeque & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW() //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(other.pid_size, true); newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size); //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { + inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW() //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(size, true); newT(pid_data + pid_start, data, pid_size); //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { + inline PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW() //printf("new vector 3 %p (%s) ... !{\n", this, typeid(T).name()); resize(pid_size, f); //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - ~PIDeque() { + inline ~PIDeque() { PIINTROSPECTION_CONTAINER_DELETE() PIINTROSPECTION_CONTAINER_FREE((pid_rsize)*sizeof(T)) //printf("delete deque %p (%s) (s=%d, rs=%d, st=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(pid_size), int(pid_rsize), int(pid_start), pid_data); @@ -71,7 +71,7 @@ public: //printf("}~\n"); } - PIDeque & operator =(const PIDeque & other) { + inline PIDeque & operator =(const PIDeque & other) { if (this == &other) return *this; deleteT(pid_data + pid_start, pid_size); alloc(other.pid_size, true); @@ -184,8 +184,8 @@ public: T * data(size_t index = 0) {return &(pid_data[pid_start + index]);} const T * data(size_t index = 0) const {return &(pid_data[pid_start + index]);} - PIDeque & clear() {resize(0); return *this;} - PIDeque & fill(const T & f = T()) { + inline PIDeque & clear() {resize(0); return *this;} + inline PIDeque & fill(const T & f = T()) { //if (sizeof(T) == 1) memset(pid_data, f, pid_size); deleteT(pid_data + pid_start, pid_size); //zeroRaw(pid_data, pid_size); @@ -193,9 +193,10 @@ public: elementNew(pid_data + i, f); return *this; } - PIDeque & assign(const T & f = T()) {return fill(f);} - PIDeque & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);} - PIDeque & resize(size_t new_size, const T & f = T()) { + inline PIDeque & assign(const T & f = T()) {return fill(f);} + inline PIDeque & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);} + + inline PIDeque & resize(size_t new_size, const T & f = T()) { if (new_size < pid_size) { deleteT(&(pid_data[new_size + pid_start]), pid_size - new_size); pid_size = new_size; @@ -210,7 +211,13 @@ public: } return *this; } - PIDeque & reserve(size_t new_size) { + inline PIDeque & _resizeRaw(size_t new_size) { + piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIDEQUE_SIMPLE_TYPE__ macro!"; + assert(0); + return *this; + } + + inline PIDeque & reserve(size_t new_size) { if (new_size <= pid_rsize) return *this; size_t os = pid_size; alloc(new_size, true); @@ -218,7 +225,7 @@ public: return *this; } - PIDeque & insert(size_t index, const T & v = T()) { + inline PIDeque & insert(size_t index, const T & v = T()) { bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); //piCout << "insert" << dir << index << pid_size << pid_rsize << pid_start << "!<"; if (dir) { @@ -238,7 +245,7 @@ public: elementNew(pid_data + pid_start + index, v); return *this; } - PIDeque & insert(size_t index, const PIDeque & other) { + inline PIDeque & insert(size_t index, const PIDeque & other) { if (other.isEmpty()) return *this; bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); //piCout << this << "insert" << dir << index << pid_size << pid_rsize << pid_start << " <- " << other.size() << "!<"; @@ -261,7 +268,7 @@ public: return *this; } - PIDeque & remove(size_t index, size_t count = 1) { + inline PIDeque & remove(size_t index, size_t count = 1) { if (count == 0) return *this; if (index + count >= pid_size) { resize(index); @@ -280,7 +287,7 @@ public: return *this; } - void swap(PIDeque & other) { + inline void swap(PIDeque & other) { piSwap(pid_data, other.pid_data); piSwap(pid_size, other.pid_size); piSwap(pid_rsize, other.pid_rsize); @@ -384,7 +391,7 @@ private: } inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementDelete(T & from) {from.~T();} - void dealloc() {deleteRaw(pid_data);} + inline void dealloc() {deleteRaw(pid_data);} inline void checkMove(bool direction) { if (pid_size >= 4) { if (pid_size < pid_rsize / 6) { @@ -474,15 +481,19 @@ private: } T * pid_data; - volatile size_t pid_size, pid_rsize; - volatile ssize_t pid_start; + size_t pid_size, pid_rsize; + ssize_t pid_start; }; #define __PIDEQUE_SIMPLE_TYPE__(T) \ template<> inline void PIDeque::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(s*sizeof(T)); memcpy(dst, src, s * sizeof(T));} \ template<> inline void PIDeque::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(sz*sizeof(T));} \ template<> inline void PIDeque::elementNew(T * to, const T & from) {(*to) = from;} \ - template<> inline void PIDeque::elementDelete(T & from) {;} + template<> inline void PIDeque::elementDelete(T & from) {;} \ + template<> inline PIDeque & PIDeque::_resizeRaw(size_t new_size) {if (new_size > pid_size) alloc(new_size, true); return *this;} \ + template<> inline PIDeque & PIDeque::clear() {pid_size = 0; return *this;} \ + template<> inline PIDeque & PIDeque::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} + #else diff --git a/src_main/containers/pivector.h b/src_main/containers/pivector.h index 781194f0..8d960b84 100755 --- a/src_main/containers/pivector.h +++ b/src_main/containers/pivector.h @@ -33,28 +33,28 @@ template class PIVector { public: - PIVector(): piv_data(0), piv_size(0), piv_rsize(0) { + inline PIVector(): piv_data(0), piv_size(0), piv_rsize(0) { //printf("new vector 1 %p (%s) ... !{\n", this, typeid(T).name()); //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); } - PIVector(const T * data, size_t size): piv_data(0), piv_size(0), piv_rsize(0) { + inline PIVector(const T * data, size_t size): piv_data(0), piv_size(0), piv_rsize(0) { //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(size); newT(piv_data, data, piv_size); //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - PIVector(const PIVector & other): piv_data(0), piv_size(0), piv_rsize(0) { + inline PIVector(const PIVector & other): piv_data(0), piv_size(0), piv_rsize(0) { //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(other.piv_size); newT(piv_data, other.piv_data, piv_size); //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); } - PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) { + inline PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) { //printf("new vector 3 %p (%s) ... !{\n", this, typeid(T).name()); resize(piv_size, f); //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); } - ~PIVector() { + inline ~PIVector() { //printf("delete vector %p (%s) (s=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(piv_size), piv_data); deleteT(piv_data, piv_size); dealloc(); @@ -63,33 +63,12 @@ public: //printf("}~\n"); } - PIVector & operator =(const PIVector & other) { + inline PIVector & operator =(const PIVector & other) { if (this == &other) return *this; - bool tj, oj; - tj = (piv_size != 0 && piv_data == 0);// || (piv_size == 0 && piv_data != 0); - oj = (other.piv_size != 0 && other.piv_data == 0);// || (other.piv_size == 0 && other.piv_data != 0); - //printf("operator= (%p = %p) (s=%d, d=%p, o.s=%d, o.d=%p) (%d, %d) ... o[\n", this, &other, int(piv_size), piv_data, int(other.piv_size), other.piv_data, int(tj), int(oj)); - if (tj) { - //printf("JUNK this\n"); - _reset(); - } else { - clear(); - } - /*if (piv_size == other.piv_size) { - for (size_t i = 0; i < piv_size; ++i) - piv_data[i] = other.piv_data[i]; - return *this; - }*/ - if (!oj) { - deleteT(piv_data, piv_size); - alloc(other.piv_size); - //zeroRaw(piv_data, piv_size); - for (size_t i = 0; i < piv_size; ++i) - elementNew(piv_data + i, other.piv_data[i]); //piv_data[i] = other.piv_data[i]; - } else { - //printf("JUNK other\n"); - } - //printf("o]\n"); + clear(); + deleteT(piv_data, piv_size); + alloc(other.piv_size); + newT(piv_data, other.piv_data, piv_size); return *this; } @@ -199,8 +178,8 @@ public: T * data(size_t index = 0) {return &(piv_data[index]);} const T * data(size_t index = 0) const {return &(piv_data[index]);} - PIVector & clear() {resize(0); return *this;} - PIVector & fill(const T & f = T()) { + inline PIVector & clear() {resize(0); return *this;} + inline PIVector & fill(const T & f = T()) { //if (sizeof(T) == 1) memset(piv_data, f, piv_size); deleteT(piv_data, piv_size); //zeroRaw(piv_data, piv_size); @@ -208,9 +187,10 @@ public: elementNew(piv_data + i, f); return *this; } - PIVector & assign(const T & f = T()) {return fill(f);} - PIVector & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);} - PIVector & resize(size_t new_size, const T & f = T()) { + inline PIVector & assign(const T & f = T()) {return fill(f);} + inline PIVector & assign(size_t new_size, const T & f) {resize(new_size); return fill(f);} + + inline PIVector & resize(size_t new_size, const T & f = T()) { if (new_size < piv_size) { T * de = &(piv_data[new_size]); deleteT(de, piv_size - new_size); @@ -221,13 +201,26 @@ public: alloc(new_size); //if (sizeof(T) == 1) memset(&(piv_data[os]), f, ds); //zeroRaw(&(piv_data[os]), new_size - os); - for (size_t i = os; i < new_size; ++i) elementNew(piv_data + i, f); + for (size_t i = os; i < new_size; ++i) + elementNew(piv_data + i, f); } return *this; } - PIVector & reserve(size_t new_size) {if (new_size <= piv_rsize) return *this; size_t os = piv_size; alloc(new_size); piv_size = os; return *this;} + inline PIVector & _resizeRaw(size_t new_size) { + piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIVECTOR_SIMPLE_TYPE__ macro!"; + assert(0); + return *this; + } - PIVector & insert(size_t index, const T & v = T()) { + inline PIVector & reserve(size_t new_size) { + if (new_size <= piv_rsize) return *this; + size_t os = piv_size; + alloc(new_size); + piv_size = os; + return *this; + } + + inline PIVector & insert(size_t index, const T & v = T()) { alloc(piv_size + 1); if (index < piv_size - 1) { size_t os = piv_size - index - 1; @@ -247,7 +240,7 @@ public: return *this; } - PIVector & remove(size_t index, size_t count = 1) { + inline PIVector & remove(size_t index, size_t count = 1) { if (count == 0) return *this; if (index + count >= piv_size) { resize(index); @@ -260,7 +253,7 @@ public: return *this; } - void swap(PIVector & other) { + inline void swap(PIVector & other) { piSwap(piv_data, other.piv_data); piSwap(piv_size, other.piv_size); piSwap(piv_rsize, other.piv_rsize); @@ -268,38 +261,38 @@ public: typedef int (*CompareFunc)(const T * , const T * ); static int compare_func(const T * t0, const T * t1) {return (*t0) < (*t1) ? -1 : ((*t0) == (*t1) ? 0 : 1);} - PIVector & sort(CompareFunc compare = compare_func) {piqsort(piv_data, piv_size, sizeof(T), (int(*)(const void * , const void * ))compare); return *this;} + inline PIVector & sort(CompareFunc compare = compare_func) {piqsort(piv_data, piv_size, sizeof(T), (int(*)(const void * , const void * ))compare); return *this;} - PIVector & enlarge(llong piv_size) {llong ns = size_s() + piv_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;} + inline PIVector & enlarge(llong piv_size) {llong ns = size_s() + piv_size; if (ns <= 0) clear(); else resize(size_t(ns)); return *this;} - PIVector & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;} - PIVector & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(piv_size); ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;} + inline PIVector & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;} + inline PIVector & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(piv_size); ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;} - PIVector & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;} - PIVector & append(const T & v) {return push_back(v);} - PIVector & operator <<(const T & v) {return push_back(v);} - PIVector & operator <<(const PIVector & other) { + inline PIVector & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;} + inline PIVector & append(const T & v) {return push_back(v);} + inline PIVector & operator <<(const T & v) {return push_back(v);} + inline PIVector & operator <<(const PIVector & other) { size_t ps = piv_size; alloc(piv_size + other.piv_size); newT(piv_data + ps, other.piv_data, other.piv_size); return *this; } - PIVector & push_front(const T & v) {insert(0, v); return *this;} - PIVector & prepend(const T & v) {return push_front(v);} + inline PIVector & push_front(const T & v) {insert(0, v); return *this;} + inline PIVector & prepend(const T & v) {return push_front(v);} - PIVector & pop_back() {if (piv_size == 0) return *this; resize(piv_size - 1); return *this;} - PIVector & pop_front() {if (piv_size == 0) return *this; remove(0); return *this;} + inline PIVector & pop_back() {if (piv_size == 0) return *this; resize(piv_size - 1); return *this;} + inline PIVector & pop_front() {if (piv_size == 0) return *this; remove(0); return *this;} - T take_back() {T t(back()); pop_back(); return t;} - T take_front() {T t(front()); pop_front(); return t;} + inline T take_back() {T t(back()); pop_back(); return t;} + inline T take_front() {T t(front()); pop_front(); return t;} template PIVector toType() const {PIVector ret(piv_size); for (uint i = 0; i < piv_size; ++i) ret[i] = ST(piv_data[i]); return ret;} private: - void _reset() {piv_size = piv_rsize = 0; piv_data = 0;} - size_t asize(size_t s) { + inline void _reset() {piv_size = piv_rsize = 0; piv_data = 0;} + inline size_t asize(size_t s) { if (s == 0) return 0; if (piv_rsize + piv_rsize >= s && piv_rsize < s) return piv_rsize + piv_rsize; @@ -311,7 +304,7 @@ private: for (size_t i = 0; i < s; ++i) elementNew(dst + i, src[i]); } - T * newRaw(size_t s) { + inline T * newRaw(size_t s) { //cout << std::dec << " ![("< inline void PIVector::newT(T * dst, const T * src, size_t s) {memcpy(dst, src, s * sizeof(T));} \ template<> inline void PIVector::deleteT(T * d, size_t sz) {;} \ template<> inline void PIVector::elementNew(T * to, const T & from) {(*to) = from;} \ - template<> inline void PIVector::elementDelete(T & from) {;} + template<> inline void PIVector::elementDelete(T & from) {;} \ + template<> inline PIVector & PIVector::_resizeRaw(size_t new_size) {alloc(new_size); return *this;} \ + template<> inline PIVector & PIVector::clear() {piv_size = 0; return *this;} \ + template<> inline PIVector & PIVector::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} + #else diff --git a/src_main/core/pibytearray.h b/src_main/core/pibytearray.h index d69a26d4..020e315c 100755 --- a/src_main/core/pibytearray.h +++ b/src_main/core/pibytearray.h @@ -33,11 +33,11 @@ __PICONTAINERS_SIMPLE_TYPE__(PIChar) 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;} \ +inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(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;} +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} class PIString; diff --git a/src_main/math/pievaluator.h b/src_main/math/pievaluator.h index b728c9f6..2a70fbba 100755 --- a/src_main/math/pievaluator.h +++ b/src_main/math/pievaluator.h @@ -212,7 +212,7 @@ private: inline complexd residue(const complexd & f, const complexd & s); inline void execFunction(const PIEvaluatorTypes::Instruction & ci); - PIVector elements; + PIDeque elements; PIVector currentVariables, variables, tmpvars, * kvars; PIVector instructions; PIStringList unknownVars;