1 /* 2 * Copyright 2023 Google LLC 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 17 #ifndef FCP_AGGREGATION_CORE_MUTABLE_VECTOR_DATA_H_ 18 #define FCP_AGGREGATION_CORE_MUTABLE_VECTOR_DATA_H_ 19 20 #include <cstddef> 21 #include <vector> 22 23 #include "fcp/aggregation/core/tensor_data.h" 24 25 namespace fcp { 26 namespace aggregation { 27 28 // MutableVectorData implements TensorData by wrapping std::vector and using it 29 // as a backing storage. MutableVectorData can be mutated using std::vector 30 // methods. 31 template <typename T> 32 class MutableVectorData : public std::vector<T>, public TensorData { 33 public: 34 // Derive constructors from the base vector class. 35 using std::vector<T>::vector; 36 37 ~MutableVectorData() override = default; 38 39 // Implementation of the base class methods. byte_size()40 size_t byte_size() const override { return this->size() * sizeof(T); } data()41 const void* data() const override { return this->std::vector<T>::data(); } 42 }; 43 44 } // namespace aggregation 45 } // namespace fcp 46 47 #endif // FCP_AGGREGATION_CORE_MUTABLE_VECTOR_DATA_H_ 48