| 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 | 483 | GenericArray::GenericArray() noexcept | |
| 34 | { | ||
| 35 | 483 | gate_array_create_empty(&this->impl); | |
| 36 | 483 | } | |
| 37 | |||
| 38 | 1 | GenericArray::GenericArray(GenericArray const& src) noexcept | |
| 39 | { | ||
| 40 | 1 | gate_array_duplicate(&this->impl, &src.impl); | |
| 41 | 1 | } | |
| 42 | ✗ | GenericArray::GenericArray(gate_array_t const& src) noexcept | |
| 43 | { | ||
| 44 | ✗ | gate_array_duplicate(&this->impl, &src); | |
| 45 | ✗ | } | |
| 46 | 2 | GenericArray& GenericArray::operator=(GenericArray const& src) noexcept | |
| 47 | { | ||
| 48 | 2 | gate_array_release(&this->impl); | |
| 49 | 2 | gate_array_duplicate(&this->impl, &src.impl); | |
| 50 | 2 | return *this; | |
| 51 | } | ||
| 52 | 962 | GenericArray::~GenericArray() noexcept | |
| 53 | { | ||
| 54 | 481 | gate_array_release(&this->impl); | |
| 55 | 481 | } | |
| 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 | 1 | GenericArray& GenericArray::operator=(GenericArray&& src) noexcept | |
| 64 | { | ||
| 65 | 1 | GenericArray tmp; | |
| 66 | 1 | src.swap(tmp); | |
| 67 | 1 | this->swap(tmp); | |
| 68 | 1 | return *this; | |
| 69 | } | ||
| 70 | #endif | ||
| 71 | |||
| 72 | 1 | GenericArray GenericArray::createFrom(gate_array_t& other) noexcept | |
| 73 | { | ||
| 74 | 1 | GenericArray ret; | |
| 75 | 1 | ret.impl = other; | |
| 76 | 1 | Mem::clear(other); | |
| 77 | 1 | return ret; | |
| 78 | } | ||
| 79 | |||
| 80 | 93 | void GenericArray::swap(GenericArray& other) noexcept | |
| 81 | { | ||
| 82 | 93 | gate::swapRefsNoExcept(this->impl, other.impl); | |
| 83 | 93 | } | |
| 84 | 2 | gate_array_t const* GenericArray::c_impl() const noexcept | |
| 85 | { | ||
| 86 | 2 | return &this->impl; | |
| 87 | } | ||
| 88 | 357 | gate_array_t* GenericArray::c_impl() noexcept | |
| 89 | { | ||
| 90 | 357 | return &this->impl; | |
| 91 | } | ||
| 92 | 28 | bool_t GenericArray::empty() const noexcept | |
| 93 | { | ||
| 94 | 28 | return this->length() == 0; | |
| 95 | } | ||
| 96 | 98 | size_t GenericArray::length() const noexcept | |
| 97 | { | ||
| 98 | 98 | return gate_array_length(&this->impl); | |
| 99 | } | ||
| 100 | 5 | size_t GenericArray::size() const noexcept | |
| 101 | { | ||
| 102 | 5 | return this->length(); | |
| 103 | } | ||
| 104 | 2 | bool_t GenericArray::contains(size_t index) const noexcept | |
| 105 | { | ||
| 106 | 2 | return index < this->length(); | |
| 107 | } | ||
| 108 | 1090 | void const* GenericArray::getItemPtr(size_t index) const noexcept | |
| 109 | { | ||
| 110 | 1090 | return gate_array_get(&this->impl, index); | |
| 111 | } | ||
| 112 | 2 | size_t GenericArray::find(gate_comparer_t comparer, void const* compareWith, size_t startAt) const noexcept | |
| 113 | { | ||
| 114 | 2 | return gate_array_find(&this->impl, comparer, compareWith, startAt); | |
| 115 | } | ||
| 116 | |||
| 117 | 1 | GenericArray GenericArray::subset(size_t offset, size_t count) const | |
| 118 | { | ||
| 119 | 1 | GenericArray arr; | |
| 120 |
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)) |
| 121 | { | ||
| 122 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 123 | } | ||
| 124 | 1 | return arr; | |
| 125 | } | ||
| 126 | 1 | GenericArray GenericArray::copy() const | |
| 127 | { | ||
| 128 | 1 | GenericArray arr; | |
| 129 |
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)) |
| 130 | { | ||
| 131 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 132 | } | ||
| 133 | 1 | return arr; | |
| 134 | } | ||
| 135 | 341 | void GenericArray::check_outofmem_nullptr(void const* ptr) | |
| 136 | { | ||
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 341 times.
|
341 | if (NULL == ptr) |
| 138 | { | ||
| 139 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 140 | } | ||
| 141 | 341 | } | |
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | 15 | GenericArrayList::GenericArrayList() noexcept | |
| 146 | { | ||
| 147 | 15 | gate_mem_clear(&impl, sizeof(impl)); | |
| 148 | 15 | } | |
| 149 | 197 | GenericArrayList::GenericArrayList(size_t itemSize, void const* source, size_t sourceLength, gate_mem_copyctor_t cctor, gate_mem_dtor_t dtor) | |
| 150 | 197 | : impl(gate_arraylist_create(itemSize, source, sourceLength, cctor, dtor)) | |
| 151 | { | ||
| 152 | 197 | check_outofmem_nullptr(this->impl.ptr); | |
| 153 | 197 | } | |
| 154 | 3 | GenericArrayList::GenericArrayList(GenericArrayList const& src) | |
| 155 | 3 | : impl(src.impl) | |
| 156 | { | ||
| 157 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (!gate_arraylist_is_null(this->impl)) |
| 158 | { | ||
| 159 | 3 | gate_arraylist_retain(&this->impl); | |
| 160 | } | ||
| 161 | 3 | } | |
| 162 | 3 | GenericArrayList& GenericArrayList::operator=(GenericArrayList const& src) | |
| 163 | { | ||
| 164 | 3 | gate_arraylist_release(&this->impl); | |
| 165 | 3 | this->impl = src.impl; | |
| 166 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (!gate_arraylist_is_null(this->impl)) |
| 167 | { | ||
| 168 | 3 | gate_arraylist_retain(&this->impl); | |
| 169 | } | ||
| 170 | 3 | return *this; | |
| 171 | } | ||
| 172 | 430 | GenericArrayList::~GenericArrayList() noexcept | |
| 173 | { | ||
| 174 | 215 | gate_arraylist_release(&this->impl); | |
| 175 | 215 | } | |
| 176 | 9 | GenericArrayList GenericArrayList::createFrom(gate_arraylist_t& al) | |
| 177 | { | ||
| 178 | 9 | GenericArrayList ret; | |
| 179 | 9 | ret.impl = al; | |
| 180 | 9 | Mem::clear(al); | |
| 181 | 9 | return ret; | |
| 182 | } | ||
| 183 | 13 | gate_arraylist_t& GenericArrayList::c_impl() | |
| 184 | { | ||
| 185 | 13 | return this->impl; | |
| 186 | } | ||
| 187 | 1 | gate_arraylist_t const& GenericArrayList::c_impl() const | |
| 188 | { | ||
| 189 | 1 | return this->impl; | |
| 190 | } | ||
| 191 | 2 | bool_t GenericArrayList::isNull() const noexcept | |
| 192 | { | ||
| 193 | 2 | return gate_arraylist_is_null(this->impl); | |
| 194 | } | ||
| 195 | 8 | void GenericArrayList::swap(GenericArrayList& that) noexcept | |
| 196 | { | ||
| 197 | 8 | gate::swapRefsNoExcept(this->impl, that.impl); | |
| 198 | 8 | } | |
| 199 | 1924 | void GenericArrayList::check_outofmem_nullptr(void const* ptr) | |
| 200 | { | ||
| 201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1924 times.
|
1924 | if (ptr == NULL) |
| 202 | { | ||
| 203 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 204 | } | ||
| 205 | 1924 | } | |
| 206 | 1 | size_t GenericArrayList::itemSize() const noexcept | |
| 207 | { | ||
| 208 | 1 | return gate_arraylist_itemsize(this->impl); | |
| 209 | } | ||
| 210 | 2081 | size_t GenericArrayList::length() const noexcept | |
| 211 | { | ||
| 212 | 2081 | return gate_arraylist_length(this->impl); | |
| 213 | } | ||
| 214 | 4 | bool_t GenericArrayList::empty() const noexcept | |
| 215 | { | ||
| 216 | 4 | return this->length() == 0; | |
| 217 | } | ||
| 218 | 1536 | void* GenericArrayList::add(void const* ptrItem) | |
| 219 | { | ||
| 220 | 1536 | return gate_arraylist_add(this->impl, ptrItem); | |
| 221 | } | ||
| 222 | 3 | void* GenericArrayList::add(void const* ptrItem, size_t repeatCount) | |
| 223 | { | ||
| 224 | 3 | return gate_arraylist_add_n(this->impl, ptrItem, repeatCount); | |
| 225 | } | ||
| 226 | 24 | void* GenericArrayList::insertAt(size_t index, void const* ptrItem) | |
| 227 | { | ||
| 228 | 24 | return gate_arraylist_insert(this->impl, index, ptrItem, 1); | |
| 229 | } | ||
| 230 | 1015 | VoidResult GenericArrayList::removeAt(size_t index) noexcept | |
| 231 | { | ||
| 232 | 1015 | result_t const res = gate_arraylist_remove(this->impl, index, 1); | |
| 233 | 1015 | return makeResult(res); | |
| 234 | } | ||
| 235 | 1 | void GenericArrayList::clear() noexcept | |
| 236 | { | ||
| 237 | 1 | gate_arraylist_clear(this->impl); | |
| 238 | 1 | } | |
| 239 | 1065 | void* GenericArrayList::getItemPtr(size_t index) noexcept | |
| 240 | { | ||
| 241 | 1065 | void* const ptr = gate_arraylist_get(this->impl, index); | |
| 242 | 1065 | return ptr; | |
| 243 | } | ||
| 244 | 15 | void const* GenericArrayList::getItemPtr(size_t index) const noexcept | |
| 245 | { | ||
| 246 | 15 | void const* const ptr = gate_arraylist_get(this->impl, index); | |
| 247 | 15 | return ptr; | |
| 248 | } | ||
| 249 | 4 | bool_t GenericArrayList::contains(size_t index) const noexcept | |
| 250 | { | ||
| 251 | 4 | return index < this->length(); | |
| 252 | } | ||
| 253 | 4 | GenericArrayList GenericArrayList::copy() const | |
| 254 | { | ||
| 255 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_arraylist_t al_copy = gate_arraylist_copy(this->impl); |
| 256 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | check_outofmem_nullptr(al_copy.ptr); |
| 257 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | return GenericArrayList::createFrom(al_copy); |
| 258 | } | ||
| 259 | 164 | GenericArray GenericArrayList::toArray() const | |
| 260 | { | ||
| 261 | 164 | GenericArray ret; | |
| 262 |
1/2✓ Branch 2 taken 164 times.
✗ Branch 3 not taken.
|
164 | gate_array_t* ptr = gate_array_create(ret.c_impl(), this->impl); |
| 263 |
1/2✓ Branch 1 taken 164 times.
✗ Branch 2 not taken.
|
164 | check_outofmem_nullptr(ptr); |
| 264 | 164 | return ret; | |
| 265 | } | ||
| 266 | |||
| 267 | } | ||
| 268 |