| 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 | 7 | Property::Property() | |
| 37 | { | ||
| 38 | 7 | gate_property_create_empty(&this->impl); | |
| 39 | 7 | } | |
| 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 | 40 | Property::Property(gate_property_t const& src_base) | |
| 116 | { | ||
| 117 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
|
40 | if (NULL == gate_property_copy(&this->impl, &src_base)) |
| 118 | { | ||
| 119 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 120 | } | ||
| 121 | 40 | } | |
| 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 | 36 | Property::Property(Property const& src) | |
| 129 | { | ||
| 130 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
|
36 | if (NULL == gate_property_copy(&this->impl, &src.impl)) |
| 131 | { | ||
| 132 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 133 | } | ||
| 134 | 36 | } | |
| 135 | 1 | Property& Property::operator=(Property const& src) | |
| 136 | { | ||
| 137 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (this != &src) |
| 138 | { | ||
| 139 | gate_property_t tmp; | ||
| 140 |
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_copy(&tmp, &src.impl)) |
| 141 | { | ||
| 142 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 143 | } | ||
| 144 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_property_destroy(&this->impl); |
| 145 | 1 | this->impl = tmp; | |
| 146 | } | ||
| 147 | 1 | return *this; | |
| 148 | } | ||
| 149 | 198 | Property::~Property() noexcept | |
| 150 | { | ||
| 151 | 99 | gate_property_destroy(&this->impl); | |
| 152 | 99 | } | |
| 153 | |||
| 154 | 2 | void Property::swap(Property& that) noexcept | |
| 155 | { | ||
| 156 | 2 | gate::swapRefs(this->impl, that.impl); | |
| 157 | 2 | } | |
| 158 | |||
| 159 | |||
| 160 | 2 | gate_property_t* Property::c_impl() | |
| 161 | { | ||
| 162 | 2 | return &this->impl; | |
| 163 | } | ||
| 164 | 20 | gate_property_t const* Property::c_impl() const | |
| 165 | { | ||
| 166 | 20 | return &this->impl; | |
| 167 | } | ||
| 168 | |||
| 169 | 71 | Property::TypeEnum Property::getType() const | |
| 170 | { | ||
| 171 | 71 | return TypeEnum(this->impl.value_type); | |
| 172 | } | ||
| 173 | |||
| 174 | 9 | bool_t Property::getBool() const | |
| 175 | { | ||
| 176 | 9 | bool_t ret = false; | |
| 177 |
7/8✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
9 | switch (this->getType()) |
| 178 | { | ||
| 179 | 1 | case Property::Type_Empty: break; | |
| 180 | 3 | case Property::Type_Bool: ret = this->impl.data.bool_value; break; | |
| 181 | 1 | case Property::Type_Int: ret = 0 != this->impl.data.int_value; break; | |
| 182 | 1 | case Property::Type_Real: ret = !gate_math_iszero(this->impl.data.real_value); break; | |
| 183 | 1 | case Property::Type_String: ret = gate_string_is_empty(&this->impl.data.string_value); break; | |
| 184 | 1 | case Property::Type_Array: ret = 0 != gate_arraylist_length(this->impl.data.array_value); break; | |
| 185 | 1 | case Property::Type_Object: ret = 0 != gate_flatmap_count(&this->impl.data.object_value); break; | |
| 186 | } | ||
| 187 | 9 | return ret; | |
| 188 | } | ||
| 189 | 22 | int64_t Property::getInt() const | |
| 190 | { | ||
| 191 | 22 | int64_t ret = 0; | |
| 192 |
7/8✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
22 | switch (this->getType()) |
| 193 | { | ||
| 194 | 1 | case Property::Type_Empty: break; | |
| 195 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | case Property::Type_Bool: ret = this->impl.data.bool_value ? 1 : 0; break; |
| 196 | 16 | case Property::Type_Int: ret = this->impl.data.int_value; break; | |
| 197 | 1 | case Property::Type_Real: ret = (int64_t)this->impl.data.real_value; break; | |
| 198 | 1 | case Property::Type_String: ret = gate_string_length(&this->impl.data.string_value); break; | |
| 199 | 1 | case Property::Type_Array: ret = gate_arraylist_length(this->impl.data.array_value); break; | |
| 200 | 1 | case Property::Type_Object: ret = gate_flatmap_count(&this->impl.data.object_value); break; | |
| 201 | } | ||
| 202 | 22 | return ret; | |
| 203 | } | ||
| 204 | 8 | real64_t Property::getReal() const | |
| 205 | { | ||
| 206 | 8 | real64_t ret = 0.0; | |
| 207 |
7/8✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
8 | switch (this->getType()) |
| 208 | { | ||
| 209 | 1 | case Property::Type_Empty: break; | |
| 210 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | case Property::Type_Bool: ret = this->impl.data.bool_value ? 1.0 : 0.0; break; |
| 211 | 1 | case Property::Type_Int: ret = (real64_t)this->impl.data.int_value; break; | |
| 212 | 2 | case Property::Type_Real: ret = this->impl.data.real_value; break; | |
| 213 | 1 | case Property::Type_String: ret = (real64_t)gate_string_length(&this->impl.data.string_value); break; | |
| 214 | 1 | case Property::Type_Array: ret = (real64_t)gate_arraylist_length(this->impl.data.array_value); break; | |
| 215 | 1 | case Property::Type_Object: ret = (real64_t)gate_flatmap_count(&this->impl.data.object_value); break; | |
| 216 | } | ||
| 217 | 8 | return ret; | |
| 218 | } | ||
| 219 | 9 | String Property::getString() const | |
| 220 | { | ||
| 221 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
9 | static StaticString const Text_True = "true"; |
| 222 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
9 | static StaticString const Text_False = "false"; |
| 223 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
9 | static StaticString const Text_Array = "[array]"; |
| 224 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
9 | static StaticString const Text_Object = "[object]"; |
| 225 | |||
| 226 | 9 | String ret; | |
| 227 |
7/8✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
9 | switch (this->getType()) |
| 228 | { | ||
| 229 | 1 | case Property::Type_Empty: break; | |
| 230 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | case Property::Type_Bool: ret = this->impl.data.bool_value ? Text_True : Text_False; break; |
| 231 | 1 | case Property::Type_Int: | |
| 232 | { | ||
| 233 | char buffer[128]; | ||
| 234 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t buffer_used = gate_str_print_int64(buffer, sizeof(buffer), this->impl.data.int_value); |
| 235 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ret = String(buffer, buffer_used); break; |
| 236 | } | ||
| 237 | 1 | case Property::Type_Real: | |
| 238 | { | ||
| 239 | char buffer[128]; | ||
| 240 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t buffer_used = gate_str_print_real(buffer, sizeof(buffer), this->impl.data.real_value, 0, 12, 0); |
| 241 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | ret = String(buffer, buffer_used); break; |
| 242 | } | ||
| 243 | 3 | case Property::Type_String: ret = String::duplicate(this->impl.data.string_value); break; | |
| 244 | 1 | case Property::Type_Array: ret = Text_Array; break; | |
| 245 | 1 | case Property::Type_Object: ret = Text_Object; break; | |
| 246 | } | ||
| 247 | 9 | return ret; | |
| 248 | } | ||
| 249 | 7 | Array<Property> Property::getArray() const | |
| 250 | { | ||
| 251 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | ArrayList<Property> list; |
| 252 | |||
| 253 |
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()) |
| 254 | { | ||
| 255 | 1 | case Property::Type_Empty: | |
| 256 | { | ||
| 257 | 1 | break; | |
| 258 | } | ||
| 259 | 1 | case Property::Type_Bool: | |
| 260 | case Property::Type_Int: | ||
| 261 | case Property::Type_Real: | ||
| 262 | case Property::Type_String: | ||
| 263 | { | ||
| 264 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | list.add(*this); |
| 265 | 1 | break; | |
| 266 | } | ||
| 267 | |||
| 268 | 4 | case Property::Type_Array: | |
| 269 | { | ||
| 270 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | size_t array_len = gate_property_array_length(&this->impl); |
| 271 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
|
17 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 272 | { | ||
| 273 |
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); |
| 274 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (var_item != NULL) |
| 275 | { | ||
| 276 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
26 | Property var(*var_item); |
| 277 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
13 | list.add(var); |
| 278 | } | ||
| 279 | } | ||
| 280 | 4 | break; | |
| 281 | } | ||
| 282 | 1 | case Property::Type_Object: | |
| 283 | { | ||
| 284 | gate_array_t names; | ||
| 285 |
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)) |
| 286 | { | ||
| 287 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 288 | } | ||
| 289 | try | ||
| 290 | { | ||
| 291 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t array_len = gate_array_length(&names); |
| 292 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 293 | { | ||
| 294 |
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); |
| 295 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (name != NULL) |
| 296 | { | ||
| 297 |
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)); |
| 298 | } | ||
| 299 | } | ||
| 300 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_array_release(&names); |
| 301 | } | ||
| 302 | ✗ | catch (...) | |
| 303 | { | ||
| 304 | ✗ | gate_array_release(&names);; | |
| 305 | ✗ | throw; | |
| 306 | } | ||
| 307 | 1 | break; | |
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | return list.toArray(); |
| 312 | } | ||
| 313 | 2 | Property::object_members_t Property::getObjectMembers() const | |
| 314 | { | ||
| 315 | 2 | Property::object_members_t ret; | |
| 316 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
2 | switch (this->getType()) |
| 317 | { | ||
| 318 | ✗ | case Property::Type_Empty: | |
| 319 | case Property::Type_Bool: | ||
| 320 | case Property::Type_Int: | ||
| 321 | case Property::Type_Real: | ||
| 322 | case Property::Type_String: | ||
| 323 | { | ||
| 324 | ✗ | break; | |
| 325 | } | ||
| 326 | 1 | case Property::Type_Array: | |
| 327 | { | ||
| 328 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t array_len = gate_property_array_length(&this->impl); |
| 329 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (size_t ndx = 0; ndx != array_len; ++ndx) |
| 330 | { | ||
| 331 |
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); |
| 332 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ptr_var != NULL) |
| 333 | { | ||
| 334 | char buffer[256]; | ||
| 335 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | Property local_var(*ptr_var); |
| 336 |
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); |
| 337 | 8 | String key = String::createStatic(buffer, buffer_used); | |
| 338 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | ret.add(key, local_var); |
| 339 | } | ||
| 340 | } | ||
| 341 | 1 | break; | |
| 342 | } | ||
| 343 | 1 | case Property::Type_Object: | |
| 344 | { | ||
| 345 | gate_array_t names; | ||
| 346 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | if (NULL != gate_property_member_names(&this->impl, &names)) |
| 347 | { | ||
| 348 | try | ||
| 349 | { | ||
| 350 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t names_count = gate_array_length(&names); |
| 351 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | for (size_t ndx = 0; ndx != names_count; ++ndx) |
| 352 | { | ||
| 353 |
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); |
| 354 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (NULL != name) |
| 355 | { | ||
| 356 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_property_t const* ptr_var = gate_property_member_get(&this->impl, name); |
| 357 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ptr_var != NULL) |
| 358 | { | ||
| 359 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | Property local_var(*ptr_var); |
| 360 | 8 | String key = String::duplicate(*name); | |
| 361 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | ret.add(key, local_var); |
| 362 | } | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_array_release(&names); |
| 367 | } | ||
| 368 | ✗ | catch (...) | |
| 369 | { | ||
| 370 | ✗ | gate_array_release(&names); | |
| 371 | } | ||
| 372 | } | ||
| 373 | 1 | break; | |
| 374 | } | ||
| 375 | } | ||
| 376 | 2 | return ret; | |
| 377 | } | ||
| 378 | |||
| 379 | 2 | size_t Property::getArrayLength() const | |
| 380 | { | ||
| 381 | 2 | return gate_property_array_length(&this->impl); | |
| 382 | } | ||
| 383 | 1 | Property Property::getArrayItem(size_t index) const | |
| 384 | { | ||
| 385 | 1 | gate_property_t const* ptr_var = gate_property_array_get(&this->impl, index); | |
| 386 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (NULL == ptr_var) |
| 387 | { | ||
| 388 | ✗ | return Property(); | |
| 389 | } | ||
| 390 | else | ||
| 391 | { | ||
| 392 | 1 | return Property(*ptr_var); | |
| 393 | } | ||
| 394 | } | ||
| 395 | 5 | void Property::addArrayItem(Property const& item) | |
| 396 | { | ||
| 397 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (NULL == gate_property_array_add(&this->impl, item.c_impl())) |
| 398 | { | ||
| 399 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 400 | } | ||
| 401 | 5 | } | |
| 402 | 1 | bool_t Property::removeArrayItem(size_t index) | |
| 403 | { | ||
| 404 | 1 | return gate_property_array_remove(&this->impl, index); | |
| 405 | } | ||
| 406 | |||
| 407 | 2 | Array<String> Property::getObjectMemberNames() const | |
| 408 | { | ||
| 409 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | ArrayList<String> name_list; |
| 410 | gate_array_t names; | ||
| 411 |
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)) |
| 412 | { | ||
| 413 | try | ||
| 414 | { | ||
| 415 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t names_count = gate_array_length(&names); |
| 416 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
|
13 | for (size_t ndx = 0; ndx != names_count; ++ndx) |
| 417 | { | ||
| 418 |
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); |
| 419 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (NULL != name) |
| 420 | { | ||
| 421 |
1/2✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
|
11 | name_list.add(String::duplicate(*name)); |
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_array_release(&names); |
| 426 | } | ||
| 427 | ✗ | catch (...) | |
| 428 | { | ||
| 429 | ✗ | gate_array_release(&names); | |
| 430 | ✗ | throw; | |
| 431 | } | ||
| 432 | } | ||
| 433 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return name_list.toArray(); |
| 434 | } | ||
| 435 | 11 | Property Property::getObjectMember(String const& name) | |
| 436 | { | ||
| 437 | 11 | gate_property_t const* ptr_var = gate_property_member_get(&this->impl, name.c_impl()); | |
| 438 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (ptr_var != NULL) |
| 439 | { | ||
| 440 | 11 | return Property(*ptr_var); | |
| 441 | } | ||
| 442 | else | ||
| 443 | { | ||
| 444 | ✗ | return Property(); | |
| 445 | } | ||
| 446 | } | ||
| 447 | 9 | void Property::addObjectMember(String const& name, Property const& value) | |
| 448 | { | ||
| 449 |
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())) |
| 450 | { | ||
| 451 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 452 | } | ||
| 453 | 9 | } | |
| 454 | 2 | bool_t Property::removeObjectMember(String const& name) | |
| 455 | { | ||
| 456 | 2 | return gate_property_member_remove(&this->impl, name.c_impl()); | |
| 457 | } | ||
| 458 | |||
| 459 | ✗ | void Property::exportToStruct(gate_struct_t* ptr_struct) | |
| 460 | { | ||
| 461 | ✗ | if (this->getType() != Property::Type_Object) | |
| 462 | { | ||
| 463 | ✗ | GATEXX_RAISE_ERROR(results::IncorrectType); | |
| 464 | } | ||
| 465 | ✗ | result_t result = gate_property_export(this->c_impl(), GATE_TYPE_STRUCT, ptr_struct); | |
| 466 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 467 | ✗ | } | |
| 468 | |||
| 469 | 1 | Property Property::createFrom(gate_property_t& movableProp) | |
| 470 | { | ||
| 471 | 1 | Property ret; | |
| 472 | 1 | ret.impl = movableProp; | |
| 473 | 1 | Mem::clear(movableProp); | |
| 474 | 1 | return ret; | |
| 475 | } | ||
| 476 | |||
| 477 | 1 | void Property::createCopy(gate_property_t& target, Property const& source) | |
| 478 | { | ||
| 479 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_property_copy(&target, source.c_impl())) |
| 480 | { | ||
| 481 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 482 | } | ||
| 483 | 1 | } | |
| 484 | 1 | void Property::assignCopy(gate_property_t& target, Property const& source) | |
| 485 | { | ||
| 486 | gate_property_t tmp; | ||
| 487 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Property::createCopy(tmp, source); |
| 488 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_property_destroy(&target); |
| 489 | 1 | target = tmp; | |
| 490 | 1 | } | |
| 491 | |||
| 492 | 1 | Property Property::createArray() | |
| 493 | { | ||
| 494 | 1 | Property p; | |
| 495 |
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)) |
| 496 | { | ||
| 497 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 498 | } | ||
| 499 | 1 | return p; | |
| 500 | } | ||
| 501 | 1 | Property Property::createObject() | |
| 502 | { | ||
| 503 | 1 | Property p; | |
| 504 |
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)) |
| 505 | { | ||
| 506 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 507 | } | ||
| 508 | 1 | return p; | |
| 509 | } | ||
| 510 | |||
| 511 | 5 | Property& Property::operator<<(Property const& newArrayItem) | |
| 512 | { | ||
| 513 | 5 | this->addArrayItem(newArrayItem); | |
| 514 | 5 | return *this; | |
| 515 | } | ||
| 516 | |||
| 517 | |||
| 518 | |||
| 519 | |||
| 520 | |||
| 521 | |||
| 522 | |||
| 523 | size_t const PropTable::InvalidIndex = GATE_PROPTABLE_INVALID_INDEX; | ||
| 524 | |||
| 525 | 1 | PropTable::PropTable() | |
| 526 | { | ||
| 527 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_proptable_create(&this->impl)) |
| 528 | { | ||
| 529 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 530 | } | ||
| 531 | 1 | } | |
| 532 | ✗ | PropTable::PropTable(PropTable const& src) | |
| 533 | { | ||
| 534 | ✗ | if (NULL == gate_proptable_copy(&this->impl, &src.impl)) | |
| 535 | { | ||
| 536 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 537 | } | ||
| 538 | ✗ | } | |
| 539 | ✗ | PropTable& PropTable::operator=(PropTable const& src) | |
| 540 | { | ||
| 541 | ✗ | PropTable that(src); | |
| 542 | ✗ | this->swap(that); | |
| 543 | ✗ | return *this; | |
| 544 | } | ||
| 545 | 2 | PropTable::~PropTable() noexcept | |
| 546 | { | ||
| 547 | 1 | gate_proptable_destroy(&this->impl); | |
| 548 | 1 | } | |
| 549 | |||
| 550 | ✗ | void PropTable::swap(PropTable& table) noexcept | |
| 551 | { | ||
| 552 | ✗ | gate::swapRefsNoExcept(this->impl, table.impl); | |
| 553 | ✗ | } | |
| 554 | 1 | gate_proptable_t* PropTable::c_impl() noexcept | |
| 555 | { | ||
| 556 | 1 | return &this->impl; | |
| 557 | } | ||
| 558 | ✗ | gate_proptable_t const* PropTable::c_impl() const noexcept | |
| 559 | { | ||
| 560 | ✗ | return &this->impl; | |
| 561 | } | ||
| 562 | |||
| 563 | 4 | size_t PropTable::insertColumn(String const& columnName, Property::TypeEnum columnType, size_t insertAt) | |
| 564 | { | ||
| 565 | 4 | result_t result = gate_proptable_insert_column(&this->impl, columnName.c_impl(), columnType, insertAt); | |
| 566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | GATEXX_CHECK_EXCEPTION(result); |
| 567 | 4 | size_t colIndex = gate_proptable_get_column_count(&this->impl) - 1; | |
| 568 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (insertAt < colIndex) |
| 569 | { | ||
| 570 | ✗ | colIndex = insertAt; | |
| 571 | } | ||
| 572 | 4 | return colIndex; | |
| 573 | } | ||
| 574 | 1 | void PropTable::removeColumn(String const& columnName) | |
| 575 | { | ||
| 576 | 1 | result_t result = gate_proptable_remove_column(&this->impl, columnName.c_impl()); | |
| 577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 578 | 1 | } | |
| 579 | 1 | void PropTable::removeColumnAt(size_t columnIndex) | |
| 580 | { | ||
| 581 | 1 | result_t result = gate_proptable_remove_column_at(&this->impl, columnIndex); | |
| 582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 583 | 1 | } | |
| 584 | 2 | void PropTable::setColumnName(size_t columnIndex, String const& newName) | |
| 585 | { | ||
| 586 | 2 | result_t result = gate_proptable_set_column_name(&this->impl, columnIndex, newName.c_impl()); | |
| 587 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 588 | 2 | } | |
| 589 | 1 | size_t PropTable::resolveColumnIndex(String const& columnName) | |
| 590 | { | ||
| 591 | 1 | size_t matchIndex = InvalidIndex; | |
| 592 |
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); |
| 593 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 594 | 1 | return matchIndex; | |
| 595 | } | ||
| 596 | |||
| 597 | 6 | size_t PropTable::getColumnCount() const | |
| 598 | { | ||
| 599 | 6 | return gate_proptable_get_column_count(&this->impl); | |
| 600 | } | ||
| 601 | 1 | String PropTable::getColumnName(size_t columnIndex) const | |
| 602 | { | ||
| 603 | 1 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 604 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_proptable_get_column_name(&this->impl, columnIndex, &tmp); |
| 605 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 606 | 2 | return String::createFrom(tmp); | |
| 607 | } | ||
| 608 | ✗ | Property::TypeEnum PropTable::getColumnType(size_t columnIndex) const | |
| 609 | { | ||
| 610 | ✗ | return Property::TypeEnum(gate_proptable_get_column_type(&this->impl, columnIndex)); | |
| 611 | } | ||
| 612 | |||
| 613 | 3 | size_t PropTable::getRowCount() const | |
| 614 | { | ||
| 615 | 3 | return gate_proptable_get_row_count(&this->impl); | |
| 616 | } | ||
| 617 | 3 | Property PropTable::getItemAt(size_t rowIndex, size_t columnIndex) const | |
| 618 | { | ||
| 619 | 3 | gate_property_t const* ptr_prop = gate_proptable_get_item_at(&this->impl, rowIndex, columnIndex); | |
| 620 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (ptr_prop) |
| 621 | { | ||
| 622 | 3 | return Property(*ptr_prop); | |
| 623 | } | ||
| 624 | else | ||
| 625 | { | ||
| 626 | ✗ | GATEXX_RAISE_ERROR(results::OutOfBounds); | |
| 627 | ✗ | return Property(); | |
| 628 | } | ||
| 629 | } | ||
| 630 | 4 | Property PropTable::getItem(size_t rowIndex, String const& columnName) const | |
| 631 | { | ||
| 632 | 4 | gate_property_t const* ptr_prop = gate_proptable_get_item(&this->impl, rowIndex, columnName.c_impl()); | |
| 633 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (ptr_prop) |
| 634 | { | ||
| 635 | 4 | return Property(*ptr_prop); | |
| 636 | } | ||
| 637 | else | ||
| 638 | { | ||
| 639 | ✗ | GATEXX_RAISE_EXCEPTION(results::NoMatch, "Cannot resolve column", 0); | |
| 640 | ✗ | return Property(); | |
| 641 | } | ||
| 642 | } | ||
| 643 | |||
| 644 | 2 | size_t PropTable::insertRow(size_t insertAt) | |
| 645 | { | ||
| 646 | 2 | result_t result = gate_proptable_insert_row(&this->impl, insertAt); | |
| 647 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 648 | 2 | size_t rowIndex = gate_proptable_get_row_count(&this->impl) - 1; | |
| 649 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (insertAt < rowIndex) |
| 650 | { | ||
| 651 | ✗ | rowIndex = insertAt; | |
| 652 | } | ||
| 653 | 2 | return rowIndex; | |
| 654 | } | ||
| 655 | 1 | void PropTable::removeRow(size_t rowIndex) | |
| 656 | { | ||
| 657 | 1 | result_t result = gate_proptable_remove_row(&this->impl, rowIndex); | |
| 658 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 659 | 1 | } | |
| 660 | |||
| 661 | 1 | void PropTable::setItemAt(size_t rowIndex, size_t columnIndex, Property const& prop) | |
| 662 | { | ||
| 663 | 1 | result_t result = gate_proptable_set_item_at(&this->impl, rowIndex, columnIndex, prop.c_impl()); | |
| 664 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 665 | 1 | } | |
| 666 | |||
| 667 | 2 | void PropTable::setItem(size_t rowIndex, String const& columnName, Property const& prop) | |
| 668 | { | ||
| 669 | 2 | result_t result = gate_proptable_set_item(&this->impl, rowIndex, columnName.c_impl(), prop.c_impl()); | |
| 670 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 671 | 2 | } | |
| 672 | |||
| 673 | 1 | Property PropTable::operator()(size_t rowIndex, size_t columnIndex) const | |
| 674 | { | ||
| 675 | 1 | return this->getItemAt(rowIndex, columnIndex); | |
| 676 | } | ||
| 677 | 2 | Property PropTable::operator()(size_t rowIndex, String const& columnName) const | |
| 678 | { | ||
| 679 | 2 | return this->getItem(rowIndex, columnName); | |
| 680 | } | ||
| 681 | |||
| 682 | |||
| 683 | } // end of namespace gate | ||
| 684 |