23.06.2014 - PICodeParser, PICodeInfo, PIConnection, new binary "pip_cmg"

This commit is contained in:
peri4
2014-06-23 21:08:27 +04:00
parent 2e5e75c4c4
commit 15a20d40ac
56 changed files with 10315 additions and 760 deletions

View File

@@ -41,8 +41,7 @@ public:
PIVector(const PIVector<T> & 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);
for (size_t i = 0; i < piv_size; ++i)
new(piv_data + i)T(other.piv_data[i]);
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) {
@@ -77,10 +76,11 @@ public:
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)
new(piv_data + i)T(other.piv_data[i]); //piv_data[i] = other.piv_data[i];
elementNew(piv_data + i, other.piv_data[i]); //piv_data[i] = other.piv_data[i];
} else {
printf("JUNK other\n");
}
@@ -174,6 +174,7 @@ public:
size_t size() const {return piv_size;}
ssize_t size_s() const {return piv_size;}
size_t length() const {return piv_size;}
size_t capacity() const {return piv_rsize;}
bool isEmpty() const {return (piv_size == 0);}
T & operator [](size_t index) {return piv_data[index];}
@@ -197,7 +198,7 @@ public:
deleteT(piv_data, piv_size);
//zeroRaw(piv_data, piv_size);
for (size_t i = 0; i < piv_size; ++i)
new(piv_data + i)T(f);
elementNew(piv_data + i, f);
return *this;
}
PIVector<T> & assign(const T & f = T()) {return fill(f);}
@@ -213,7 +214,7 @@ 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) new(piv_data + i)T(f);
for (size_t i = os; i < new_size; ++i) elementNew(piv_data + i, f);
}
return *this;
}
@@ -226,18 +227,27 @@ public:
memmove(&(piv_data[index + 1]), &(piv_data[index]), os * sizeof(T));
}
//zeroRaw(&(piv_data[index]), 1);
new(piv_data + index)T(v);
elementNew(piv_data + index, v);
return *this;
}
PIVector<T> & insert(size_t index, const PIVector<T> & other) {
if (other.isEmpty()) return *this;
ssize_t os = piv_size - index;
alloc(piv_size + other.pid_size, true);
if (os > 0)
memmove(&(piv_data[index + other.piv_size]), &(piv_data[index]), os * sizeof(T));
newT(piv_data + index, other.piv_data, other.piv_size);
return *this;
}
PIVector<T> & remove(size_t index, size_t count = 1) {
if (count == 0) return *this;
if (index + count >= piv_size) {
resize(index);
return *this;
}
size_t os = piv_size - index - count;
T * de = &(piv_data[index]);
deleteT(de, count);
deleteT(&(piv_data[index]), count);
memmove(&(piv_data[index]), &(piv_data[index + count]), os * sizeof(T));
piv_size -= count;
return *this;
@@ -258,14 +268,13 @@ public:
PIVector<T> & 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<T> & removeAll(const T & v) {for (llong i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;}
PIVector<T> & push_back(const T & v) {alloc(piv_size + 1); new(piv_data + piv_size - 1)T(v); return *this;}
PIVector<T> & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;}
PIVector<T> & append(const T & v) {return push_back(v);}
PIVector<T> & operator <<(const T & v) {return push_back(v);}
PIVector<T> & operator <<(const PIVector<T> & t) {
PIVector<T> & operator <<(const PIVector<T> & other) {
size_t ps = piv_size;
alloc(piv_size + t.piv_size);
for (int i = 0; i < t.piv_size; ++i)
new(piv_data + ps + i)T(t.piv_data[i]);
alloc(piv_size + other.piv_size);
newT(piv_data + ps, other.piv_data, other.piv_size);
return *this;
}
@@ -288,6 +297,10 @@ private:
while (s_ >> t) ++t;
return (1 << t);
}
inline void newT(T * dst, const T * src, size_t s) {
for (size_t i = 0; i < s; ++i)
elementNew(dst + i, src[i]);
}
T * newRaw(size_t s) {
//cout << std::dec << " ![("<<this<<")newRaw " << s << " elements ... <\n" << endl;
//uchar * ret = new uchar[s * sizeof(T)];
@@ -300,11 +313,11 @@ private:
if (piv_tdata == 0) piv_tdata = (T*)(malloc(s * sizeof(T)));
else piv_tdata = (T*)(realloc(piv_tdata, s * sizeof(T)));
}*/
void deleteT(T * d, size_t sz) {
inline void deleteT(T * d, size_t sz) {
//cout << " ~[("<<this<<")deleteT " << std::dec << sz << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
if ((uchar*)d != 0) {
for (size_t i = 0; i < sz; ++i)
d[i].~T();
elementDelete(d[i]);
//zeroRaw(d, sz);
}
//cout << " > ok]~" << endl;
@@ -320,6 +333,8 @@ private:
if ((uchar*)d != 0) memset(d, 0, s*sizeof(T));
//cout << " > ok]~" << endl;
}
inline void elementNew(T * to, const T & from) {new(to)T(from);}
inline void elementDelete(T & from) {from.~T();}
void dealloc() {deleteRaw(piv_data);}
inline void alloc(size_t new_size) {
if (new_size <= piv_rsize) {
@@ -348,7 +363,7 @@ private:
T * piv_data;
size_t piv_size, piv_rsize;
};
/*
#define __PIVECTOR_SIMPLE_FUNCTIONS__(T) \
template<> inline PIVector<T>::~PIVector() {dealloc(); _reset();} \
template<> inline PIVector<T> & PIVector<T>::push_back(const T & v) {alloc(piv_size + 1); piv_data[piv_size - 1] = v; return *this;} \
@@ -377,6 +392,7 @@ private:
return *this; \
} \
template<> inline PIVector<T> & PIVector<T>::remove(size_t index, size_t count) { \
if (count == 0) return *this; \
if (index + count >= piv_size) { \
resize(index); \
return *this; \
@@ -399,7 +415,12 @@ __PIVECTOR_SIMPLE_FUNCTIONS__(llong)
__PIVECTOR_SIMPLE_FUNCTIONS__(ullong)
__PIVECTOR_SIMPLE_FUNCTIONS__(float)
__PIVECTOR_SIMPLE_FUNCTIONS__(double)
__PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)
__PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)*/
#define __PIVECTOR_SIMPLE_TYPE__(T) \
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {memcpy(dst, src, s * sizeof(T));} \
template<> inline void PIVector<T>::deleteT(T * d, size_t sz) {;} \
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
template<> inline void PIVector<T>::elementDelete(T & from) {;}
#else
@@ -484,7 +505,7 @@ public:
#endif
};
#define __PIVECTOR_SIMPLE_FUNCTIONS__(T)
#define __PIVECTOR_SIMPLE_TYPE__(T)
#endif