Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional name for an agent? #76

Closed
eao197 opened this issue Feb 3, 2024 · 2 comments
Closed

Optional name for an agent? #76

eao197 opened this issue Feb 3, 2024 · 2 comments
Assignees
Milestone

Comments

@eao197
Copy link
Member

eao197 commented Feb 3, 2024

For some case (like logging and run-time monitoring) may be useful to have a possibility to specify a name for an agent. That name has to be stored inside so_5::agent_t and should be available via a pointer/reference to so_5::agent_t.

@eao197 eao197 added this to the SO-5.8.2 milestone Feb 3, 2024
@eao197 eao197 self-assigned this Feb 3, 2024
@eao197
Copy link
Member Author

eao197 commented Feb 3, 2024

I don't think it's a good idea to place another std::string into so_5::agent_t, because in the most cases it will be an empty value.

Maybe something like that:

namespace so_5
{

// Public stuff.

struct anonymous_agent_id_t { std::array<char, N> m_ptr_as_id; };
struct named_agent_id_t { std::string_view m_name; }
using agent_name_t = std::variant<anonymous_agent_id_t, named_agent_id_t>;

[[nodiscard]]
std::string_view to_string_view(const agent_name_t & name);

class agent_t {
public:
  [[nodiscard]]
  agent_name_t
  so_agent_name() const noexcept;

private:
  std::unique_ptr<char[]> m_agent_name;
};

} /* namespace so_5 */

If the name is not specified in the constructor (via modificators for context_t object) then agent_t::m_agent_name will be nullptr. And agent_t::so_agent_name() will return an instance of anonymous_agent_id_t where m_ptr_as_id will hold a string representation of agent's this pointer.

If the name is specified, then agent_t::m_agent_name will contain a copy of name inside, and agent_t::so_agent_name() will return named_agent_id_t that references this name.

So if the name is not used the space penalty will be just sizeof(std::unique_ptr<char[]>) (8 bytes for 64-bit platform).

@eao197
Copy link
Member Author

eao197 commented Mar 22, 2024

It's a part of v.5.8.2 release.

@eao197 eao197 closed this as completed Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant