PageRenderTime 297ms CodeModel.GetById 121ms app.highlight 97ms RepoModel.GetById 74ms app.codeStats 1ms

/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
 1#ifndef __MORDOR_MEMORY_STREAM_H__
 2#define __MORDOR_MEMORY_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "buffer.h"
 6#include "stream.h"
 7
 8namespace Mordor {
 9
10class MemoryStream : public Stream
11{
12public:
13    typedef boost::shared_ptr<MemoryStream> ptr;
14public:
15    MemoryStream();
16    MemoryStream(const Buffer &b);
17
18    bool supportsRead() { return true; }
19    bool supportsWrite() { return true; }
20    bool supportsSeek() { return true; }
21    bool supportsSize() { return true; }
22    bool supportsTruncate() { return true; }
23    bool supportsFind() { return true; }
24
25    size_t read(Buffer &b, size_t len);
26    size_t read(void *buffer, size_t length);
27    size_t write(const Buffer &b, size_t len);
28    size_t write(const void *b, size_t len);
29    long long seek(long long offset, Anchor anchor = BEGIN);
30    long long size();
31    void truncate(long long size);
32    ptrdiff_t find(char delim, size_t sanitySize = ~0, bool throwIfNotFound = true);
33    ptrdiff_t find(const std::string &str, size_t sanitySize = ~0, bool throwIfNotFound = true);
34
35    // Direct access to memory
36    const Buffer &buffer() const { return m_original; }
37    const Buffer &readBuffer() const { return m_read; }
38
39private:
40    template <class T> size_t readInternal(T &buffer, size_t length);
41    template <class T> size_t writeInternal(const T &buffer, size_t length);
42
43private:
44    Buffer m_read;
45    Buffer m_original;
46    size_t m_offset;
47};
48
49}
50
51#endif