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/objects.hpp" | ||
29 | |||
30 | #include "gate/exceptions.hpp" | ||
31 | #include "gate/results.hpp" | ||
32 | |||
33 | namespace gate | ||
34 | { | ||
35 | |||
36 | 131 | Object::Object(gate_object_ptr_t obj_ptr) noexcept | |
37 | 131 | : object_ref_ptr(obj_ptr) | |
38 | { | ||
39 | |||
40 | 131 | } | |
41 | 13 | Object::Object(Object const& obj) noexcept | |
42 | 13 | : object_ref_ptr(obj.object_ref_ptr) | |
43 | { | ||
44 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if (this->object_ref_ptr != NULL) |
45 | { | ||
46 | 13 | gate_object_retain(this->object_ref_ptr); | |
47 | } | ||
48 | 13 | } | |
49 | 12 | Object& Object::operator=(Object const& that) noexcept | |
50 | { | ||
51 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (this != &that) |
52 | { | ||
53 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (that.object_ref_ptr != NULL) |
54 | { | ||
55 | 12 | gate_object_retain(that.object_ref_ptr); | |
56 | } | ||
57 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (this->object_ref_ptr != NULL) |
58 | { | ||
59 | 12 | gate_object_release(this->object_ref_ptr); | |
60 | } | ||
61 | 12 | this->object_ref_ptr = that.object_ref_ptr; | |
62 | } | ||
63 | 12 | return *this; | |
64 | } | ||
65 | 288 | Object::~Object() noexcept | |
66 | { | ||
67 |
1/2✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
|
144 | if (this->object_ref_ptr != NULL) |
68 | { | ||
69 | 144 | gate_object_release(this->object_ref_ptr); | |
70 | } | ||
71 | 144 | } | |
72 | |||
73 | 5 | String Object::getInterfaceName() | |
74 | { | ||
75 | 5 | char const* name = NULL; | |
76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (this->object_ref_ptr == NULL) |
77 | { | ||
78 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
79 | } | ||
80 | else | ||
81 | { | ||
82 | 5 | name = gate_object_get_interface_name(this->object_ref_ptr); | |
83 | } | ||
84 | 5 | return String::createStatic(name); | |
85 | } | ||
86 | |||
87 | ✗ | gate_object_t* Object::c_impl() noexcept | |
88 | { | ||
89 | ✗ | return this->object_ref_ptr; | |
90 | } | ||
91 | |||
92 | 1 | bool_t Object::operator!() const noexcept | |
93 | { | ||
94 | 1 | return this->empty(); | |
95 | } | ||
96 | 7 | bool_t Object::empty() const noexcept | |
97 | { | ||
98 | 7 | return this->object_ref_ptr == NULL; | |
99 | } | ||
100 | |||
101 | |||
102 | |||
103 | ✗ | void Object::swap(Object& that) noexcept | |
104 | { | ||
105 | ✗ | gate::swapRefs(this->object_ref_ptr, that.object_ref_ptr); | |
106 | ✗ | } | |
107 | |||
108 | |||
109 | |||
110 | |||
111 | 12 | IObject::~IObject() | |
112 | { | ||
113 | 12 | } | |
114 | |||
115 | |||
116 | |||
117 | |||
118 | 1 | Startable::Startable(gate_startable_t* obj) | |
119 | 1 | : object_impl_t(obj) | |
120 | { | ||
121 | 1 | } | |
122 | ✗ | Startable::Startable(Startable const& src) | |
123 | ✗ | : object_impl_t(src) | |
124 | { | ||
125 | ✗ | } | |
126 | |||
127 | ✗ | Startable& Startable::operator=(Startable const& src) | |
128 | { | ||
129 | ✗ | object_impl_t::operator=(src); | |
130 | ✗ | return *this; | |
131 | } | ||
132 | |||
133 | 1 | void Startable::start() | |
134 | { | ||
135 | 1 | result_t result = gate_startable_start(this->impl_ptr); | |
136 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
137 | 1 | } | |
138 | 1 | void Startable::stop() | |
139 | { | ||
140 | 1 | result_t result = gate_startable_stop(this->impl_ptr); | |
141 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
142 | 1 | } | |
143 | 3 | enumint_t Startable::getStatus() | |
144 | { | ||
145 | 3 | gate_enumint_t status = gate_startable_get_status(this->impl_ptr); | |
146 | 3 | return status; | |
147 | } | ||
148 | |||
149 | |||
150 | |||
151 | |||
152 | |||
153 | 1 | MemoryBlock::MemoryBlock(size_t blockLength) | |
154 | 1 | : object_impl_t(gate_memoryblock_create(blockLength)) | |
155 | { | ||
156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!this->c_impl()) |
157 | { | ||
158 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
159 | } | ||
160 | 1 | } | |
161 | |||
162 | 3 | MemoryBlock::MemoryBlock(void const* sourceBlockBytes, size_t blockLength) | |
163 | 3 | : object_impl_t(gate_memoryblock_create(blockLength)) | |
164 | { | ||
165 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (!this->c_impl()) |
166 | { | ||
167 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
168 | } | ||
169 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | void* ptrContent = this->getContent(); |
170 | 3 | Mem::copy(ptrContent, sourceBlockBytes, blockLength); | |
171 | 3 | } | |
172 | |||
173 | 1 | MemoryBlock::MemoryBlock(gate_memoryblock_t* obj) | |
174 | 1 | : object_impl_t(obj) | |
175 | { | ||
176 | 1 | } | |
177 | 4 | MemoryBlock::MemoryBlock(MemoryBlock const& src) | |
178 | 4 | : object_impl_t(src) | |
179 | { | ||
180 | 4 | } | |
181 | 1 | MemoryBlock& MemoryBlock::operator=(MemoryBlock const& src) | |
182 | { | ||
183 | 1 | object_impl_t::operator=(src); | |
184 | 1 | return *this; | |
185 | } | ||
186 | |||
187 | 6 | size_t MemoryBlock::getSize() const | |
188 | { | ||
189 | 6 | return gate_memoryblock_get_size(this->c_impl()); | |
190 | } | ||
191 | 4 | void* MemoryBlock::getContent() | |
192 | { | ||
193 | 4 | return gate_memoryblock_get_content(this->c_impl()); | |
194 | } | ||
195 | 5 | void const* MemoryBlock::getContent() const | |
196 | { | ||
197 | 5 | return gate_memoryblock_get_content(this->c_impl()); | |
198 | } | ||
199 | 4 | intptr_t MemoryBlock::compare(void const* block, size_t blockLength) const | |
200 | { | ||
201 | 4 | void const* thisContent = this->getContent(); | |
202 | 4 | size_t size = this->getSize(); | |
203 | 4 | intptr_t ret = 0; | |
204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (size < blockLength) |
205 | { | ||
206 | ✗ | ret = -1; | |
207 | } | ||
208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | else if (size > blockLength) |
209 | { | ||
210 | ✗ | size = blockLength; | |
211 | ✗ | ret = 1; | |
212 | } | ||
213 | 4 | intptr_t compareResult = Mem::compare(thisContent, block, size); | |
214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (compareResult != 0) |
215 | { | ||
216 | ✗ | ret = compareResult; | |
217 | } | ||
218 | 4 | return ret; | |
219 | } | ||
220 | 1 | intptr_t MemoryBlock::compare(MemoryBlock const& block) const | |
221 | { | ||
222 | 1 | return this->compare(block.getContent(), block.getSize()); | |
223 | } | ||
224 | |||
225 | 1 | bool MemoryBlock::equals(MemoryBlock const& block) const | |
226 | { | ||
227 | 1 | return this->compare(block) == 0; | |
228 | } | ||
229 | 3 | bool MemoryBlock::equals(void const* block, size_t blockLength) const | |
230 | { | ||
231 | 3 | return this->compare(block, blockLength) == 0; | |
232 | } | ||
233 | |||
234 | } // end of namespace gate | ||
235 | |||
236 |