GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_structs.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 20 59 33.9%
Functions: 8 21 38.1%
Branches: 3 8 37.5%

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
30 #include "gate/structs.hpp"
31
32
33 namespace gate
34 {
35
36 ConstStruct::ConstStruct(gate_struct_t const* ptr) noexcept
37 : impl(ptr)
38 {
39
40 }
41 ConstStruct::ConstStruct(ConstStruct const& src) noexcept
42 : impl(src.impl)
43 {
44
45 }
46 ConstStruct& ConstStruct::operator=(ConstStruct const& src) noexcept
47 {
48 this->impl = src.impl;
49 return *this;
50 }
51 2 ConstStruct::~ConstStruct() noexcept
52 {
53 1 this->impl = NULL;
54 1 }
55
56 gate_struct_t const* ConstStruct::c_impl() const
57 {
58 return this->impl;
59 }
60
61 1 size_t ConstStruct::getStructSize() const
62 {
63 1 return gate_struct_length(this->impl);
64 }
65 1 String ConstStruct::getStructName() const
66 {
67 1 return String::createStatic(gate_struct_get_name(this->impl));
68 }
69
70 7 size_t ConstStruct::getMemberCount() const
71 {
72 7 return gate_struct_get_member_count(this->impl);
73 }
74 12 gate_type_id_t ConstStruct::getMemberType(size_t index) const
75 {
76 12 return gate_struct_get_member_type(this->impl, index);
77 }
78 21 String ConstStruct::getMemberName(size_t index) const
79 {
80 21 return String::createStatic(gate_struct_get_member_name(this->impl, index));
81 }
82 6 size_t ConstStruct::getMemberIndex(String const& memberName) const
83 {
84 6 size_t const count = this->getMemberCount();
85
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 for (size_t index = 0; index != count; ++index)
86 {
87
2/2
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 15 times.
21 if (this->getMemberName(index) == memberName)
88 {
89 6 return index;
90 }
91 }
92 return (size_t)-1;
93 }
94
95 gate_type_id_t ConstStruct::getMemberType(String const& memberName) const
96 {
97 return gate_struct_get_member_type_by_string(this->impl, memberName.c_impl());
98 }
99
100 12 void const* ConstStruct::getMemberPtr(size_t index) const
101 {
102 12 return gate_struct_get_member(this->impl, index);
103 }
104
105 void const* ConstStruct::getMemberPtr(String const& memberName) const
106 {
107 return gate_struct_get_member_by_string(this->impl, memberName.c_impl());
108 }
109
110
111
112 MutableStruct::MutableStruct(gate_struct_t* ptr) noexcept
113 : ConstStruct(ptr), mut_impl(ptr)
114 {
115 }
116 MutableStruct::MutableStruct(MutableStruct const& src) noexcept
117 : ConstStruct(src), mut_impl(src.mut_impl)
118 {
119 }
120 MutableStruct& MutableStruct::operator=(MutableStruct const& src) noexcept
121 {
122 ConstStruct::operator=(src);
123 this->mut_impl = src.mut_impl;
124 return *this;
125 }
126 MutableStruct::~MutableStruct() noexcept
127 {
128 this->mut_impl = NULL;
129 }
130
131 gate_struct_t* MutableStruct::c_impl()
132 {
133 return this->mut_impl;
134 }
135
136 void* MutableStruct::getMemberPtr(size_t index)
137 {
138 return gate_struct_get_mutable_member(this->mut_impl, index);
139 }
140 void* MutableStruct::getMemberPtr(String const& memberName)
141 {
142 size_t cnt = this->getMemberCount();
143 for (size_t n = 0; n != cnt; ++n)
144 {
145 if (this->getMemberName(n) == memberName)
146 {
147 return this->getMemberPtr(n);
148 }
149 }
150 return NULL;
151 }
152
153 } // end of namespace gate
154