Menu

so-5.5.4 make_agent and make_agent_with_binding methods

Yauheni Akhotnikau

The creation of agent instances was one of the few places where usage of operator new() was necessary. The agents creation could look like:

// With unique_ptr...
std::unique_ptr< my_agent > a{ new my_agent{ env, params } };

// Or with unique_ptr, but different way...
auto a = std::unique_ptr< my_agent >{ new my_agent{ env, params } };

// Or directly during adding agent to a coop.
coop->add_agent( new my_agent{ env, params } );

This approach of agent creation was inherited from the times when advanced C++11 features like variadic templates and rvalue references were not supported in all major C++ compilers at the required quality level. But times have changed. Now SObjectizer-5.5 actively uses variadic templates and doesn't support old compilers without this very important C++11 feature. Because of that a new, more convenient way for agent creation has been introduced in version 5.5.4.

Just compare:

// The pre-5.5.4 way:
auto a = std::unique_ptr< my_agent >{ new my_agent{ env, params } };

// The 5.5.4 way:
auto a = env.make_agent< my_agent >( params );

The same make_agent has been added to agent_coop_t class:

// The pre-5.5.4 way:
auto a = std::unique_ptr< my_agent >{ new my_agent{ env, params } };
coop->add_agent( std::move( a ) );
coop->add_agent( new your_agent{ env, different_params } );

// The 5.5.4 way:
auto a = env.make_agent< my_agent >( params );
coop->add_agent( std::move( a ) );
coop->make_agent< your_agent >( different_params );

There is also agent_coop_t::make_agent_with_binder() method for the case when new agent should be bound to the specific dispatcher:

auto disp = so_5::disp::active_obj::create_private_disp( env );
coop->make_agent_with_binder< my_agent >( disp->binder(), params );
coop->make_agent_with_binder< your_agent >( disp->binder(), different_params );

Attention! Please note that new make_agent and make_agent_with_binder methods require that the first argument of agent's constructor must be a reference to so_5::rt::environment_t object.


Related

Wiki: so-5.5.4 Version Info

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.