25 #include "common/span.h" 26 #include "common/endian.h" 27 #include "common/file.h" 28 #include "common/memstream.h" 29 #include "common/scummsys.h" 30 #include "common/str.h" 31 #include "common/textconsole.h" 37 uint16 READ_SCIENDIAN_UINT16(
const void *ptr);
38 void WRITE_SCIENDIAN_UINT16(
void *ptr, uint16 val);
42 uint16 READ_SCI11ENDIAN_UINT16(
const void *ptr);
43 uint32 READ_SCI11ENDIAN_UINT32(
const void *ptr);
44 void WRITE_SCI11ENDIAN_UINT16(
void *ptr, uint16 val);
45 void WRITE_SCI11ENDIAN_UINT32(
void *ptr, uint32 val);
48 uint16 READ_SCI32ENDIAN_UINT16(
const void *ptr);
51 #pragma mark SciSpanImpl - SciSpanIterator 53 namespace SciSpanInternal {
54 template <
typename Span,
bool IsConst>
57 typedef typename Span::value_type span_value_type;
61 typedef typename Span::difference_type difference_type;
62 typedef typename Common::RemoveConst<span_value_type>::type value_type;
68 inline SciSpanIterator(span_type *span,
const difference_type index) : super_type(span, index) {}
73 super_type::operator=(other);
84 return operator+(-delta);
88 assert(this->_span == other._span);
89 return this->_index - other._index;
92 inline int16 getInt16SE()
const {
93 return this->_span->getInt16SEAt(this->_index);
96 inline uint16 getUint16SE()
const {
97 return this->_span->getUint16SEAt(this->_index);
100 inline uint16 getUint16SE32()
const {
101 return this->_span->getUint16SE32At(this->_index);
104 inline int32 getInt32SE()
const {
105 return this->_span->getInt32SEAt(this->_index);
108 inline uint32 getUint32SE()
const {
109 return this->_span->getUint32SEAt(this->_index);
112 inline void setUint16SE(uint16 value)
const {
113 this->_span->setUint16SEAt(this->_index, value);
117 inline void setUint32SE(uint32 value)
const {
118 this->_span->setUint32SEAt(this->_index, value);
129 template <
typename ValueType,
template <
typename>
class Derived>
132 typedef Derived<ValueType> derived_type;
134 template <
typename T,
template <
typename>
class U>
friend class SciSpanImpl;
135 #if defined(CXXTEST_RUNNING) && CXXTEST_RUNNING 136 friend class ::SpanTestSuite;
140 typedef typename super_type::value_type value_type;
141 typedef typename super_type::difference_type difference_type;
142 typedef typename super_type::index_type index_type;
143 typedef typename super_type::size_type size_type;
146 typedef typename super_type::pointer pointer;
147 typedef typename super_type::const_pointer const_pointer;
148 typedef typename super_type::reference reference;
149 typedef typename super_type::const_reference const_reference;
154 const size_type size_,
156 const size_type sourceByteOffset_ = 0) :
157 super_type(data_, size_, name_, sourceByteOffset_) {}
159 template <
typename Other>
160 inline SciSpanImpl(
const Other &other) : super_type(other) {}
162 inline const_iterator cbegin()
const {
return const_iterator(&this->impl(), 0); }
163 inline const_iterator cend()
const {
return const_iterator(&this->impl(), this->size()); }
164 inline const_iterator begin()
const {
return const_iterator(&this->impl(), 0); }
165 inline const_iterator end()
const {
return const_iterator(&this->impl(), this->size()); }
166 inline iterator begin() {
return iterator(&this->impl(), 0); }
167 inline iterator end() {
return iterator(&this->impl(), this->size()); }
170 #pragma mark SciSpan - Data access 173 inline int16 getInt16SEAt(
const size_type index)
const {
174 return (int16)getUint16SEAt(index);
177 inline uint16 getUint16SEAt(
const size_type index)
const {
178 this->validate(index,
sizeof(uint16));
179 return READ_SCI11ENDIAN_UINT16(this->data() + index);
182 inline uint16 getUint16SE32At(
const size_type index)
const {
183 this->validate(index,
sizeof(uint16));
184 return READ_SCI32ENDIAN_UINT16(this->data() + index);
187 inline int32 getInt32SEAt(
const size_type index)
const {
188 return (int32)getUint32SEAt(index);
191 inline uint32 getUint32SEAt(
const size_type index)
const {
192 this->validate(index,
sizeof(uint32));
193 return READ_SCI11ENDIAN_UINT32(this->data() + index);
196 inline void setUint16SEAt(
const size_type index, uint16 value) {
197 this->validate(index,
sizeof(uint16), Common::kValidateWrite);
198 WRITE_SCI11ENDIAN_UINT16(this->data() + index, value);
201 inline void setUint32SEAt(
const size_type index, uint32 value) {
202 this->validate(index,
sizeof(uint32), Common::kValidateWrite);
203 WRITE_SCI11ENDIAN_UINT32(this->data() + index, value);
207 #pragma mark SciSpanImpl - ForwardIterator 216 inline const_reference operator*()
const {
217 this->validate(0,
sizeof(value_type));
221 inline reference operator*() {
222 this->validate(0,
sizeof(value_type));
226 inline mutable_derived_type &operator+=(
const difference_type delta) {
227 this->validate(0, delta *
sizeof(value_type), Common::kValidateSeek);
228 this->_data += delta;
229 this->_size -= delta;
233 inline mutable_derived_type &operator++() {
234 return operator+=(1);
237 inline mutable_derived_type operator++(
int) {
238 mutable_derived_type span(this->impl());
243 inline mutable_derived_type operator+(
const difference_type delta)
const {
244 mutable_derived_type span(this->impl());
250 template <
typename ValueType>
257 inline SciSpan() : super_type() {}
259 inline SciSpan(
const pointer data_,
260 const size_type size_,
262 const size_type sourceByteOffset_ = 0) :
263 super_type(data_, size_, name_, sourceByteOffset_) {}
265 template <
typename Other>
266 inline SciSpan(
const Other &other) : super_type(other) {}
Definition: type-traits.h:28