APIs for inspecting and serializing the contents of a named type registry.
More...
APIs for inspecting and serializing the contents of a named type registry.
◆ infix_registry_iterator_t
An opaque handle to a registry iterator. Created by infix_registry_iterator_begin.
◆ infix_registry_create_in_arena()
Creates a new named type registry that allocates from a user-provided arena.
This advanced function allows multiple registries and trampolines to share a single memory arena, enabling pointer sharing and reducing memory overhead. The user is responsible for managing the lifetime of the provided arena.
- Parameters
-
| [in] | arena | The user-managed arena to use for all internal allocations. |
- Returns
- A pointer to the new registry, or
nullptr on allocation failure.
- Note
- The registry should still be destroyed with
infix_registry_destroy, but this will not free the user-provided arena itself.
Creates a new named type registry that allocates from a user-provided arena.
A registry acts as a dictionary for infix types, allowing you to define complex structs, unions, or aliases once and refer to them by name (e.g., @MyStruct) in any signature string. This is essential for managing complex, recursive, or mutually-dependent types.
- Parameters
-
| [in] | arena | The arena to allocate from. |
- Returns
- A pointer to the new registry, or
nullptr on allocation failure. The returned handle must be freed with infix_registry_destroy.
◆ infix_registry_is_defined()
Checks if a type with the given name is fully defined in the registry.
This function will return false for names that are only forward-declared but have not been given a definition.
- Parameters
-
| [in] | registry | The registry to search. |
| [in] | name | The name of the type to check (e.g., "MyStruct"). |
- Returns
true if a complete definition for the name exists, false otherwise.
This function will return false for names that are only forward-declared (e.g., via @Name;) but have not been given a complete definition.
- Parameters
-
| [in] | registry | The registry to search. |
| [in] | name | The name of the type to check (e.g., "MyStruct"). |
- Returns
true if a complete definition for the name exists, false otherwise.
◆ infix_registry_iterator_begin()
Initializes an iterator for traversing the types in a registry.
- Parameters
-
| [in] | registry | The registry to iterate over. |
- Returns
- An initialized iterator. If the registry is empty, the first call to
infix_registry_iterator_next on this iterator will return false.
This function creates an iterator that can be used with infix_registry_iterator_next to loop through all fully-defined types in a registry. The order of traversal is not guaranteed.
- Parameters
-
| [in] | registry | The registry to iterate over. |
- Returns
- An initialized iterator. If the registry is empty, the first call to
infix_registry_iterator_next on this iterator will return false.
printf("Found type: %s\n", name);
}
infix_registry_t * registry
Definition 008_registry_introspection.c:35
c23_nodiscard const infix_type * infix_registry_iterator_get_type(const infix_registry_iterator_t *)
Gets the infix_type object of the type at the iterator's current position.
Definition type_registry.c:769
c23_nodiscard infix_registry_iterator_t infix_registry_iterator_begin(const infix_registry_t *)
Initializes an iterator for traversing the types in a registry.
Definition type_registry.c:695
c23_nodiscard bool infix_registry_iterator_next(infix_registry_iterator_t *)
Advances the iterator to the next defined type in the registry.
Definition type_registry.c:708
c23_nodiscard const char * infix_registry_iterator_get_name(const infix_registry_iterator_t *)
Gets the name of the type at the iterator's current position.
Definition type_registry.c:755
Internal definition of a registry iterator.
Definition infix_internals.h:190
A semi-opaque structure that describes a C type.
Definition infix.h:211
◆ infix_registry_iterator_get_name()
Gets the name of the type at the iterator's current position.
- Parameters
-
| [in] | iterator | The iterator. |
- Returns
- The name of the type (e.g., "MyStruct"), or
nullptr if the iterator is invalid or at the end.
- Parameters
-
| [in] | iterator | The iterator, which must have been successfully advanced by infix_registry_iterator_next. |
- Returns
- The name of the type (e.g., "Point"), or
nullptr if the iterator is invalid or has reached the end of the collection.
◆ infix_registry_iterator_get_type()
Gets the infix_type object of the type at the iterator's current position.
- Parameters
-
| [in] | iterator | The iterator. |
- Returns
- A pointer to the canonical
infix_type object, or nullptr if the iterator is invalid or at the end.
- Parameters
-
| [in] | iterator | The iterator, which must have been successfully advanced by infix_registry_iterator_next. |
- Returns
- A pointer to the canonical
infix_type object, or nullptr if the iterator is invalid or has reached the end of the collection.
◆ infix_registry_iterator_next()
Advances the iterator to the next defined type in the registry.
- Parameters
-
| [in,out] | iterator | The iterator to advance. |
- Returns
true if the iterator was advanced to a valid type, or false if there are no more types.
- Parameters
-
| [in,out] | iterator | The iterator to advance. |
- Returns
true if the iterator was advanced to a valid type, or false if there are no more types to visit.
◆ infix_registry_lookup_type()
Retrieves the canonical infix_type object for a given name from the registry.
- Parameters
-
| [in] | registry | The registry to search. |
| [in] | name | The name of the type to retrieve. |
- Returns
- A pointer to the canonical
infix_type object if found and fully defined. Returns nullptr if the name is not found or is only a forward declaration. The returned pointer is owned by the registry and is valid for its lifetime.
- Parameters
-
| [in] | registry | The registry to search. |
| [in] | name | The name of the type to retrieve (e.g., "Point"). |
- Returns
- A pointer to the canonical
infix_type object if found and fully defined. Returns nullptr if the name is not found or is only a forward declaration. The returned pointer is owned by the registry and is valid for its lifetime.
◆ infix_registry_print()
Serializes all defined types within a registry into a single, human-readable string.
The output format is a sequence of definitions (e.g., @Name = { ... };) separated by newlines, suitable for logging, debugging, or saving to a file. This function will not print forward declarations that have not been fully defined.
- Parameters
-
| [out] | buffer | The output buffer to write the string into. |
| [in] | buffer_size | The size of the output buffer. |
| [in] | registry | The registry to serialize. |
- Returns
INFIX_SUCCESS on success, or INFIX_ERROR_INVALID_ARGUMENT if the buffer is too small.
The output format is a sequence of definitions (e.g., @Name = { ... };) separated by newlines, suitable for logging, debugging, or saving to a file. This function will not print forward declarations that have not been fully defined. The order of definitions in the output string is not guaranteed.
- Parameters
-
| [out] | buffer | The output buffer to write the string into. |
| [in] | buffer_size | The size of the output buffer. |
| [in] | registry | The registry to serialize. |
- Returns
INFIX_SUCCESS on success, or INFIX_ERROR_INVALID_ARGUMENT if the buffer is too small or another error occurs.