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 | #include "gate/values.hpp" | ||
29 | |||
30 | namespace gate | ||
31 | { | ||
32 | 10 | Value::Value() noexcept | |
33 | 10 | : value(gate_value_t()) | |
34 | { | ||
35 | 10 | gate_value_create(GATE_TYPE_EMPTY, NULL, &this->value); | |
36 | 10 | } | |
37 | |||
38 | 30 | Value::Value(Value const& src) | |
39 | 30 | : value(gate_value_t()) | |
40 | { | ||
41 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
|
30 | if (NULL == gate_value_create(src.value.value_type, &src.value.content.ptr_value, &this->value)) |
42 | { | ||
43 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
44 | } | ||
45 | 30 | } | |
46 | |||
47 | 10 | Value::Value(gate_value_t const& nativeValue) | |
48 | 10 | : value(gate_value_t()) | |
49 | { | ||
50 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (NULL == gate_value_create(nativeValue.value_type, &nativeValue.content.ptr_value, &this->value)) |
51 | { | ||
52 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
53 | } | ||
54 | 10 | } | |
55 | |||
56 | 120 | Value::~Value() noexcept | |
57 | { | ||
58 | 60 | gate_value_release(&this->value); | |
59 | 60 | } | |
60 | |||
61 | 10 | void Value::swap(Value& src) noexcept | |
62 | { | ||
63 | 10 | gate_value_t tmp = src.value; | |
64 | 10 | src.value = this->value; | |
65 | 10 | this->value = tmp; | |
66 | 10 | } | |
67 | |||
68 | 10 | Value& Value::operator=(Value const& src) | |
69 | { | ||
70 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | Value that(src); |
71 | 10 | this->swap(that); | |
72 | 20 | return *this; | |
73 | } | ||
74 | |||
75 | 10 | gate_type_id_t Value::Type() const noexcept | |
76 | { | ||
77 | 10 | return this->value.value_type; | |
78 | } | ||
79 | 10 | gate_value_t* Value::c_impl() noexcept | |
80 | { | ||
81 | 10 | return &this->value; | |
82 | } | ||
83 | 10 | gate_value_t const* Value::c_impl() const noexcept | |
84 | { | ||
85 | 10 | return &this->value; | |
86 | } | ||
87 | |||
88 | 10 | bool_t Value::exportAs(String& val) const | |
89 | { | ||
90 | 10 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | result_t result = gate_value_load_string(this->value.value_type, &this->value.content.ptr_value, &tmp); |
92 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (GATE_FAILED(result)) return false; |
93 | 10 | val = String::createFrom(tmp); | |
94 | 10 | return true; | |
95 | } | ||
96 | |||
97 | 10 | String Value::toString() const | |
98 | { | ||
99 | 10 | String text; | |
100 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | this->exportAs(text); |
101 | 10 | return text; | |
102 | } | ||
103 | |||
104 | |||
105 | #define ValueExportAs(valuePtr, loadFunction, outputValuePtr) \ | ||
106 | result_t result = loadFunction((valuePtr)->value.value_type, &((valuePtr)->value.content.ptr_value), (outputValuePtr)); \ | ||
107 | return GATE_SUCCEEDED(result) | ||
108 | |||
109 | 1 | bool_t Value::exportAs(bool_t& val) const { ValueExportAs(this, gate_value_load_bool, &val); } | |
110 | 1 | bool_t Value::exportAs(int8_t& val) const { ValueExportAs(this, gate_value_load_int8, &val); } | |
111 | 1 | bool_t Value::exportAs(int16_t& val) const { ValueExportAs(this, gate_value_load_int16, &val); } | |
112 | 1 | bool_t Value::exportAs(int32_t& val) const { ValueExportAs(this, gate_value_load_int32, &val); } | |
113 | 1 | bool_t Value::exportAs(int64_t& val) const { ValueExportAs(this, gate_value_load_int64, &val); } | |
114 | ✗ | bool_t Value::exportAs(uint8_t& val) const { ValueExportAs(this, gate_value_load_uint8, &val); } | |
115 | 1 | bool_t Value::exportAs(uint16_t& val) const { ValueExportAs(this, gate_value_load_uint16, &val); } | |
116 | 1 | bool_t Value::exportAs(uint32_t& val) const { ValueExportAs(this, gate_value_load_uint32, &val); } | |
117 | 1 | bool_t Value::exportAs(uint64_t& val) const { ValueExportAs(this, gate_value_load_uint64, &val); } | |
118 | 1 | bool_t Value::exportAs(real32_t& val) const { ValueExportAs(this, gate_value_load_real32, &val); } | |
119 | 1 | bool_t Value::exportAs(real64_t& val) const { ValueExportAs(this, gate_value_load_real64, &val); } | |
120 | |||
121 | } // end of namespace gate | ||
122 |