darksaga
28th August 2007, 01:05
hi all,
I have a little question about serialization, shown by the following example:
class MyClass
{
public:
MyClass(){}
~MyClass(){}
void save(QDataStream &out){
out << (qint32)_id;
out << (qint32)_sizeX;
out << (qint32)_sizeY;
out << (qint32)_sizeZ;
}
void load_Version1(QDataStream &in){
qint32 id, sizeX, sizeY, sizeZ;
in >> id;
in >> sizeX;
in >> sizeY;
in >> sizeZ;
_id = id;
_sizeX = sizeX;
_sizeY = sizeY;
_sizeZ = sizeZ;
}
void load_Version2(QDataStream &in){
in >> _id;
in >> _sizeX;
in >> _sizeY;
in >> _sizeZ;
}
private:
int _id;
int _sizeX;
int _sizeY;
int _sizeZ;
};
using load_Version1 to load my data should be safe in terms of data integrity, afaik
doing things like in load_Version1 is a little longish, imo, especially when the list of various types of private members grows
so, would it be ok & safe to use load_Version2 to shorten things???
personally I don't think it is safe...
if load_Version2 isn't ok, as i assume, is there another possibility to shorten the amount of code?
would something like
in >> (qint32)_id; work?
I hope you get, what I talk about :rolleyes:
greetz
darksaga
I have a little question about serialization, shown by the following example:
class MyClass
{
public:
MyClass(){}
~MyClass(){}
void save(QDataStream &out){
out << (qint32)_id;
out << (qint32)_sizeX;
out << (qint32)_sizeY;
out << (qint32)_sizeZ;
}
void load_Version1(QDataStream &in){
qint32 id, sizeX, sizeY, sizeZ;
in >> id;
in >> sizeX;
in >> sizeY;
in >> sizeZ;
_id = id;
_sizeX = sizeX;
_sizeY = sizeY;
_sizeZ = sizeZ;
}
void load_Version2(QDataStream &in){
in >> _id;
in >> _sizeX;
in >> _sizeY;
in >> _sizeZ;
}
private:
int _id;
int _sizeX;
int _sizeY;
int _sizeZ;
};
using load_Version1 to load my data should be safe in terms of data integrity, afaik
doing things like in load_Version1 is a little longish, imo, especially when the list of various types of private members grows
so, would it be ok & safe to use load_Version2 to shorten things???
personally I don't think it is safe...
if load_Version2 isn't ok, as i assume, is there another possibility to shorten the amount of code?
would something like
in >> (qint32)_id; work?
I hope you get, what I talk about :rolleyes:
greetz
darksaga