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

📄 filereader.cpp

📁 It s a tool designed to extract as much information as possible from Bluetooth devices without the r
💻 CPP
字号:
/* -*- c++ -*- ---------------------------------------------------------------   Copyright (C) 2005, SWECO, All Rights Reserved.   Implementation of FileReader class   Author: Zsolt Molnar (Zsolt.Molnar@ieee.org)   ---------------------------------------------------------------------------*/#include <unistd.h>#include <iostream>#include "FileReader.hh"namespace { 	const char rcs_id[] = "$Id$"; }size_t FileReader::_bufLen = FR_DEF_BUFLEN;FileReader::FileReader(const string& aFileName)	: _file(aFileName.c_str()),	  _fileName(aFileName){	// EMPTY}FileReader::~FileReader(){	close();}string FileReader::nextLine(){	if (!_file) {		return "";	}	string line;	char buf[_bufLen];	do {		int i = 0;		while (i < _bufLen - 1) {			char c = _file.get();			if (c == '\n' || _file.eof()) {				break;			}			buf[i] = c;			++i;		}		buf[i] = '\0';		line += buf;	} while (!_file.eof() && strlen(buf) == _bufLen - 1);	return line;}bool FileReader::isEnd(){	return !_file || _file.eof();}void FileReader::close(){	_file.close();}void FileReader::remove(){	close();	unlink(_fileName.c_str());}#ifdef __TEST__#include <assert.h>bool FileReader::test(){	const char* fname = "/tmp/freader_test";	ofstream test(fname);	string line1 = "";	string line2 = "asdas";	string line3 = "sdjklofhsdkl fdsoklfj osad";	test << line1 << endl << line2 << endl << line3;	_bufLen = 10;	test.close();	FileReader freader(fname);	// Cannot be at the end...	assert(!freader.isEnd());	// Read the first line	string rline = freader.nextLine();	assert(!freader.isEnd());	assert(rline == line1);	// read the next line	rline = freader.nextLine();	assert(!freader.isEnd());	assert(rline == line2);	// read the next line	rline = freader.nextLine();	assert(freader.isEnd());	assert(rline == line3);	// read teh next line while no more liness...	rline = freader.nextLine();	assert(freader.isEnd());	assert(rline.empty());	// remove the file	freader.remove();	ifstream testFile(fname);	// it must not be there	assert(!testFile);		unlink(fname);	cout << "FileReader test passed" << endl;	return true;}#endif // #ifdef __TEST__

⌨️ 快捷键说明

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