memVolume.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MEMVOLUME_H_
  23. #define _MEMVOLUME_H_
  24. #ifndef _VOLUME_H_
  25. #include "core/volume.h"
  26. #endif
  27. #ifndef _TDICTIONARY_H_
  28. #include "core/util/tDictionary.h"
  29. #endif
  30. namespace Torque
  31. {
  32. using namespace FS;
  33. namespace Mem
  34. {
  35. struct MemFileData;
  36. struct MemDirectoryData;
  37. class MemDirectory;
  38. //-----------------------------------------------------------------------------
  39. class MemFileSystem: public FileSystem
  40. {
  41. public:
  42. MemFileSystem(String volume);
  43. ~MemFileSystem();
  44. String getTypeStr() const { return "Mem"; }
  45. FileNodeRef resolve(const Path& path);
  46. FileNodeRef create(const Path& path,FileNode::Mode);
  47. bool remove(const Path& path);
  48. bool rename(const Path& from,const Path& to);
  49. Path mapTo(const Path& path);
  50. Path mapFrom(const Path& path);
  51. private:
  52. String mVolume;
  53. MemDirectoryData* mRootDir;
  54. MemDirectory* getParentDir(const Path& path, FileNodeRef& parentRef);
  55. };
  56. //-----------------------------------------------------------------------------
  57. /// Mem stdio file access.
  58. /// This class makes use the fopen, fread and fwrite for buffered io.
  59. class MemFile: public File
  60. {
  61. public:
  62. MemFile(MemFileSystem* fs, MemFileData* fileData);
  63. virtual ~MemFile();
  64. Path getName() const;
  65. NodeStatus getStatus() const;
  66. bool getAttributes(Attributes*);
  67. U32 getPosition();
  68. U32 setPosition(U32,SeekMode);
  69. bool open(AccessMode);
  70. bool close();
  71. U32 read(void* dst, U32 size);
  72. U32 write(const void* src, U32 size);
  73. private:
  74. U32 calculateChecksum();
  75. MemFileSystem* mFileSystem;
  76. MemFileData* mFileData;
  77. NodeStatus mStatus;
  78. U32 mCurrentPos;
  79. bool _updateInfo();
  80. void _updateStatus();
  81. };
  82. //-----------------------------------------------------------------------------
  83. class MemDirectory: public Directory
  84. {
  85. public:
  86. MemDirectory(MemFileSystem* fs, MemDirectoryData* dir);
  87. ~MemDirectory();
  88. Path getName() const;
  89. NodeStatus getStatus() const;
  90. bool getAttributes(Attributes*);
  91. bool open();
  92. bool close();
  93. bool read(Attributes*);
  94. private:
  95. friend class MemFileSystem;
  96. MemFileSystem* mFileSystem;
  97. MemDirectoryData* mDirectoryData;
  98. U32 calculateChecksum();
  99. NodeStatus mStatus;
  100. U32 mSearchIndex;
  101. };
  102. } // Namespace
  103. } // Namespace
  104. #endif