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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TEENAGENT_SEGMENT_H
24 #define TEENAGENT_SEGMENT_H
25 
26 #include "common/stream.h"
27 #include "common/endian.h"
28 
29 namespace TeenAgent {
30 
31 class Segment {
32 	uint32 _size;
33 	byte *_data;
34 
35 public:
Segment()36 	Segment() : _size(0), _data(0) {}
37 	~Segment();
38 
39 	void read(Common::ReadStream *s, uint32 _size);
40 
get_byte(uint32 offset)41 	inline byte get_byte(uint32 offset) const {
42 		assert(offset < _size);
43 		return _data[offset];
44 	}
45 
get_word(uint32 offset)46 	inline uint16 get_word(uint32 offset) const {
47 		assert(offset + 1 < _size);
48 		return READ_LE_UINT16(_data + offset);
49 	}
50 
set_byte(uint32 offset,byte v)51 	inline void set_byte(uint32 offset, byte v) const {
52 		assert(offset < _size);
53 		_data[offset] = v;
54 	}
55 
set_word(uint32 offset,uint16 v)56 	inline void set_word(uint32 offset, uint16 v) const {
57 		assert(offset + 1 < _size);
58 		return WRITE_LE_UINT16(_data + offset, v);
59 	}
60 
ptr(uint32 addr)61 	const byte *ptr(uint32 addr) const {
62 		assert(addr < _size);
63 		return _data + addr;
64 	}
65 
ptr(uint32 addr)66 	byte *ptr(uint32 addr) {
67 		assert(addr < _size);
68 		return _data + addr;
69 	}
70 
size()71 	uint size() const { return _size; }
72 };
73 
74 } // End of namespace TeenAgent
75 
76 #endif
77