GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_structs.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 58 59 98.3%
Functions: 21 21 100.0%
Branches: 6 8 75.0%

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