blob: f7b5ef8561b0971d8cf553ce26e4d2e7a3d04f1b [file] [log] [blame]
Ben Clayton9a6acc42022-07-27 20:50:40 +00001// Copyright 2022 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SRC_TINT_OVERRIDE_ID_H_
16#define SRC_TINT_OVERRIDE_ID_H_
17
18#include <stdint.h>
Loko Kunga4314fa2022-11-04 01:44:43 +000019#include <functional>
Ben Clayton9a6acc42022-07-27 20:50:40 +000020
dan sinclair22b4dd22023-07-21 00:40:07 +000021#include "src/tint/utils/reflection/reflection.h"
Austin Engc982cd42022-11-22 22:23:55 +000022
Ben Clayton9a6acc42022-07-27 20:50:40 +000023namespace tint {
24
25/// OverrideId is a numerical identifier for an override variable, unique per program.
26struct OverrideId {
27 uint16_t value = 0;
Austin Engc982cd42022-11-22 22:23:55 +000028
29 /// Reflect the fields of this struct so that it can be used by tint::ForeachField()
30 TINT_REFLECT(value);
Ben Clayton9a6acc42022-07-27 20:50:40 +000031};
32
33/// Equality operator for OverrideId
34/// @param lhs the OverrideId on the left of the '=' operator
35/// @param rhs the OverrideId on the right of the '=' operator
36/// @returns true if `lhs` is equal to `rhs`
37inline bool operator==(OverrideId lhs, OverrideId rhs) {
38 return lhs.value == rhs.value;
39}
40
41/// Less-than operator for OverrideId
42/// @param lhs the OverrideId on the left of the '<' operator
43/// @param rhs the OverrideId on the right of the '<' operator
44/// @returns true if `lhs` comes before `rhs`
45inline bool operator<(OverrideId lhs, OverrideId rhs) {
46 return lhs.value < rhs.value;
47}
48
49} // namespace tint
50
51namespace std {
52
53/// Custom std::hash specialization for tint::OverrideId.
54template <>
55class hash<tint::OverrideId> {
56 public:
57 /// @param id the override identifier
58 /// @return the hash of the override identifier
59 inline std::size_t operator()(tint::OverrideId id) const {
60 return std::hash<decltype(tint::OverrideId::value)>()(id.value);
61 }
62};
63
64} // namespace std
65
66#endif // SRC_TINT_OVERRIDE_ID_H_