1 /* 2 * Copyright 2024 The Android Open Source Project 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 #pragma once 18 19 #include <ftl/mixins.h> 20 #include <sys/types.h> 21 #include <string> 22 23 #include <ostream> 24 25 namespace android::ui { 26 27 // Type-safe wrapper for a logical display id. 28 struct LogicalDisplayId : ftl::Constructible<LogicalDisplayId, int32_t>, 29 ftl::Equatable<LogicalDisplayId>, 30 ftl::Orderable<LogicalDisplayId> { 31 using Constructible::Constructible; 32 valLogicalDisplayId33 constexpr auto val() const { return ftl::to_underlying(*this); } 34 isValidLogicalDisplayId35 constexpr bool isValid() const { return val() >= 0; } 36 toStringLogicalDisplayId37 std::string toString() const { return std::to_string(val()); } 38 39 static const LogicalDisplayId INVALID; 40 static const LogicalDisplayId DEFAULT; 41 }; 42 43 constexpr inline LogicalDisplayId LogicalDisplayId::INVALID{-1}; 44 constexpr inline LogicalDisplayId LogicalDisplayId::DEFAULT{0}; 45 46 inline std::ostream& operator<<(std::ostream& stream, LogicalDisplayId displayId) { 47 return stream << displayId.val(); 48 } 49 50 } // namespace android::ui 51 52 namespace std { 53 template <> 54 struct hash<android::ui::LogicalDisplayId> { 55 size_t operator()(const android::ui::LogicalDisplayId& displayId) const { 56 return hash<int32_t>()(displayId.val()); 57 } 58 }; 59 } // namespace std