ovr_sdk

diff LibOVR/Src/Kernel/OVR_File.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_File.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,530 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   Kernel
     1.7 +Filename    :   OVR_File.h
     1.8 +Content     :   Header for all internal file management - functions and structures
     1.9 +                to be inherited by OS specific subclasses.
    1.10 +Created     :   September 19, 2012
    1.11 +Notes       : 
    1.12 +
    1.13 +Notes       :   errno may not be preserved across use of BaseFile member functions
    1.14 +            :   Directories cannot be deleted while files opened from them are in use
    1.15 +                (For the GetFullName function)
    1.16 +
    1.17 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.18 +
    1.19 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.20 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.21 +which is provided at the time of installation or download, or which 
    1.22 +otherwise accompanies this software in either electronic or hard copy form.
    1.23 +
    1.24 +You may obtain a copy of the License at
    1.25 +
    1.26 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.27 +
    1.28 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.29 +distributed under the License is distributed on an "AS IS" BASIS,
    1.30 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.31 +See the License for the specific language governing permissions and
    1.32 +limitations under the License.
    1.33 +
    1.34 +************************************************************************************/
    1.35 +
    1.36 +#ifndef OVR_File_h
    1.37 +#define OVR_File_h
    1.38 +
    1.39 +#include "OVR_RefCount.h"
    1.40 +#include "OVR_Std.h"
    1.41 +#include "OVR_Alg.h"
    1.42 +
    1.43 +#include <stdio.h>
    1.44 +#include "OVR_String.h"
    1.45 +
    1.46 +namespace OVR {
    1.47 +
    1.48 +// ***** Declared classes
    1.49 +class   FileConstants;
    1.50 +class   File;
    1.51 +class   DelegatedFile;
    1.52 +class   BufferedFile;
    1.53 +
    1.54 +
    1.55 +// ***** Flags for File & Directory accesses
    1.56 +
    1.57 +class FileConstants
    1.58 +{
    1.59 +public:
    1.60 +
    1.61 +    // *** File open flags
    1.62 +    enum OpenFlags
    1.63 +    {
    1.64 +        Open_Read       = 1,
    1.65 +        Open_Write      = 2,
    1.66 +        Open_ReadWrite  = 3,
    1.67 +
    1.68 +        // Opens file and truncates it to zero length
    1.69 +        // - file must have write permission
    1.70 +        // - when used with Create, it opens an existing 
    1.71 +        //   file and empties it or creates a new file
    1.72 +        Open_Truncate   = 4,
    1.73 +
    1.74 +        // Creates and opens new file 
    1.75 +        // - does not erase contents if file already
    1.76 +        //   exists unless combined with Truncate
    1.77 +        Open_Create     = 8,
    1.78 +
    1.79 +         // Returns an error value if the file already exists
    1.80 +        Open_CreateOnly = 24,
    1.81 +
    1.82 +        // Open file with buffering
    1.83 +        Open_Buffered    = 32
    1.84 +    };
    1.85 +
    1.86 +    // *** File Mode flags
    1.87 +    enum Modes
    1.88 +    {
    1.89 +        Mode_Read       = 0444,
    1.90 +        Mode_Write      = 0222,
    1.91 +        Mode_Execute    = 0111,
    1.92 +
    1.93 +        Mode_ReadWrite  = 0666
    1.94 +    };
    1.95 +
    1.96 +    // *** Seek operations
    1.97 +    enum SeekOps
    1.98 +    {
    1.99 +        Seek_Set        = 0,
   1.100 +        Seek_Cur        = 1,
   1.101 +        Seek_End        = 2
   1.102 +    };
   1.103 +
   1.104 +    // *** Errors
   1.105 +    enum Errors
   1.106 +    {
   1.107 +        Error_FileNotFound  = 0x1001,
   1.108 +        Error_Access        = 0x1002,
   1.109 +        Error_IOError       = 0x1003,
   1.110 +        Error_DiskFull      = 0x1004
   1.111 +    };
   1.112 +};
   1.113 +
   1.114 +
   1.115 +//-----------------------------------------------------------------------------------
   1.116 +// ***** File Class
   1.117 +
   1.118 +// The pure virtual base random-access file
   1.119 +// This is a base class to all files
   1.120 +
   1.121 +class File : public RefCountBase<File>, public FileConstants
   1.122 +{   
   1.123 +public:
   1.124 +    File() { }
   1.125 +    // ** Location Information
   1.126 +
   1.127 +    // Returns a file name path relative to the 'reference' directory
   1.128 +    // This is often a path that was used to create a file
   1.129 +    // (this is not a global path, global path can be obtained with help of directory)
   1.130 +    virtual const char* GetFilePath() = 0;
   1.131 +                                                                                        
   1.132 +
   1.133 +    // ** File Information
   1.134 +
   1.135 +    // Return 1 if file's usable (open)
   1.136 +    virtual bool        IsValid() = 0;
   1.137 +    // Return 1 if file's writable, otherwise 0                                         
   1.138 +    virtual bool        IsWritable() = 0;
   1.139 +                                                                                        
   1.140 +    // Return position
   1.141 +    virtual int         Tell() = 0;
   1.142 +    virtual int64_t     LTell() = 0;
   1.143 +    
   1.144 +    // File size                                                                        
   1.145 +    virtual int         GetLength() = 0;
   1.146 +    virtual int64_t     LGetLength() = 0;
   1.147 +                                                                                        
   1.148 +    // Returns file stats                                                               
   1.149 +    // 0 for failure                                                                    
   1.150 +    //virtual bool      Stat(FileStats *pfs) = 0;
   1.151 +                                                                                        
   1.152 +    // Return errno-based error code                                                    
   1.153 +    // Useful if any other function failed                                              
   1.154 +    virtual int         GetErrorCode() = 0;
   1.155 +                                                                                        
   1.156 +                                                                                        
   1.157 +    // ** Stream implementation & I/O
   1.158 +
   1.159 +    // Blocking write, will write in the given number of bytes to the stream
   1.160 +    // Returns : -1 for error
   1.161 +    //           Otherwise number of bytes read 
   1.162 +    virtual int         Write(const uint8_t *pbufer, int numBytes) = 0;
   1.163 +    // Blocking read, will read in the given number of bytes or less from the stream
   1.164 +    // Returns : -1 for error
   1.165 +    //           Otherwise number of bytes read,
   1.166 +    //           if 0 or < numBytes, no more bytes available; end of file or the other side of stream is closed
   1.167 +    virtual int         Read(uint8_t *pbufer, int numBytes) = 0;
   1.168 +
   1.169 +    // Skips (ignores) a given # of bytes
   1.170 +    // Same return values as Read
   1.171 +    virtual int         SkipBytes(int numBytes) = 0;
   1.172 +        
   1.173 +    // Returns the number of bytes available to read from a stream without blocking
   1.174 +    // For a file, this should generally be number of bytes to the end
   1.175 +    virtual int         BytesAvailable() = 0;
   1.176 +
   1.177 +    // Causes any implementation's buffered data to be delivered to destination
   1.178 +    // Return 0 for error
   1.179 +    virtual bool        Flush() = 0;
   1.180 +                                                                                            
   1.181 +
   1.182 +    // Need to provide a more optimized implementation that doe snot necessarily involve a lot of seeking
   1.183 +    inline bool         IsEOF() { return !BytesAvailable(); }
   1.184 +    
   1.185 +
   1.186 +    // Seeking                                                                              
   1.187 +    // Returns new position, -1 for error                                                   
   1.188 +    virtual int         Seek(int offset, int origin=Seek_Set) = 0;
   1.189 +    virtual int64_t     LSeek(int64_t offset, int origin=Seek_Set) = 0;
   1.190 +    // Seek simplification
   1.191 +    int                 SeekToBegin()           {return Seek(0); }
   1.192 +    int                 SeekToEnd()             {return Seek(0,Seek_End); }
   1.193 +    int                 Skip(int numBytes)     {return Seek(numBytes,Seek_Cur); }
   1.194 +                        
   1.195 +
   1.196 +    // Appends other file data from a stream
   1.197 +    // Return -1 for error, else # of bytes written
   1.198 +    virtual int         CopyFromStream(File *pstream, int byteSize) = 0;
   1.199 +
   1.200 +    // Closes the file
   1.201 +    // After close, file cannot be accessed 
   1.202 +    virtual bool        Close() = 0;
   1.203 +
   1.204 +
   1.205 +    // ***** Inlines for convenient primitive type serialization
   1.206 +
   1.207 +    // Read/Write helpers
   1.208 +private:
   1.209 +    uint64_t  PRead64()           { uint64_t v = 0; Read((uint8_t*)&v, 8); return v; }
   1.210 +    uint32_t  PRead32()           { uint32_t v = 0; Read((uint8_t*)&v, 4); return v; }
   1.211 +    uint16_t  PRead16()           { uint16_t v = 0; Read((uint8_t*)&v, 2); return v; }
   1.212 +    uint8_t PRead8()            { uint8_t  v = 0; Read((uint8_t*)&v, 1); return v; }
   1.213 +    void    PWrite64(uint64_t v)  { Write((uint8_t*)&v, 8); }
   1.214 +    void    PWrite32(uint32_t v)  { Write((uint8_t*)&v, 4); }
   1.215 +    void    PWrite16(uint16_t v)  { Write((uint8_t*)&v, 2); }
   1.216 +    void    PWrite8(uint8_t v)  { Write((uint8_t*)&v, 1); }
   1.217 +
   1.218 +public:
   1.219 +
   1.220 +    // Writing primitive types - Little Endian
   1.221 +    inline void    WriteUByte(uint8_t v)       { PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v));     }
   1.222 +    inline void    WriteSByte(int8_t v)        { PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v));     }
   1.223 +    inline void    WriteUInt8(uint8_t v)       { PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v));     }
   1.224 +    inline void    WriteSInt8(int8_t v)        { PWrite8((uint8_t)Alg::ByteUtil::SystemToLE(v));     }
   1.225 +    inline void    WriteUInt16(uint16_t v)       { PWrite16((uint16_t)Alg::ByteUtil::SystemToLE(v));   }
   1.226 +    inline void    WriteSInt16(int16_t v)       { PWrite16((uint16_t)Alg::ByteUtil::SystemToLE(v));   }
   1.227 +    inline void    WriteUInt32(uint32_t v)       { PWrite32((uint32_t)Alg::ByteUtil::SystemToLE(v));   }
   1.228 +    inline void    WriteSInt32(int32_t v)       { PWrite32((uint32_t)Alg::ByteUtil::SystemToLE(v));   }
   1.229 +    inline void    WriteUInt64(uint64_t v)       { PWrite64((uint64_t)Alg::ByteUtil::SystemToLE(v));   }
   1.230 +    inline void    WriteSInt64(int64_t v)       { PWrite64((uint64_t)Alg::ByteUtil::SystemToLE(v));   }
   1.231 +    inline void    WriteFloat(float v)         { v = Alg::ByteUtil::SystemToLE(v); Write((uint8_t*)&v, 4); } 
   1.232 +    inline void    WriteDouble(double v)       { v = Alg::ByteUtil::SystemToLE(v); Write((uint8_t*)&v, 8); }
   1.233 +    // Writing primitive types - Big Endian
   1.234 +    inline void    WriteUByteBE(uint8_t v)     { PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v));     }
   1.235 +    inline void    WriteSByteBE(int8_t v)      { PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v));     }
   1.236 +    inline void    WriteUInt8BE(uint16_t v)      { PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v));     }
   1.237 +    inline void    WriteSInt8BE(int16_t v)      { PWrite8((uint8_t)Alg::ByteUtil::SystemToBE(v));     }
   1.238 +    inline void    WriteUInt16BE(uint16_t v)     { PWrite16((uint16_t)Alg::ByteUtil::SystemToBE(v));   }
   1.239 +    inline void    WriteSInt16BE(uint16_t v)     { PWrite16((uint16_t)Alg::ByteUtil::SystemToBE(v));   }
   1.240 +    inline void    WriteUInt32BE(uint32_t v)     { PWrite32((uint32_t)Alg::ByteUtil::SystemToBE(v));   }
   1.241 +    inline void    WriteSInt32BE(uint32_t v)     { PWrite32((uint32_t)Alg::ByteUtil::SystemToBE(v));   }
   1.242 +    inline void    WriteUInt64BE(uint64_t v)     { PWrite64((uint64_t)Alg::ByteUtil::SystemToBE(v));   }
   1.243 +    inline void    WriteSInt64BE(uint64_t v)     { PWrite64((uint64_t)Alg::ByteUtil::SystemToBE(v));   }
   1.244 +    inline void    WriteFloatBE(float v)       { v = Alg::ByteUtil::SystemToBE(v); Write((uint8_t*)&v, 4); }
   1.245 +    inline void    WriteDoubleBE(double v)     { v = Alg::ByteUtil::SystemToBE(v); Write((uint8_t*)&v, 8); }
   1.246 +        
   1.247 +    // Reading primitive types - Little Endian
   1.248 +    inline uint8_t ReadUByte()                 { return (uint8_t)Alg::ByteUtil::LEToSystem(PRead8());    }
   1.249 +    inline int8_t  ReadSByte()                 { return (int8_t)Alg::ByteUtil::LEToSystem(PRead8());    }
   1.250 +    inline uint8_t ReadUInt8()                 { return (uint8_t)Alg::ByteUtil::LEToSystem(PRead8());    }
   1.251 +    inline int8_t  ReadSInt8()                 { return (int8_t)Alg::ByteUtil::LEToSystem(PRead8());    }
   1.252 +    inline uint16_t  ReadUInt16()                { return (uint16_t)Alg::ByteUtil::LEToSystem(PRead16());  }
   1.253 +    inline int16_t ReadSInt16()                { return (int16_t)Alg::ByteUtil::LEToSystem(PRead16());  }
   1.254 +    inline uint32_t  ReadUInt32()                { return (uint32_t)Alg::ByteUtil::LEToSystem(PRead32());  }
   1.255 +    inline int32_t ReadSInt32()                { return (int32_t)Alg::ByteUtil::LEToSystem(PRead32());  }
   1.256 +    inline uint64_t  ReadUInt64()                { return (uint64_t)Alg::ByteUtil::LEToSystem(PRead64());  }
   1.257 +    inline int64_t ReadSInt64()                { return (int64_t)Alg::ByteUtil::LEToSystem(PRead64());  }
   1.258 +    inline float   ReadFloat()                 { float v = 0.0f; Read((uint8_t*)&v, 4); return Alg::ByteUtil::LEToSystem(v); }
   1.259 +    inline double  ReadDouble()                { double v = 0.0; Read((uint8_t*)&v, 8); return Alg::ByteUtil::LEToSystem(v); }
   1.260 +    // Reading primitive types - Big Endian
   1.261 +    inline uint8_t ReadUByteBE()               { return (uint8_t)Alg::ByteUtil::BEToSystem(PRead8());    }
   1.262 +    inline int8_t  ReadSByteBE()               { return (int8_t)Alg::ByteUtil::BEToSystem(PRead8());    }
   1.263 +    inline uint8_t ReadUInt8BE()               { return (uint8_t)Alg::ByteUtil::BEToSystem(PRead8());    }
   1.264 +    inline int8_t  ReadSInt8BE()               { return (int8_t)Alg::ByteUtil::BEToSystem(PRead8());    }
   1.265 +    inline uint16_t  ReadUInt16BE()              { return (uint16_t)Alg::ByteUtil::BEToSystem(PRead16());  }
   1.266 +    inline int16_t ReadSInt16BE()              { return (int16_t)Alg::ByteUtil::BEToSystem(PRead16());  }
   1.267 +    inline uint32_t  ReadUInt32BE()              { return (uint32_t)Alg::ByteUtil::BEToSystem(PRead32());  }
   1.268 +    inline int32_t ReadSInt32BE()              { return (int32_t)Alg::ByteUtil::BEToSystem(PRead32());  }
   1.269 +    inline uint64_t  ReadUInt64BE()              { return (uint64_t)Alg::ByteUtil::BEToSystem(PRead64());  }
   1.270 +    inline int64_t ReadSInt64BE()              { return (int64_t)Alg::ByteUtil::BEToSystem(PRead64());  }
   1.271 +    inline float   ReadFloatBE()               { float v = 0.0f; Read((uint8_t*)&v, 4); return Alg::ByteUtil::BEToSystem(v); }
   1.272 +    inline double  ReadDoubleBE()              { double v = 0.0; Read((uint8_t*)&v, 8); return Alg::ByteUtil::BEToSystem(v); }
   1.273 +};
   1.274 +
   1.275 +
   1.276 +// *** Delegated File
   1.277 +
   1.278 +class DelegatedFile : public File
   1.279 +{
   1.280 +protected:
   1.281 +    // Delegating file pointer
   1.282 +    Ptr<File>     pFile;
   1.283 +
   1.284 +    // Hidden default constructor
   1.285 +    DelegatedFile() : pFile(0)                             { }
   1.286 +    DelegatedFile(const DelegatedFile &source) : File()    { OVR_UNUSED(source); }
   1.287 +public:
   1.288 +    // Constructors
   1.289 +    DelegatedFile(File *pfile) : pFile(pfile)     { }
   1.290 +
   1.291 +    // ** Location Information  
   1.292 +    virtual const char* GetFilePath()                               { return pFile->GetFilePath(); }    
   1.293 +
   1.294 +    // ** File Information                                                      
   1.295 +    virtual bool        IsValid()                                   { return pFile && pFile->IsValid(); }   
   1.296 +    virtual bool        IsWritable()                                { return pFile->IsWritable(); }
   1.297 +//  virtual bool        IsRecoverable()                             { return pFile->IsRecoverable(); }          
   1.298 +                                                                    
   1.299 +    virtual int         Tell()                                      { return pFile->Tell(); }
   1.300 +    virtual int64_t     LTell()                                     { return pFile->LTell(); }
   1.301 +    
   1.302 +    virtual int         GetLength()                                 { return pFile->GetLength(); }
   1.303 +    virtual int64_t     LGetLength()                                { return pFile->LGetLength(); }
   1.304 +    
   1.305 +    //virtual bool      Stat(FileStats *pfs)                        { return pFile->Stat(pfs); }
   1.306 +    
   1.307 +    virtual int         GetErrorCode()                              { return pFile->GetErrorCode(); }
   1.308 +    
   1.309 +    // ** Stream implementation & I/O
   1.310 +    virtual int         Write(const uint8_t *pbuffer, int numBytes)   { return pFile->Write(pbuffer,numBytes); }  
   1.311 +    virtual int         Read(uint8_t *pbuffer, int numBytes)          { return pFile->Read(pbuffer,numBytes); }   
   1.312 +    
   1.313 +    virtual int         SkipBytes(int numBytes)                     { return pFile->SkipBytes(numBytes); }      
   1.314 +    
   1.315 +    virtual int         BytesAvailable()                            { return pFile->BytesAvailable(); } 
   1.316 +    
   1.317 +    virtual bool        Flush()                                     { return pFile->Flush(); }
   1.318 +                                                                    
   1.319 +    // Seeking                                                      
   1.320 +    virtual int         Seek(int offset, int origin=Seek_Set)       { return pFile->Seek(offset,origin); }
   1.321 +    virtual int64_t     LSeek(int64_t offset, int origin=Seek_Set)   { return pFile->LSeek(offset,origin); }
   1.322 +
   1.323 +    virtual int         CopyFromStream(File *pstream, int byteSize) { return pFile->CopyFromStream(pstream,byteSize); }
   1.324 +                        
   1.325 +    // Closing the file 
   1.326 +    virtual bool        Close()                                     { return pFile->Close(); }    
   1.327 +};
   1.328 +
   1.329 +
   1.330 +//-----------------------------------------------------------------------------------
   1.331 +// ***** Buffered File
   1.332 +
   1.333 +// This file class adds buffering to an existing file
   1.334 +// Buffered file never fails by itself; if there's not
   1.335 +// enough memory for buffer, no buffer's used
   1.336 +
   1.337 +class BufferedFile : public DelegatedFile
   1.338 +{   
   1.339 +protected:  
   1.340 +    enum BufferModeType
   1.341 +    {
   1.342 +        NoBuffer,
   1.343 +        ReadBuffer,
   1.344 +        WriteBuffer
   1.345 +    };
   1.346 +
   1.347 +    // Buffer & the mode it's in
   1.348 +    uint8_t*        pBuffer;
   1.349 +    BufferModeType  BufferMode;
   1.350 +    // Position in buffer
   1.351 +    unsigned        Pos;
   1.352 +    // Data in buffer if reading
   1.353 +    unsigned        DataSize;
   1.354 +    // Underlying file position 
   1.355 +    uint64_t        FilePos;
   1.356 +
   1.357 +    // Initializes buffering to a certain mode
   1.358 +    bool    SetBufferMode(BufferModeType mode);
   1.359 +    // Flushes buffer
   1.360 +    // WriteBuffer - write data to disk, ReadBuffer - reset buffer & fix file position  
   1.361 +    void    FlushBuffer();
   1.362 +    // Loads data into ReadBuffer
   1.363 +    // WARNING: Right now LoadBuffer() assumes the buffer's empty
   1.364 +    void    LoadBuffer();
   1.365 +
   1.366 +    // Hidden constructor
   1.367 +    BufferedFile();
   1.368 +    BufferedFile(const BufferedFile &) : DelegatedFile(), pBuffer(NULL), BufferMode(NoBuffer), Pos(0), DataSize(0), FilePos(0) { }
   1.369 +
   1.370 +public:
   1.371 +
   1.372 +    // Constructor
   1.373 +    // - takes another file as source
   1.374 +    BufferedFile(File *pfile);
   1.375 +    ~BufferedFile();
   1.376 +    
   1.377 +    
   1.378 +    // ** Overridden functions
   1.379 +
   1.380 +    // We override all the functions that can possibly
   1.381 +    // require buffer mode switch, flush, or extra calculations
   1.382 +    virtual int         Tell();
   1.383 +    virtual int64_t     LTell();
   1.384 +
   1.385 +    virtual int         GetLength();
   1.386 +    virtual int64_t     LGetLength();
   1.387 +
   1.388 +//  virtual bool        Stat(GFileStats *pfs);  
   1.389 +
   1.390 +    virtual int         Write(const uint8_t *pbufer, int numBytes);
   1.391 +    virtual int         Read(uint8_t *pbufer, int numBytes);
   1.392 +
   1.393 +    virtual int         SkipBytes(int numBytes);
   1.394 +
   1.395 +    virtual int         BytesAvailable();
   1.396 +
   1.397 +    virtual bool        Flush();
   1.398 +
   1.399 +    virtual int         Seek(int offset, int origin=Seek_Set);
   1.400 +    virtual int64_t     LSeek(int64_t offset, int origin=Seek_Set);
   1.401 +
   1.402 +    virtual int         CopyFromStream(File *pstream, int byteSize);
   1.403 +    
   1.404 +    virtual bool        Close();    
   1.405 +};                          
   1.406 +
   1.407 +
   1.408 +//-----------------------------------------------------------------------------------
   1.409 +// ***** Memory File
   1.410 +
   1.411 +class MemoryFile : public File
   1.412 +{
   1.413 +public:
   1.414 +
   1.415 +    const char* GetFilePath()       { return FilePath.ToCStr(); }
   1.416 +
   1.417 +    bool        IsValid()           { return Valid; }
   1.418 +    bool        IsWritable()        { return false; }
   1.419 +
   1.420 +    bool        Flush()             { return true; }
   1.421 +    int         GetErrorCode()      { return 0; }
   1.422 +
   1.423 +    int         Tell()              { return FileIndex; }
   1.424 +    int64_t     LTell()             { return (int64_t) FileIndex; }
   1.425 +
   1.426 +    int         GetLength()         { return FileSize; }
   1.427 +    int64_t     LGetLength()        { return (int64_t) FileSize; }
   1.428 +
   1.429 +    bool        Close()
   1.430 +    {
   1.431 +        Valid = false;
   1.432 +        return false;
   1.433 +    }
   1.434 +
   1.435 +    int         CopyFromStream(File *pstream, int byteSize)
   1.436 +    {   OVR_UNUSED2(pstream, byteSize);
   1.437 +        return 0;
   1.438 +    }
   1.439 +
   1.440 +    int         Write(const uint8_t *pbuffer, int numBytes)
   1.441 +    {   OVR_UNUSED2(pbuffer, numBytes);
   1.442 +        return 0;
   1.443 +    }
   1.444 +
   1.445 +    int         Read(uint8_t *pbufer, int numBytes)
   1.446 +    {
   1.447 +        if (FileIndex + numBytes > FileSize)
   1.448 +        {
   1.449 +            numBytes = FileSize - FileIndex;
   1.450 +        }
   1.451 +
   1.452 +        if (numBytes > 0)
   1.453 +        {
   1.454 +            ::memcpy (pbufer, &FileData [FileIndex], numBytes);
   1.455 +
   1.456 +            FileIndex += numBytes;
   1.457 +        }
   1.458 +
   1.459 +        return numBytes;
   1.460 +    }
   1.461 +
   1.462 +    int         SkipBytes(int numBytes)
   1.463 +    {
   1.464 +        if (FileIndex + numBytes > FileSize)
   1.465 +        {
   1.466 +            numBytes = FileSize - FileIndex;
   1.467 +        }
   1.468 +
   1.469 +        FileIndex += numBytes;
   1.470 +
   1.471 +        return numBytes;
   1.472 +    }
   1.473 +
   1.474 +    int         BytesAvailable()
   1.475 +    {
   1.476 +        return (FileSize - FileIndex);
   1.477 +    }
   1.478 +
   1.479 +    int         Seek(int offset, int origin = Seek_Set)
   1.480 +    {
   1.481 +        switch (origin)
   1.482 +        {
   1.483 +        case Seek_Set : FileIndex  = offset;               break;
   1.484 +        case Seek_Cur : FileIndex += offset;               break;
   1.485 +        case Seek_End : FileIndex  = FileSize - offset;  break;
   1.486 +        }
   1.487 +
   1.488 +        return FileIndex;
   1.489 +    }
   1.490 +
   1.491 +    int64_t     LSeek(int64_t offset, int origin = Seek_Set)
   1.492 +    {
   1.493 +        return (int64_t) Seek((int) offset, origin);
   1.494 +    }
   1.495 +
   1.496 +public:
   1.497 +
   1.498 +    MemoryFile (const String& fileName, const uint8_t *pBuffer, int buffSize)
   1.499 +        : FilePath(fileName)
   1.500 +    {
   1.501 +        FileData  = pBuffer;
   1.502 +        FileSize  = buffSize;
   1.503 +        FileIndex = 0;
   1.504 +        Valid     = (!fileName.IsEmpty() && pBuffer && buffSize > 0) ? true : false;
   1.505 +    }
   1.506 +
   1.507 +    // pfileName should be encoded as UTF-8 to support international file names.
   1.508 +    MemoryFile (const char* pfileName, const uint8_t *pBuffer, int buffSize)
   1.509 +        : FilePath(pfileName)
   1.510 +    {
   1.511 +        FileData  = pBuffer;
   1.512 +        FileSize  = buffSize;
   1.513 +        FileIndex = 0;
   1.514 +        Valid     = (pfileName && pBuffer && buffSize > 0) ? true : false;
   1.515 +    }
   1.516 +private:
   1.517 +
   1.518 +    String       FilePath;
   1.519 +    const uint8_t *FileData;
   1.520 +    int          FileSize;
   1.521 +    int          FileIndex;
   1.522 +    bool         Valid;
   1.523 +};
   1.524 +
   1.525 +
   1.526 +// ***** Global path helpers
   1.527 +
   1.528 +// Find trailing short filename in a path.
   1.529 +const char* OVR_CDECL GetShortFilename(const char* purl);
   1.530 +
   1.531 +} // OVR
   1.532 +
   1.533 +#endif