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