/** * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _PANDA_VERIFIER_ABSTRACT_INDEX_HPP #define _PANDA_VERIFIER_ABSTRACT_INDEX_HPP #include "index.h" #include "util/hash.h" #include namespace panda::verifier { template class AbstractIndex : private Index { using Base = Index; public: AbstractIndex() = default; AbstractIndex(const AbstractIndex &) = default; AbstractIndex(AbstractIndex &&) = default; AbstractIndex &operator=(const AbstractIndex &) = default; AbstractIndex &operator=(AbstractIndex &&) = default; ~AbstractIndex() = default; bool IsValid() const { return Base::IsValid(); } bool operator==(const AbstractIndex &rhs) const { return static_cast(static_cast(*this)) == static_cast(static_cast(rhs)); } bool operator!=(const AbstractIndex &rhs) const { return !operator==(rhs); } bool operator<(const AbstractIndex &rhs) const { return static_cast(static_cast(*this)) < static_cast(static_cast(rhs)); } bool operator<=(const AbstractIndex &rhs) const { return static_cast(static_cast(*this)) <= static_cast(static_cast(rhs)); } private: AbstractIndex(Int val) : Base {val} {} AbstractIndex &operator=(Int val) { Base::operator=(val); return *this; } void Invalidate() { Base::Invalidate(); } operator Int() const { return Base::operator Int(); } template friend struct std::hash; friend Friend; friend struct std::hash>; }; } // namespace panda::verifier namespace std { template struct hash> { size_t operator()(const panda::verifier::AbstractIndex &i) const noexcept { return panda::verifier::StdHash(i.operator Int()); } }; } // namespace std #endif // !_PANDA_VERIFIER_ABSTRACT_INDEX_HPP