Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-02-08 13:12:41 +0000
committerStijn Buys <ingar@osirion.org>2009-02-08 13:12:41 +0000
commit43f7733dfdd8700430a238d230ed573c12e72c87 (patch)
treea3fd4dea40ae291ee8bed1dfb3472324e1657fe0 /src/filesystem/filestream.cc
parent48892cf81a5ef06103286947b2eb55c7c46681a4 (diff)
added filesystem::FileStream
Diffstat (limited to 'src/filesystem/filestream.cc')
-rw-r--r--src/filesystem/filestream.cc60
1 files changed, 60 insertions, 0 deletions
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());
+}
+
+}