2018-06-09 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / liboffloadmic / runtime / offload_iterator.h
blobbaf25afbb2fbf6f95006eb2c15221f38394441e4
1 /*
2 Copyright (c) 2014-2016 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 /*! \file
32 \brief Iterator of Variable tables list used by the runtime library
35 #ifndef OFFLOAD_ITERATOR_H_INCLUDED
36 #define OFFLOAD_ITERATOR_H_INCLUDED
38 #include <iterator>
39 #include "offload_table.h"
41 // The following class is for iteration over var table.
42 // It was extracted and moved to this offload_iterator.h file from offload_table.h
43 // to solve the problem with compiling with VS 2010. The problem was in incompatibility
44 // of STL objects in VS 2010 with ones in later VS versions.
46 // var table list iterator
47 class Iterator : public std::iterator<std::input_iterator_tag,
48 VarTable::Entry> {
49 public:
50 Iterator() : m_node(0), m_entry(0) {}
52 explicit Iterator(TableList<VarTable>::Node *node) {
53 new_node(node);
56 Iterator& operator++() {
57 if (m_entry != 0) {
58 m_entry++;
59 while (m_entry->name == 0) {
60 m_entry++;
62 if (m_entry->name == reinterpret_cast<const char*>(-1)) {
63 new_node(m_node->next);
66 return *this;
69 bool operator==(const Iterator &other) const {
70 return m_entry == other.m_entry;
73 bool operator!=(const Iterator &other) const {
74 return m_entry != other.m_entry;
77 const VarTable::Entry* operator*() const {
78 return m_entry;
81 private:
82 void new_node(TableList<VarTable>::Node *node) {
83 m_node = node;
84 m_entry = 0;
85 while (m_node != 0) {
86 m_entry = m_node->table.entries;
87 while (m_entry->name == 0) {
88 m_entry++;
90 if (m_entry->name != reinterpret_cast<const char*>(-1)) {
91 break;
93 m_node = m_node->next;
94 m_entry = 0;
98 private:
99 TableList<VarTable>::Node *m_node;
100 const VarTable::Entry *m_entry;
103 #endif // OFFLOAD_ITERATOR_H_INCLUDED