PageRenderTime 151ms CodeModel.GetById 50ms app.highlight 5ms RepoModel.GetById 75ms app.codeStats 0ms

/mordor/streams/singleplex.h

http://github.com/mozy/mordor
C Header | 48 lines | 37 code | 10 blank | 1 comment | 8 complexity | 205a333ac001063260f879fb55077c42 MD5 | raw file
 1#ifndef __MORDOR_SINGLEPLEX_STREAM_H__
 2#define __MORDOR_SINGLEPLEX_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "filter.h"
 6
 7namespace Mordor {
 8
 9class SingleplexStream : public FilterStream
10{
11public:
12    enum Type {
13        READ,
14        WRITE
15    };
16
17    SingleplexStream(Stream::ptr parent, Type type, bool own = true);
18
19    bool supportsRead() { return m_type == READ; }
20    bool supportsWrite() { return m_type == WRITE; }
21    bool supportsTruncate()
22    { return m_type == WRITE && parent()->supportsTruncate(); }
23    bool supportsFind()
24    { return m_type == READ && parent()->supportsFind(); }
25    bool supportsUnread()
26    { return m_type == READ && parent()->supportsUnread(); }
27
28    void close(CloseType type = BOTH);
29
30    size_t read(Buffer &buffer, size_t length);
31    size_t read(void *buffer, size_t length);
32    size_t write(const Buffer &buffer, size_t length);
33    size_t write(const void *buffer, size_t length);
34    void truncate(long long size);
35    void flush(bool flushParent = true);
36    ptrdiff_t find(char delimiter, size_t sanitySize = ~0,
37        bool throwIfNotFound = true);
38    ptrdiff_t find(const std::string &delimiter,
39        size_t sanitySize = ~0, bool throwIfNotFound = true);
40    void unread(const Buffer &buffer, size_t length);
41
42private:
43    Type m_type;
44};
45
46}
47
48#endif