/* * Copyright 2019 The libgav1 Authors * * 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. */ // libgav1::Vector implementation #ifndef LIBGAV1_SRC_UTILS_VECTOR_H_ #define LIBGAV1_SRC_UTILS_VECTOR_H_ #include <cassert> #include <cstddef> #include <cstdlib> #include <cstring> #include <iterator> #include <new> #include <type_traits> #include <utility> #include "src/utils/compiler_attributes.h" namespace libgav1 { namespace internal { static constexpr size_t kMinVectorAllocation = …; // Returns the smallest power of two greater or equal to 'value'. inline size_t NextPow2(size_t value) { … } // Returns the smallest capacity greater or equal to 'value'. inline size_t NextCapacity(size_t value) { … } //------------------------------------------------------------------------------ // Data structure equivalent to std::vector but returning false and to its last // valid state on memory allocation failure. // std::vector with a custom allocator does not fill this need without // exceptions. template <typename T> class VectorBase { … }; } // namespace internal //------------------------------------------------------------------------------ // Vector class that does *NOT* construct the content on resize(). // Should be reserved to plain old data. template <typename T> class VectorNoCtor : public internal::VectorBase<T> { … }; // This generic vector class will call the constructors. template <typename T> class Vector : public internal::VectorBase<T> { … }; //------------------------------------------------------------------------------ // Define non-member swap() functions in the namespace in which VectorNoCtor // and Vector are implemented. See Effective C++, Item 25. template <typename T> void swap(VectorNoCtor<T>& a, VectorNoCtor<T>& b) { … } template <typename T> void swap(Vector<T>& a, Vector<T>& b) { … } //------------------------------------------------------------------------------ } // namespace libgav1 #endif // LIBGAV1_SRC_UTILS_VECTOR_H_