SObjectizer  5.8
Loading...
Searching...
No Matches
so_5::agent_identity_t Class Reference

Helper class for holding agent's identity (name or pointer). More...

#include <agent_identity.hpp>

Classes

struct  actual_name_t
 Type for case when agent has user-provided name. More...
 
struct  pointer_only_t
 Type for case when agent has no user-provided name. More...
 
struct  to_ostream_visitor_t
 
struct  to_string_visitor_t
 

Public Member Functions

bool has_actual_name () const noexcept
 Does agent have an actual name?
 
std::string_view actual_name () const noexcept
 Attempt to get an agent name.
 
std::string to_string () const
 Transform identity into a string.
 

Private Types

using value_t = std::variant< pointer_only_t, actual_name_t >
 Type of identity holder.
 

Private Member Functions

 agent_identity_t (const agent_t *pointer) noexcept
 Initializing constructor for case when agent has no user specified name.
 
 agent_identity_t (std::string_view name) noexcept
 Initializing constructor for case when agent has a user specified name.
 

Private Attributes

value_t m_value
 Agent's identity.
 

Friends

class agent_t
 
std::ostream & operator<< (std::ostream &to, const agent_identity_t &what)
 

Detailed Description

Helper class for holding agent's identity (name or pointer).

Since v.5.8.2 agents may have an optional name. If a name is set for agent a reference to this name can be returned by agent_t::so_agent_name(). But if a name is not specified then only a pointer to agent (agent_t's this value) can be used as agent's identity.

This type is intended to be used as a thin wrapper that covers cases described above. It holds a reference to agent's name if the name is specified or just pointer to an agent if there is no name. This type can be seen as a more convenient version of:

std::variant<std::string_view, const agent_t*>;
Attention
Objects of this type hold references, not values. So it's not safe to store them for a long time. Please consider to store std::string objects returned by to_string() methods instead of agent_identity_t objects.
Since
v.5.8.2

Definition at line 48 of file agent_identity.hpp.

Member Typedef Documentation

◆ value_t

Type of identity holder.

Definition at line 133 of file agent_identity.hpp.

Constructor & Destructor Documentation

◆ agent_identity_t() [1/2]

so_5::agent_identity_t::agent_identity_t ( const agent_t * pointer)
inlineprivatenoexcept

Initializing constructor for case when agent has no user specified name.

Definition at line 139 of file agent_identity.hpp.

◆ agent_identity_t() [2/2]

so_5::agent_identity_t::agent_identity_t ( std::string_view name)
inlineprivatenoexcept

Initializing constructor for case when agent has a user specified name.

Definition at line 144 of file agent_identity.hpp.

Member Function Documentation

◆ actual_name()

std::string_view so_5::agent_identity_t::actual_name ( ) const
inlinenodiscardnoexcept

Attempt to get an agent name.

Returns
empty std::string_view if agent has no an actual name.

Definition at line 163 of file agent_identity.hpp.

◆ has_actual_name()

bool so_5::agent_identity_t::has_actual_name ( ) const
inlinenodiscardnoexcept

Does agent have an actual name?

Definition at line 152 of file agent_identity.hpp.

◆ to_string()

std::string so_5::agent_identity_t::to_string ( ) const
inlinenodiscard

Transform identity into a string.

Definition at line 174 of file agent_identity.hpp.

Friends And Related Symbol Documentation

◆ agent_t

friend class agent_t
friend

Definition at line 50 of file agent_identity.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & to,
const agent_identity_t & what )
friend

Definition at line 179 of file agent_identity.hpp.

Member Data Documentation

◆ m_value

value_t so_5::agent_identity_t::m_value
private

Agent's identity.

Definition at line 136 of file agent_identity.hpp.


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