transactionfile.h

来自「该代码是将MSDN中的httpsvr MFC代码移植到STL。含有VC完整应用程」· C头文件 代码 · 共 82 行

H
82
字号
#if !defined(TransactionFile_H)
#define TransactionFile_H



#include <string>
using namespace std;


#include "Lock.h"
#include "SysEvent.h"

////////////////////////////////////////////////////////////////////////////////
// TransactionFile
//
// Purpose: text file class

class TransactionFile :
	public Lock,
	public SysEvent
{
	long	m_readOffset;			// current read offset
	long	m_writeOffset;			// current write offset
	DWORD	m_readWait;				// time (ms) to wait after read
	DWORD	m_writeWait;			// time (ms) to wait after write
	DWORD	m_openFlags;			// flags used to open file
	string	m_name;					// name of file

public:
	HANDLE	m_hFile;


	TransactionFile ();
	~TransactionFile (); 

	// show error
	void	showLastError	();
	bool	invalidFile		();

	// open methods
	bool	create			( string & fileName );
	bool	open			( string & fileName );
	bool	openAlways		( string & fileName );
	bool	open			( string & fileName, DWORD openFlags );
	void	close			();

	// file info/position methods
	bool	setPosition		( DWORD position, bool read = true );
	long	size			();
	bool	offsetPosition	( DWORD offset, bool read = true  );

	// clear the file
	void	clear			();

	// read/write methods
	bool	write			( LPTSTR pBuffer, DWORD noToWrite, bool wait = true );
	bool	read			( LPTSTR pBuffer, DWORD noToRead, bool wait = true );

	void    operator <<		( string & buffer )
	{
		write( (LPTSTR) buffer.c_str(), buffer.size() );
	}

	operator HANDLE () 
	{ 
		return m_hFile; 
	}

	void setReadWait ( DWORD wait )
	{ m_readWait = wait; }

	void setWriteWait ( DWORD wait )
	{ m_writeWait = wait; }

};


void operator << ( stringstream & strm, TransactionFile & file );
void operator << ( TransactionFile & file, stringstream & strm );


#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?