Debian Codegraph @

include/idatastream.h

raw
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #if !defined(INCLUDED_IDATASTREAM_H)
23 #define INCLUDED_IDATASTREAM_H
24
25 #include <cstddef>
26
27 class StreamBase
28 {
29 public:
30 virtual ~StreamBase() {}
31 typedef std::size_t size_type;
32 typedef unsigned char byte_type;
33 };
34
35 /// \brief A read-only byte-stream.
36 class InputStream : public StreamBase
37 {
38 public:
39 /// \brief Attempts to read the next \p length bytes from the stream to \p buffer.
40 /// Returns the number of bytes actually stored in \p buffer.
41 virtual size_type read(byte_type* buffer, size_type length) = 0;
42 };
43
44 /// \brief A write-only byte-stream.
45 class OutputStream : public StreamBase
46 {
47 public:
48 /// \brief Attempts to write \p length bytes to the stream from \p buffer.
49 /// Returns the number of bytes actually read from \p buffer.
50 virtual size_type write(const byte_type* buffer, size_type length) = 0;
51 };
52
53 class SeekableStream
54 {
55 public:
56 typedef int offset_type;
57 typedef std::size_t position_type;
58
59 enum seekdir
60 {
61 beg,
62 cur,
63 end,
64 };
65
66 virtual ~SeekableStream() {}
67 /// \brief Sets the current \p position of the stream relative to the start.
68 virtual position_type seek(position_type position) = 0;
69 /// \brief Sets the current \p position of the stream relative to either the start, end or current position.
70 virtual position_type seek(offset_type offset, seekdir direction) = 0;
71 /// \brief Returns the current position of the stream.
72 virtual position_type tell() const = 0;
73 };
74
75 /// \brief A seekable read-only byte-stream.
76 class SeekableInputStream : public InputStream, public SeekableStream
77 {
78 };
79
80 /// \brief A seekable write-only byte-stream.
81 class SeekableOutputStream : public OutputStream, public SeekableStream
82 {
83 };
84
85 #endif