ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Index.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ONERT_UTIL_INDEX_H__
18#define __ONERT_UTIL_INDEX_H__
19
20#include <functional>
21#include <limits>
22#include <stdint.h>
23#include <string>
24
25namespace onert::util
26{
27
36template <typename T, typename DummyTag> class Index
37{
38private:
39 static inline const T UNDEFINED = std::numeric_limits<T>::max();
40
41public:
45 explicit Index(void) : _index{UNDEFINED} {}
51 explicit Index(const T o) : _index{o} {}
57 Index(const Index &o) = default;
58
65 Index &operator=(const T o)
66 {
67 _index = o;
68 return *this;
69 }
70
77 Index &operator=(const Index &o) = default;
78
85 bool operator==(T o) const { return _index == o; }
92 bool operator==(const Index &o) const { return _index == o._index; }
99 bool operator!=(T o) const { return !(*this == o); }
106 bool operator!=(const Index &o) const { return !(*this == o); }
107
114 {
115 Index temp = *this;
116 _index++;
117 return temp;
118 }
119
125 bool valid() const { return _index != UNDEFINED; }
131 bool undefined() const { return _index == UNDEFINED; }
137 T value() const { return _index; }
138
139 bool operator<(const Index &I) const { return value() < I.value(); }
140
146 static T max() { return UNDEFINED - 1; }
147
148private:
149 T _index;
150};
151
152} // namespace onert::util
153
154namespace std
155{
156
157template <typename T, typename Tag> struct hash<::onert::util::Index<T, Tag>>
158{
159 size_t operator()(const ::onert::util::Index<T, Tag> &index) const noexcept
160 {
161 return hash<T>()(index.value());
162 }
163};
164
165} // namespace std
166
167#endif // __ONERT_UTIL_INDEX_H__
A wrapper class for unsigned integral Index NOTE : Max value of the underlying type is used as the in...
Definition Index.h:37
Index(void)
Construct a new Index object.
Definition Index.h:45
bool undefined() const
Check whether the value is undefined.
Definition Index.h:131
bool operator!=(const Index &o) const
Inquality operator.
Definition Index.h:106
Index & operator=(const Index &o)=default
Copy assignment operator.
Index operator++(int)
Post increment operator.
Definition Index.h:113
Index(const T o)
Construct a new Index object with a value in the underlying type.
Definition Index.h:51
bool operator<(const Index &I) const
Definition Index.h:139
bool operator==(const Index &o) const
Equality operator.
Definition Index.h:92
bool valid() const
Check whether the value is valid or not.
Definition Index.h:125
Index & operator=(const T o)
Assign a value in the underlying time.
Definition Index.h:65
static T max()
Return max index value.
Definition Index.h:146
T value() const
Return underlying value.
Definition Index.h:137
bool operator==(T o) const
Equality operator.
Definition Index.h:85
Index(const Index &o)=default
Copy Constructor.
bool operator!=(T o) const
Inquality operator.
Definition Index.h:99