Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 1 | // 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 Kung | a4314fa | 2022-11-04 01:44:43 +0000 | [diff] [blame] | 19 | #include <functional> |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 20 | |
dan sinclair | 22b4dd2 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 21 | #include "src/tint/utils/reflection/reflection.h" |
Austin Eng | c982cd4 | 2022-11-22 22:23:55 +0000 | [diff] [blame] | 22 | |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 23 | namespace tint { |
| 24 | |
| 25 | /// OverrideId is a numerical identifier for an override variable, unique per program. |
| 26 | struct OverrideId { |
| 27 | uint16_t value = 0; |
Austin Eng | c982cd4 | 2022-11-22 22:23:55 +0000 | [diff] [blame] | 28 | |
| 29 | /// Reflect the fields of this struct so that it can be used by tint::ForeachField() |
| 30 | TINT_REFLECT(value); |
Ben Clayton | 9a6acc4 | 2022-07-27 20:50:40 +0000 | [diff] [blame] | 31 | }; |
| 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` |
| 37 | inline 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` |
| 45 | inline bool operator<(OverrideId lhs, OverrideId rhs) { |
| 46 | return lhs.value < rhs.value; |
| 47 | } |
| 48 | |
| 49 | } // namespace tint |
| 50 | |
| 51 | namespace std { |
| 52 | |
| 53 | /// Custom std::hash specialization for tint::OverrideId. |
| 54 | template <> |
| 55 | class 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_ |