www.pudn.com > ElectronicAlbums.rar > PicSerialize.cpp


// PicSerialize.cpp: implementation of the CPicSerialize class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "PicSerialize.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CPicSerialize::CPicSerialize() 
{ 
	m_nPage = 0; 
} 
 
CPicSerialize::~CPicSerialize() 
{ 
	for(int i = 0; i < ebookItems.size(); ++i) 
	{ 
		delete ebookItems[i]; 
	} 
	ebookItems.clear(); 
} 
 
void CPicSerialize::Serialize(CArchive& ar) 
{ 
	if(ar.IsStoring()) 
	{ 
		ar << m_nPage; 
		for(int i = 0; i < m_nPage; ++i) 
		{ 
			ar << ebookItems[i]->nPage; 
			ar << ebookItems[i]->ePageType; 
			ar << ebookItems[i]->picPath1; 
			if(ebookItems[i]->ePageType == 	LEFTTORIGHT || ebookItems[i]->ePageType == UPTODOWN) 
			{ 
				ar << ebookItems[i]->picPath2; 
			} 
		} 
	} 
	else 
	{ 
		ar >> m_nPage; 
		for(int i = 0; i < m_nPage; ++i) 
		{ 
			EBook_Item* pItem = new EBook_Item; 
			ar >> pItem->nPage; 
			ar >> pItem->ePageType; 
			ar >> pItem->picPath1; 
			if(pItem->ePageType == 	LEFTTORIGHT || pItem->ePageType == UPTODOWN) 
			{ 
				ar >> pItem->picPath2; 
			} 
			ebookItems.push_back(pItem); 
		} 
	} 
} 
 
 
void CPicSerialize::InsertNewPage(int nPage, int pageType, CString& path1, CString& path2) 
{ 
	if(nPage <= m_nPage)  //ÐÞ¸Ä 
	{ 
		ebookItems[nPage - 1]->ePageType = pageType; 
		ebookItems[nPage - 1]->picPath1 = path1; 
		ebookItems[nPage - 1]->picPath2 = path2; 
	} 
	else //²åÈëеÄÒ³ 
	{ 
		EBook_Item* pItem = new EBook_Item; 
		pItem->nPage = nPage; 
		pItem->ePageType = pageType; 
		pItem->picPath1 = path1; 
		pItem->picPath2 = path2; 
		 
		ebookItems.push_back(pItem); 
		m_nPage ++; 
	} 
} 
 
void CPicSerialize::GetPageofIndex(int nIndex, int& pageType, CString& path1, CString& path2) 
{ 
	ASSERT(nIndex >0 && nIndex <=  ebookItems.size()); 
	pageType = ebookItems[nIndex - 1]->ePageType; 
	path1 = ebookItems[nIndex - 1]->picPath1; 
	path2 = ebookItems[nIndex - 1]->picPath2; 
} 
 
void CPicSerialize::UpdatePath(CString &begPath) 
{ 
	int index; 
	for(int i = 0; i < m_nPage; ++i) 
	{ 
		if(!ebookItems[i]->picPath1.IsEmpty()) 
		{ 
			CString& refPath = ebookItems[i]->picPath1; 
			index = refPath.Find('\\'); 
			if(index == -1) 
				continue; 
			refPath.Delete(0, index); 
			refPath = begPath + refPath; 
		} 
 
		if(!ebookItems[i]->picPath2.IsEmpty()) 
		{ 
			CString& refPath = ebookItems[i]->picPath2; 
			index = refPath.Find('\\'); 
			if(index == -1) 
				continue; 
			refPath.Delete(0, index); 
			refPath = begPath + refPath; 
		} 
	} 
}