Sound Open Firmware
Loading...
Searching...
No Matches
fixed_array.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2022 Intel Corporation. All rights reserved.
4 */
6
7#ifndef _ADSP_FIXED_ARRAY_H_
8#define _ADSP_FIXED_ARRAY_H_
9
10#include <stddef.h>
11
12namespace intel_adsp
13{
14 /* \brief Fixed-size container of continuous elements whose size is specified at runtime.
15 *
16 * This container is very similar to the C-array except that its fixed-size is specified at
17 * runtime.
18 * It acts as a facade to expose a memory buffer as a array of elements with same type.
19 *
20 * \tparam VALUE type of the array elements.
21 */
22 template < class VALUE >
23 struct FixedArray {
24 typedef VALUE ValueType;
25
28 explicit FixedArray(ValueType *array, size_t length) :
29 array_(array), length_(length)
30 {}
31
40 ValueType GetValue(int index = 0) const
41 {
42 return array_[index];
43 }
44
49 ValueType operator[](int index) const
50 {
51 return GetValue(index);
52 }
53
56 size_t GetLength(void) const
57 {
58 return length_;
59 }
60
63 void Copy(ValueType *array, size_t length) const
64 {
65 length = MIN(length, length_);
66 for (int i = 0 ; i < length ; i++)
67 array[i] = array_[i];
68 }
69
70 private:
71 ValueType * const array_;
72 size_t const length_;
73 };
74
75} /* namespace intel_adsp */
76
77#endif /* #ifndef _ADSP_FIXED_ARRAY_H_ */
Definition fixed_array.h:13
#define MIN(a, b)
Definition numbers.h:19
VALUE ValueType
Definition fixed_array.h:24
FixedArray(ValueType *array, size_t length)
Initializes a new instance of FixedArray.
Definition fixed_array.h:28
void Copy(ValueType *array, size_t length) const
Copies the values wrapped by the FixedArray into the given C-array.
Definition fixed_array.h:63
size_t GetLength(void) const
Gets the number of elements.
Definition fixed_array.h:56
ValueType operator[](int index) const
Subscript operator.
Definition fixed_array.h:49
ValueType GetValue(int index=0) const
Gets value at the given index of the array.
Definition fixed_array.h:40
uint32_t length
Definition tlv.h:1