bufferStream.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _BUFFERSTREAM_H_
  23. #define _BUFFERSTREAM_H_
  24. #ifndef _PLATFORM_FILEIO_H_
  25. #include "platform/platformFileIO.h"
  26. #endif
  27. #ifndef _STREAM_H_
  28. #include "io/stream.h"
  29. #endif
  30. //-Mat this class is completely stripped down, it's only purpose is
  31. //to allow writing to a buffer when a Stream is expected, Used for compiling DSO
  32. //straight to memory without saving to a filesystem
  33. class BufferStream : public Stream
  34. {
  35. public:
  36. enum
  37. {
  38. BUFFER_SIZE = 8 * 1024, // this can be changed to anything appropriate
  39. BUFFER_INVALID = 0xffffffff // file offsets must all be less than this
  40. };
  41. protected:
  42. U32 mBufferLen;
  43. U32 mReadPosition;
  44. //putting this after U32's will long align the data
  45. U8 mBuffer[BUFFER_SIZE];
  46. public:
  47. BufferStream(); // default constructor
  48. virtual ~BufferStream(); // destructor
  49. // mandatory methods from Stream base class...
  50. virtual bool hasCapability(const Capability i_cap) const { return false; }
  51. virtual U32 getPosition() const { return mReadPosition; }
  52. virtual bool setPosition(const U32 i_newPosition) { return mReadPosition = i_newPosition; }
  53. virtual U32 getStreamSize() { return mBufferLen; }
  54. virtual void close();
  55. virtual void open();
  56. U8 *getBuffer() { return mBuffer; }
  57. U32 getBufferLength() { return mBufferLen; }
  58. protected:
  59. // more mandatory methods from Stream base class...
  60. virtual bool _read(const U32 i_numBytes, void *o_pBuffer);
  61. virtual bool _write(const U32 i_numBytes, const void* i_pBuffer);
  62. void init();
  63. bool fillBuffer(const U32 i_startPosition) { return false; }
  64. void clearBuffer() {}
  65. static void calcBlockHead(const U32 i_position, U32 *o_blockHead) {}
  66. static void calcBlockBounds(const U32 i_position, U32 *o_blockHead, U32 *o_blockTail) {}
  67. void setStatus() {}
  68. };
  69. #endif // _BUFFERSTREAM_H_