24#include <shared_mutex>
29#include <parcel/parcel.h>
48 [[nodiscard]] parcel::json_t
schema()
const {
66 static_assert(std::derived_from<T, parcel::ICell>,
67 "EventTypeRegistry::add<T>: T must be a parcel ICell-derived event type");
68 std::unique_lock lock(mu_);
69 registry_.register_kind(T::descriptor());
75 [[nodiscard]] std::vector<EventTypeInfo>
types()
const {
76 std::shared_lock lock(mu_);
77 std::vector<EventTypeInfo> out;
78 for (
const auto& desc : registry_.all()) {
79 const std::string_view kind = desc->kind();
94 [[nodiscard]] std::optional<EventTypeInfo>
find(
const std::string_view name_or_kind)
const {
95 std::shared_lock lock(mu_);
96 const auto desc = resolve(name_or_kind);
100 const std::string_view kind = desc->kind();
109 [[nodiscard]]
bool contains(
const std::string_view name_or_kind)
const {
110 std::shared_lock lock(mu_);
111 return resolve(name_or_kind) !=
nullptr;
116 [[nodiscard]] parcel::json_t
schema(
const std::string_view name_or_kind)
const {
117 std::shared_lock lock(mu_);
118 const auto desc = resolve(name_or_kind);
121 std::string{name_or_kind} +
"'"};
123 return desc->to_json();
130 [[nodiscard]] parcel::cell_type_descriptor_t
131 resolve(
const std::string_view name_or_kind)
const {
133 return registry_.find(name_or_kind);
138 return registry_.find(kind);
141 mutable std::shared_mutex mu_;
142 parcel::ParcelRegistry registry_;
175#define CONDUIT_REGISTER_EVENT(Ident) \
176 inline const ::conduit::EventTypeRegistrar<Ident> conduit_event_type_registrar_##Ident {}
Catalog of conduit event types.
Definition event_type_registry.hpp:58
std::optional< EventTypeInfo > find(const std::string_view name_or_kind) const
Look up a type by bare name ("order.created") or full kind ("conduit:event:order.created").
Definition event_type_registry.hpp:94
EventTypeRegistry()=default
std::vector< EventTypeInfo > types() const
All registered event types (descriptors whose kind starts with event_kind_prefix; parcel builtins are...
Definition event_type_registry.hpp:75
bool contains(const std::string_view name_or_kind) const
Whether a type with the given name or kind is registered.
Definition event_type_registry.hpp:109
EventTypeRegistry & add()
Register the descriptor for event type T (derived from conduit::Event<T, Name>, hence an ICell-derive...
Definition event_type_registry.hpp:65
parcel::json_t schema(const std::string_view name_or_kind) const
Per-type JSON schema for the given name or kind.
Definition event_type_registry.hpp:116
Raised by EventTypeRegistry::schema when the requested name or kind is not registered.
Definition exception.hpp:63
Event<Self, Name> library base built on parcel::SelfStructCell.
Root exception hierarchy for the conduit library.
Definition builder.hpp:22
EventTypeRegistry & global_event_types()
Program-wide event type catalog.
Definition event_type_registry.hpp:147
std::vector< EventTypeInfo > registered_event_types()
Snapshot of every type registered in the program-wide catalog.
Definition event_type_registry.hpp:163
constexpr std::string_view event_kind_prefix
Wire-kind prefix shared by every conduit event type.
Definition event.hpp:21
Identity + shape for one registered event type.
Definition event_type_registry.hpp:37
std::string_view name
Bare event name, e.g. "order.created".
Definition event_type_registry.hpp:38
std::string_view kind_id
Full wire kind, e.g. "conduit:event:order.created".
Definition event_type_registry.hpp:39
parcel::DisplayInfo display_info() const
Cell-level display info, lifted straight from the descriptor.
Definition event_type_registry.hpp:43
parcel::json_t schema() const
Per-type JSON schema: {kind, display_info, category, fields:[…]}.
Definition event_type_registry.hpp:48
parcel::cell_type_descriptor_t descriptor
Definition event_type_registry.hpp:40
Self-registering object: constructing one registers T into global_event_types().
Definition event_type_registry.hpp:156
EventTypeRegistrar() noexcept
Definition event_type_registry.hpp:157