LCOV - code coverage report
Current view: top level - u8stream/include/u8arena - universal_arena_list.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 29 29 100.0 %
Date: 2024-10-26 21:44:38 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* File: universal_arena_list.inl; Copyright and License: see below */
       2             : 
       3             : #include "u8/u8_log.h"
       4             : #include <stdint.h>
       5             : #include <assert.h>
       6             : 
       7           1 : static inline void universal_arena_list_init( universal_arena_list_t *this_,
       8             :                                               universal_memory_arena_t *allocator )
       9             : {
      10           1 :     assert( allocator != NULL );
      11           1 :     (*this_).begin = NULL;
      12           1 :     (*this_).allocator = allocator;
      13           1 : }
      14             : 
      15           1 : static inline void universal_arena_list_destroy( universal_arena_list_t *this_ )
      16             : {
      17           1 :     assert( (*this_).allocator != NULL );
      18           1 :     (*this_).allocator = NULL;
      19           1 :     (*this_).begin = NULL;
      20           1 : }
      21             : 
      22           4 : static inline u8_error_t universal_arena_list_append( universal_arena_list_t *this_, void* element )
      23             : {
      24           4 :     assert( (*this_).allocator != NULL );
      25           4 :     u8_error_t err = U8_ERROR_NONE;
      26             : 
      27             :     universal_arena_list_element_t *new_ele;
      28           4 :     err = universal_memory_arena_get_block( (*this_).allocator, sizeof(universal_arena_list_element_t), (void**)&new_ele );
      29           4 :     if ( err == U8_ERROR_NONE )
      30             :     {
      31           3 :         universal_arena_list_element_init( new_ele, element, NULL );
      32             : 
      33           3 :         if ( (*this_).begin == NULL )
      34             :         {
      35           1 :             (*this_).begin = new_ele;
      36             :         }
      37             :         else
      38             :         {
      39           2 :             universal_arena_list_element_t *find_last = (*this_).begin;
      40           5 :             for ( bool finished = false; ( ! finished ); )
      41             :             {
      42           3 :                 if ( universal_arena_list_element_get_next( find_last ) == NULL )
      43             :                 {
      44           2 :                     universal_arena_list_element_set_next( find_last, new_ele );
      45           2 :                     finished = true;
      46             :                 }
      47             :                 else
      48             :                 {
      49           1 :                     find_last = universal_arena_list_element_get_next( find_last );
      50             :                 }
      51             :             }
      52             :         }
      53             :     }
      54             : 
      55           4 :     return err;
      56             : }
      57             : 
      58           2 : static inline universal_arena_list_element_t* universal_arena_list_get_begin( universal_arena_list_t *this_ )
      59             : {
      60           2 :     return (*this_).begin;
      61             : }
      62             : 
      63           1 : static inline universal_arena_list_element_t* universal_arena_list_get_end( universal_arena_list_t *this_ )
      64             : {
      65           1 :     return NULL;
      66             : }
      67             : 
      68             : 
      69             : /*
      70             : Copyright 2021-2024 Andreas Warnke
      71             : 
      72             : Licensed under the Apache License, Version 2.0 (the "License");
      73             : you may not use this file except in compliance with the License.
      74             : You may obtain a copy of the License at
      75             : 
      76             :     http://www.apache.org/licenses/LICENSE-2.0
      77             : 
      78             : Unless required by applicable law or agreed to in writing, software
      79             : distributed under the License is distributed on an "AS IS" BASIS,
      80             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      81             : See the License for the specific language governing permissions and
      82             : limitations under the License.
      83             : */

Generated by: LCOV version 1.16