Share via


CArchive Class

Allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted.

class CArchive

Members

Public Constructors

Name

Description

CArchive::CArchive

Creates a CArchive object.

Public Methods

Name

Description

CArchive::Abort

Closes an archive without throwing an exception.

CArchive::Close

Flushes unwritten data and disconnects from the CFile.

CArchive::Flush

Flushes unwritten data from the archive buffer.

CArchive::GetFile

Gets the CFile object pointer for this archive.

CArchive::GetObjectSchema

Called from the Serialize function to determine the version of the object that is being deserialized.

CArchive::IsBufferEmpty

Determines whether the buffer has been emptied during a Windows Sockets receive process.

CArchive::IsLoading

Determines whether the archive is loading.

CArchive::IsStoring

Determines whether the archive is storing.

CArchive::MapObject

Places objects in the map that are not serialized to the file, but that are available for subobjects to reference.

CArchive::Read

Reads raw bytes.

CArchive::ReadClass

Reads a class reference previously stored with WriteClass.

CArchive::ReadObject

Calls an object's Serialize function for loading.

CArchive::ReadString

Reads a single line of text.

CArchive::SerializeClass

Reads or writes the class reference to the CArchive object depending on the direction of the CArchive.

CArchive::SetLoadParams

Sets the size to which the load array grows. Must be called before any object is loaded or before MapObject or ReadObject is called.

CArchive::SetObjectSchema

Sets the object schema stored in the archive object.

CArchive::SetStoreParams

Sets the hash table size and the block size of the map used to identify unique objects during the serialization process.

CArchive::Write

Writes raw bytes.

CArchive::WriteClass

Writes a reference to the CRuntimeClass to the CArchive.

CArchive::WriteObject

Calls an object's Serialize function for storing.

CArchive::WriteString

Writes a single line of text.

Public Operators

Name

Description

CArchive::operator <<

Stores objects and primitive types to the archive.

CArchive::operator >>

Loads objects and primitive types from the archive.

Public Data Members

Name

Description

CArchive::m_pDocument

Remarks

CArchive does not have a base class.

Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called "serialization."

You can think of an archive object as a kind of binary stream. Like an input/output stream, an archive is associated with a file and permits the buffered writing and reading of data to and from storage. An input/output stream processes sequences of ASCII characters, but an archive processes binary object data in an efficient, nonredundant format.

You must create a CFile object before you can create a CArchive object. In addition, you must ensure that the archive's load/store status is compatible with the file's open mode. You are limited to one active archive per file.

When you construct a CArchive object, you attach it to an object of class CFile (or a derived class) that represents an open file. You also specify whether the archive will be used for loading or storing. A CArchive object can process not only primitive types but also objects of CObject-derived classes designed for serialization. A serializable class usually has a Serialize member function, and it usually uses the DECLARE_SERIAL and IMPLEMENT_SERIAL macros, as described under class CObject.

The overloaded extraction (>>) and insertion (<<) operators are convenient archive programming interfaces that support both primitive types and CObject-derived classes.

CArchive also supports programming with the MFC Windows Sockets classes CSocket and CSocketFile. The IsBufferEmpty member function supports that usage.

For more information on CArchive, see the articles Serialization and Windows Sockets: Using Sockets with Archives.

Inheritance Hierarchy

CArchive

Requirements

Header: afx.h

See Also

Reference

Hierarchy Chart

CFile Class

CObject Class

CSocket Class

CSocketFile Class