From 43f7733dfdd8700430a238d230ed573c12e72c87 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 8 Feb 2009 13:12:41 +0000 Subject: added filesystem::FileStream --- src/filesystem/filestream.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/filesystem/filestream.cc (limited to 'src/filesystem/filestream.cc') diff --git a/src/filesystem/filestream.cc b/src/filesystem/filestream.cc new file mode 100644 index 0000000..693d1c1 --- /dev/null +++ b/src/filesystem/filestream.cc @@ -0,0 +1,60 @@ +/* + filesystem/ifilestream.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "filesystem/filesystem.h" +#include "filesystem/filestream.h" + +namespace filesystem { + +IFileStream::IFileStream(const char *name) : std::ifstream() +{ + if (name) + fstream_name.assign(name); + + open(name); +} + +IFileStream::IFileStream(const std::string &name) : std::ifstream(), fstream_name(name) +{ + open(fstream_name); +} + +void IFileStream::open(const char *name) +{ + if (!name) { + if (is_open()) { + close(); + } + fstream_name.clear(); + fstream_filename.clear(); + return; + } + + fstream_name.assign(name); + + for (SearchPath::iterator path = searchpath().begin(); path != searchpath().end(); path++) { + fstream_filename.assign((*path)); + fstream_filename.append(fstream_name); +/* +#ifdef _WIN32 + for (size_t i = 0; i < fstream_filename.size(); i++) + if (fstream_filename[i] == '/') fstream_filename[i] = '\\'; +#endif +*/ + std::ifstream::open(fstream_filename.c_str()); + if (good()) + return; + } + + fstream_filename.clear(); +} + +void IFileStream::open(const std::string &name) +{ + open(name.c_str()); +} + +} -- cgit v1.2.3