ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
26{
27namespace util
28{
29
38template <typename T, typename DummyTag> class Index
39{
40private:
41 static const T UNDEFINED = std::numeric_limits<T>::max();
42
43public:
47 explicit Index(void) : _index{UNDEFINED} {}
53 explicit Index(const T o) : _index{o} {}
59 Index(const Index &o) = default;
60
67 Index &operator=(const T o)
68 {
69 _index = o;
70 return *this;
71 }
72
79 Index &operator=(const Index &o) = default;
80
87 bool operator==(T o) const { return _index == o; }
94 bool operator==(const Index &o) const { return _index == o._index; }
101 bool operator!=(T o) const { return !(*this == o); }
108 bool operator!=(const Index &o) const { return !(*this == o); }
109
116 {
117 Index temp = *this;
118 _index++;
119 return temp;
120 }
121
127 bool valid() const { return _index != UNDEFINED; }
133 bool undefined() const { return _index == UNDEFINED; }
139 T value() const { return _index; }
140
141 bool operator<(const Index &I) const { return value() < I.value(); }
142
148 static T max() { return UNDEFINED - 1; }
149
150private:
151 T _index;
152};
153
154} // namespace util
155} // namespace onert
156
157namespace std
158{
159
160template <typename T, typename Tag> struct hash<::onert::util::Index<T, Tag>>
161{
162 size_t operator()(const ::onert::util::Index<T, Tag> &index) const noexcept
163 {
164 return hash<T>()(index.value());
165 }
166};
167
168} // namespace std
169
170#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:39
Index(void)
Construct a new Index object.
Definition Index.h:47
bool undefined() const
Check whether the value is undefined.
Definition Index.h:133
bool operator!=(const Index &o) const
Inquality operator.
Definition Index.h:108
Index & operator=(const Index &o)=default
Copy assignment operator.
Index operator++(int)
Post increment operator.
Definition Index.h:115
Index(const T o)
Construct a new Index object with a value in the underlying type.
Definition Index.h:53
bool operator<(const Index &I) const
Definition Index.h:141
bool operator==(const Index &o) const
Equality operator.
Definition Index.h:94
bool valid() const
Check whether the value is valid or not.
Definition Index.h:127
Index & operator=(const T o)
Assign a value in the underlying time.
Definition Index.h:67
static T max()
Return max index value.
Definition Index.h:148
T value() const
Return underlying value.
Definition Index.h:139
bool operator==(T o) const
Equality operator.
Definition Index.h:87
Index(const Index &o)=default
Copy Constructor.
bool operator!=(T o) const
Inquality operator.
Definition Index.h:101
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54