// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include "JFJochException.h" template class AutoIncrVector { std::vector v; T fill_value{}; public: AutoIncrVector() = default; AutoIncrVector(T fill_value) : fill_value(fill_value) {} T& operator[](int64_t pos ) { if (pos < 0) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Negative vector pos"); if (pos >= v.size()) v.resize(pos + 1, fill_value); return v[pos]; } const T& operator[](int64_t pos) const { if (pos < 0) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Negative vector pos"); if (pos >= v.size()) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Vector pos out of bounds"); return v[pos]; } void reserve(int64_t size) { if (size < 0) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Negative size for std::vector reserve"); v.reserve(size); } const std::vector &vec() const { return v; } auto size() const { return v.size(); } bool empty() const { return v.empty(); } void Clear() { v.clear(); } };