CMemoryReadWriteFile.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __C_MEMORY_READ_WRITE_FILE_H_INCLUDED__
  5. #define __C_MEMORY_READ_WRITE_FILE_H_INCLUDED__
  6. #include "IWriteFile.h"
  7. #include "IReadFile.h"
  8. #include "irrArray.h"
  9. #include "irrString.h"
  10. #include "memory.h"
  11. namespace irr
  12. {
  13. namespace io
  14. {
  15. //! Provides write access to an array as if it is a file.
  16. class CMemoryReadWriteFile : public virtual IWriteFile, public virtual IReadFile
  17. {
  18. public:
  19. CMemoryReadWriteFile(const c8* filename=0);
  20. //! Reads an amount of bytes from the file.
  21. //! \param buffer: Pointer to buffer of bytes to write.
  22. //! \param sizeToWrite: Amount of bytes to written to the file.
  23. //! \return Returns how much bytes were written.
  24. virtual size_t write(const void* buffer, size_t sizeToWrite);
  25. //! Changes position in file, returns true if successful.
  26. //! \param finalPos: Destination position in the file.
  27. //! \param relativeMovement: If set to true, the position in the file is
  28. //! changed relative to current position. Otherwise the position is changed
  29. //! from begin of file.
  30. //! \return Returns true if successful, otherwise false.
  31. virtual bool seek(long finalPos, bool relativeMovement = false);
  32. //! Returns size of file.
  33. //! \return Returns the size of the file in bytes.
  34. virtual long getSize() const;
  35. //! Reads an amount of bytes from the file.
  36. //! \param buffer: Pointer to buffer where to read bytes will be written to.
  37. //! \param sizeToRead: Amount of bytes to read from the file.
  38. //! \return Returns how much bytes were read.
  39. virtual size_t read(void* buffer, size_t sizeToRead);
  40. //! Returns the current position in the file.
  41. //! \return Returns the current position in the file in bytes.
  42. virtual long getPos() const;
  43. //! Returns name of file.
  44. //! \return Returns the file name as zero terminated character string.
  45. virtual const io::path& getFileName() const;
  46. //! Flush the content of the buffer in the file
  47. virtual bool flush() IRR_OVERRIDE;
  48. //! Returns file data as an array
  49. core::array<c8>& getData();
  50. private:
  51. core::array<c8> Data;
  52. io::path FileName;
  53. long Pos;
  54. };
  55. } // end namespace io
  56. } // end namespace irr
  57. #endif // __C_MEMORY_READ_WRITE_FILE_H_INCLUDED__