PageRenderTime 203ms CodeModel.GetById 81ms app.highlight 4ms RepoModel.GetById 116ms app.codeStats 1ms

/mordor/streams/limited.h

http://github.com/mozy/mordor
C Header | 44 lines | 32 code | 11 blank | 1 comment | 0 complexity | 526c6243c27b9ef2bb0e9f01b4ee0a94 MD5 | raw file
 1#ifndef __MORDOR_LIMITED_STREAM_H__
 2#define __MORDOR_LIMITED_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "filter.h"
 6
 7namespace Mordor {
 8
 9class LimitedStream : public MutatingFilterStream
10{
11public:
12    typedef boost::shared_ptr<LimitedStream> ptr;
13
14public:
15    LimitedStream(Stream::ptr parent, long long size, bool own = true);
16
17    void reset() { m_pos = 0; }
18    void reset(long long size) { m_pos = 0; m_size = size; }
19
20    bool strict() { return m_strict; }
21    void strict(bool strict) { m_strict = strict; }
22
23    bool supportsSeek() { return parent()->supportsSeek(); }
24    bool supportsTell() { return true; }
25    bool supportsSize() { return true; }
26    bool supportsTruncate() { return false; }
27
28    using MutatingFilterStream::read;
29    size_t read(Buffer &b, size_t len);
30    using MutatingFilterStream::write;
31    size_t write(const Buffer &b, size_t len);
32    long long seek(long long offset, Anchor anchor = BEGIN);
33    long long size();
34    void truncate(long long size);
35    void unread(const Buffer &b, size_t len);
36
37private:
38    long long m_pos, m_size;
39    bool m_strict;
40};
41
42}
43
44#endif