GCC Code Coverage Report


Directory: src/gate/
File: src/gate/enumerators.c
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 28 34 82.4%
Functions: 7 8 87.5%
Branches: 2 6 33.3%

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/enumerators.h"
30 #include "gate/memalloc.h"
31
32 2255 gate_bool_t gate_enumerator_valid(gate_enumerator_t const* enumerator)
33 {
34 2255 return enumerator->is_valid(enumerator);
35 }
36 2233 gate_bool_t gate_enumerator_next(gate_enumerator_t* enumerator)
37 {
38 2233 return enumerator->next(enumerator);
39 }
40 2449 void const* gate_enumerator_get(gate_enumerator_t const* enumerator)
41 {
42 2449 return enumerator->get(enumerator);
43 }
44
45 void const* gate_enumerator_next_item(gate_enumerator_t* enumerator)
46 {
47 if (enumerator->next(enumerator))
48 {
49 return enumerator->get(enumerator);
50 }
51 else
52 {
53 return NULL;
54 }
55 }
56
57
58
59 11 static gate_bool_t gate_enumerator_c_array_is_valid(struct gate_enumerator_class const* enumerator)
60 {
61 11 return enumerator->current_position < enumerator->end_position;
62 }
63 10 static gate_bool_t gate_enumerator_c_array_next(struct gate_enumerator_class* enumerator)
64 {
65 10 gate_size_t item_size = (gate_size_t)enumerator->handles[0];
66 10 char* new_ptr = (char*)enumerator->current_position + item_size;
67 10 enumerator->current_position = new_ptr;
68 10 return enumerator->current_position < enumerator->end_position;
69 }
70 10 static void const* gate_enumerator_c_array_get(struct gate_enumerator_class const* enumerator)
71 {
72
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (enumerator->current_position < enumerator->end_position)
73 {
74 10 return (void const*)enumerator->current_position;
75 }
76 else
77 {
78 return NULL;
79 }
80 }
81
82 1 gate_enumerator_t* gate_enumerator_for_array(gate_enumerator_t* enumerator,
83 void const* begin,
84 gate_size_t item_size,
85 gate_size_t item_count)
86 {
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (item_size == 0)
88 {
89 return NULL;
90 }
91 else
92 {
93 1 gate_mem_clear(enumerator, sizeof(gate_enumerator_t));
94 1 enumerator->is_valid = &gate_enumerator_c_array_is_valid;
95 1 enumerator->next = &gate_enumerator_c_array_next;
96 1 enumerator->get = &gate_enumerator_c_array_get;
97
98 1 enumerator->ptr_origin = begin;
99 1 enumerator->current_position = (void*)begin;
100 1 enumerator->end_position = (void*)((char const*)begin + item_size * item_count);
101
102 1 enumerator->handles[0] = (void*)item_size;
103 1 enumerator->handles[1] = (void*)item_count;
104 1 return enumerator;
105 }
106
107 }
108