Click here to Skip to main content
15,880,405 members
Articles / Desktop Programming / MFC

MFC - Multiple inheritance and serialization

Rate me:
Please Sign up or sign in to vote.
4.80/5 (34 votes)
29 Oct 2003CPOL14 min read 163.3K   4.2K   73  
Describing a solution to allow namespaces, multiple inheritance, and serialization in an MFC program
#include "StdAfx.h"
#include "appdoc.h"

namespace GE_{ namespace App{

	IMPLEMENT_DYNCREATE(CAppDoc, CDocument)

	CAppDoc::CAppDoc(void)
	{
	}

	CAppDoc::~CAppDoc(void)
	{
	}

	BOOL CAppDoc::OnNewDocument()
	{
		if(!CDocument::OnNewDocument()) return false;
		_pRoot = new Data::CAssembled;  //will relese the old root
		_pRoot->_pDocument = this;

		_list.push_back(_pRoot);	//can be drawn
		
		return !!_pRoot;
	}
	
	void CAppDoc::Serialize(CArchive& ar)
	{
		//instantiate the archive associated maps
		Safe::SArchiveMaps maps(ar);

		//save and load the pointers
		if (ar.IsStoring())
		{
			ar << _pRoot;
			ar << _list;
		}
		else
		{
			ar >> _pRoot;
			ar >> _list;
		}
	}

	CRect CAppDoc::GetDocBounds() const
	{
		TList::const_iterator i;
		CRect rcDoc(0,0,1,1);
		for(i=_list.begin(); i!=_list.end(); i++)
		{
			if(! *i) continue;
			rcDoc |= (**i).GetBounds();
		}
		return rcDoc;
	}

}}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Italy Italy
Born and living in Milan (Italy), I'm an engineer in electronics actually working in the ICT department of an important oil/gas & energy company as responsible for planning and engineering of ICT infrastructures.
Interested in programming since the '70s, today I still define architectures for the ICT, deploying dedicated specific client application for engineering purposes, working with C++, MFC, STL, and recently also C# and D.

Comments and Discussions