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

📄 localfilesystem.cpp

📁 光滑质点无网格法SPH并行计算程序
💻 CPP
字号:
//      ___                       ___           ___           ___       ___     //     /\__\          ___        /\__\         /\  \         /\__\     /\  \.    //    /::|  |        /\  \      /::|  |       /::\  \       /:/  /    /::\  \.   //   /:|:|  |        \:\  \    /:|:|  |      /:/\:\  \     /:/  /    /:/\:\  \.  //  /:/|:|__|__      /::\__\  /:/|:|  |__   /:/  \:\  \   /:/  /    /::\~\:\  \. // /:/ |::::\__\  __/:/\/__/ /:/ |:| /\__\ /:/__/_\:\__\ /:/__/    /:/\:\ \:\__\.// \/__/~~/:/  / /\/:/  /    \/__|:|/:/  / \:\  /\ \/__/ \:\  \    \:\~\:\ \/__///       /:/  /  \::/__/         |:/:/  /   \:\ \:\__\    \:\  \    \:\ \:\__\.  //      /:/  /    \:\__\         |::/  /     \:\/:/  /     \:\  \    \:\ \/__/  //     /:/  /      \/__/         /:/  /       \::/  /       \:\__\    \:\__\.    //     \/__/                     \/__/         \/__/         \/__/     \/__/    // // =============================================================================//                       Minimalist OpenGL Environment// =============================================================================//// This file is part of Minimalist OpenGL Environment (MinGLE)//// Version: 0.2.0// Author: Balazs Domonkos// Filename: src/LocalFileSystem.cpp// Creation Date: December 12th 2007// Revision Date: December 12th 2007////// The Minimalist OpenGL Environment is free software: you can// redistribute it and/or modify it under the terms of the GNU// General Public License as published by the Free Software// Foundation, either version 3 of the License, or (at your// option) any later version.//// The Minimalist OpenGL Environment is distributed in the hope// that it will be useful, but WITHOUT ANY WARRANTY; without// even the implied warranty of MERCHANTABILITY or FITNESS FOR// A PARTICULAR PURPOSE. See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License// along with Minimalist OpenGL Environment.  If not, see // <http://www.gnu.org/licenses/>. See the COPYING file included // with this distribution file for license details.///// @file LocalFileSystem.cpp/// Local file system class// Header that contains the declaration#include <LocalFileSystem.h>// MinGLE headers#include <Exception.h>// System headers#include <stdio.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>namespace MinGLE {LocalFileSystem::LocalFileSystem(std::string rootDirectory) :	mRootDirectory(rootDirectory) {}LocalFileSystem::~LocalFileSystem() {	// Nothing to do}std::string LocalFileSystem::getURL(const std::string& filename) const {	return LocalFileSystemManager::PROTOCOL_STRING + VirtualFileSystemManager::PROTOCOL_SEPARATOR + mRootDirectory + filename;}VirtualFileSystem::FileHandle LocalFileSystem::open(		const std::string& filename, const std::string& mode) {	VirtualFileSystem::FileHandle f = (VirtualFileSystem::FileHandle) fopen(			(mRootDirectory+filename).c_str(), mode.c_str());	Assert(f, "LocalFileSystem::open");	return f;}void LocalFileSystem::close(VirtualFileSystem::FileHandle f) {	Assert(!fclose((FILE *) f), "LocalFileSystem::close");}bool LocalFileSystem::eof(VirtualFileSystem::FileHandle f) {	return feof((FILE *) f);}int LocalFileSystem::getchar(VirtualFileSystem::FileHandle f) {	return fgetc((FILE *) f);}int LocalFileSystem::putchar(int ch, VirtualFileSystem::FileHandle f) {	return fputc(ch, (FILE *) f);}int LocalFileSystem::read(void *ptr, int size, int count,		VirtualFileSystem::FileHandle f) {	return fread(ptr, size, count, (FILE *) f);}int LocalFileSystem::write(const void *ptr, int size, int count,		VirtualFileSystem::FileHandle f) {	return fwrite(ptr, size, count, (FILE *) f);}int LocalFileSystem::seek(VirtualFileSystem::FileHandle f, int numbytes,		int where) {	return fseek((FILE *) f, numbytes, where);}int LocalFileSystem::tell(VirtualFileSystem::FileHandle f) {	return ftell((FILE *) f);}bool LocalFileSystem::exists(const std::string& path) {	struct stat buffer;	int status = lstat((mRootDirectory+path).c_str(), &buffer);	// File exists	if (!status)		return true;	// File does not exist	else if (errno == ENOTDIR || errno == ENOENT)		return false;	// Error occured	Except("LocalFileSystem::exists",			"An error occured when testing existance of " + path);	return false;}VirtualFileSystem::DirectoryEntryList LocalFileSystem::listDirectory(conststd::string& directoryName, const unsigned mask) {	// Open directory	DIR *dp;	Assert((dp = opendir((mRootDirectory+directoryName).c_str())),			"LocalFileSystem::readDirectory");	// List files	struct dirent *ep;	VirtualFileSystem::DirectoryEntryList deList;	while ((ep = readdir(dp))) {		// Get entry type		DirectoryEntryType deType = UNKNOWN;		switch (ep->d_type) {		case DT_REG:			deType = REGULAR;			break;		case DT_DIR:			deType = DIRECTORY;			break;		case DT_FIFO:			deType = FIFO;			break;		case DT_SOCK:			deType = SOCKET;			break;		case DT_CHR:			deType = CHARACTER_DEVICE;			break;		case DT_BLK:			deType = BLOCK_DEVICE;			break;		}		DirectoryEntry entry = { ep->d_name, deType };		deList.push_back(entry);	}	// Close directory	closedir(dp);	// Sort directory entries	_sortDirectoryEntryList(deList);	return deList;}// =============================================================================const std::string LocalFileSystemManager::PROTOCOL_STRING = "file";LocalFileSystemManager::~LocalFileSystemManager() {	// Nothing to do}void LocalFileSystemManager::registerVirtualFileSystemManager() {	VirtualFileSystemManager::registerImplementation(LocalFileSystemManager::PROTOCOL_STRING, new LocalFileSystemManager());}VirtualFileSystem *LocalFileSystemManager::_createVirtualFileSystem(		const std::string& connectionString) {	return new LocalFileSystem(connectionString);}} // namespace MinGLE

⌨️ 快捷键说明

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