dagan
asked on
serialize a CUIntArray?
Hi all,
I am trying to serialize a CUIntArray, but as far as I can see, CUIntArray.Serialize() is not implemented and so CObject.Serialize() is called.
I also tried to override :
CArchive& operator<<( CArchive& ar, const CUIntArray arrUint );
CArchive& operator>>( CArchive& ar, CUIntArray arrUint );
but then I get a
"binary '<<' : no operator defined which takes a left-hand operand of type 'class CArchive' (or there is no acceptable conversion)" errors on compile.
so,
1. Is there a proper way to serialize a non-template array?
2. Is there a reason why CUIntArray.Serialize is not implemented?
3. Is my "operator<<(...)" syntax incorrect?
4. Any other ideas?
thanxs in advance,
Dagan
I am trying to serialize a CUIntArray, but as far as I can see, CUIntArray.Serialize() is not implemented and so CObject.Serialize() is called.
I also tried to override :
CArchive& operator<<( CArchive& ar, const CUIntArray arrUint );
CArchive& operator>>( CArchive& ar, CUIntArray arrUint );
but then I get a
"binary '<<' : no operator defined which takes a left-hand operand of type 'class CArchive' (or there is no acceptable conversion)" errors on compile.
so,
1. Is there a proper way to serialize a non-template array?
2. Is there a reason why CUIntArray.Serialize is not implemented?
3. Is my "operator<<(...)" syntax incorrect?
4. Any other ideas?
thanxs in advance,
Dagan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK.
void CYurUIntArray::Serialize(C Archive& ar){
ASSERT_VALID(this);
CObject::Serialize(ar);
if (ar.IsStoring()){
ar.WriteCount(m_nSize);
for (int i = 0; i < m_nSize; i++)
ar << m_pData[i];
}else{
DWORD nOldSize = ar.ReadCount();
SetSize(nOldSize);
for (int i = 0; i < m_nSize; i++)
ar >> m_pData[i];
}
}
That can be sufficient for You.
void CYurUIntArray::Serialize(C
ASSERT_VALID(this);
CObject::Serialize(ar);
if (ar.IsStoring()){
ar.WriteCount(m_nSize);
for (int i = 0; i < m_nSize; i++)
ar << m_pData[i];
}else{
DWORD nOldSize = ar.ReadCount();
SetSize(nOldSize);
for (int i = 0; i < m_nSize; i++)
ar >> m_pData[i];
}
}
That can be sufficient for You.
ASKER
Eventually I believe that this is what I'll do... meanwhile you'll excuse me for not giving you the points since I wanna give others the chance to answer THE OTHER QUESTIONS.
I promise that if I won't get better answers, you'll be rewarded for yours.
It's just that it seems a little weird that there's no pretty solution built in.