A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
a11::nodes::NodeMap Class Reference

A thread-safe registry of AsyncNodes keyed by id. More...

#include <cpp/a11/nodes/node_map.h>

Inheritance diagram for a11::nodes::NodeMap:
[legend]

Public Member Functions

 ~NodeMap ()=default
 
absl::StatusOr< std::shared_ptr< AsyncNode > > Get (std::string node_id)
 Return the node for an id, creating it if it does not exist.
 
absl::StatusOr< std::shared_ptr< AsyncNode > > GetIfExists (std::string_view node_id) const
 Return the node for an id without creating it.
 
absl::StatusOr< std::shared_ptr< AsyncNode > > Discard (std::string_view node_id, const std::shared_ptr< AsyncNode > &expected=nullptr)
 Remove the node for an id.
 
bool Contains (std::string_view node_id) const
 Report whether a node with the given id exists.
 
size_t Size () const
 Return the number of nodes currently in the map.
 

Static Public Member Functions

static absl::StatusOr< std::shared_ptr< NodeMap > > Create (ChunkStoreFactory factory={})
 Create a node map.
 

Detailed Description

A thread-safe registry of AsyncNodes keyed by id.

Nodes are created lazily on first access via the map's ChunkStoreFactory. Instances are heap-allocated and shared via Create.

Constructor & Destructor Documentation

◆ ~NodeMap()

a11::nodes::NodeMap::~NodeMap ( )
default

Member Function Documentation

◆ Contains()

bool a11::nodes::NodeMap::Contains ( std::string_view  node_id) const

Report whether a node with the given id exists.

Parameters
node_idThe node identifier.
Returns
True if the map holds a node under that id.

◆ Create()

absl::StatusOr< std::shared_ptr< NodeMap > > a11::nodes::NodeMap::Create ( ChunkStoreFactory  factory = {})
static

Create a node map.

Parameters
factoryFactory invoked to build the backing store for each new node; a default store is used when omitted.
Returns
The new map, or an error status on failure.

◆ Discard()

absl::StatusOr< std::shared_ptr< AsyncNode > > a11::nodes::NodeMap::Discard ( std::string_view  node_id,
const std::shared_ptr< AsyncNode > &  expected = nullptr 
)

Remove the node for an id.

Parameters
node_idThe node identifier.
expectedIf non-null, only remove when the stored node matches this one (compare-and-remove).
Returns
The removed node, or an error status on failure.

◆ Get()

absl::StatusOr< std::shared_ptr< AsyncNode > > a11::nodes::NodeMap::Get ( std::string  node_id)

Return the node for an id, creating it if it does not exist.

Parameters
node_idThe node identifier.
Returns
The node, or an error status on failure.

◆ GetIfExists()

absl::StatusOr< std::shared_ptr< AsyncNode > > a11::nodes::NodeMap::GetIfExists ( std::string_view  node_id) const

Return the node for an id without creating it.

Parameters
node_idThe node identifier.
Returns
The node, or nullptr if it does not exist (or an error status).

◆ Size()

size_t a11::nodes::NodeMap::Size ( ) const

Return the number of nodes currently in the map.

Returns
The node count.

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