PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
blIteratorAPI.hpp
Go to the documentation of this file.
1#ifndef BL_IteratorAPI_HPP
2#define BL_IteratorAPI_HPP
4
5//-------------------------------------------------------------------
6// FILE: blIteratorAPI.hpp
7// CLASS: None
8// BASE CLASS: None
9//
10// PURPOSE: This API provides a flexible "smart" iterator, a
11// static array class, and a container class to wrap
12// raw static or dynamic arrays.
13//
14// The API introduces two types of iterators:
15//
16// - Raw iterators -- They wrap raw pointers and can be
17// used to add the concept of iterators
18// to contiguous buffer storage classes.
19//
20// - Smart iterators -- They add "smart" functionality to
21// buffers which already defined raw
22// iterators.
23// By specifying an "Advance" functor,
24// the user can change the behaviour of
25// the iterator.
26//
27// ASSUMPTIONS: - Assumptions made for raw iterators:
28//
29// - The buffer is contiguous
30//
31// - Assumptions made for smart iterators:
32//
33// - The buffer has to define the following members:
34//
35// - size() -- Returns the buffer's size/length
36//
37// - iterator
38// - const_iterator
39// - reverse_iterator
40// - const_reverse_iterator
41//
42// - begin()
43// - end()
44// - cbegin()
45// - cend()
46// - rbegin()
47// - rend()
48// - crbegin()
49// - crend()
50//
51// LOGIC: - The library works in the following way:
52//
53// - It introduces the concept of an "Advance Functor"
54//
55// - This functor is specified by the user to
56// advance the iterator forward/backward in
57// different ways:
58// - For ex. advance the iterator linearly but
59// never passing the buffer's beginning nor its end.
60// - For ex. advance the iterator circularly.
61// - Or the user can provide an "Advance Functor"
62// to advance the iterator whichever other
63// way.
64//
65// - It introduces the concept of a "begin/end" functor
66//
67// - This functor is specified by the user to
68// call the "begin" and "end" functions of a
69// container and to determine the type of
70// iterator.
71//
72// - The functor defines two static functions:
73//
74// - ::begin -- Calls the container's begin
75// function, whatever that is.
76// - ::end -- Calls the container's "end"
77// function, whatever that is.
78//
79// - For ex. If we want to apply a smart iterator
80// to a std::set, we would create a
81// begin/end functor that would call
82// the set's "begin" and "end" functions.
83// Or maybe we want to traverse the
84// set backwards, so the functor would
85// call the set's "rbegin" and "rend"
86// functions.
87//
88// - It gives random access to non-contiguous buffers
89// - For examples, buffers that don't offer random access
90// like std::set, can be used in algorithms that require
91// random access functionality.
92//
93// - The iterators can be used in standard algorithms.
94// - NOTE: Care must be taken when advancing iterators
95// circularly, because algorithms could fall
96// into infinite loops.
97//
98// AUTHOR: Vincenzo Barbato
99// http://www.barbatolabs.com
100// navyenzo@gmail.com
101//
102// LICENSE: MIT-LICENCE
103// http://www.opensource.org/licenses/mit-license.php
104//-------------------------------------------------------------------
106
107//-------------------------------------------------------------------
109{
110 // A collection of simple functions used to
111 // get smart pointers of resources
114
115
116
117
118 // These classes define a raw pointer
119 // iterator and reverse iterator for
120 // iterating through raw arrays of data
127 // A simple static templated array
128 // with some helper functions such
129 // as begin, end, size that makes
130 // it easy to work with iterators
131 // defined in this library
132
133 #include "blArray.hpp"
134
135
136
137
138 // This class is used to wrap a raw
139 // static or dynamic array with the
140 // basic functionality needed to use
141 // the array with the smart iterators
142 // in the blIteratorAPI library
146
147
148
149 // Functors defined in this file are used
150 // by iterators in the blIteratorAPI library
151 // to "advance" and to get "begin" and "end"
152 // iterators.
153
154 #include "blIteratorFunctors.hpp"
156
157
159 // This class provides a generic iterator which
160 // wraps a user specified container.
161 // The iterator is customizable through user-provided
162 // begin, end, advance and distance functors.
163 // Through the user-provided functors, the iterator
164 // can for example be made circular, be made to never
165 // go pass its end, be made to skip every other place
166 // while moving forward, be made into a reverse iterator
167 // or much more.
168
169 #include "blIterator.hpp"
170
171
172
173
174 // Define some useful linear iterators
175
176 template<typename blContainerType>
177 class blLinearIterator : public blIterator<blContainerType,blAdvanceLinearly,blBeginEnd>{using blIterator<blContainerType,blAdvanceLinearly,blBeginEnd>::blIterator;};
179 template<typename blContainerType>
180 class blLinearConstIterator : public blIterator<blContainerType,blAdvanceLinearly,blcBeginEnd>{using blIterator<blContainerType,blAdvanceLinearly,blcBeginEnd>::blIterator;};
182 template<typename blContainerType>
183 class blLinearReverseIterator : public blIterator<blContainerType,blAdvanceLinearly,blrBeginEnd>{using blIterator<blContainerType,blAdvanceLinearly,blrBeginEnd>::blIterator;};
184
185 template<typename blContainerType>
186 class blLinearConstReverseIterator : public blIterator<blContainerType,blAdvanceLinearly,blcrBeginEnd>{using blIterator<blContainerType,blAdvanceLinearly,blcrBeginEnd>::blIterator;};
187
188 // Define some useful circular iterators
189
190 template<typename blContainerType>
191 class blCircularIterator : public blIterator<blContainerType,blAdvanceCircularly,blBeginEnd>{using blIterator<blContainerType,blAdvanceCircularly,blBeginEnd>::blIterator;};
192
193 template<typename blContainerType>
194 class blCircularConstIterator : public blIterator<blContainerType,blAdvanceCircularly,blcBeginEnd>{using blIterator<blContainerType,blAdvanceCircularly,blcBeginEnd>::blIterator;};
195
196 template<typename blContainerType>
197 class blCircularReverseIterator : public blIterator<blContainerType,blAdvanceCircularly,blrBeginEnd>{using blIterator<blContainerType,blAdvanceCircularly,blrBeginEnd>::blIterator;};
198
199 template<typename blContainerType>
200 class blCircularConstReverseIterator : public blIterator<blContainerType,blAdvanceCircularly,blcrBeginEnd>{using blIterator<blContainerType,blAdvanceCircularly,blcrBeginEnd>::blIterator;};
202//-------------------------------------------------------------------
203
204
205#endif // BL_IteratorAPI_HPP