• 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 /**
17  * @addtogroup GraphicGeometry
18  * @{
19  *
20  * @brief Defines Arc.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 #ifndef GRAPHIC_LTE_GEOMETRY_PLAINDATA_ARRAY_H
26 #define GRAPHIC_LTE_GEOMETRY_PLAINDATA_ARRAY_H
27 
28 #include "gfx_utils/diagram/common/common_basics.h"
29 #include "gfx_utils/graphic_log.h"
30 #include "gfx_utils/heap_base.h"
31 #include "securec.h"
32 namespace OHOS {
33 /**
34  * @file geometry_plaindata_array.h
35  *
36  * @brief Defines GeometryPlainDataArray,Variable capacity.
37  *
38  * @since 1.0
39  * @version 1.0
40  */
41 template <class T>
42 class GeometryPlainDataArray : public HeapBase {
43 public:
44     using SelfType = GeometryPlainDataArray<T>;
45 
~GeometryPlainDataArray()46     ~GeometryPlainDataArray()
47     {
48         GeometryArrayAllocator<T>::Deallocate(data_, size_);
49     }
50 
GeometryPlainDataArray()51     GeometryPlainDataArray() : data_(0), size_(0) {}
52     /**
53      *
54      * @brief Construct definitions podarray array.
55      * @param size Initial capacity.
56      * @since 1.0
57      * @version 1.0
58      */
GeometryPlainDataArray(uint32_t size)59     GeometryPlainDataArray(uint32_t size)
60         : data_(GeometryArrayAllocator<T>::Allocate(size)), size_(size) {}
61 
GeometryPlainDataArray(const SelfType & podArray)62     GeometryPlainDataArray(const SelfType& podArray)
63         : data_(GeometryArrayAllocator<T>::Allocate(podArray.size_)), size_(podArray.size_)
64     {
65         if (memcpy_s(data_, sizeof(T) * size_, podArray.data_, sizeof(T) * size_) != EOK) {
66             GRAPHIC_LOGE("GeometryPlainDataArray fail");
67         }
68     }
69 
70     const SelfType& operator=(const SelfType& podArray)
71     {
72         Resize(podArray.GetSize());
73         if (memcpy_s(data_, sizeof(T) * size_, podArray.data_, sizeof(T) * size_) != EOK) {
74             GRAPHIC_LOGE("GeometryPlainDataArray fail");
75         }
76         return *this;
77     }
78     /**
79      * @brief Gets the element of the specified index.
80      *
81      * @since 1.0
82      * @version 1.0
83      */
84     const T& operator[](uint32_t index) const
85     {
86         return data_[index];
87     }
88     /**
89      * @brief Gets the element of the specified index.
90      *
91      * @since 1.0
92      * @version 1.0
93      */
94     T& operator[](uint32_t index)
95     {
96         return data_[index];
97     }
98     /**
99      * @brief Gets the element of the specified index.
100      *
101      * @since 1.0
102      * @version 1.0
103      */
ValueAt(uint32_t index)104     T ValueAt(uint32_t index) const
105     {
106         return data_[index];
107     }
108     /**
109      * @brief Gets the element of the specified index.
110      *
111      * @since 1.0
112      * @version 1.0
113      */
IndexAt(uint32_t index)114     const T& IndexAt(uint32_t index) const
115     {
116         return data_[index];
117     }
118     /**
119      * @brief Gets the element of the specified index.
120      *
121      * @since 1.0
122      * @version 1.0
123      */
IndexAt(uint32_t index)124     T& IndexAt(uint32_t index)
125     {
126         return data_[index];
127     }
128     /**
129      * @brief Get element header address.
130      *
131      * @since 1.0
132      * @version 1.0
133      */
Data()134     const T* Data() const
135     {
136         return data_;
137     }
138     /**
139      * @brief Get element header address.
140      *
141      * @since 1.0
142      * @version 1.0
143      */
Data()144     T* Data()
145     {
146         return data_;
147     }
148 
149     /**
150      *
151      * @brief Modify the capacity of the definitions podarray array.
152      * @param size capacity
153      * @since 1.0
154      * @version 1.0
155      */
Resize(uint32_t size)156     void Resize(uint32_t size)
157     {
158         if (size != size_) {
159             GeometryArrayAllocator<T>::Deallocate(data_, size_);
160             data_ = GeometryArrayAllocator<T>::Allocate(size_ = size);
161         }
162     }
163     /**
164      * @brief Get the number of elements.
165      *
166      * @since 1.0
167      * @version 1.0
168      */
GetSize()169     uint32_t GetSize() const
170     {
171         return size_;
172     }
173 
174 private:
175     T* data_;
176     uint32_t size_;
177 };
178 } // namespace OHOS
179 #endif
180