git-svn-id: svn://db.shs.com.ru/pip@803 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -35,33 +35,28 @@ template <typename T>
|
||||
class PIVector {
|
||||
public:
|
||||
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);
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
}
|
||||
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());
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
alloc(size);
|
||||
newT(piv_data, data, piv_size);
|
||||
//printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data);
|
||||
}
|
||||
inline 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());
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
alloc(other.piv_size);
|
||||
newT(piv_data, other.piv_data, piv_size);
|
||||
//printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data);
|
||||
}
|
||||
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());
|
||||
PIINTROSPECTION_CONTAINER_NEW(T)
|
||||
resize(piv_size, f);
|
||||
//printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data);
|
||||
}
|
||||
inline ~PIVector() {
|
||||
//printf("delete vector %p (%s) (s=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(piv_size), piv_data);
|
||||
inline virtual ~PIVector() {
|
||||
PIINTROSPECTION_CONTAINER_DELETE(T)
|
||||
PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize)*sizeof(T))
|
||||
deleteT(piv_data, piv_size);
|
||||
dealloc();
|
||||
//deleteRaw(piv_tdata);
|
||||
_reset();
|
||||
//printf("}~\n");
|
||||
}
|
||||
|
||||
inline PIVector<T> & operator =(const PIVector<T> & other) {
|
||||
@@ -182,9 +177,8 @@ public:
|
||||
|
||||
inline PIVector<T> & clear() {resize(0); return *this;}
|
||||
inline PIVector<T> & 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);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, piv_size*sizeof(T))
|
||||
for (size_t i = 0; i < piv_size; ++i)
|
||||
elementNew(piv_data + i, f);
|
||||
return *this;
|
||||
@@ -201,8 +195,7 @@ public:
|
||||
if (new_size > piv_size) {
|
||||
size_t os = piv_size;
|
||||
alloc(new_size);
|
||||
//if (sizeof(T) == 1) memset(&(piv_data[os]), f, ds);
|
||||
//zeroRaw(&(piv_data[os]), new_size - os);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, (new_size-os)*sizeof(T))
|
||||
for (size_t i = os; i < new_size; ++i)
|
||||
elementNew(piv_data + i, f);
|
||||
}
|
||||
@@ -231,7 +224,7 @@ public:
|
||||
size_t os = piv_size - index - 1;
|
||||
memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T));
|
||||
}
|
||||
//zeroRaw(&(piv_data[index]), 1);
|
||||
PIINTROSPECTION_CONTAINER_USED(T, sizeof(T))
|
||||
elementNew(piv_data + index, v);
|
||||
return *this;
|
||||
}
|
||||
@@ -273,7 +266,7 @@ public:
|
||||
inline 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;}
|
||||
inline PIVector<T> & 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<T> & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;}
|
||||
inline PIVector<T> & push_back(const T & v) {alloc(piv_size + 1); PIINTROSPECTION_CONTAINER_USED(T, sizeof(T)); elementNew(piv_data + piv_size - 1, v); return *this;}
|
||||
inline PIVector<T> & append(const T & v) {return push_back(v);}
|
||||
inline PIVector<T> & append(const PIVector<T> & other) {
|
||||
size_t ps = piv_size;
|
||||
@@ -312,15 +305,12 @@ private:
|
||||
return (1 << t);
|
||||
}
|
||||
inline void newT(T * dst, const T * src, size_t s) {
|
||||
PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T))
|
||||
for (size_t i = 0; i < s; ++i)
|
||||
elementNew(dst + i, src[i]);
|
||||
}
|
||||
inline T * newRaw(size_t s) {
|
||||
//cout << std::dec << " ![("<<this<<")newRaw " << s << " elements ... <\n" << endl;
|
||||
//uchar * ret = new uchar[s * sizeof(T)];
|
||||
uchar * ret = (uchar*)(malloc(s * sizeof(T)));//new uchar[];
|
||||
//zeroRaw((T*)ret, s);
|
||||
//cout << std::hex << " > (new 0x" << (llong)ret << ") ok]!" << endl;
|
||||
return (T*)ret;
|
||||
}
|
||||
/*void reallocRawTemp(size_t s) {
|
||||
@@ -328,24 +318,18 @@ private:
|
||||
else piv_tdata = (T*)(realloc(piv_tdata, s * sizeof(T)));
|
||||
}*/
|
||||
inline void deleteT(T * d, size_t sz) {
|
||||
//cout << " ~[("<<this<<")deleteT " << std::dec << sz << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
|
||||
PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T))
|
||||
if ((uchar*)d != 0) {
|
||||
for (size_t i = 0; i < sz; ++i)
|
||||
elementDelete(d[i]);
|
||||
//zeroRaw(d, sz);
|
||||
}
|
||||
//cout << " > ok]~" << endl;
|
||||
}
|
||||
inline void deleteRaw(T *& d) {
|
||||
//cout << " ~[("<<this<<")deleteRaw " << std::dec << piv_rsize << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
|
||||
if ((uchar*)d != 0) free((uchar*)d);
|
||||
d = 0;
|
||||
//cout << " > ok]~" << endl;
|
||||
}
|
||||
inline void zeroRaw(T * d, size_t s) {
|
||||
//cout << " ~[("<<this<<")zeroRaw " << std::dec << s << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
|
||||
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();}
|
||||
@@ -355,19 +339,15 @@ private:
|
||||
piv_size = new_size;
|
||||
return;
|
||||
}
|
||||
//int os = piv_size;
|
||||
piv_size = new_size;
|
||||
size_t as = asize(new_size);
|
||||
if (as == piv_rsize) return;
|
||||
//if(as > 1000) piCout << "too much vector size" << new_size << as;
|
||||
PIINTROSPECTION_CONTAINER_ALLOC(T, (as-piv_rsize)*sizeof(T))
|
||||
|
||||
//cout << std::hex << " ![("<<this<<")realloc " << piv_data << " data ... <\n" << endl;
|
||||
T * p_d = (T*)(realloc((void*)(piv_data), as*sizeof(T)));
|
||||
assert(p_d);
|
||||
piv_data = p_d;
|
||||
//zeroRaw(&(piv_data[os]), as - os);
|
||||
piv_rsize = as;
|
||||
//cout << std::hex << " > (new 0x" << (llong)piv_data << ") ok]!" << endl;
|
||||
/*piv_rsize = as;
|
||||
T * pd = newRaw(piv_rsize);
|
||||
if (os > 0 && piv_data != 0) {
|
||||
@@ -434,13 +414,14 @@ __PIVECTOR_SIMPLE_FUNCTIONS__(float)
|
||||
__PIVECTOR_SIMPLE_FUNCTIONS__(double)
|
||||
__PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)*/
|
||||
#define __PIVECTOR_SIMPLE_TYPE__(T) \
|
||||
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIVector<T>::deleteT(T * d, size_t sz) {;} \
|
||||
template<> inline void PIVector<T>::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T)); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \
|
||||
template<> inline void PIVector<T>::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \
|
||||
template<> inline void PIVector<T>::elementNew(T * to, const T & from) {(*to) = from;} \
|
||||
template<> inline void PIVector<T>::elementDelete(T & from) {;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::_resizeRaw(size_t new_size) {alloc(new_size); return *this;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::clear() {piv_size = 0; return *this;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);}
|
||||
template<> inline PIVector<T> & PIVector<T>::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size*sizeof(T)); piv_size = 0; return *this;} \
|
||||
template<> inline PIVector<T> & PIVector<T>::assign(size_t new_size, const T & f) {\
|
||||
_resizeRaw(new_size); return fill(f);}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user