Panda3D
Loading...
Searching...
No Matches
iterator_types.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file iterator_types.h
10 * @author drose
11 * @date 1999-02-10
12 */
13
14#ifndef ITERATOR_TYPES_H
15#define ITERATOR_TYPES_H
16
17#include "dtoolbase.h"
18
19/**
20 * This is an iterator adaptor that converts any iterator that returns a pair
21 * (e.g. a map iterator) into one that returns just the first component of
22 * that pair.
23 */
24template<class pair_iterator>
25class first_of_pair_iterator : public pair_iterator {
26public:
27 typedef typename pair_iterator::value_type::first_type value_type;
28
29 first_of_pair_iterator() = default;
30 first_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { }
31
32 value_type operator *() {
33 return pair_iterator::operator *().first;
34 }
35};
36
37/**
38 * This is an iterator adaptor that converts any iterator that returns a pair
39 * (e.g. a map iterator) into one that returns just the second component of
40 * that pair.
41 */
42template<class pair_iterator>
43class second_of_pair_iterator : public pair_iterator {
44public:
45 typedef typename pair_iterator::value_type::second_type value_type;
46
47 second_of_pair_iterator() = default;
48 second_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { }
49
50 value_type operator *() {
51 return pair_iterator::operator *().second;
52 }
53};
54
55/**
56 * This is an iterator adaptor that explicitly typecasts each value returned
57 * by the base iterator to the indicated type.
58 */
59template<class base_iterator, class new_type>
60class typecast_iterator : public base_iterator {
61public:
62 typedef new_type value_type;
63
64 typecast_iterator() = default;
65 typecast_iterator(const base_iterator &init) : base_iterator(init) { }
66
67 value_type operator *() {
68 return (new_type)base_iterator::operator *();
69 }
70};
71
72#endif
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
This is an iterator adaptor that explicitly typecasts each value returned by the base iterator to the...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.