| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, 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/properties.hpp" | ||
| 30 | #include "gate/exceptions.hpp" | ||
| 31 | #include "gate/mathematics.h" | ||
| 32 | |||
| 33 | namespace gate | ||
| 34 | { | ||
| 35 | |||
| 36 | 20 | Property::Property() | |
| 37 | { | ||
| 38 | 20 | gate_property_create_empty(&this->impl); | |
| 39 | 20 | } | |
| 40 | 1 | Property::Property(bool_t const& bool_value) | |
| 41 | { | ||
| 42 | 1 | gate_property_create_bool(&this->impl, bool_value); | |
| 43 | 1 | } | |
| 44 | 3 | Property::Property(int64_t int_value) | |
| 45 | { | ||
| 46 | 3 | gate_property_create_int(&this->impl, int_value); | |
| 47 | 3 | } | |
| 48 | 1 | Property::Property(real32_t const& flt_value) | |
| 49 | { | ||
| 50 | 1 | gate_property_create_real(&this->impl, flt_value); | |
| 51 | 1 | } | |
| 52 | 1 | Property::Property(real64_t const& dbl_value) | |
| 53 | { | ||
| 54 | 1 | gate_property_create_real(&this->impl, dbl_value); | |
| 55 | 1 | } | |
| 56 | 1 | Property::Property(gate_string_t const* ptr_string) | |
| 57 | { | ||
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_property_create_string(&this->impl, ptr_string)) |
| 59 | { | ||
| 60 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 61 | } | ||
| 62 | 1 | } | |
| 63 | 2 | Property::Property(char const* c_string) | |
| 64 | { | ||
| 65 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (NULL == gate_property_create_text(&this->impl, c_string)) |
| 66 | { | ||
| 67 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 68 | } | ||
| 69 | 2 | } | |
| 70 | 5 | Property::Property(String const& string_value) | |
| 71 | { | ||
| 72 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (NULL == gate_property_create_string(&this->impl, string_value.c_impl())) |
| 73 | { | ||
| 74 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 75 | } | ||
| 76 | 5 | } | |
| 77 | 1 | Property::Property(Array<Property> const& array_value) | |
| 78 | { | ||
| 79 | gate_property_t* result; | ||
| 80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (array_value.empty()) |
| 81 | { | ||
| 82 | ✗ | result = gate_property_create_array(&this->impl, NULL, 0); | |
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | 1 | result = gate_property_create_array(&this->impl, array_value[0].c_impl(), array_value.length()); | |
| 87 | } | ||
| 88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (result == NULL) |
| 89 | { | ||
| 90 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 91 | } | ||
| 92 | 1 | } | |
| 93 | 1 | Property::Property(object_members_t const& object_value) | |
| 94 | { | ||
| 95 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_property_create_object(&this->impl)) |
| 96 | { | ||
| 97 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 98 | } | ||
| 99 | try | ||
| 100 | { | ||
| 101 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | object_members_t::enumerator_t e = object_value.enumerate(); |
| 102 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | while (e.valid()) |
| 103 | { | ||
| 104 |
3/6✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
|
4 | this->addObjectMember(e->key(), e->value()); |
| 105 | 4 | e.next(); | |
| 106 | } | ||
| 107 | } | ||
| 108 | ✗ | catch (...) | |
| 109 | { | ||
| 110 | ✗ | gate_property_destroy(&this->impl); | |
| 111 | ✗ | throw; | |
| 112 | } | ||
| 113 | 1 | } | |
| 114 | |||
| 115 | 79 | Property::Property(gate_property_t const& src_base) | |
| 116 | { | ||
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
|
79 | if (NULL == gate_property_copy(&this->impl, &src_base)) |
| 118 | { | ||
| 119 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 120 | } | ||
| 121 | 79 | } | |
| 122 | ✗ | Property::Property(gate_struct_t const* ptr_struct) | |
| 123 | { | ||
| 124 | ✗ | result_t result = gate_property_import(&this->impl, GATE_TYPE_STRUCT, ptr_struct); | |
| 125 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 126 | ✗ | } | |
| 127 | |||
| 128 | 63 | Property::Property(Property const& src) | |
| 129 | { | ||
| 130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 63 times.
|
63 | if (NULL == gate_property_copy(&this->impl, &src.impl)) |
| 131 | { | ||
| 132 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 133 | } | ||
| 134 | 63 | } | |
| 135 | 3 | Property& Property::operator=(Property const& src) | |
| 136 | { | ||
| 137 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (this != &src) |
| 138 | { | ||
| 139 | gate_property_t tmp; | ||
| 140 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
3 | if (NULL == gate_property_copy(&tmp, &src.impl)) |
| 141 | { | ||
| 142 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 143 | } | ||
| 144 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | gate_property_destroy(&this->impl); |
| 145 | 3 | this->impl = tmp; | |
| 146 | } | ||
| 147 | 3 | return *this; | |
| 148 | } | ||
| 149 | 356 | Property::~Property() noexcept | |
| 150 | { | ||
| 151 | 178 | gate_property_destroy(&this->impl); | |
| 152 | 178 | } | |
| 153 | |||
| 154 | 6 | void Property::swap(Property& that) noexcept | |
| 155 | { | ||
| 156 | 6 | gate::swapRefs(this->impl, that.impl); | |
| 157 | 6 | } | |
| 158 | |||
| 159 | |||
| 160 | 6 | gate_property_t* Property::c_impl() | |
| 161 | { | ||
| 162 | 6 | return &this->impl; | |
| 163 | } | ||
| 164 | 23 | gate_property_t const* Property::c_impl() const | |
| 165 | { | ||
| 166 | 23 | return &this->impl; | |
| 167 | } | ||
| 168 | |||
| 169 | 35 | Property::TypeEnum Property::getType() const | |
| 170 | { | ||
| 171 | 35 | return TypeEnum(this->impl.value_type); | |
| 172 | } | ||
| 173 | |||
| 174 | 10 | bool_t Property::getBool() const | |
| 175 | { | ||
| 176 | bool_t ret; | ||
| 177 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | result_t result = gate_property_get_bool(&this->impl, &ret); |
| 178 |
3/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 1 times.
|
10 | return GATE_SUCCEEDED(result) ? ret : false; |
| 179 | } | ||
| 180 | 28 | int64_t Property::getInt() const | |
| 181 | { | ||
| 182 | int64_t ret; | ||
| 183 |
1/2✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
|
28 | result_t result = gate_property_get_int(&this->impl, &ret); |
| 184 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | return GATE_SUCCEEDED(result) ? ret : 0; |
| 185 | } | ||
| 186 | 9 | real64_t Property::getReal() const | |
| 187 | { | ||
| 188 | real64_t ret; | ||
| 189 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | result_t result = gate_property_get_real(&this->impl, &ret); |
| 190 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | return GATE_SUCCEEDED(result) ? ret : 0.0; |
| 191 | } | ||
| 192 | 15 | String Property::getString() const | |
| 193 | { | ||
| 194 | gate_string_t str; | ||
| 195 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
15 | result_t result = gate_property_get_string(&this->impl, &str); |
| 196 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
30 | return GATE_SUCCEEDED(result) ? String::createFrom(str) : String(); |
| 197 | } | ||
| 198 | 7 | Array<Property> Property::getArray() const | |
| 199 | { | ||
| 200 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | ArrayList<Property> list; |
| 201 | |||
| 202 |
4/5✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
7 | switch (this->getType()) |
| 203 | { | ||
| 204 | 1 | case Property::Type_Empty: | |
| 205 | { | ||
| 206 | 1 | break; | |
| 207 | } | ||
| 208 | 1 | case Property::Type_Bool: | |
| 209 | case Property::Type_Int: | ||
| 210 | case Property::Type_Real: | ||
| 211 | case Property::Type_String: | ||
| 212 | { | ||
| 213 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | list.add(*this); |
| 214 | 1 | break; | |
| 215 | } | ||
| 216 | |||
| 217 | 4 | case Property::Type_Array: | |
| 218 | { | ||
| 219 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | size_t array_len = gate_property_array_length(&this->impl); |
| 220 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
|
17 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 221 | { | ||
| 222 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | gate_property_t const* var_item = gate_property_array_get(&this->impl, ndx); |
| 223 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (var_item != NULL) |
| 224 | { | ||
| 225 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
26 | Property var(*var_item); |
| 226 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | list.add(var); |
| 227 | } | ||
| 228 | } | ||
| 229 | 4 | break; | |
| 230 | } | ||
| 231 | 1 | case Property::Type_Object: | |
| 232 | { | ||
| 233 | gate_array_t names; | ||
| 234 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_property_member_names(&this->impl, &names)) |
| 235 | { | ||
| 236 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 237 | } | ||
| 238 | try | ||
| 239 | { | ||
| 240 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t array_len = gate_array_length(&names); |
| 241 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 242 | { | ||
| 243 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_string_t const* name = (gate_string_t const*)gate_array_get(&names, ndx); |
| 244 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (name != NULL) |
| 245 | { | ||
| 246 |
2/4✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
|
4 | list.add(String::duplicate(*name)); |
| 247 | } | ||
| 248 | } | ||
| 249 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_array_release(&names); |
| 250 | } | ||
| 251 | ✗ | catch (...) | |
| 252 | { | ||
| 253 | ✗ | gate_array_release(&names);; | |
| 254 | ✗ | throw; | |
| 255 | } | ||
| 256 | 1 | break; | |
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | return list.toArray(); |
| 261 | } | ||
| 262 | 4 | Property::object_members_t Property::getObjectMembers() const | |
| 263 | { | ||
| 264 | 4 | Property::object_members_t ret; | |
| 265 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
4 | switch (this->getType()) |
| 266 | { | ||
| 267 | ✗ | case Property::Type_Empty: | |
| 268 | case Property::Type_Bool: | ||
| 269 | case Property::Type_Int: | ||
| 270 | case Property::Type_Real: | ||
| 271 | case Property::Type_String: | ||
| 272 | { | ||
| 273 | ✗ | break; | |
| 274 | } | ||
| 275 | 1 | case Property::Type_Array: | |
| 276 | { | ||
| 277 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t array_len = gate_property_array_length(&this->impl); |
| 278 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 279 | { | ||
| 280 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_property_t const* ptr_var = gate_property_array_get(&this->impl, ndx); |
| 281 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ptr_var != NULL) |
| 282 | { | ||
| 283 | char buffer[256]; | ||
| 284 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | Property local_var(*ptr_var); |
| 285 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_size_t buffer_used = gate_str_print_int64(buffer, sizeof(buffer), (int64_t)ndx); |
| 286 | 8 | String key = String::createStatic(buffer, buffer_used); | |
| 287 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | ret.add(key, local_var); |
| 288 | } | ||
| 289 | } | ||
| 290 | 1 | break; | |
| 291 | } | ||
| 292 | 3 | case Property::Type_Object: | |
| 293 | { | ||
| 294 | gate_array_t names; | ||
| 295 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | if (NULL != gate_property_member_names(&this->impl, &names)) |
| 296 | { | ||
| 297 | try | ||
| 298 | { | ||
| 299 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | size_t names_count = gate_array_length(&names); |
| 300 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 3 times.
|
10 | for (size_t ndx = 0; ndx != names_count; ++ndx) |
| 301 | { | ||
| 302 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | gate_string_t const* name = (gate_string_t const*)gate_array_get(&names, ndx); |
| 303 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (NULL != name) |
| 304 | { | ||
| 305 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | gate_property_t const* ptr_var = gate_property_member_get(&this->impl, name); |
| 306 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | if (ptr_var != NULL) |
| 307 | { | ||
| 308 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | Property local_var(*ptr_var); |
| 309 | 14 | String key = String::duplicate(*name); | |
| 310 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | ret.add(key, local_var); |
| 311 | } | ||
| 312 | } | ||
| 313 | } | ||
| 314 | |||
| 315 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | gate_array_release(&names); |
| 316 | } | ||
| 317 | ✗ | catch (...) | |
| 318 | { | ||
| 319 | ✗ | gate_array_release(&names); | |
| 320 | } | ||
| 321 | } | ||
| 322 | 3 | break; | |
| 323 | } | ||
| 324 | } | ||
| 325 | 4 | return ret; | |
| 326 | } | ||
| 327 | |||
| 328 | 4 | size_t Property::getArrayLength() const | |
| 329 | { | ||
| 330 | 4 | return gate_property_array_length(&this->impl); | |
| 331 | } | ||
| 332 | 7 | Property Property::getArrayItem(size_t index) const | |
| 333 | { | ||
| 334 | 7 | gate_property_t const* ptr_var = gate_property_array_get(&this->impl, index); | |
| 335 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (NULL == ptr_var) |
| 336 | { | ||
| 337 | ✗ | return Property(); | |
| 338 | } | ||
| 339 | else | ||
| 340 | { | ||
| 341 | 7 | return Property(*ptr_var); | |
| 342 | } | ||
| 343 | } | ||
| 344 | 5 | void Property::addArrayItem(Property const& item) | |
| 345 | { | ||
| 346 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (NULL == gate_property_array_add(&this->impl, item.c_impl())) |
| 347 | { | ||
| 348 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 349 | } | ||
| 350 | 5 | } | |
| 351 | 1 | bool_t Property::removeArrayItem(size_t index) | |
| 352 | { | ||
| 353 | 1 | return gate_property_array_remove(&this->impl, index); | |
| 354 | } | ||
| 355 | |||
| 356 | 2 | Array<String> Property::getObjectMemberNames() const | |
| 357 | { | ||
| 358 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | ArrayList<String> name_list; |
| 359 | gate_array_t names; | ||
| 360 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (NULL != gate_property_member_names(&this->impl, &names)) |
| 361 | { | ||
| 362 | try | ||
| 363 | { | ||
| 364 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t names_count = gate_array_length(&names); |
| 365 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
|
13 | for (size_t ndx = 0; ndx != names_count; ++ndx) |
| 366 | { | ||
| 367 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | gate_string_t const* name = (gate_string_t const*)gate_array_get(&names, ndx); |
| 368 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (NULL != name) |
| 369 | { | ||
| 370 |
1/2✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
11 | name_list.add(String::duplicate(*name)); |
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 374 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_array_release(&names); |
| 375 | } | ||
| 376 | ✗ | catch (...) | |
| 377 | { | ||
| 378 | ✗ | gate_array_release(&names); | |
| 379 | ✗ | throw; | |
| 380 | } | ||
| 381 | } | ||
| 382 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return name_list.toArray(); |
| 383 | } | ||
| 384 | 20 | Property Property::getObjectMember(String const& name) | |
| 385 | { | ||
| 386 | 20 | gate_property_t const* ptr_var = gate_property_member_get(&this->impl, name.c_impl()); | |
| 387 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (ptr_var != NULL) |
| 388 | { | ||
| 389 | 20 | return Property(*ptr_var); | |
| 390 | } | ||
| 391 | else | ||
| 392 | { | ||
| 393 | ✗ | return Property(); | |
| 394 | } | ||
| 395 | } | ||
| 396 | 9 | void Property::addObjectMember(String const& name, Property const& value) | |
| 397 | { | ||
| 398 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
|
9 | if (NULL == gate_property_member_add(&this->impl, name.c_impl(), value.c_impl())) |
| 399 | { | ||
| 400 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 401 | } | ||
| 402 | 9 | } | |
| 403 | 2 | bool_t Property::removeObjectMember(String const& name) | |
| 404 | { | ||
| 405 | 2 | return gate_property_member_remove(&this->impl, name.c_impl()); | |
| 406 | } | ||
| 407 | |||
| 408 | ✗ | void Property::exportToStruct(gate_struct_t* ptr_struct) | |
| 409 | { | ||
| 410 | ✗ | if (this->getType() != Property::Type_Object) | |
| 411 | { | ||
| 412 | ✗ | GATEXX_RAISE_ERROR(results::IncorrectType); | |
| 413 | } | ||
| 414 | ✗ | result_t result = gate_property_export(this->c_impl(), GATE_TYPE_STRUCT, ptr_struct); | |
| 415 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 416 | ✗ | } | |
| 417 | |||
| 418 | 1 | Property Property::createFrom(gate_property_t& movableProp) | |
| 419 | { | ||
| 420 | 1 | Property ret; | |
| 421 | 1 | ret.impl = movableProp; | |
| 422 | 1 | Mem::clear(movableProp); | |
| 423 | 1 | return ret; | |
| 424 | } | ||
| 425 | |||
| 426 | 1 | void Property::createCopy(gate_property_t& target, Property const& source) | |
| 427 | { | ||
| 428 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_property_copy(&target, source.c_impl())) |
| 429 | { | ||
| 430 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 431 | } | ||
| 432 | 1 | } | |
| 433 | 1 | void Property::assignCopy(gate_property_t& target, Property const& source) | |
| 434 | { | ||
| 435 | gate_property_t tmp; | ||
| 436 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property::createCopy(tmp, source); |
| 437 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_property_destroy(&target); |
| 438 | 1 | target = tmp; | |
| 439 | 1 | } | |
| 440 | |||
| 441 | 1 | Property Property::createArray() | |
| 442 | { | ||
| 443 | 1 | Property p; | |
| 444 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_property_create_array(&p.impl, NULL, 0)) |
| 445 | { | ||
| 446 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 447 | } | ||
| 448 | 1 | return p; | |
| 449 | } | ||
| 450 | 1 | Property Property::createObject() | |
| 451 | { | ||
| 452 | 1 | Property p; | |
| 453 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_property_create_object(&p.impl)) |
| 454 | { | ||
| 455 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 456 | } | ||
| 457 | 1 | return p; | |
| 458 | } | ||
| 459 | |||
| 460 | 5 | Property& Property::operator<<(Property const& newArrayItem) | |
| 461 | { | ||
| 462 | 5 | this->addArrayItem(newArrayItem); | |
| 463 | 5 | return *this; | |
| 464 | } | ||
| 465 | |||
| 466 | |||
| 467 | |||
| 468 | |||
| 469 | |||
| 470 | |||
| 471 | |||
| 472 | size_t const PropTable::InvalidIndex = GATE_PROPTABLE_INVALID_INDEX; | ||
| 473 | |||
| 474 | 1 | PropTable::PropTable() | |
| 475 | { | ||
| 476 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_proptable_create(&this->impl)) |
| 477 | { | ||
| 478 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 479 | } | ||
| 480 | 1 | } | |
| 481 | ✗ | PropTable::PropTable(PropTable const& src) | |
| 482 | { | ||
| 483 | ✗ | if (NULL == gate_proptable_copy(&this->impl, &src.impl)) | |
| 484 | { | ||
| 485 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 486 | } | ||
| 487 | ✗ | } | |
| 488 | ✗ | PropTable& PropTable::operator=(PropTable const& src) | |
| 489 | { | ||
| 490 | ✗ | PropTable that(src); | |
| 491 | ✗ | this->swap(that); | |
| 492 | ✗ | return *this; | |
| 493 | } | ||
| 494 | 2 | PropTable::~PropTable() noexcept | |
| 495 | { | ||
| 496 | 1 | gate_proptable_destroy(&this->impl); | |
| 497 | 1 | } | |
| 498 | |||
| 499 | ✗ | void PropTable::swap(PropTable& table) noexcept | |
| 500 | { | ||
| 501 | ✗ | gate::swapRefsNoExcept(this->impl, table.impl); | |
| 502 | ✗ | } | |
| 503 | 1 | gate_proptable_t* PropTable::c_impl() noexcept | |
| 504 | { | ||
| 505 | 1 | return &this->impl; | |
| 506 | } | ||
| 507 | ✗ | gate_proptable_t const* PropTable::c_impl() const noexcept | |
| 508 | { | ||
| 509 | ✗ | return &this->impl; | |
| 510 | } | ||
| 511 | |||
| 512 | 4 | size_t PropTable::insertColumn(String const& columnName, Property::TypeEnum columnType, size_t insertAt) | |
| 513 | { | ||
| 514 | 4 | result_t result = gate_proptable_insert_column(&this->impl, columnName.c_impl(), columnType, insertAt); | |
| 515 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 516 | 4 | size_t colIndex = gate_proptable_get_column_count(&this->impl) - 1; | |
| 517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (insertAt < colIndex) |
| 518 | { | ||
| 519 | ✗ | colIndex = insertAt; | |
| 520 | } | ||
| 521 | 4 | return colIndex; | |
| 522 | } | ||
| 523 | 1 | void PropTable::removeColumn(String const& columnName) | |
| 524 | { | ||
| 525 | 1 | result_t result = gate_proptable_remove_column(&this->impl, columnName.c_impl()); | |
| 526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 527 | 1 | } | |
| 528 | 1 | void PropTable::removeColumnAt(size_t columnIndex) | |
| 529 | { | ||
| 530 | 1 | result_t result = gate_proptable_remove_column_at(&this->impl, columnIndex); | |
| 531 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 532 | 1 | } | |
| 533 | 2 | void PropTable::setColumnName(size_t columnIndex, String const& newName) | |
| 534 | { | ||
| 535 | 2 | result_t result = gate_proptable_set_column_name(&this->impl, columnIndex, newName.c_impl()); | |
| 536 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 537 | 2 | } | |
| 538 | 1 | size_t PropTable::resolveColumnIndex(String const& columnName) | |
| 539 | { | ||
| 540 | 1 | size_t matchIndex = InvalidIndex; | |
| 541 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | result_t result = gate_proptable_resolve_column(&this->impl, columnName.c_impl(), &matchIndex); |
| 542 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 543 | 1 | return matchIndex; | |
| 544 | } | ||
| 545 | |||
| 546 | 6 | size_t PropTable::getColumnCount() const | |
| 547 | { | ||
| 548 | 6 | return gate_proptable_get_column_count(&this->impl); | |
| 549 | } | ||
| 550 | 1 | String PropTable::getColumnName(size_t columnIndex) const | |
| 551 | { | ||
| 552 | 1 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 553 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_proptable_get_column_name(&this->impl, columnIndex, &tmp); |
| 554 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 555 | 2 | return String::createFrom(tmp); | |
| 556 | } | ||
| 557 | ✗ | Property::TypeEnum PropTable::getColumnType(size_t columnIndex) const | |
| 558 | { | ||
| 559 | ✗ | return Property::TypeEnum(gate_proptable_get_column_type(&this->impl, columnIndex)); | |
| 560 | } | ||
| 561 | |||
| 562 | 3 | size_t PropTable::getRowCount() const | |
| 563 | { | ||
| 564 | 3 | return gate_proptable_get_row_count(&this->impl); | |
| 565 | } | ||
| 566 | 3 | Property PropTable::getItemAt(size_t rowIndex, size_t columnIndex) const | |
| 567 | { | ||
| 568 | 3 | gate_property_t const* ptr_prop = gate_proptable_get_item_at(&this->impl, rowIndex, columnIndex); | |
| 569 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (ptr_prop) |
| 570 | { | ||
| 571 | 3 | return Property(*ptr_prop); | |
| 572 | } | ||
| 573 | else | ||
| 574 | { | ||
| 575 | ✗ | GATEXX_RAISE_ERROR(results::OutOfBounds); | |
| 576 | ✗ | return Property(); | |
| 577 | } | ||
| 578 | } | ||
| 579 | 4 | Property PropTable::getItem(size_t rowIndex, String const& columnName) const | |
| 580 | { | ||
| 581 | 4 | gate_property_t const* ptr_prop = gate_proptable_get_item(&this->impl, rowIndex, columnName.c_impl()); | |
| 582 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ptr_prop) |
| 583 | { | ||
| 584 | 4 | return Property(*ptr_prop); | |
| 585 | } | ||
| 586 | else | ||
| 587 | { | ||
| 588 | ✗ | GATEXX_RAISE_EXCEPTION(results::NoMatch, "Cannot resolve column", 0); | |
| 589 | ✗ | return Property(); | |
| 590 | } | ||
| 591 | } | ||
| 592 | |||
| 593 | 2 | size_t PropTable::insertRow(size_t insertAt) | |
| 594 | { | ||
| 595 | 2 | result_t result = gate_proptable_insert_row(&this->impl, insertAt); | |
| 596 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 597 | 2 | size_t rowIndex = gate_proptable_get_row_count(&this->impl) - 1; | |
| 598 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (insertAt < rowIndex) |
| 599 | { | ||
| 600 | ✗ | rowIndex = insertAt; | |
| 601 | } | ||
| 602 | 2 | return rowIndex; | |
| 603 | } | ||
| 604 | 1 | void PropTable::removeRow(size_t rowIndex) | |
| 605 | { | ||
| 606 | 1 | result_t result = gate_proptable_remove_row(&this->impl, rowIndex); | |
| 607 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 608 | 1 | } | |
| 609 | |||
| 610 | 1 | void PropTable::setItemAt(size_t rowIndex, size_t columnIndex, Property const& prop) | |
| 611 | { | ||
| 612 | 1 | result_t result = gate_proptable_set_item_at(&this->impl, rowIndex, columnIndex, prop.c_impl()); | |
| 613 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 614 | 1 | } | |
| 615 | |||
| 616 | 2 | void PropTable::setItem(size_t rowIndex, String const& columnName, Property const& prop) | |
| 617 | { | ||
| 618 | 2 | result_t result = gate_proptable_set_item(&this->impl, rowIndex, columnName.c_impl(), prop.c_impl()); | |
| 619 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 620 | 2 | } | |
| 621 | |||
| 622 | 1 | Property PropTable::operator()(size_t rowIndex, size_t columnIndex) const | |
| 623 | { | ||
| 624 | 1 | return this->getItemAt(rowIndex, columnIndex); | |
| 625 | } | ||
| 626 | 2 | Property PropTable::operator()(size_t rowIndex, String const& columnName) const | |
| 627 | { | ||
| 628 | 2 | return this->getItem(rowIndex, columnName); | |
| 629 | } | ||
| 630 | |||
| 631 | |||
| 632 | } // end of namespace gate | ||
| 633 |