PCMFileSystemManager.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00027
00028 #ifndef __PCM_FILESYSTEMMANAGER_H__
00029 # define __PCM_FILESYSTEMMANAGER_H__
00030
00031
00032
00033
00034
00035 # include "PCMPremeditations.h"
00036
00037 # include "PCMSingleton.h"
00038
00039 # include "PCMException.h"
00040
00041 # include "PCMLogger.h"
00042
00043 # include "PCMContainer.h"
00044
00045 # include "PCMPointer.h"
00046
00047
00048
00049
00050
00051 # include <string>
00052
00053 # include <list>
00054
00055 # include <queue>
00056
00057 # include <stack>
00058
00059
00060
00061
00062
00063 # include <squirrel/squirrel.h>
00064 # include <squirrel/sqstdio.h>
00065 # include <squirrel/sqstdaux.h>
00066 # include <squirrel/sqplus.h>
00067
00068 namespace ParCompMark
00069 {
00070
00076 class FileSystemManager:public Singleton < FileSystemManager >
00077 {
00078
00079
00080
00081
00082 # ifdef PARCOMPMARK_TEST
00083 friend class ParCompMarkTest::TestFileSystemManager;
00084 # endif
00085
00086
00087
00088
00089
00091
00092
00100 public:static void squirrelGlue()
00101 {
00102 ::SqPlus::SQClassDef < FileSystemManager >
00103 (_T("FileSystemManager")).staticFunc(&FileSystemManager::getInstance,
00104 _T("getInstance")).func(&FileSystemManager::existsDataFile,
00105 _T("existsDataFile"));
00106 }
00107
00109
00110
00111
00112
00113
00114 public:
00115
00117 enum FileOperation
00118 {
00119
00121 READ,
00122
00124 WRITE,
00125
00127 APPEND
00128 };
00129
00130
00131
00132
00133
00134 public:
00135
00137 typedef Pointer < FILE,
00138 Mutex > CFilePointer;
00139
00141 typedef Pointer < std::fstream,
00142 Mutex > CppFilePointer;
00143
00144
00145
00146
00147
00149
00150
00151 public:
00152
00158 static const u32 MAX_PATH;
00159
00165 static const std::string PATH_SEPARATOR;
00166
00168
00169
00170
00171
00172
00174
00175
00176 protected:
00177
00183 bool mInitialized;
00184
00190 std::string mAppDirectory;
00191
00197 std::string mDataDirectory;
00198
00204 std::string mHomeDirectory;
00205
00211 std::string mCurrentDirectory;
00212
00218 std::string mIniFile;
00219
00221
00222
00223
00224
00225
00227
00228
00229 public:
00230
00236 FileSystemManager(const std::string & appDirectory =
00237 "~/.ParCompMark/", const std::string & iniFile = "parcompmark.ini");
00238
00242 virtual ~ FileSystemManager();
00243
00245
00246
00247
00248
00249
00251
00252
00253 public:
00254
00260 const bool & getInitialized() const;
00261
00267 const std::string & getAppDirectory() const;
00268
00274 void setAppDirectory(const std::string & appdirectory);
00275
00281 const std::string & getDataDirectory() const;
00282
00288 void setDataDirectory(const std::string & datadirectory);
00289
00295 const std::string & getHomeDirectory() const;
00296
00302 const std::string & getCurrentDirectory() const;
00303
00309 const std::string & getIniFile() const;
00310
00312
00313
00314
00315
00316
00318
00319
00320 public:
00321
00326 static FileSystemManager *getInstance();
00327
00332 static void closeFile(FileSystemManager::CppFilePointer & fp);
00333
00338 static void closeFile(FileSystemManager::CFilePointer & fp);
00339
00341
00342
00343
00344
00345
00347
00348
00349 public:
00350
00354 virtual void initialize();
00355
00359 virtual void finalize();
00360
00366 virtual bool existsDirectory(const std::string & name) const;
00367
00373 virtual bool createDirectory(const std::string & name) const;
00374
00379 virtual std::string findDataDirectory() const;
00380
00387 virtual bool existsLibrary(const std::string & library,
00388 const std::vector < std::string > &additionalPaths =
00389 std::vector < std::string > ())const;
00390
00397 virtual std::string findLibraryPath(const std::string & library,
00398 const std::vector < std::string > &additionalPaths =
00399 std::vector < std::string > ())const;
00400
00406 virtual std::list < std::string > listDirectory(const std::string & directory) const;
00407
00413 virtual std::list < std::string > listDataDirectory(const std::string & directory) const;
00414
00420 virtual bool existsFile(const std::string & name) const;
00421
00427 virtual bool existsAppFile(const std::string & name) const;
00428
00434 virtual bool existsDataFile(const char *name) const;
00435
00442 virtual FileSystemManager::CFilePointer openFileC(const std::string & name,
00443 const FileOperation & operation =
00444 FileSystemManager::READ) const;
00445
00452 virtual FileSystemManager::CFilePointer openAppFileC(const std::string & name,
00453 const FileOperation & operation =
00454 FileSystemManager::READ) const;
00455
00462 virtual FileSystemManager::CFilePointer openDataFileC(const std::string & name,
00463 const FileOperation & operation =
00464 FileSystemManager::READ) const;
00465
00472 virtual FileSystemManager::CppFilePointer openFileCpp(const std::string & name,
00473 const FileOperation & operation =
00474 FileSystemManager::READ) const;
00475
00482 virtual FileSystemManager::CppFilePointer openAppFileCpp(const std::string & name,
00483 const FileOperation & operation =
00484 FileSystemManager::READ) const;
00485
00492 virtual FileSystemManager::CppFilePointer openDataFileCpp(const std::string & name,
00493 const FileOperation & operation =
00494 FileSystemManager::READ) const;
00495
00501 virtual std::string getPathDataFile(const std::string & name) const;
00502
00508 virtual std::string readTextFile(const std::string & name) const;
00509
00515 virtual std::string readAppTextFile(const std::string & name) const;
00516
00522 virtual std::string readDataTextFile(const std::string & name) const;
00523
00524 protected:
00525
00529 virtual void _findHomeDirectory();
00530
00536 virtual std::string _replaceHomeChar(const std::string & path) const;
00537
00546 virtual std::string _translateToAbsolutePath(const std::string & path) const;
00547
00551 virtual void _createAppDirectory();
00552
00554
00555 };
00556
00557
00558
00559
00560
00561 # include "PCMFileSystemManager_impl.h"
00562
00563 }
00564
00565
00567 DECLARE_INSTANCE_TYPE_NAME(ParCompMark::FileSystemManager, FileSystemManager);
00568
00569 #endif