• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "data_buffer.h"
17 
18 #include <new>
19 
20 namespace OHOS {
21 namespace DistributedHardware {
DataBuffer(size_t capacity)22 DataBuffer::DataBuffer(size_t capacity)
23 {
24     if (capacity != 0) {
25         data_ = new (std::nothrow) uint8_t[capacity] {0};
26         if (data_ != nullptr) {
27             capacity_ = capacity;
28         }
29     }
30 }
31 
~DataBuffer()32 DataBuffer::~DataBuffer()
33 {
34     if (data_ != nullptr) {
35         delete []data_;
36         data_ = nullptr;
37     }
38 
39     capacity_ = 0;
40 }
41 
Capacity() const42 size_t DataBuffer::Capacity() const
43 {
44     return capacity_;
45 }
46 
Data() const47 uint8_t *DataBuffer::Data() const
48 {
49     return data_;
50 }
51 } // namespace DistributedHardware
52 } // namespcae OHOS