I have 3 classes, CSite, CSiteDB and CMainFrame.
CMainFrame Class adds pages to the property page and also submits the data using this function:
void CMainFrame::NewSiteDialog()
{
CManagerDlgSheet dlgManager(_T("SiteManager"
,this);
CManagerGeneralPage pageGeneral;
CManagerSettingsPage pageSettings;
CManagerLogPage pageLogs;
CManagerSchedulingPage pageSchedule;
dlgManager.AddPage(&pageGeneral);
dlgManager.AddPage(&pageSettings);
dlgManager.AddPage(&pageLogs);
dlgManager.AddPage(&pageSchedule);
if ( dlgManager.DoModal() == IDOK )
{
CSite NewSite(pageGeneral.m_strSiteName);
NewSite.m_strHostAddress = pageGeneral.m_strAddress;
NewSite.m_strComments = pageGeneral.m_strComments;
NewSite.m_strPassword = pageGeneral.m_strPassword;
NewSite.m_strUserName = pageGeneral.m_strUsername;
NewSite.m_nPort = pageGeneral.m_nPort;
NewSite.m_strErrorFile = pageLogs.m_strErrorFile;
m_dbMainDatabase.InsertSite(NewSite);
}
}
The CSite Class has all the variables stored in it and CSiteDB has the function insertsite which adds the site to the COBArray. Here is the function of CSiteDB class:
void CSiteDB::InsertSite(CSite NewSite)
{
// Gets a pointer to the object that was passed.
CSite* pSite = new CSite(NewSite);
// Simplified insertion sort algorithm to keep the array sorted.
if (m_nArraySize == 0)
{
AfxMessageBox("array size is 0 at this time"
;
m_SiteArray.Add(pSite);
}
else
{
int nCurrentIndex = 0;
// Compares the names of existing objects with the ones to be inserted.
while (NewSite.m_strHostName > GetSitePointer(nCurrentIndex)->m_strHostName)
{
nCurrentIndex += 1;
// Ensures that the array does not go out of bounds
if (nCurrentIndex == m_nArraySize)
break;
}
// Inserts the item.
m_SiteArray.InsertAt(nCurrentIndex, pSite);
}
// Increment the element count.
m_nArraySize += 1;
}
I wish to serialize all the data that is being passed. I have declared_serial both CSite as well as CSiteDB.
In CSiteDB, I have this function:
void CSiteDB::Serialize(CArchive& ar)
{
//Call the base class function
CObject::Serialize(ar);
//Storing the information into the archive
if(ar.IsStoring()){
//add the insert site thing here
}else{
//add the array thing here.
}
}
However, I am new to C++ and don't know how to use this function to serialize the data passed to the array.
Thanks
Amardeep
CMainFrame Class adds pages to the property page and also submits the data using this function:
void CMainFrame::NewSiteDialog()
{
CManagerDlgSheet dlgManager(_T("SiteManager"
CManagerGeneralPage pageGeneral;
CManagerSettingsPage pageSettings;
CManagerLogPage pageLogs;
CManagerSchedulingPage pageSchedule;
dlgManager.AddPage(&pageGeneral);
dlgManager.AddPage(&pageSettings);
dlgManager.AddPage(&pageLogs);
dlgManager.AddPage(&pageSchedule);
if ( dlgManager.DoModal() == IDOK )
{
CSite NewSite(pageGeneral.m_strSiteName);
NewSite.m_strHostAddress = pageGeneral.m_strAddress;
NewSite.m_strComments = pageGeneral.m_strComments;
NewSite.m_strPassword = pageGeneral.m_strPassword;
NewSite.m_strUserName = pageGeneral.m_strUsername;
NewSite.m_nPort = pageGeneral.m_nPort;
NewSite.m_strErrorFile = pageLogs.m_strErrorFile;
m_dbMainDatabase.InsertSite(NewSite);
}
}
The CSite Class has all the variables stored in it and CSiteDB has the function insertsite which adds the site to the COBArray. Here is the function of CSiteDB class:
void CSiteDB::InsertSite(CSite NewSite)
{
// Gets a pointer to the object that was passed.
CSite* pSite = new CSite(NewSite);
// Simplified insertion sort algorithm to keep the array sorted.
if (m_nArraySize == 0)
{
AfxMessageBox("array size is 0 at this time"
m_SiteArray.Add(pSite);
}
else
{
int nCurrentIndex = 0;
// Compares the names of existing objects with the ones to be inserted.
while (NewSite.m_strHostName > GetSitePointer(nCurrentIndex)->m_strHostName)
{
nCurrentIndex += 1;
// Ensures that the array does not go out of bounds
if (nCurrentIndex == m_nArraySize)
break;
}
// Inserts the item.
m_SiteArray.InsertAt(nCurrentIndex, pSite);
}
// Increment the element count.
m_nArraySize += 1;
}
I wish to serialize all the data that is being passed. I have declared_serial both CSite as well as CSiteDB.
In CSiteDB, I have this function:
void CSiteDB::Serialize(CArchive& ar)
{
//Call the base class function
CObject::Serialize(ar);
//Storing the information into the archive
if(ar.IsStoring()){
//add the insert site thing here
}else{
//add the array thing here.
}
}
However, I am new to C++ and don't know how to use this function to serialize the data passed to the array.
Thanks
Amardeep