MFC中的CArchive(1)

本文介绍了MFC中CArchive类的相关内容,包括缓冲区指针、构造函数以及IsLoading()函数的用法。CArchive类用于文件的序列化操作,它根据IsLoading()返回值来判断读写模式,并在构造时初始化缓冲区。
摘要由CSDN通过智能技术生成

1.先贴上该类:

class CArchive
{
protected:
enum SchemaMapReservedRefs { objTypeArrayRef = 1 };
enum LoadArrayObjType{ typeUndefined = 0, typeCRuntimeClass = 1, typeCObject = 2 };
public:
// Flag values
enum Mode { store = 0, load = 1, bNoFlushOnDelete = 2, bNoByteSwap = 4 };


CArchive(CFile* pFile, UINT nMode, int nBufSize = 4096, void* lpBuf = NULL);
~CArchive();


// Attributes
BOOL IsLoading() const;
BOOL IsStoring() const;
BOOL IsByteSwapping() const;
BOOL IsBufferEmpty() const;


CFile* GetFile() const;
UINT GetObjectSchema(); // only valid when reading a CObject*
void SetObjectSchema(UINT nSchema);


// pointer to document being serialized -- must set to serialize
//  COleClientItems in a document!
CDocument* m_pDocument;


// Operations
UINT Read(void* lpBuf, UINT nMax);
void EnsureRead(void *lpBuf, UINT nCount);
void Write(const void* lpBuf, UINT nMax);
void Flush();
void Close();
void Abort();   // close and shutdown without exceptions


// reading and writing strings
void WriteString(LPCTSTR lpsz);
LPTSTR ReadString(_Out_z_cap_(nMax+1) LPTSTR lpsz, _In_ UINT nMax);
BOOL ReadString(CString& rString);


public:
// Object I/O is pointer based to avoid added construction overhead.
// Use the Serialize member function directly for embedded objects.
friend CArchive& AFXAPI operator<<(CArchive& ar, const CObject* pOb);


friend CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb);
friend CArchive& AFXAPI operator>>(CArchive& ar, const CObject*& pOb);


// insertion operations
CArchive& operator<<(BYTE by);
CArchive& operator<<(WORD w);
CArchive& operator<<(LONG l);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值