1/* This file is part of Strigi Desktop Search
2 *
3 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#ifndef STRIGI_SUBINPUTSTREAM_H
21#define STRIGI_SUBINPUTSTREAM_H
22
23#include <strigi/strigiconfig.h>
24#include "streambase.h"
25
26namespace Strigi {
27
28/**
29 * @brief Provides access to part of an InputStream only.
30 *
31 * This class allows you to treat a part of in InputStream as
32 * a stream in its own right. For example, <tt>substream.position()</tt>
33 * will return a value relative to the point that the underlying
34 * stream was at when the SubInputStream was created.
35 *
36 * It will prevent data being read from before the point at
37 * which the underlying stream was when the substream was
38 * created. Optionally, it can limit the size of the sub
39 * stream, preventing data from being read past a certain
40 * point even if the underlying stream has more data.
41 */
42class STREAMS_EXPORT SubInputStream : public InputStream {
43private:
44 const int64_t m_offset;
45 InputStream *m_input;
46public:
47 /**
48 * @brief Create a SubInputStream from an InputStream.
49 *
50 * If the @p size parameter is not given, or is -1,
51 * there is no limit on the amount of data that can
52 * be read from the stream other than the amount of
53 * data remaining in the underlying stream.
54 *
55 * If @p size is less than -1, behaviour is undefined.
56 *
57 * @param input the stream to be used as the source of the data
58 * for this substream
59 * @param size the maximum amount of data that may be read
60 * from this substream
61 */
62 explicit SubInputStream(InputStream *input, int64_t size=-1);
63 int32_t read(const char*& start, int32_t min, int32_t max);
64 int64_t reset(int64_t pos);
65 int64_t skip(int64_t ntoskip);
66};
67
68} //end namespace Strigi
69
70#endif
71