Skip to content

Class zmbt::Environment

ClassList > zmbt > Environment

Controlled environment data storage. More...

  • #include <environment.hpp>

Classes

Type Name
class InterfaceHandle
Environment extension handling the interface data.
class TypedInterfaceHandle <class Interface>
Environment API handler for specific interface.

Public Functions

Type Name
PersistentConfig Config () const
bool ContainsShared (boost::json::string_view fmtstr, A &&... arg) const
Check if shared variable exists.
object_id DefaultObjectId (interface_id const & ifc_id) const
lock_t DeferLock () const
Get the Environment thread lock with std::defer_lock tag.
void DumpJsonData (std::ostream & os)
Dump current environment state in prettified JSON.
Environment ()
Environment (Environment &&) = default
Environment (Environment const &) = default
SignalOperatorHandler GetOperator (boost::json::string_view name) const
SignalOperatorHandler GetOperatorOrDefault (boost::json::string_view name) const
boost::json::string GetOrRegisterInterface (object_id const & obj_id, interface_id const & ifc_id)
boost::json::string GetOrRegisterParametricTrigger (object_id const & obj_id, interface_id const & ifc_id)
std::shared_ptr< T > GetShared (boost::json::string_view fmtstr, A &&... arg) const
Get the shared data associated with object and string key.
T GetVar (object_id obj, std::string key)
Get the environment variable.
T GetVar (std::string key)
boost::json::value GetVar (object_id obj, std::string key)
boost::json::value GetVar (std::string key)
T GetVarOrDefault (object_id obj, std::string key, T default_value=reflect::signal_traits< T >::init())
Get the environment variable or use default.
T GetVarOrDefault (std::string key, T default_value=reflect::signal_traits< T >::init())
boost::json::value GetVarOrDefault (object_id obj, std::string key, boost::json::value default_value=nullptr)
boost::json::value GetVarOrDefault (std::string key, boost::json::value default_value=nullptr)
T GetVarOrUpdate (object_id obj, std::string key, T update_value)
Get or update the environment variable.
T GetVarOrUpdate (std::string key, T update_value)
boost::json::value GetVarOrUpdate (object_id obj, std::string key, boost::json::value update_value)
boost::json::value GetVarOrUpdate (std::string key, boost::json::value update_value)
Environment & HandleTestFailure (boost::json::value const & diagnostics)
bool HasAction (boost::json::string_view key) const
bool HasTrigger (boost::json::string_view key) const
interface_id InterfaceId (boost::json::string_view interface_key) const
lock_t Lock () const
Get the Environment thread lock.
object_id ObjectId (boost::json::string_view interface_key) const
Environment & RegisterAction (std::function< void()> action, boost::json::string_view fmtstr, A &&... arg)
Environment & RegisterAnonymousInterface (interface_id const & ifc_id, object_id const & obj_id)
enable_if_t< is_ifc_handle< I >::value, Environment & > RegisterAnonymousInterface (I && interface, object_id const & obj_id=object_id{ifc_host_nullptr< I >})
boost::json::string RegisterAnonymousTrigger (H && host, I && interface)
Environment & RegisterInterface (boost::json::string_view key, interface_id const & ifc_id, object_id const & obj_id)
Register interface to enable FFI in the test model runners.
enable_if_t< is_ifc_handle< I >::value, Environment & > RegisterInterface (boost::json::string_view key, I && interface, object_id const & obj_id=object_id{ifc_host_nullptr< I >})
Environment & RegisterOperator (boost::json::string_view key, SignalOperatorHandler const & op)
Register operator handler to enable FFI for type decoration in the test model runners.
Environment & RegisterOperator (SignalOperatorHandler const & op)
interface_id RegisterParametricTriggerIfc (I && interface)
object_id RegisterParametricTriggerObj (T && obj)
Environment & RegisterPrototypes (I && interface)
Environment & RegisterTrigger (boost::json::string_view key, I && interface, H && host)
Register test trigger to enable FFI in the test model runners.
Environment & RegisterTrigger (boost::json::string_view key, I && interface)
void ResetAll ()
Clear all data.
void ResetAllFor (object_id obj)
Clear data associated with the object.
Environment & ResetFailureHandler ()
Reset the test handler to default.
void ResetInterfaceData ()
Clear all interface data (accessed via ArgsFor/ReturnFor)
void ResetInterfaceDataFor (object_id obj)
Clear interface data associated with the object (accessed via ArgsFor/ReturnFor)
Environment & RunAction (boost::json::string_view fmtstr, A &&... arg)
Environment & SetFailureHandler (std::function< void(boost::json::value const &)> const & fn)
Set custom test failure handler.
Environment & SetPrettyPrint (bool const pretty_print=true)
Set pretty print JSON values.
void SetShared (std::shared_ptr< T > data, boost::json::string_view fmtstr, A &&... arg)
Set the shared data associated with key.
void SetVar (object_id obj, std::string key, T var)
Set the environment variable.
void SetVar (std::string key, T var)
lock_t TryLock () const
Get the Environment thread lock with std::try_to_lock tag.
JsonNode & json_data ()
JsonNode const & json_data () const
Environment & operator= (Environment &&) = default
Environment & operator= (Environment const &) = default
virtual ~Environment ()

Public Static Functions

Type Name
boost::json::string autokey (object_id const & obj_id, interface_id const & ifc_id)

Protected Types

Type Name
typedef std::function< void(boost::json::value const &)> FailureHandler
typedef reflect::invocation_args_t< ifc_pointer_t< T > > argsref_t
typedef mp_transform< rvref_to_val, argsref_t< I > > hookout_args_t
typedef typename EnvironmentData::lock_t lock_t
typedef reflect::invocation_ret_t< ifc_pointer_t< T > > return_t
typedef mp_if< std::is_rvalue_reference< T >, std::remove_reference_t< T >, T > rvref_to_val
typedef reflect::invocation_args_unqf_t< ifc_pointer_t< T > > unqf_args_t

Protected Attributes

Type Name
std::shared_ptr< PersistentConfig > config_
std::shared_ptr< EnvironmentData > data_

Detailed Description

Handles signal values and calls counters to/from environment, using interface pointers as keys

Public Functions Documentation

function Config

PersistentConfig zmbt::Environment::Config () const

function ContainsShared

Check if shared variable exists.

template<class... A>
inline bool zmbt::Environment::ContainsShared (
    boost::json::string_view fmtstr,
    A &&... arg
) const


function DefaultObjectId

object_id zmbt::Environment::DefaultObjectId (
    interface_id const & ifc_id
) const

function DeferLock

Get the Environment thread lock with std::defer_lock tag.

lock_t zmbt::Environment::DeferLock () const


function DumpJsonData

Dump current environment state in prettified JSON.

void zmbt::Environment::DumpJsonData (
    std::ostream & os
) 

Parameters:

  • os output stream

function Environment [1/3]

zmbt::Environment::Environment () 

function Environment [2/3]

zmbt::Environment::Environment (
    Environment &&
) = default

function Environment [3/3]

zmbt::Environment::Environment (
    Environment const &
) = default

function GetOperator

SignalOperatorHandler zmbt::Environment::GetOperator (
    boost::json::string_view name
) const

function GetOperatorOrDefault

SignalOperatorHandler zmbt::Environment::GetOperatorOrDefault (
    boost::json::string_view name
) const

function GetOrRegisterInterface

boost::json::string zmbt::Environment::GetOrRegisterInterface (
    object_id const & obj_id,
    interface_id const & ifc_id
) 

function GetOrRegisterParametricTrigger

boost::json::string zmbt::Environment::GetOrRegisterParametricTrigger (
    object_id const & obj_id,
    interface_id const & ifc_id
) 

function GetShared

Get the shared data associated with object and string key.

template<class T, class... A>
inline std::shared_ptr< T > zmbt::Environment::GetShared (
    boost::json::string_view fmtstr,
    A &&... arg
) const

Dynamic polymorphism is not supported, as the type safety is ensured by comparing typeid(T). If the type T is not exactly the same as was used on corresponding SetShared call, the method will throw environment_error.

If corresponding data was not set, the metod return nullptr.

Template parameters:

  • T
  • A

Parameters:

  • fmtstr key format string
  • arg key format arguments

Returns:

std::shared_ptr<T>


function GetVar [1/4]

Get the environment variable.

template<class T>
inline T zmbt::Environment::GetVar (
    object_id obj,
    std::string key
) 

Template parameters:

  • T

Parameters:

  • obj
  • key

Returns:

T


function GetVar [2/4]

template<class T>
inline T zmbt::Environment::GetVar (
    std::string key
) 

function GetVar [3/4]

inline boost::json::value zmbt::Environment::GetVar (
    object_id obj,
    std::string key
) 

function GetVar [4/4]

inline boost::json::value zmbt::Environment::GetVar (
    std::string key
) 

function GetVarOrDefault [1/4]

Get the environment variable or use default.

template<class T>
inline T zmbt::Environment::GetVarOrDefault (
    object_id obj,
    std::string key,
    T default_value=reflect::signal_traits < T >::init()
) 

Template parameters:

  • T

Parameters:

  • obj
  • key
  • default_value

Returns:

T


function GetVarOrDefault [2/4]

template<class T>
inline T zmbt::Environment::GetVarOrDefault (
    std::string key,
    T default_value=reflect::signal_traits < T >::init()
) 

function GetVarOrDefault [3/4]

inline boost::json::value zmbt::Environment::GetVarOrDefault (
    object_id obj,
    std::string key,
    boost::json::value default_value=nullptr
) 

function GetVarOrDefault [4/4]

inline boost::json::value zmbt::Environment::GetVarOrDefault (
    std::string key,
    boost::json::value default_value=nullptr
) 

function GetVarOrUpdate [1/4]

Get or update the environment variable.

template<class T>
inline T zmbt::Environment::GetVarOrUpdate (
    object_id obj,
    std::string key,
    T update_value
) 

Template parameters:

  • T

Parameters:

  • obj
  • key
  • update_value

Returns:

T


function GetVarOrUpdate [2/4]

template<class T>
inline T zmbt::Environment::GetVarOrUpdate (
    std::string key,
    T update_value
) 

function GetVarOrUpdate [3/4]

inline boost::json::value zmbt::Environment::GetVarOrUpdate (
    object_id obj,
    std::string key,
    boost::json::value update_value
) 

function GetVarOrUpdate [4/4]

inline boost::json::value zmbt::Environment::GetVarOrUpdate (
    std::string key,
    boost::json::value update_value
) 

function HandleTestFailure

Environment & zmbt::Environment::HandleTestFailure (
    boost::json::value const & diagnostics
) 

function HasAction

bool zmbt::Environment::HasAction (
    boost::json::string_view key
) const

function HasTrigger

bool zmbt::Environment::HasTrigger (
    boost::json::string_view key
) const

function InterfaceId

interface_id zmbt::Environment::InterfaceId (
    boost::json::string_view interface_key
) const

function Lock

Get the Environment thread lock.

lock_t zmbt::Environment::Lock () const


function ObjectId

object_id zmbt::Environment::ObjectId (
    boost::json::string_view interface_key
) const

function RegisterAction

template<class... A>
inline Environment & zmbt::Environment::RegisterAction (
    std::function< void()> action,
    boost::json::string_view fmtstr,
    A &&... arg
) 

function RegisterAnonymousInterface [1/2]

inline Environment & zmbt::Environment::RegisterAnonymousInterface (
    interface_id const & ifc_id,
    object_id const & obj_id
) 

function RegisterAnonymousInterface [2/2]

template<class I>
inline enable_if_t< is_ifc_handle< I >::value, Environment & > zmbt::Environment::RegisterAnonymousInterface (
    I && interface,
    object_id const & obj_id=object_id { ifc_host_nullptr < I >}
) 

function RegisterAnonymousTrigger

template<class H, class I>
inline boost::json::string zmbt::Environment::RegisterAnonymousTrigger (
    H && host,
    I && interface
) 

function RegisterInterface [1/2]

Register interface to enable FFI in the test model runners.

Environment & zmbt::Environment::RegisterInterface (
    boost::json::string_view key,
    interface_id const & ifc_id,
    object_id const & obj_id
) 

Parameters:

  • obj_id object associated with callable
  • ifc_id callable handle
  • key string key, unique per environment

Returns:


function RegisterInterface [2/2]

template<class I>
inline enable_if_t< is_ifc_handle< I >::value, Environment & > zmbt::Environment::RegisterInterface (
    boost::json::string_view key,
    I && interface,
    object_id const & obj_id=object_id { ifc_host_nullptr < I >}
) 

function RegisterOperator [1/2]

Register operator handler to enable FFI for type decoration in the test model runners.

Environment & zmbt::Environment::RegisterOperator (
    boost::json::string_view key,
    SignalOperatorHandler const & op
) 

Parameters:

  • op operator handler
  • key string key, unique per environment

Returns:


function RegisterOperator [2/2]

inline Environment & zmbt::Environment::RegisterOperator (
    SignalOperatorHandler const & op
) 

function RegisterParametricTriggerIfc

template<class I>
inline interface_id zmbt::Environment::RegisterParametricTriggerIfc (
    I && interface
) 

function RegisterParametricTriggerObj

template<class T>
inline object_id zmbt::Environment::RegisterParametricTriggerObj (
    T && obj
) 

function RegisterPrototypes

template<class I>
inline Environment & zmbt::Environment::RegisterPrototypes (
    I && interface
) 

function RegisterTrigger [1/2]

Register test trigger to enable FFI in the test model runners.

template<class I, class H>
inline Environment & zmbt::Environment::RegisterTrigger (
    boost::json::string_view key,
    I && interface,
    H && host
) 

Template parameters:

  • H
  • I

Parameters:

  • host callable host object
  • interface callable interface handle
  • key string key, unique per environment

Returns:


function RegisterTrigger [2/2]

template<class I>
inline Environment & zmbt::Environment::RegisterTrigger (
    boost::json::string_view key,
    I && interface
) 

function ResetAll

Clear all data.

void zmbt::Environment::ResetAll () 


function ResetAllFor

Clear data associated with the object.

void zmbt::Environment::ResetAllFor (
    object_id obj
) 

Parameters:

  • obj

function ResetFailureHandler

Reset the test handler to default.

Environment & zmbt::Environment::ResetFailureHandler () 


function ResetInterfaceData

Clear all interface data (accessed via ArgsFor/ReturnFor)

void zmbt::Environment::ResetInterfaceData () 

Warning:

this will invalidate interface records


function ResetInterfaceDataFor

Clear interface data associated with the object (accessed via ArgsFor/ReturnFor)

void zmbt::Environment::ResetInterfaceDataFor (
    object_id obj
) 

Warning:

this will invalidate interface records

Parameters:

  • obj

function RunAction

template<class... A>
inline Environment & zmbt::Environment::RunAction (
    boost::json::string_view fmtstr,
    A &&... arg
) 

function SetFailureHandler

Set custom test failure handler.

Environment & zmbt::Environment::SetFailureHandler (
    std::function< void(boost::json::value const &)> const & fn
) 


function SetPrettyPrint

Set pretty print JSON values.

Environment & zmbt::Environment::SetPrettyPrint (
    bool const pretty_print=true
) 


function SetShared

Set the shared data associated with key.

template<class T, class... A>
inline void zmbt::Environment::SetShared (
    std::shared_ptr< T > data,
    boost::json::string_view fmtstr,
    A &&... arg
) 

this will prolong the original data lifetime

Template parameters:

  • T
  • A

Parameters:

  • data
  • fmtstr key format string
  • arg key format arguments

function SetVar [1/2]

Set the environment variable.

template<class T>
inline void zmbt::Environment::SetVar (
    object_id obj,
    std::string key,
    T var
) 

Template parameters:

  • T

Parameters:

  • obj
  • key
  • var

function SetVar [2/2]

template<class T>
inline void zmbt::Environment::SetVar (
    std::string key,
    T var
) 

function TryLock

Get the Environment thread lock with std::try_to_lock tag.

lock_t zmbt::Environment::TryLock () const


function json_data [1/2]

inline JsonNode & zmbt::Environment::json_data () 

function json_data [2/2]

inline JsonNode const & zmbt::Environment::json_data () const

function operator=

Environment & zmbt::Environment::operator= (
    Environment &&
) = default

function operator=

Environment & zmbt::Environment::operator= (
    Environment const &
) = default

function ~Environment

inline virtual zmbt::Environment::~Environment () 

Public Static Functions Documentation

function autokey

static inline boost::json::string zmbt::Environment::autokey (
    object_id const & obj_id,
    interface_id const & ifc_id
) 

Protected Types Documentation

typedef FailureHandler

using zmbt::Environment::FailureHandler =  std::function<void(boost::json::value const&)>;

typedef argsref_t

using zmbt::Environment::argsref_t =  reflect::invocation_args_t<ifc_pointer_t<T> >;

typedef hookout_args_t

using zmbt::Environment::hookout_args_t =  mp_transform<rvref_to_val, argsref_t<I> >;

typedef lock_t

using zmbt::Environment::lock_t =  typename EnvironmentData::lock_t;

typedef return_t

using zmbt::Environment::return_t =  reflect::invocation_ret_t<ifc_pointer_t<T> >;

typedef rvref_to_val

using zmbt::Environment::rvref_to_val =  mp_if<std::is_rvalue_reference<T>, std::remove_reference_t<T>, T>;

typedef unqf_args_t

using zmbt::Environment::unqf_args_t =  reflect::invocation_args_unqf_t<ifc_pointer_t<T> >;

Protected Attributes Documentation

variable config_

std::shared_ptr<PersistentConfig> zmbt::Environment::config_;

variable data_

std::shared_ptr<EnvironmentData> zmbt::Environment::data_;


The documentation for this class was generated from the following file zmbt-framework/zmbt-framework/backends/cxx/include/zmbt/model/environment.hpp