git-svn-id: svn://db.shs.com.ru/pip@512 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
10
main.cpp
10
main.cpp
@@ -3,8 +3,14 @@
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PIConnection conn;
|
PIVector2D<PIVariant> v(2, 2, PIVector<PIVariant>() << PIVariant(1) << PIVariant(2) << PIVariant(3) << PIVariant(4));
|
||||||
conn.configureFromConfig("0.conf");
|
piCout << v;
|
||||||
|
PIByteArray ba;
|
||||||
|
ba << v;
|
||||||
|
piCout << ba.size();
|
||||||
|
PIVector2D<PIVariant> v2;
|
||||||
|
ba >> v2;
|
||||||
|
piCout << v2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ public:
|
|||||||
}
|
}
|
||||||
PIVector<T> toPlainVector() const {return mat;}
|
PIVector<T> toPlainVector() const {return mat;}
|
||||||
|
|
||||||
|
inline PIVector2D<T> & _resizeRaw(size_t r, size_t c) {
|
||||||
|
piCout << "Error, \"resizeRaw()\" only allowed for simple type declared with __PIVECTOR_SIMPLE_TYPE__ macro!";
|
||||||
|
assert(0);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void copyRow(size_t start, const T * data, size_t size) {
|
inline void copyRow(size_t start, const T * data, size_t size) {
|
||||||
for (size_t i = 0; i < size; i++)
|
for (size_t i = 0; i < size; i++)
|
||||||
@@ -156,4 +162,23 @@ inline PICout operator <<(PICout s, const PIVector2D<T> & v) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define __PIVECTOR2D_SIMPLE_TYPE__(T) \
|
||||||
|
template<> inline void PIVector2D<T>::copyRow(size_t start, const T * data, size_t size) {memcpy(mat.data(start), data, size * sizeof(T));} \
|
||||||
|
template<> inline PIVector2D<T> & PIVector2D<T>::_resizeRaw(size_t r, size_t c) {rows_ = r; cols_ = c; mat._resizeRaw(r*c); return *this;}
|
||||||
|
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(bool)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(char)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(uchar)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(short)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(ushort)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(int)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(uint)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(long)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(ulong)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(llong)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(ullong)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(float)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(double)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(ldouble)
|
||||||
|
|
||||||
#endif // PIVECTOR2D_H
|
#endif // PIVECTOR2D_H
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "pichar.h"
|
#include "pichar.h"
|
||||||
#include "pibitarray.h"
|
#include "pibitarray.h"
|
||||||
#include "pimap.h"
|
#include "pimap.h"
|
||||||
|
#include "pivector2d.h"
|
||||||
|
|
||||||
__PICONTAINERS_SIMPLE_TYPE__(PIChar)
|
__PICONTAINERS_SIMPLE_TYPE__(PIChar)
|
||||||
|
|
||||||
@@ -37,7 +38,11 @@ inline PIByteArray & operator >>(PIByteArray & s, PIVector<T> & v) {assert(s.siz
|
|||||||
template<> \
|
template<> \
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & 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;} \
|
inline PIByteArray & operator <<(PIByteArray & s, const PIDeque<T> & 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<> \
|
template<> \
|
||||||
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & 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;}
|
inline PIByteArray & operator >>(PIByteArray & s, PIDeque<T> & 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 PIVector2D<T> & v) {s << int(v.rows()) << int(v.cols()); 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, PIVector2D<T> & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;}
|
||||||
|
|
||||||
|
|
||||||
class PIString;
|
class PIString;
|
||||||
@@ -244,6 +249,8 @@ inline PIByteArray & operator <<(PIByteArray & s, const PIMap<Key, T> & v) {
|
|||||||
s << v.pim_content;
|
s << v.pim_content;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D<T> & v) {s << int(v.rows()) << int(v.cols()) << v.toPlainVector(); return s;}
|
||||||
|
|
||||||
|
|
||||||
//! \relatesalso PIByteArray \brief Restore operator
|
//! \relatesalso PIByteArray \brief Restore operator
|
||||||
@@ -263,6 +270,9 @@ inline PIByteArray & operator >>(PIByteArray & s, PIMap<Key, T> & v) {
|
|||||||
s >> v.pim_content;
|
s >> v.pim_content;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline PIByteArray & operator >>(PIByteArray & s, PIVector2D<T> & v) {assert(s.size_s() >= 8); int r,c; PIVector<T> tmp; s >> r >> c >> tmp; v = PIVector2D<T>(r, c, tmp); return s;}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline PIByteArray & operator <<(PIByteArray & s, const T & ) {piCout << "[PIByteArray] Warning: using undeclared operator <<!"; return s;}
|
inline PIByteArray & operator <<(PIByteArray & s, const T & ) {piCout << "[PIByteArray] Warning: using undeclared operator <<!"; return s;}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <complex>
|
#include <complex>
|
||||||
#include "pimathbase.h"
|
#include "pimathbase.h"
|
||||||
#include "pibytearray.h"
|
#include "pibytearray.h"
|
||||||
|
#include "pivector2d.h"
|
||||||
|
|
||||||
#define PIP_MATH_COMPLEX
|
#define PIP_MATH_COMPLEX
|
||||||
|
|
||||||
@@ -49,6 +50,10 @@ __PICONTAINERS_SIMPLE_TYPE__(complexi)
|
|||||||
__PICONTAINERS_SIMPLE_TYPE__(complexf)
|
__PICONTAINERS_SIMPLE_TYPE__(complexf)
|
||||||
__PICONTAINERS_SIMPLE_TYPE__(complexd)
|
__PICONTAINERS_SIMPLE_TYPE__(complexd)
|
||||||
__PICONTAINERS_SIMPLE_TYPE__(complexld)
|
__PICONTAINERS_SIMPLE_TYPE__(complexld)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(complexi)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(complexf)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(complexd)
|
||||||
|
__PIVECTOR2D_SIMPLE_TYPE__(complexld)
|
||||||
__PIBYTEARRAY_SIMPLE_TYPE__(complexi)
|
__PIBYTEARRAY_SIMPLE_TYPE__(complexi)
|
||||||
__PIBYTEARRAY_SIMPLE_TYPE__(complexf)
|
__PIBYTEARRAY_SIMPLE_TYPE__(complexf)
|
||||||
__PIBYTEARRAY_SIMPLE_TYPE__(complexd)
|
__PIBYTEARRAY_SIMPLE_TYPE__(complexd)
|
||||||
|
|||||||
Reference in New Issue
Block a user