]> icculus.org git repositories - divverent/netradiant.git/blob - include/idatastream.h
better shadeangle support by jal
[divverent/netradiant.git] / include / idatastream.h
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   typedef std::size_t size_type;
31   typedef unsigned char byte_type;
32 };
33
34 /// \brief A read-only byte-stream.
35 class InputStream : public StreamBase
36 {
37 public:
38   /// \brief Attempts to read the next \p length bytes from the stream to \p buffer.
39   /// Returns the number of bytes actually stored in \p buffer.
40   virtual size_type read(byte_type* buffer, size_type length) = 0;
41 };
42
43 /// \brief A write-only byte-stream.
44 class OutputStream : public StreamBase
45 {
46 public:
47   /// \brief Attempts to write \p length bytes to the stream from \p buffer.
48   /// Returns the number of bytes actually read from \p buffer.
49   virtual size_type write(const byte_type* buffer, size_type length) = 0;
50 };
51
52 class SeekableStream
53 {
54 public:
55   typedef int offset_type;
56   typedef std::size_t position_type;
57
58   enum seekdir
59   {
60     beg,
61     cur,
62     end,
63   };
64
65   /// \brief Sets the current \p position of the stream relative to the start.
66   virtual position_type seek(position_type position) = 0;
67   /// \brief Sets the current \p position of the stream relative to either the start, end or current position.
68   virtual position_type seek(offset_type offset, seekdir direction) = 0;
69   /// \brief Returns the current position of the stream.
70   virtual position_type tell() const = 0;
71 };
72
73 /// \brief A seekable read-only byte-stream.
74 class SeekableInputStream : public InputStream, public SeekableStream
75 {
76 };
77
78 /// \brief A seekable write-only byte-stream.
79 class SeekableOutputStream : public OutputStream, public SeekableStream
80 {
81 };
82
83 #endif