SObjectizer  5.8
Loading...
Searching...
No Matches
so_5/hello_world/main.cpp
/*
* A sample of the simpliest agent.
*/
#include <iostream>
// Main SObjectizer header files.
#include <so_5/all.hpp>
// Definition of an agent for SObjectizer.
class a_hello_t final : public so_5::agent_t
{
public:
// A reaction to start of work in SObjectizer.
void so_evt_start() override
{
std::cout << "Hello, world! This is SObjectizer v.5 ("
<< SO_5_VERSION << ")" << std::endl;
// Shutting down SObjectizer.
}
// A reaction to finish of work in SObjectizer.
void so_evt_finish() override
{
std::cout << "Bye! This was SObjectizer v.5." << std::endl;
}
};
int main()
{
try
{
// Starting SObjectizer.
// A function for SO Environment initialization.
[]( so_5::environment_t & env )
{
// Creating and registering single agent as a cooperation.
env.register_agent_as_coop( env.make_agent< a_hello_t >() );
} );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
A base class for agents.
Definition agent.hpp:673
agent_t(environment_t &env)
Constructor.
Definition agent.cpp:775
virtual void so_evt_finish()
Hook of agent finish in SObjectizer.
Definition agent.cpp:838
environment_t & so_environment() const noexcept
Access to the SObjectizer Environment which this agent is belong.
Definition agent.cpp:987
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Definition agent.cpp:832
SObjectizer Environment.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
void stop() noexcept
Send a shutdown signal to the Run-Time.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
Definition api.hpp:142
#define SO_5_VERSION
Definition version.hpp:69