Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / MFC

The Ultimate Toolbox Home Page

Rate me:
Please Sign up or sign in to vote.
4.97/5 (141 votes)
25 Aug 2007CPOL13 min read 3.2M   91.4K   476  
The Ultimate Toolbox is now Open Source
// ==========================================================================
// 							Class Specification : COXSerializer
// ==========================================================================

// Header file : OXSRLZR.H

// This software along with its related components, documentation and files ("The Libraries")
// is � 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is
// governed by a software license agreement ("Agreement").  Copies of the Agreement are
// available at The Code Project (www.codeproject.com), as part of the package you downloaded
// to obtain this file, or directly from our office.  For a copy of the license governing
// this software, you may contact us at legalaffairs@codeproject.com, or by calling 416-849-8900.                      
                         
// //////////////////////////////////////////////////////////////////////////

// Properties:
//	NO	Abstract class (does not have any objects)
//	NO	Is derived from CWnd
//	NO  Two stage creation (constructor & Initialize())
//	NO 	Has a message map
//	NO  Needs a resource (template)

//	NO	Persistent objects (saveable on disk)      
//	YES	Uses exceptions

// //////////////////////////////////////////////////////////////////////////

// Description :         
//	COXSerializer class
//    BOOL Initialize(LPCTSTR pFileName, CObject* pObject);
//    ---------------------------------------------------------
//    Set the filename that has to be serialized and its relative object.
//    return FALSE only if an invalid string pointer or a CObject derived
//    object pointer or a not serializable object is passed .
//    Initialize can be called anytime.
//
//    BOOL Load(BOOL DisplayException = TRUE);
//    ----------------------------------------
//    Loads the object from the archive. The object and the file name
//    are to be set by the Initialize function.
//    DisplayException=FALSE: No messages by messagebox are displayed  
//    return FALSE if this object was not initialized or a Exception was
//    encounterd. (see FileException,ArchiveException and MemoryException
//    public data member to obtains more informations)
//
//    BOOL Save(BOOL DisplayException = TRUE);
//    ----------------------------------------------------  
//    Store the object to the archive. The object and the file name
//    are to be set by the Initialize function.
//    DisplayException=FALSE: No messages by messagebox are displayed  
//    return FALSE if this object was not initialized or a Exception was
//    encounterd. (see FileException,ArchiveException and MemoryException
//    public data member to obtains more informations)

// Remark:
//


// Prerequisites (necessary conditions):
//		

/////////////////////////////////////////////////////////////////////////////


#ifndef __OXSRLZR_H__
#define __OXSRLZR_H__


#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "OXDllExt.h"


class OX_CLASS_DECL COXSerializer : public CObject
{
// Data Members
public:
    CFileException    m_fileException;		// exceptions as data member
	CArchiveException m_archiveException;	// if you chose not to display exceptions
    BOOL              m_bMemoryException;	// then you can check them via these members

protected:
    BOOL				m_bInitialized;		// if initialized or not
    CString				m_sFileName;		// the filename of the file to serialize from or to
    CObject*			m_pObject;			// the object to serialize

private:

// Member Functions
public:
    COXSerializer();
	// --- In: none
	// --- Out: none
	// --- Returns: none
	// --- Effect: constructs the object

	virtual ~COXSerializer();
	// --- In: none
	// --- Out: none
	// --- Returns: none
	// --- Effect: destructs the object

    BOOL Initialize(CString sFileName, CObject* pObject);
	// --- In: sFileName: the filename of the file you want to serialize to or from
	//		   pObject: the parent object you want to serialize
	// --- Out: none
	// --- Returns: if the initialization was successful
	// --- Effect: initialize and checks if the object is serializable

    BOOL Load(BOOL bDisplayException = TRUE);
	// --- In: bDisplayException: if the exception is reported
	// --- Out: none
	// --- Returns: if successful or not
	// --- Effect: loads the object (see initialize) from file 

    BOOL Save(BOOL bDisplayException = TRUE);
	// --- In: bDisplayException: if the exception is reported
	// --- Out: none
	// --- Returns: if successful or not
	// --- Effect: saves the object (see initialize) to file 

protected:

private:
};

#endif // __SERIALIZE_ENH_H__

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
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions