Request final critique
Well thanks to the help of this group, I feel like I have a version
control and serialize paradigm that is on the way to being something
I can be comfortable with.
I have analyzed the file dump enough to know what is being written
so if I had to I could read it back in if one of MFC's Classes like
CMapStringToString's serialize ever broke. But stepping thru all of the
code that CmStS and CArchive offers shows me it is far surpassed to
anything I could come up with at this point. Experimenting shows it
handles end of file resulting from corrupt unexpected input data etc etc.
In addition I have added my own File ID value at the beginning
of the file just to check right off the bat if the file type is one
previously written.
However if anyone has the time, I would appreciate a final
critique to shoot down any areas where I may be in errant structure,
or destructive coding, since I consider the version and serialization to be
the foundation of an App, and I don't want it foo barred coming out of
the gate.
So blast away at my ignorance, I will learn from it.
Code below.
// in MyDocClass header file
.............
protected:
CMapStringToString ExpMap1;
struct VerStruct
{
CString Ver, CpyRt, Corp;
};
VerStruct VerData;
DWORD FileID;
.............
// in MyDocClass constructor
CFileHandlingDoc::CFileHandlingDoc( )
{
// Fetch stuff from included AppVer.h file that also
// feeds all App requests for version data, that idea
// courtesy of David Webber
VerData.Ver.Format( _T("Version %d.%d.%d.%d"),
VERMAJ, VERMIN, VERFIX, BUILDNUMBER );
VerData.CpyRt = _T(CPY_RIGHT_YR);
VerData.Corp = _T(CORP_NAME);
FileID = 0x1234ABCD;
}
// and in MyDocClass Serialize func
void CFileHandlingDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring( ) )
{
ar << FileID;
ar << VerData.Ver << VerData.CpyRt << VerData.Corp;
ar.SerializeClass(RUNTIME_CLASS(CMapStringToString));
ExpMap1.Serialize(ar);
}
else
{
ar >> FileID;
if (FileID != 0x1234ABCD)
{
CWnd* pWnd = AfxGetMainWnd( )->GetActiveWindow( );
pWnd->MessageBox( _T("Incorrect File format, operation aborted"),
_T("! ALERT !"), MB_OK | MB_ICONINFORMATION );
return;
}
ar >> VerData.Ver >> VerData.CpyRt >> VerData.Corp;
if (VerData.Ver.Right(7) == _T("1.0.0.0"))
{
ar.SerializeClass(RUNTIME_CLASS(CMapStringToString));
ExpMap1.Serialize(ar);
}
if (VerData.Ver.Right(7) == _T("1.0.0.1"))
{
// 1.0.0.1 stuff
}
}
}
---for any who may care or want to see the written file dump it is
below,
The 1st DWORD is my FileID of 1234ABCD (dump little endian)
The 1st line 5th byte (4th byte 0 based) is 0Fh (15d) is the length
of 1st CString, followed by the 15d bytes of string contents.
The 2nd line 5th byte is 12h (18d) is the length of the 2nd CString,
followed by the 18d bytes of string contents.
The 3rd line, 8th byte is 03 is the length of the 3rd
CString, followed by the 3 bytes ofstring contents. then the CmStS
stuff.
Which first starts with an FFFF (new class tag)i.e. different
than the MyDocClass so far(?). Then the 0000 version schema of CmStS.
Then 0012h length of the CmStS's class name, followed by the 18d
bytes if the class name, then what appears to be a count of the
total CmStS keys in the file, a value of 03. Then the value of 01
which appears to denote the size or length of the 1st key value to
follow, then the first key of "a" . Then the value of 03 again which
appears to denote the length of the assoc value which follows and
is "WWW". Then a value of 01 for the length of 2nd key followed by
the key value of "b" . Then a value of 04 for the length of the assoc
value of "ZZZZ", then the value of 01 for the length of the 3rd key
followed by the key value of "c". Then the value of 4 for the length
of the following assoc value which is "DDDD".
CD AB 34 12 0F 56 65 72 73 69 6F 6E 20 31 2E 30 ??4Version 1.0
2E 30 2E 30 12 43 6F 70 79 72 69 67 68 74 20 28 .0.0Copyright (
43 29 20 32 30 31 30 03 44 54 4D FF FF 00 00 12 C) 2010RBC??
00 43 4D 61 70 53 74 72 69 6E 67 54 6F 53 74 72 CMapStringToStr
69 6E 67 03 00 01 61 03 57 57 57 01 62 04 5A 5A ingaWWWbZZ
5A 5A 01 63 04 44 44 44 44 ZZcDDDD
0 1 2 3 4 5 6 7 8 9 A B C D E F zero base hex ct
1 2 3 4 5 6 7 8 9 A B C D E F 10 one base hex ct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 one base dec ct