⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textfile.h

📁 一个c++实现的acd的例子。 ----ACDCommandListener.cpp ---ACDCommandListenerThread.cpp ---ACDConfig.cpp ---a
💻 H
字号:
#if !defined(TextFile_H)
#define TextFile_H

#include <sstream>
#include <string>
using namespace std;


#include "Lock.h"
#include "TimeStamp.h"




/////////////////////////////////////////////////////////////////////////////
// File status

//##ModelId=424BB6400343
struct TextFileStatus
{
	//##ModelId=424BB6400354
	TimeStamp	_ctime;					// creation date/time of file
	//##ModelId=424BB6400364
	TimeStamp	_mtime;					// last modification date/time of file
	//##ModelId=424BB6400369
	TimeStamp	_atime;					// last access date/time of file
	//##ModelId=424BB6400374
	LONG		_size;					// logical size of file in bytes
	//##ModelId=424BB6400382
	DWORD		_attribute;				// logical OR of CFile::Attribute enum values
	//##ModelId=424BB6400392
	TCHAR		_szFullName[_MAX_PATH];	// absolute path name

};

////////////////////////////////////////////////////////////////////////////////
// TextFile
//
// Purpose: text file class


//##ModelId=424BB64003E0
class TextFile :
	private Lock
{
	//##ModelId=424BB64003E2
	DWORD	_openFlags;			// flags used to open file
	//##ModelId=424BB6410008
	string	_name;				// name of file

public:
	//##ModelId=424BB6410017
	HANDLE	_hFile;


	//##ModelId=424BB6410018
	TextFile ();
	//##ModelId=424BB6410019
	~TextFile (); 

	//##ModelId=424BB6410141
	enum OpenFlags {
		//##ModelId=424BB6410150
		modeRead =          0x0000,
		//##ModelId=424BB6410151
		modeWrite =         0x0001,
		//##ModelId=424BB641015F
		modeReadWrite =     0x0002,
		//##ModelId=424BB6410160
		shareCompat =       0x0000,
		//##ModelId=424BB641016F
		shareExclusive =    0x0010,
		//##ModelId=424BB6410170
		shareDenyWrite =    0x0020,
		//##ModelId=424BB641017E
		shareDenyRead =     0x0030,
		//##ModelId=424BB641017F
		shareDenyNone =     0x0040,
		//##ModelId=424BB641018E
		modeNoInherit =     0x0080,
		//##ModelId=424BB641018F
		modeCreate =        0x1000,
		//##ModelId=424BB641019E
		modeNoTruncate =    0x2000,
		//##ModelId=424BB641019F
		typeText =          0x4000, // typeText and typeBinary are used in
		//##ModelId=424BB64101AD
		typeBinary =   (int)0x8000 // derived classes only
		};

	//##ModelId=424BB64101BD
	enum Attribute {
		//##ModelId=424BB64101BF
		normal =    0x00,
		//##ModelId=424BB64101CC
		readOnly =  0x01,
		//##ModelId=424BB64101CD
		hidden =    0x02,
		//##ModelId=424BB64101DC
		system =    0x04,
		//##ModelId=424BB64101DD
		volume =    0x08,
		//##ModelId=424BB64101EC
		directory = 0x10,
		//##ModelId=424BB64101ED
		archive =   0x20
		};

	//##ModelId=424BB641020B
	enum SeekPosition { begin = 0x0, current = 0x1, end = 0x2 };

	enum { hFileNull = -1 };

	//##ModelId=424BB6410027
	bool isValid ()
	{
		if ( !invalidFile() )
			return true;
		else
			return false;
	}


	// show error
	//##ModelId=424BB6410028
	void	showLastError	();
	//##ModelId=424BB6410029
	bool	invalidFile		();

	// open methods
	//##ModelId=424BB6410036
	bool	create			( string & fileName );
	//##ModelId=424BB6410038
	bool	open			( string & fileName );
	//##ModelId=424BB6410047
	bool	openFastRead	( string & fileName );

	//##ModelId=424BB6410055
	bool	openAlways		( string & fileName );
	//##ModelId=424BB6410057
	bool	open			( string & fileName, DWORD openFlags );
	//##ModelId=424BB6410066
	void	close			();
	//##ModelId=424BB6410067
	bool	create			();
	//##ModelId=424BB6410075
	void	release			();

	// file info/position methods
	//##ModelId=424BB6410076
	bool	setPosition		( DWORD position );
	//##ModelId=424BB6410084
	long	size			();
	//##ModelId=424BB6410085
	bool	offsetPosition	( DWORD offset );

	// clear the file
	//##ModelId=424BB6410094
	void	clear			();

	// read/write methods
	//##ModelId=424BB6410095
	bool	write			( LPTSTR pBuffer, DWORD noToWrite );
	//##ModelId=424BB64100A4
	bool	read			( LPTSTR pBuffer, DWORD noToRead );

	// file status
	//##ModelId=424BB64100A7
		   bool getStatus	( TextFileStatus& rStatus );
	//##ModelId=424BB64100B4
	static bool getStatus	( LPCTSTR lpszFileName, TextFileStatus& rStatus );
	//##ModelId=424BB64100C4
	static bool setStatus	( LPCTSTR lpszFileName, TextFileStatus& status );

	// file manipulation
	//##ModelId=424BB64100D2
	static bool rename		( LPCTSTR lpszOldName, LPCTSTR lpszNewName );
	//##ModelId=424BB64100D6
	static bool remove		( LPCTSTR lpszFileName );

	// file path
	//##ModelId=424BB64100E4
	static bool getFullPath		( LPTSTR lpszPathOut, LPCTSTR lpszFileIn );
	//##ModelId=424BB64100F3
	static bool getRoot			( LPCTSTR lpszPath, string & strRoot );
	//##ModelId=424BB6410101
	static bool comparePath		( LPCTSTR lpszPath1, LPCTSTR lpszPath2 );
	//##ModelId=424BB6410105
	static long getFileTitle	( LPCTSTR lpszPathName, LPTSTR lpszTitle, UINT nMax );

	// operators
	//##ModelId=424BB6410115
	TextFile &  operator << ( string & buffer )
	{
		write( (LPTSTR) buffer.c_str(), buffer.size() );
		return *this;
	}

	//##ModelId=424BB6410122
	TextFile &  operator >> ( stringstream & strm )
	{
		write( (LPTSTR) strm.str().c_str(), strm.str().size() );
		return *this;
	}

	//##ModelId=424BB6410124
	TextFile &  operator << ( LPCTSTR buffer )
	{
		write( (LPTSTR) buffer, lstrlen(buffer) );
		return *this;
	}

	//##ModelId=424BB6410131
	TextFile &  operator << ( LPTSTR buffer )
	{
		write( buffer, lstrlen(buffer) );
		return *this;
	}

	//##ModelId=424BB6410133
	operator HANDLE ()
	{
		return _hFile;
	}

	// test if file open
	//##ModelId=424BB6410140
	bool isOpen ()
	{
		if ( _hFile == 0 || _hFile == INVALID_HANDLE_VALUE )
			return false;
		else
			return true;
	}
};

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


inline bool isDirSep(TCHAR ch)
{
	return (ch == '\\' || ch == '/');
}

//##ModelId=424BB64100A7
inline
bool TextFile::getStatus ( TextFileStatus& rStatus )
{
	return TextFile::getStatus( _name.c_str(), rStatus );
}



#endif

⌨️ 快捷键说明

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