1 /** 2 * Copyright 2019 Huawei Technologies Co., Ltd 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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_ 18 19 namespace mindspore { 20 namespace dataset { 21 template <typename Enum> 22 Enum operator|(Enum lhs, Enum rhs) { 23 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 24 using underlying = typename std::underlying_type<Enum>::type; 25 return static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); 26 } 27 28 template <typename Enum> 29 Enum operator&(Enum lhs, Enum rhs) { 30 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 31 using underlying = typename std::underlying_type<Enum>::type; 32 return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); 33 } 34 35 template <typename Enum> 36 Enum operator^(Enum lhs, Enum rhs) { 37 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 38 using underlying = typename std::underlying_type<Enum>::type; 39 return static_cast<Enum>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); 40 } 41 42 template <typename Enum> 43 Enum &operator|=(Enum &lhs, Enum rhs) { 44 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 45 using underlying = typename std::underlying_type<Enum>::type; 46 lhs = static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs)); 47 return lhs; 48 } 49 50 template <typename Enum> 51 Enum &operator&=(Enum &lhs, Enum rhs) { 52 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 53 using underlying = typename std::underlying_type<Enum>::type; 54 lhs = static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs)); 55 return lhs; 56 } 57 58 template <typename Enum> 59 Enum &operator^=(Enum &lhs, Enum rhs) { 60 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 61 using underlying = typename std::underlying_type<Enum>::type; 62 lhs = static_cast<Enum>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs)); 63 return lhs; 64 } 65 66 template <typename Enum> 67 Enum operator~(Enum v) { 68 static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type"); 69 using underlying = typename std::underlying_type<Enum>::type; 70 return static_cast<Enum>(~static_cast<underlying>(v)); 71 } 72 } // namespace dataset 73 } // namespace mindspore 74 75 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_ 76