VFileSystem.h

Go to the documentation of this file.
00001 #ifndef __LDK_VFILESYSTEM_H__
00002 #define __LDK_VFILESYSTEM_H__
00003 
00005 //   Copyright (C) 2003-2006 Lorien Dunn.
00006 //
00007 //   Contact: loriendunn AT users DOT sourceforge DOT net
00008 //
00009 //   This software is provided 'as-is', without any express or implied warranty.
00010 //   In no event will the authors be held liable for any damages arising from
00011 //   the use of this software.
00012 //
00013 //   Permission is granted to anyone to use this software for any purpose,
00014 //   including commercial applications, and to alter it and redistribute it
00015 //   freely, subject to the following restrictions:
00016 //
00017 //   1. The origin of this software must not be misrepresented; you must not
00018 //   claim that you wrote the original software. If you use this software in a
00019 //   product, an acknowledgment in the product documentation would be
00020 //   appreciated but is not required.
00021 //
00022 //   2. Altered source versions must be plainly marked as such, and must not be
00023 //   misrepresented as being the original software.
00024 //
00025 //   3. This notice may not be removed or altered from any source distribution.
00026 //
00028 
00034 
00038 
00039 #include "LDK/Types.h"
00040 #include "LDK/VFile.h"
00041 #include "LDK/String.h"
00042 #include <vector>
00043 #include <list>
00044 
00045 namespace LDK
00046 {
00047 typedef std::vector<String,Allocator<String> > StringVec;
00048 typedef SmartPointer<StringVec> SmartStringVec;
00049 
00154 namespace Details
00155 {
00156 class LDK_API PerThreadVFS
00157 {
00158     SmartFile mStdIn;
00159     SmartFile mStdOut;
00160     SmartFile mStdErr;
00161 public:
00162     PerThreadVFS();
00163     ~PerThreadVFS();
00164 
00165     inline SmartFile& stdIn()  { return mStdIn; }
00166     inline SmartFile& stdOut() { return mStdOut; }
00167     inline SmartFile& stdErr() { return mStdErr; }
00168     void stdIn(SmartFile f);
00169     void stdOut(SmartFile f);
00170     void stdErr(SmartFile f);
00171 };
00172 }//namespace Details
00173 
00174 class LDK_API VFileSystem : public Singleton<Details::PerThreadVFS>
00175 {
00176 
00177 private:
00178 
00179     static void cleanup();
00180     VFileSystem();
00181     VFileSystem(const VFileSystem&);
00182     VFileSystem(const VFileSystem*);
00183     ~VFileSystem();
00184 
00185 public:
00186 
00187     static void initialise(const char* argv0);
00188 
00194     inline static SmartFile stdIn() { return instance().stdIn(); }
00195 
00201     inline static SmartFile stdOut() { return instance().stdOut(); }
00202 
00208     inline static SmartFile stdErr() { return instance().stdErr(); }
00209 
00217     inline static void stdIn(SmartFile f) { instance().stdIn(f); }
00218 
00226     inline static void stdOut(SmartFile f) { instance().stdOut(f); }
00227 
00235     inline static void stdErr(SmartFile f) { instance().stdErr(f); }
00236 
00280     static void defaultConfig(const char* organisation, const char* appName,
00281         const char* archiveExt, bool includeCdRoms, bool archivesFirst);
00282 
00292     static void addToSearchPath(const char* dirName, bool append=true);
00293 
00303     static void removeFromSearchPath(const char* dirName);
00304 
00317     static void writeDir(const char* dirName);
00318 
00324     static const char* writeDir();
00325 
00334     static SmartFile openRead(const char* fileName, bool text);
00335 
00344     static SmartFile openWrite(const char* fileName, bool text);
00345 
00355     static SmartFile openAppend(const char* fileName, bool text);
00356 
00362     static SmartStringVec searchDirs();
00363 
00376     static SmartStringVec cdRomDirs();
00377 
00405     static SmartStringVec enumerateFiles(const char* dir);
00406 
00416     static const char* dirSeperator();
00417 
00425     static const char* baseDir();
00426 
00438     static const char* userDir();
00439 
00454     static void makeDir(const char* dirName);
00455 
00463     static bool isDir(const char* fileName);
00464 
00482     static void deleteFile(const char* fileName);
00483 
00499     static const char* realDirectory(const char* fileName);
00500 
00508     static bool exists(const char* fileName);
00509 };
00510 
00511 }//namespace LDK
00512 
00513 #endif //__LDK_VFILESYSTEM_H__

Generated on Fri Aug 17 18:32:26 2007 for LDK by  doxygen 1.5.1