15490a39dSopenharmony_ci/*
25490a39dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
35490a39dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45490a39dSopenharmony_ci * you may not use this file except in compliance with the License.
55490a39dSopenharmony_ci * You may obtain a copy of the License at
65490a39dSopenharmony_ci *
75490a39dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85490a39dSopenharmony_ci *
95490a39dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105490a39dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115490a39dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125490a39dSopenharmony_ci * See the License for the specific language governing permissions and
135490a39dSopenharmony_ci * limitations under the License.
145490a39dSopenharmony_ci */
155490a39dSopenharmony_ci#ifndef ARRAY_BUFFER_UTIL_H
165490a39dSopenharmony_ci#define ARRAY_BUFFER_UTIL_H
175490a39dSopenharmony_ci
185490a39dSopenharmony_ci#include <memory>
195490a39dSopenharmony_ci
205490a39dSopenharmony_cinamespace OHOS {
215490a39dSopenharmony_cinamespace IntellVoiceUtils {
225490a39dSopenharmony_citemplate<class T>
235490a39dSopenharmony_ciclass ArrayBufferUtil {
245490a39dSopenharmony_cipublic:
255490a39dSopenharmony_ci    ~ArrayBufferUtil() = default;
265490a39dSopenharmony_ci
275490a39dSopenharmony_ci    T *GetData()
285490a39dSopenharmony_ci    {
295490a39dSopenharmony_ci        if (data_ == nullptr) {
305490a39dSopenharmony_ci            return nullptr;
315490a39dSopenharmony_ci        }
325490a39dSopenharmony_ci
335490a39dSopenharmony_ci        return data_.get();
345490a39dSopenharmony_ci    }
355490a39dSopenharmony_ci    uint32_t GetSize() const
365490a39dSopenharmony_ci    {
375490a39dSopenharmony_ci        return size_;
385490a39dSopenharmony_ci    }
395490a39dSopenharmony_ci
405490a39dSopenharmony_ci    template<typename C>
415490a39dSopenharmony_ci    friend std::unique_ptr<ArrayBufferUtil<C>> CreateArrayBuffer(uint32_t size, const C *data);
425490a39dSopenharmony_ci
435490a39dSopenharmony_ciprivate:
445490a39dSopenharmony_ci    ArrayBufferUtil() = default;
455490a39dSopenharmony_ci    bool Init(uint32_t size, const T *data = nullptr);
465490a39dSopenharmony_ci    std::unique_ptr<T[]> data_ = nullptr;
475490a39dSopenharmony_ci    uint32_t size_ = 0;
485490a39dSopenharmony_ci};
495490a39dSopenharmony_ci
505490a39dSopenharmony_ciusing Uint8ArrayBuffer = ArrayBufferUtil<uint8_t>;
515490a39dSopenharmony_citemplate<class T> std::unique_ptr<ArrayBufferUtil<T>> CreateArrayBuffer(uint32_t size, const T *data = nullptr);
525490a39dSopenharmony_ci
535490a39dSopenharmony_ci}
545490a39dSopenharmony_ci}
555490a39dSopenharmony_ci#endif
56