/** * 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_UTIL_SHIFTED_VECTOR_H__ #define PANDA_VERIFIER_UTIL_SHIFTED_VECTOR_H__ #include "runtime/include/mem/panda_containers.h" namespace panda::verifier { template class VECTOR = PandaVector> class ShiftedVector : public VECTOR { using Base = VECTOR; public: ShiftedVector() = default; ShiftedVector(typename Base::size_type size) : Base(size) {} typename Base::reference operator[](int idx) { return Base::operator[](static_cast(idx + SHIFT)); } typename Base::const_reference &operator[](int idx) const { return Base::operator[](static_cast(idx + SHIFT)); } typename Base::reference at(int idx) { return Base::at(static_cast(idx + SHIFT)); } typename Base::const_reference &at(int idx) const { return Base::at(static_cast(idx + SHIFT)); } bool InValidRange(int idx) const { return idx + SHIFT >= 0 && static_cast(idx + SHIFT) < Base::size(); } int begin_index() const { return -SHIFT; } int end_index() const { return static_cast(Base::size()) - SHIFT; } void ExtendToInclude(int idx) { if (idx >= end_index()) { Base::resize(Base::size() + static_cast(idx - end_index() + 1)); } } }; } // namespace panda::verifier #endif // !PANDA_VERIFIER_UTIL_SHIFTED_VECTOR_H__