ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
scispan.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 DGDS_UTIL_H
23 #define DGDS_UTIL_H
24 
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"
32 
33 namespace Dgds {
34 
36 enum kSciDebugLevels {
37  kDebugLevelSound = 1 << 7,
38 };
39 
40 
41 #pragma mark -
42 #pragma mark SciSpanImpl - SciSpanIterator
43 
44 namespace SciSpanInternal {
45  template <typename Span, bool IsConst>
46  class SciSpanIterator : public Common::SpanInternal::SpanIterator<Span, IsConst> {
48  typedef typename Span::value_type span_value_type;
50 
51  public:
52  typedef typename Span::difference_type difference_type;
53  typedef typename Common::RemoveConst<span_value_type>::type value_type;
56 
57  inline SciSpanIterator() : super_type() {}
58 
59  inline SciSpanIterator(span_type *span, const difference_type index) : super_type(span, index) {}
60 
61  inline SciSpanIterator(const SciSpanIterator &other) : super_type(other) {}
62 
63  inline SciSpanIterator &operator=(const SciSpanIterator &other) {
64  super_type::operator=(other);
65  return *this;
66  }
67 
68  inline SciSpanIterator operator+(const difference_type delta) const {
69  SciSpanIterator it(*this);
70  it += delta;
71  return it;
72  }
73 
74  };
75 } // End of namespace SciSpanInternal
76 
82 template <typename ValueType, template <typename> class Derived>
83 class SciSpanImpl : public Common::NamedSpanImpl<ValueType, Derived> {
85  typedef Derived<ValueType> derived_type;
86 
87  template <typename T, template <typename> class U> friend class SciSpanImpl;
88 #if defined(CXXTEST_RUNNING) && CXXTEST_RUNNING
89  friend class ::SpanTestSuite;
90 #endif
91 
92 public:
93  typedef typename super_type::value_type value_type;
94  typedef typename super_type::difference_type difference_type;
95  typedef typename super_type::index_type index_type;
96  typedef typename super_type::size_type size_type;
99  typedef typename super_type::pointer pointer;
100  typedef typename super_type::const_pointer const_pointer;
101  typedef typename super_type::reference reference;
102  typedef typename super_type::const_reference const_reference;
103 
104  inline SciSpanImpl() : super_type() {}
105 
106  inline SciSpanImpl(const pointer data_,
107  const size_type size_,
108  const Common::String &name_ = Common::String(),
109  const size_type sourceByteOffset_ = 0) :
110  super_type(data_, size_, name_, sourceByteOffset_) {}
111 
112  template <typename Other>
113  inline SciSpanImpl(const Other &other) : super_type(other) {}
114 
115  inline const_iterator cbegin() const { return const_iterator(&this->impl(), 0); }
116  inline const_iterator cend() const { return const_iterator(&this->impl(), this->size()); }
117  inline const_iterator begin() const { return const_iterator(&this->impl(), 0); }
118  inline const_iterator end() const { return const_iterator(&this->impl(), this->size()); }
119  inline iterator begin() { return iterator(&this->impl(), 0); }
120  inline iterator end() { return iterator(&this->impl(), this->size()); }
121 
122 #pragma mark -
123 #pragma mark SciSpanImpl - ForwardIterator
124 
125 // Spans that are used as ForwardIterators must not be allowed inside of
126 // SpanOwner, since this will result in the wrong pointer to memory to be
127 // deleted
128 private:
129  typedef typename Common::RemoveConst<Derived<ValueType> >::type mutable_derived_type;
130 
131 public:
132 
133  inline const_reference operator*() const {
134  this->validate(0, sizeof(value_type));
135  return *this->_data;
136  }
137 
138  inline reference operator*() {
139  this->validate(0, sizeof(value_type));
140  return *this->_data;
141  }
142 
143  inline mutable_derived_type &operator+=(const difference_type delta) {
144  this->validate(0, delta * sizeof(value_type), Common::kValidateSeek);
145  this->_data += delta;
146  this->_size -= delta;
147  return this->impl();
148  }
149 
150  inline mutable_derived_type &operator++() {
151  return operator+=(1);
152  }
153 
154  inline mutable_derived_type operator++(int) {
155  mutable_derived_type span(this->impl());
156  operator+=(1);
157  return span;
158  }
159 
160  inline mutable_derived_type operator+(const difference_type delta) const {
161  mutable_derived_type span(this->impl());
162  span += delta;
163  return span;
164  }
165 };
166 
167 template <typename ValueType>
168 class SciSpan : public SciSpanImpl<ValueType, SciSpan> {
170 
171 public:
172  COMMON_SPAN_TYPEDEFS
173 
174  inline SciSpan() : super_type() {}
175 
176  inline SciSpan(const pointer data_,
177  const size_type size_,
178  const Common::String &name_ = Common::String(),
179  const size_type sourceByteOffset_ = 0) :
180  super_type(data_, size_, name_, sourceByteOffset_) {}
181 
182  template <typename Other>
183  inline SciSpan(const Other &other) : super_type(other) {}
184 };
185 
186 } // End of namespace Dgds
187 
188 #endif // DGDS_UTIL_H
Definition: str.h:59
Definition: scispan.h:83
Definition: span.h:713
Definition: ads.h:28
Definition: span.h:254
Definition: type-traits.h:28
Definition: scispan.h:168
Definition: span.h:690