GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_arrays.cpp
Date: 2026-05-04 21:11:01
Exec Total Coverage
Lines: 98 124 79.0%
Functions: 34 40 85.0%
Branches: 9 24 37.5%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/arrays.hpp"
30
31 namespace gate
32 {
33 326 GenericArray::GenericArray() noexcept
34 {
35 326 gate_array_create_empty(&this->impl);
36 326 }
37
38 GenericArray::GenericArray(GenericArray const& src) noexcept
39 {
40 gate_array_duplicate(&this->impl, &src.impl);
41 }
42 GenericArray::GenericArray(gate_array_t const& src) noexcept
43 {
44 gate_array_duplicate(&this->impl, &src);
45 }
46 GenericArray& GenericArray::operator=(GenericArray const& src) noexcept
47 {
48 gate_array_release(&this->impl);
49 gate_array_duplicate(&this->impl, &src.impl);
50 return *this;
51 }
52 650 GenericArray::~GenericArray() noexcept
53 {
54 325 gate_array_release(&this->impl);
55 325 }
56
57 #if defined(GATE_COMPILER_SUPPORTS_CPP_MOVEREFS)
58 1 GenericArray::GenericArray(GenericArray&& src) noexcept
59 1 : impl(src.impl)
60 {
61 1 gate_array_create_empty(&src.impl);
62 1 }
63 GenericArray& GenericArray::operator=(GenericArray&& src) noexcept
64 {
65 GenericArray tmp;
66 src.swap(tmp);
67 this->swap(tmp);
68 return *this;
69 }
70 #endif
71
72 57 void GenericArray::swap(GenericArray& other) noexcept
73 {
74 57 gate::swapRefsNoExcept(this->impl, other.impl);
75 57 }
76 1 gate_array_t const* GenericArray::c_impl() const noexcept
77 {
78 1 return &this->impl;
79 }
80 237 gate_array_t* GenericArray::c_impl() noexcept
81 {
82 237 return &this->impl;
83 }
84 14 bool_t GenericArray::empty() const noexcept
85 {
86 14 return this->length() == 0;
87 }
88 60 size_t GenericArray::length() const noexcept
89 {
90 60 return gate_array_length(&this->impl);
91 }
92 5 size_t GenericArray::size() const noexcept
93 {
94 5 return this->length();
95 }
96 2 bool_t GenericArray::contains(size_t index) const noexcept
97 {
98 2 return index < this->length();
99 }
100 1076 void const* GenericArray::getItemPtr(size_t index) const noexcept
101 {
102 1076 return gate_array_get(&this->impl, index);
103 }
104 1 GenericArray GenericArray::subset(size_t offset, size_t count) const
105 {
106 1 GenericArray arr;
107
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_array_subset(&arr.impl, &this->impl, offset, count))
108 {
109 GATEXX_RAISE_ERROR(results::OutOfMemory);
110 }
111 1 return arr;
112 }
113 1 GenericArray GenericArray::copy() const
114 {
115 1 GenericArray arr;
116
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_array_copy(&arr.impl, &this->impl))
117 {
118 GATEXX_RAISE_ERROR(results::OutOfMemory);
119 }
120 1 return arr;
121 }
122 232 void GenericArray::check_outofmem_nullptr(void const* ptr)
123 {
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 232 times.
232 if (NULL == ptr)
125 {
126 GATEXX_RAISE_ERROR(results::OutOfMemory);
127 }
128 232 }
129
130
131
132 4 GenericArrayList::GenericArrayList() noexcept
133 4 : impl(NULL)
134 {
135 4 }
136 132 GenericArrayList::GenericArrayList(size_t itemSize, void const* source, size_t sourceLength, gate_mem_copyctor_t cctor, gate_mem_dtor_t dtor)
137 {
138 132 this->impl = gate_arraylist_create(itemSize, source, sourceLength, cctor, dtor);
139 132 check_outofmem_nullptr(this->impl);
140 132 }
141 7 GenericArrayList::GenericArrayList(gate_arraylist_t al)
142 7 : impl(al)
143 {
144 7 }
145 GenericArrayList::GenericArrayList(GenericArrayList const& src)
146 : impl(src.impl)
147 {
148 if (this->impl != NULL)
149 {
150 gate_arraylist_retain(this->impl);
151 }
152 }
153 1 GenericArrayList& GenericArrayList::operator=(GenericArrayList const& src)
154 {
155 1 gate_arraylist_release(this->impl);
156 1 this->impl = src.impl;
157
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this->impl != NULL)
158 {
159 1 gate_arraylist_retain(this->impl);
160 }
161 1 return *this;
162 }
163 286 GenericArrayList::~GenericArrayList() noexcept
164 {
165 143 gate_arraylist_release(this->impl);
166 143 }
167 11 gate_arraylist_t GenericArrayList::c_impl() const
168 {
169 11 return this->impl;
170 }
171 8 void GenericArrayList::swap(GenericArrayList& that) noexcept
172 {
173 8 gate::swapRefsNoExcept(this->impl, that.impl);
174 8 }
175 1543 void GenericArrayList::check_outofmem_nullptr(void const* ptr)
176 {
177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1543 times.
1543 if (ptr == NULL)
178 {
179 GATEXX_RAISE_ERROR(results::OutOfMemory);
180 }
181 1543 }
182 size_t GenericArrayList::itemSize() const noexcept
183 {
184 return gate_arraylist_itemsize(this->impl);
185 }
186 2068 size_t GenericArrayList::length() const noexcept
187 {
188 2068 return gate_arraylist_length(this->impl);
189 }
190 3 bool_t GenericArrayList::empty() const noexcept
191 {
192 3 return this->length() == 0;
193 }
194 1299 void* GenericArrayList::add(void const* ptrItem)
195 {
196 1299 return gate_arraylist_add(this->impl, ptrItem);
197 }
198 1 void* GenericArrayList::add(void const* ptrItem, size_t repeatCount)
199 {
200 1 return gate_arraylist_add_n(this->impl, ptrItem, repeatCount);
201 }
202 3 void* GenericArrayList::insertAt(size_t index, void const* ptrItem)
203 {
204 3 return gate_arraylist_insert(this->impl, index, ptrItem, 1);
205 }
206 1006 VoidResult GenericArrayList::removeAt(size_t index) noexcept
207 {
208 1006 result_t const res = gate_arraylist_remove(this->impl, index, 1);
209 1006 return makeResult(res);
210 }
211 1 void GenericArrayList::clear() noexcept
212 {
213 1 gate_arraylist_clear(this->impl);
214 1 }
215 1058 void* GenericArrayList::getItemPtr(size_t index) noexcept
216 {
217 1058 void* const ptr = gate_arraylist_get(this->impl, index);
218 1058 return ptr;
219 }
220 9 void const* GenericArrayList::getItemPtr(size_t index) const noexcept
221 {
222 9 void const* const ptr = gate_arraylist_get(this->impl, index);
223 9 return ptr;
224 }
225 4 bool_t GenericArrayList::contains(size_t index) const noexcept
226 {
227 4 return index < this->length();
228 }
229 3 GenericArrayList GenericArrayList::copy() const
230 {
231 3 gate_arraylist_t al_copy = gate_arraylist_copy(this->impl);
232 3 check_outofmem_nullptr(al_copy);
233 3 return GenericArrayList(al_copy);
234 }
235 108 GenericArray GenericArrayList::toArray() const
236 {
237 108 GenericArray ret;
238
1/2
✓ Branch 2 taken 108 times.
✗ Branch 3 not taken.
108 gate_array_t* ptr = gate_array_create(ret.c_impl(), this->impl);
239
1/2
✓ Branch 1 taken 108 times.
✗ Branch 2 not taken.
108 check_outofmem_nullptr(ptr);
240 108 return ret;
241 }
242
243 }
244