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

📄 file.h

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 H
字号:
// File.h
// This file is (C) 2002-2003 Royce Mitchell III and released under the BSD license

#ifndef FILE_H
#define FILE_H

#ifdef WIN32
#  include <io.h>
#elif defined(UNIX)
#  include <sys/stat.h>
#  include <unistd.h>
#endif
#include <string>

class File
{
public:
	File() : _f(0)
	{
	}

	File ( const char* filename, const char* mode ) : _f(0)
	{
		open ( filename, mode );
	}

	~File()
	{
		close();
	}

	bool open ( const char* filename, const char* mode );

	bool seek ( long offset )
	{
		return !fseek ( _f, offset, SEEK_SET );
	}

	int get()
	{
		return fgetc ( _f );
	}

	bool put ( int c )
	{
		return fputc ( c, _f ) != EOF;
	}

	std::string getline ( bool strip_crlf = false );

	// this function searches for the next end-of-line and puts all data it
	// finds until then in the 'line' parameter.
	//
	// call continuously until the function returns false ( no more data )
	bool next_line ( std::string& line, bool strip_crlf );

	/*
	example usage:

	bool mycallback ( const std::string& line, int line_number, long lparam )
	{
		std::cout << line << std::endl;
		return true; // continue enumeration
	}

	File f ( "file.txt", "rb" ); // open file for binary read-only ( i.e. "rb" )
	f.enum_lines ( mycallback, 0, true );
	*/

	bool enum_lines ( bool (*callback)(const std::string& line, int line_number, long lparam), long lparam, bool strip_crlf );

	bool read ( void* data, unsigned len )
	{
		return len == fread ( data, 1, len, _f );
	}

	bool write ( const void* data, unsigned len )
	{
		return len == fwrite ( data, 1, len, _f );
	}

	size_t length();

	void close();

	bool isopened()
	{
		return _f != 0;
	}

	bool eof()
	{
		return feof(_f) ? true : false;
	}

	FILE* operator * ()
	{
		return _f;
	}

	static bool LoadIntoString ( std::string& s, const char* filename );
	static bool SaveFromString ( const char* filename, const std::string& s, bool binary );

private:
	File(const File&) {}
	const File& operator = ( const File& ) { return *this; }

	FILE * _f;
};

#endif//FILE_H

⌨️ 快捷键说明

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