The Pedigree Project 0.1
IteratorAdapter.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_UTILITIES_ITERATORADAPTER_H
21#define KERNEL_UTILITIES_ITERATORADAPTER_H
22
31template <typename T, class Iterator>
33 public:
38 inline IteratorAdapter(const Iterator& x) : m_Iterator(x) {}
41 template <typename T2, class Iterator2>
47 inline ~IteratorAdapter() {}
48
52 m_Iterator = x.m_Iterator;
53 return *this;
54 }
57 template <typename T2, class Iterator2>
59 m_Iterator = x.__getIterator();
60 return *this;
61 }
66 inline bool operator==(const IteratorAdapter& x) const {
67 if (m_Iterator != x.m_Iterator)
68 return false;
69 return true;
70 }
74 ++m_Iterator;
75 return *this;
76 }
80 --m_Iterator;
81 return *this;
82 }
85 inline T& operator*() {
86 return reinterpret_cast<T&>(*m_Iterator);
87 }
90 return reinterpret_cast<T&>(*m_Iterator);
91 }
92
95 inline const Iterator& __getIterator() const {
96 return m_Iterator;
97 }
101 return m_Iterator;
102 }
103
104 private:
107};
108
111#endif
IteratorAdapter reinterpret_casts an Iterators element to another type.
IteratorAdapter & operator--()
IteratorAdapter(const IteratorAdapter &x)
bool operator==(const IteratorAdapter &x) const
const Iterator & __getIterator() const
IteratorAdapter(const IteratorAdapter< T2, Iterator2 > &x)
IteratorAdapter & operator=(const IteratorAdapter< T2, Iterator2 > &x)
Iterator & __getIterator()
IteratorAdapter & operator++()
IteratorAdapter & operator=(const IteratorAdapter &x)
IteratorAdapter(const Iterator &x)
An iterator applicable for many data structures.
Definition Iterator.h:41