C Container Collection (CCC)
Loading...
Searching...
No Matches
private_flat_buffer.h File Reference

The Private Flat Buffer Types and Interface. More...

#include "../types.h"
Include dependency graph for private_flat_buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Detailed Description

The Private Flat Buffer Types and Interface.

The standard contiguous flat buffer is the foundation for many other containers. It is the standard, reliable, dynamic buffer. It points to externally managed memory so that the metadata struct is separate from the memory it manages.

Data Structures

struct  CCC_Flat_buffer
 

Macros

#define CCC_private_flat_buffer_default(private_type_name)
 
#define CCC_private_flat_buffer_for( private_type_name, private_capacity, private_count, private_data...)
 
#define CCC_private_flat_buffer_from( private_allocator, private_optional_capacity, private_compound_literal_array...)
 
#define CCC_private_flat_buffer_with_capacity( private_type_name, private_allocator, private_capacity)
 
#define CCC_private_flat_buffer_with_storage( private_count, private_compound_literal_array...)
 
#define CCC_private_flat_buffer_emplace( private_flat_buffer_pointer, index, private_type_compound_literal...)
 
#define CCC_private_flat_buffer_emplace_back( private_flat_buffer_pointer, private_allocator_pointer, private_type_compound_literal...)
 

Macro Definition Documentation

◆ CCC_private_flat_buffer_default

#define CCC_private_flat_buffer_default (   private_type_name)
Value:
(struct CCC_Flat_buffer) { \
.sizeof_type = sizeof(private_type_name), \
.alignof_type = alignof(private_type_name), \
}
Definition: private_flat_buffer.h:40
size_t alignof_type
Definition: private_flat_buffer.h:50

◆ CCC_private_flat_buffer_emplace

#define CCC_private_flat_buffer_emplace (   private_flat_buffer_pointer,
  index,
  private_type_compound_literal... 
)
Value:
(__extension__({ \
__auto_type private_i = (index); \
typeof(private_type_compound_literal) *private_flat_buffer_res \
= CCC_flat_buffer_at((private_flat_buffer_pointer), private_i); \
if (private_flat_buffer_res) { \
*private_flat_buffer_res = private_type_compound_literal; \
} \
private_flat_buffer_res; \
}))
void * CCC_flat_buffer_at(CCC_Flat_buffer const *buffer, size_t index)
return the element at slot index in buf.

◆ CCC_private_flat_buffer_emplace_back

#define CCC_private_flat_buffer_emplace_back (   private_flat_buffer_pointer,
  private_allocator_pointer,
  private_type_compound_literal... 
)
Value:
(__extension__({ \
typeof(private_type_compound_literal) *private_flat_buffer_res \
(private_flat_buffer_pointer), (private_allocator_pointer) \
); \
if (private_flat_buffer_res) { \
*private_flat_buffer_res = private_type_compound_literal; \
} \
private_flat_buffer_res; \
}))
void * CCC_flat_buffer_allocate_back(CCC_Flat_buffer *buffer, CCC_Allocator const *allocator)
allocates a new slot from the Flat_buffer at the end of the contiguous array. A slot is equivalent to...

◆ CCC_private_flat_buffer_for

#define CCC_private_flat_buffer_for (   private_type_name,
  private_capacity,
  private_count,
  private_data... 
)
Value:
(struct CCC_Flat_buffer) { \
.data = (private_data), .sizeof_type = sizeof(private_type_name), \
.alignof_type = alignof(private_type_name), .count = (private_count), \
.capacity = (private_capacity), \
}
size_t count
Definition: private_flat_buffer.h:44
size_t sizeof_type
Definition: private_flat_buffer.h:48

Initializes the Flat_buffer with a default size of 0. However the user can specify that the Flat_buffer has some count of elements from index [0, capacity - 1) at initialization time. The Flat_buffer assumes these elements are contiguous.

◆ CCC_private_flat_buffer_from

#define CCC_private_flat_buffer_from (   private_allocator,
  private_optional_capacity,
  private_compound_literal_array... 
)
Value:
(struct { struct CCC_Flat_buffer private; }){(__extension__({ \
typeof(*private_compound_literal_array) \
*private_flat_buffer_initializer_list \
= private_compound_literal_array; \
typeof(*private_flat_buffer_initializer_list) \
); \
size_t const private_n \
= sizeof(private_compound_literal_array) \
/ sizeof(*private_flat_buffer_initializer_list); \
size_t const private_cap = private_optional_capacity; \
&private_buf, \
(private_n > private_cap ? private_n : private_cap), \
&(private_allocator) \
) \
== CCC_RESULT_OK) { \
(void)memcpy( \
private_buf.data, \
private_flat_buffer_initializer_list, \
private_n * sizeof(*private_flat_buffer_initializer_list) \
); \
private_buf.count = private_n; \
} \
private_buf; \
}))}.private
CCC_Result CCC_flat_buffer_reserve(CCC_Flat_buffer *buffer, size_t to_add, CCC_Allocator const *allocator)
Reserves space for at least to_add more elements.
#define CCC_private_flat_buffer_default(private_type_name)
Definition: private_flat_buffer.h:54
void * data
Definition: private_flat_buffer.h:42
@ CCC_RESULT_OK
Definition: types.h:194

For dynamic containers to perform the allocation and initialization in one convenient step for user.

◆ CCC_private_flat_buffer_with_capacity

#define CCC_private_flat_buffer_with_capacity (   private_type_name,
  private_allocator,
  private_capacity 
)
Value:
(struct { struct CCC_Flat_buffer private; }){(__extension__({ \
struct CCC_Flat_buffer private_buf \
= CCC_private_flat_buffer_default(private_type_name); \
&private_buf, (private_capacity), &(private_allocator) \
); \
private_buf; \
}))}.private

For dynamic containers to perform initialization and reservation of memory in one step.

◆ CCC_private_flat_buffer_with_storage

#define CCC_private_flat_buffer_with_storage (   private_count,
  private_compound_literal_array... 
)
Value:
(struct CCC_Flat_buffer) { \
.data = (private_compound_literal_array), \
.sizeof_type = sizeof(*private_compound_literal_array), \
.alignof_type = alignof(*private_compound_literal_array), \
.count = private_count, \
.capacity = sizeof(private_compound_literal_array) \
/ sizeof(*private_compound_literal_array), \
}

Clang is more forgiving with what qualifies as a constant expression for both constructing compound literals and using static asserts. The static asserts are so helpful that it is worth every effort to give them to the user. GCC is not so forgiving.

Initializes a fixed size buffer with no allocation or context.