iokit.cpp

来自「The ROSETTA C++ library is a collection 」· C++ 代码 · 共 139 行

CPP
139
字号
//-------------------------------------------------------------------// Author........: Aleksander 豩rn// Date..........:// Description...:// Revisions.....://===================================================================#include <stdafx.h> // Precompiled headers.#include <copyright.h>#include <kernel/utilities/iokit.h>#include <kernel/utilities/delimiter.h>#include <kernel/system/fstream.h>#include <kernel/basic/string.h>//-------------------------------------------------------------------// Static stuff.//===================================================================unsigned int  IOKit::buffersize_ = 10240;char         *IOKit::buffer_     = NULL;//-------------------------------------------------------------------// Methods for class IOKit.//===================================================================//-------------------------------------------------------------------// Method........: AllocateBuffer// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......: More optimal reuse of allocated buffer is possible.// Revisions.....://===================================================================boolIOKit::AllocateBuffer(unsigned int buffersize) {	// Reuse current buffer?	if ((buffer_ != NULL) && (buffersize == buffersize_))		return true;	buffersize_ = buffersize;	// Deallocate current buffer?	if (buffer_ != NULL)		delete [] buffer_;	// Allocate new buffer.	buffer_ = new char[buffersize_];	return (buffer_ != NULL);}//-------------------------------------------------------------------// Method........: Open// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolIOKit::Open(ifstream &stream, const String &filename) {	stream.open(filename.GetBuffer(), ios::in | ios::nocreate);	return (1 == stream.is_open());}//-------------------------------------------------------------------// Method........: Open// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolIOKit::Open(ofstream &stream, const String &filename, bool append) {	if (!append)		stream.open(filename.GetBuffer());	else		stream.open(filename.GetBuffer(), ios::out | ios::app);	return (1 == stream.is_open());}//-------------------------------------------------------------------// Method........: Close// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolIOKit::Close(ifstream &stream) {	stream.close();	return true;}//-------------------------------------------------------------------// Method........: Close// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolIOKit::Close(ofstream &stream) {	stream.close();	return true;}//-------------------------------------------------------------------// Method........: Save// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....: 970511 A

⌨️ 快捷键说明

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