1/*
2 * Copyright (c) 2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20/*
21    RangeIterator.h
22    Copyright (c) 2004-2011 Apple Inc. All rights reserved.
23 */
24
25#pragma once
26#ifndef __AUTO_RANGEITERATOR__
27#define __AUTO_RANGEITERATOR__
28
29
30#include "Definitions.h"
31
32
33namespace Auto {
34
35
36    //----- RangeIterator -----//
37
38    //
39    // Iterate over a range of memory
40    //
41
42    template <class T> class RangeIterator : public Range {
43
44      public:
45
46        //
47        // Constructors
48        //
49        RangeIterator(void *address, const usword_t size)
50        : Range(address, size)
51        {}
52
53        RangeIterator(void *address, void *end)
54        : Range(address, end)
55        {}
56
57        RangeIterator(Range &range)
58        : Range(range)
59        {}
60
61
62        //
63        // next
64        //
65        // Returns next entry in the range or NULL if no more entries available.
66        //
67        inline T *next() {
68            // if cursor is still in range
69            if (address() < end()) {
70                // capture cursor position
71                T *_next = (T *)address();
72                // advance for next call
73                set_address((void *)(_next + 1));
74                // return captured cursor position
75                return _next;
76            }
77
78            // at end
79            return NULL;
80        }
81
82    };
83
84
85};
86
87#endif // __AUTO_RANGEITERATOR__
88
89