SObjectizer
5.7
|
Since v.5.5.3 there is a possibility to tune agent options. For example, if it is required to change subscription storage for an agent it could be written as:
But what if we want to create a derived class from my_agent_with_many_subscriptions
and specify additional agent's options in the constructor of the derived class? How can we do that?
The only way for that in v.5.5.3 was the definition of another constructor for base class. That constructor must receive so_5::rt::agent_tuning_options_t object:
But this approach requires definition of yet another constructor for an agent. And yet another constructor of agent of derived class and so on. And the definition of another constructor in base class is not always possible if that class is coming from 3rd-party library and we don't want to patch the library source code.
Version 5.5.4 provides the solution for that problem.
Since v.5.5.4 it is possible to define agent's constructors which accept argument of the type so_5::rt::agent_t::context_t
(which is an alias for so_5::rt::agent_context_t
). This type can be seen as a pair of reference to SObjectizer Environment object and so_5::rt::agent_tuning_option_t object. The context_t instance can be used instead of environment_t reference. It allows to write like this:
Please note two important features of context_t
:
so_5::rt::agent_t
it is possible to use short form (e.g. context_t
instead of so_5::rt::agent_t::context_t
or so_5::rt::agent_context_t
) inside any class derived from so_5::rt::agent_t
;agent_coop_t::make_agent()
and environment_t::make_agent()
will work with agent classes for those the first argument of a constructor has type context_t
. It is because context_t
is implicitly constructed from reference to environment_t
.Because of that the usage of context_t
instead environment_t
is recommended since v.5.5.4.