//
//  tb_component.h
//  Tightbeam

#ifndef __TIGHTBEAM_COMPONENT_H
#define __TIGHTBEAM_COMPONENT_H

#include <sys/cdefs.h>
__ptrcheck_abi_assume_single()

#include <Tightbeam/tightbeam.h>

TB_ASSUME_NONNULL_BEGIN
__TB_BEGIN_DECLS

struct tb_component_admission_table_s {
    const char * _Nonnull __null_terminated identifier;
    size_t count;
    const uint64_t * _Nullable __counted_by(count) list;
};

struct tb_component_admission_list_s {
    size_t count;
    struct tb_component_admission_table_s * _Nonnull * _Nonnull __counted_by(count) tables;
};

typedef const struct tb_component_admission_table_s * _Nonnull tb_component_decode_admission_t;

/// Perform an admission check of the given `selector` against a list of allows selectors.
///
/// This function is a private interface contract between this framework and code generated by the Tightbeam
/// compiler when performing runtime type checking.
///
/// @param table
/// An admission table listing the valid selector identifiers for the indicated type.
///
/// @param selector
/// The selector to be tested.
///
/// @return
/// This function will return `true` if the selector is found in the given admission table, or if no admission
/// table was given. If a table is supplied but the selector is not found, this function returns `false`.
TB_EXPORT
bool
tb_component_admission_search(
        const struct tb_component_admission_table_s * _Nullable table,
        uint64_t selector);

TB_EXPORT
bool
tb_component_admission_search_multiple(
        const tb_component_decode_admission_t * _Nullable __counted_by(count) list,
        size_t count, uint64_t selector);

__TB_END_DECLS
TB_ASSUME_NONNULL_END

#endif // __TIGHTBEAM_COMPONENT_H
