• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
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 V4L2_CAMERA_HAL_ARRAY_VECTOR_H_
18 #define V4L2_CAMERA_HAL_ARRAY_VECTOR_H_
19 
20 #include <array>
21 #include <vector>
22 
23 namespace v4l2_camera_hal {
24 // ArrayVector behaves like a std::vector of fixed length C arrays,
25 // with push_back accepting std::arrays to standardize length.
26 // Specific methods to get number of arrays/number of elements
27 // are provided and an ambiguous "size" is not, to avoid accidental
28 // incorrect use.
29 template <class T, size_t N>
30 class ArrayVector {
31  public:
data()32   const T* data() const { return mItems.data(); }
33   // The number of arrays.
num_arrays()34   size_t num_arrays() const { return mItems.size() / N; }
35   // The number of elements amongst all arrays.
total_num_elements()36   size_t total_num_elements() const { return mItems.size(); }
37 
38   // Access the ith array.
39   const T* operator[](int i) const { return mItems.data() + (i * N); }
40   T* operator[](int i) { return mItems.data() + (i * N); }
41 
push_back(const std::array<T,N> & values)42   void push_back(const std::array<T, N>& values) {
43     mItems.insert(mItems.end(), values.begin(), values.end());
44   }
45 
46  private:
47   std::vector<T> mItems;
48 };
49 
50 }  // namespace v4l2_camera_hal
51 
52 #endif  // V4L2_CAMERA_HAL_ARRAY_VECTOR_H_
53