1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 16 #ifndef PANDA_VERIFICATION_UTIL_ACCESS_H_ 17 #define PANDA_VERIFICATION_UTIL_ACCESS_H_ 18 19 #include <type_traits> 20 21 namespace panda::verifier::access { 22 23 struct ReadOnly { 24 }; 25 struct ReadWrite { 26 }; 27 28 template <typename T> 29 inline constexpr bool if_readonly = std::is_same_v<T, ReadOnly>; 30 31 template <typename T> 32 inline constexpr bool if_readwrite = std::is_same_v<T, ReadWrite>; 33 34 template <typename T, typename R> 35 using enable_if_readonly = std::enable_if_t<std::is_same_v<T, ReadOnly>, R>; 36 37 template <typename T, typename R> 38 using enable_if_readwrite = std::enable_if_t<std::is_same_v<T, ReadWrite>, R>; 39 40 #define ACCESS_IS_READONLY_OR_READWRITE(A) \ 41 static_assert(std::is_same_v<A, panda::verifier::access::ReadOnly> || \ 42 std::is_same_v<A, panda::verifier::access::ReadWrite>) 43 44 } // namespace panda::verifier::access 45 46 #endif // PANDA_VERIFICATION_UTIL_ACCESS_H_ 47