ScummVM API documentation
nuvie_io.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_FILES_NUVIE_IO_H
23 #define NUVIE_FILES_NUVIE_IO_H
24 
25 #include "common/stream.h"
26 
27 namespace Ultima {
28 namespace Nuvie {
29 
30 class Configuration;
31 
32 class NuvieIO {
33 protected:
34  uint32 size;
35  uint32 pos;
36 public:
37  NuvieIO();
38  virtual ~NuvieIO();
39 
40  virtual void close() {
41  size = 0;
42  pos = 0;
43  };
44 
45  virtual uint8 read1() {
46  return 0;
47  };
48  virtual uint16 read2() {
49  return 0;
50  };
51  virtual uint32 read4() {
52  return 0;
53  };
54 
55  unsigned char *readAll();
56  unsigned char *readBuf(uint32 read_size, uint32 *bytes_read);
57  virtual bool readToBuf(unsigned char *buf, uint32 buf_size) {
58  return false;
59  };
60 
61 
62  virtual bool write1(uint8 src) {
63  return false;
64  };
65  virtual bool write2(uint16 src) {
66  return false;
67  };
68  virtual bool write4(uint32 src) {
69  return false;
70  };
71  virtual uint32 writeBuf(const unsigned char *src, uint32 src_size) {
72  return 0;
73  };
74  virtual uint32 write(NuvieIO *src) {
75  return 0;
76  };
77 
78  uint32 get_size() const {
79  return size;
80  };
81 
82 
83  inline void seekStart() {
84  seek(0);
85  };
86  inline void seekEnd() {
87  seek(size);
88  };
89  virtual void seek(uint32 new_pos) = 0;
90 
91  inline bool is_end() const {
92  return (pos == size - 1);
93  };
94  inline bool is_eof() const {
95  return (size == 0 || pos >= size);
96  };
97  uint32 position() const {
98  return pos;
99  };
100 };
101 
102 #define NUVIE_BUF_COPY true
103 #define NUVIE_BUF_NOCOPY false
104 
105 
106 class NuvieIOBuffer: public NuvieIO {
107 protected:
108 
109  unsigned char *data;
110  bool copied_data;
111 
112 public:
113  NuvieIOBuffer();
114  ~NuvieIOBuffer() override;
115 
116  bool open(unsigned char *buf, uint32 buf_size, bool copy_buf = NUVIE_BUF_COPY);
117 
118  void close() override;
119 
120  unsigned char *get_raw_data() {
121  return data;
122  }; //hehe evil
123 
124  uint8 read1() override;
125  uint16 read2() override;
126  uint32 read4() override;
127  bool readToBuf(unsigned char *buf, uint32 buf_size) override;
128 
129  bool write1(uint8 src) override;
130  bool write2(uint16 src) override;
131  bool write4(uint32 src) override;
132  uint32 writeBuf(const unsigned char *src, uint32 src_size) override;
133  uint32 write(NuvieIO *src) override;
134 
135  void seek(uint32 new_pos) override;
136 };
137 
138 extern char *strgets(char *str, int n, Common::ReadStream *stream);
139 
140 } // End of namespace Nuvie
141 } // End of namespace Ultima
142 
143 #endif
Definition: detection.h:27
Definition: nuvie_io.h:106
Definition: stream.h:385
Definition: nuvie_io.h:32