Skip to main content

ContractRegistry Class

Holds a set of Contracts and runs them to produce a ValidationReport. More...

Declaration

class simaai::neat::ContractRegistry { ... }

Included Headers

#include <ContractRegistry.h>

Public Member Typedefs Index

usingContractPtr = std::shared_ptr< Contract >

Shared-pointer alias for a Contract. More...

Public Constructors Index

ContractRegistry ()=default

Construct an empty registry. More...

Public Member Functions Index

ContractRegistry &add (ContractPtr c)

Add or replace a contract (keyed by id()); returns *this for chaining. More...

template <class T, class... Args>
ContractRegistry &emplace (Args &&... args)

Convenience: construct a contract of type T from args and add it. More...

boolremove (const std::string &id)

Remove a contract by id. Returns true if removed. More...

voidclear ()

Drop all contracts; the registry becomes empty. More...

std::size_tsize () const noexcept

Number of contracts currently registered. More...

boolempty () const noexcept

True if no contracts are registered. More...

ContractPtrget (const std::string &id) const

Get a contract by id (nullptr if missing). More...

std::vector< std::string >ids () const

Deterministic list of ids in insertion order. More...

ValidationReportvalidate (std::span< const std::shared_ptr< Node > > nodes, const ValidationContext &ctx) const

Run all contracts and return a ValidationReport. More...

Private Member Attributes Index

std::unordered_map< std::string, ContractPtr >by_id_
std::vector< std::string >order_

Description

Holds a set of Contracts and runs them to produce a ValidationReport.

Insertion order is preserved (and used as evaluation order). Adding a contract whose id() matches an existing one replaces the old contract in place. The registry is intentionally small and STL-only.

See Also

Contract

See Also

ValidationReport

See Also

Validators::DefaultRegistry

Definition at line 41 of file ContractRegistry.h.

Public Member Typedefs

ContractPtr

using simaai::neat::ContractRegistry::ContractPtr = std::shared_ptr<Contract>

Shared-pointer alias for a Contract.

Definition at line 44 of file ContractRegistry.h.

Public Constructors

ContractRegistry()

simaai::neat::ContractRegistry::ContractRegistry ()
default

Construct an empty registry.

Definition at line 47 of file ContractRegistry.h.

Public Member Functions

add()

ContractRegistry & simaai::neat::ContractRegistry::add (ContractPtr c)
inline

Add or replace a contract (keyed by id()); returns *this for chaining.

Definition at line 50 of file ContractRegistry.h.

clear()

void simaai::neat::ContractRegistry::clear ()
inline

Drop all contracts; the registry becomes empty.

Definition at line 88 of file ContractRegistry.h.

emplace()

template <class T, class... Args>
ContractRegistry & simaai::neat::ContractRegistry::emplace (Args &&... args)
inline

Convenience: construct a contract of type T from args and add it.

Definition at line 66 of file ContractRegistry.h.

empty()

bool simaai::neat::ContractRegistry::empty ()
inline noexcept

True if no contracts are registered.

Definition at line 98 of file ContractRegistry.h.

get()

ContractPtr simaai::neat::ContractRegistry::get (const std::string & id)
inline

Get a contract by id (nullptr if missing).

Definition at line 103 of file ContractRegistry.h.

ids()

std::vector< std::string > simaai::neat::ContractRegistry::ids ()
inline

Deterministic list of ids in insertion order.

Definition at line 109 of file ContractRegistry.h.

remove()

bool simaai::neat::ContractRegistry::remove (const std::string & id)
inline

Remove a contract by id. Returns true if removed.

Definition at line 71 of file ContractRegistry.h.

size()

std::size_t simaai::neat::ContractRegistry::size ()
inline noexcept

Number of contracts currently registered.

Definition at line 94 of file ContractRegistry.h.

validate()

ValidationReport simaai::neat::ContractRegistry::validate (std::span< const std::shared_ptr< Node > > nodes, const ValidationContext & ctx)
inline

Run all contracts and return a ValidationReport.

Defensive behavior:

  • contract violations should be reported (not thrown)
  • if a Contract throws, registry converts that into an internal ERROR issue

Definition at line 120 of file ContractRegistry.h.

Private Member Attributes

by_id_

std::unordered_map<std::string, ContractPtr> simaai::neat::ContractRegistry::by_id_

Definition at line 157 of file ContractRegistry.h.

order_

std::vector<std::string> simaai::neat::ContractRegistry::order_

Definition at line 158 of file ContractRegistry.h.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.