struct ZZ{ int a,b,c;};template <int sizeType> void setSizeVector(intptr_t vec, int size) { QVector<std::array<char,sizeType>> *z2 = (QVector<std::array<char,sizeType>>*)vec; z2->resize(size);}int main(int argc, char *argv[]){ QVector<ZZ> z1; intptr_t p = (intptr_t)&z1; const int size_t = sizeof(ZZ); setSizeVector<size_t>(p, 11); qDebug()<<z1.size(); return 0;}
struct S1: public Serialize { int a,b,c; S1() { ADDVALUE(a); ADDVALUE(b); ADDVALUE(c); }};struct S2: public Serialize { QVector<S1> ss; S2() { ADDVECTOR(S1, ss); } void resizeVectorsOnLoad(IniFormat *ini) { ss.resize(ini->sizeVectGroup("ss")); }}; // todo removemain() { S2 in, out; in.ss.resize(2);// заполняем in in.save("test2.cfg"); out.load("test2.cfg");// in == out
C++ (Qt)MyStream stream;..stream << theB.a << theB.b << theB.s; // сериализуем объект класса B...stream << theA.b; // сериализуем объект класса A..
C++ (Qt)template <class T>MyStream & operator << ( MyStream & stream, const QVector<T> & vec ){...}
C++ (Qt)#include "B.h"
#include "B1.h"#include "В2.h"#include "B3.h"void serialize(void *p, int size) {...if (type_info(p).name()=="2B1") ((QVector<B1>*)p)->resize(size);else if(type_info(p).name()=="2B2") ((QVector<B2>*)p)->resize(size);else if(type_info(p).name()=="2B3") ((QVector<B3>*)p)->resize(size);... }
virtual void resizeVectors(IniData ini) {b1.resize(ini.sizeVector("b1");b2.resize(ini.sizeVector("b2");b3.resize(ini.sizeVector("b3");}
void serialize(void *p, int size) {...if (type_info(p).name()=="2B1") ((QVector<B1>*)p)->resize(size);else if(type_info(p).name()=="2B2") ((QVector<B2>*)p)->resize(size);else if(type_info(p).name()=="2B3") ((QVector<B3>*)p)->resize(size);... }