PageRenderTime 17ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/mordor/streams/memory.h

http://github.com/mozy/mordor
C Header | 51 lines | 39 code | 10 blank | 2 comment | 0 complexity | 20966d829a191062cf1a7dff2a9e28d2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_MEMORY_STREAM_H__
  2. #define __MORDOR_MEMORY_STREAM_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include "buffer.h"
  5. #include "stream.h"
  6. namespace Mordor {
  7. class MemoryStream : public Stream
  8. {
  9. public:
  10. typedef boost::shared_ptr<MemoryStream> ptr;
  11. public:
  12. MemoryStream();
  13. MemoryStream(const Buffer &b);
  14. bool supportsRead() { return true; }
  15. bool supportsWrite() { return true; }
  16. bool supportsSeek() { return true; }
  17. bool supportsSize() { return true; }
  18. bool supportsTruncate() { return true; }
  19. bool supportsFind() { return true; }
  20. size_t read(Buffer &b, size_t len);
  21. size_t read(void *buffer, size_t length);
  22. size_t write(const Buffer &b, size_t len);
  23. size_t write(const void *b, size_t len);
  24. long long seek(long long offset, Anchor anchor = BEGIN);
  25. long long size();
  26. void truncate(long long size);
  27. ptrdiff_t find(char delim, size_t sanitySize = ~0, bool throwIfNotFound = true);
  28. ptrdiff_t find(const std::string &str, size_t sanitySize = ~0, bool throwIfNotFound = true);
  29. // Direct access to memory
  30. const Buffer &buffer() const { return m_original; }
  31. const Buffer &readBuffer() const { return m_read; }
  32. private:
  33. template <class T> size_t readInternal(T &buffer, size_t length);
  34. template <class T> size_t writeInternal(const T &buffer, size_t length);
  35. private:
  36. Buffer m_read;
  37. Buffer m_original;
  38. size_t m_offset;
  39. };
  40. }
  41. #endif