OGLplus  (0.59.0) a C++ wrapper for rendering APIs

router_address.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_ROUTER_ADDRESS_HPP
10 #define EAGINE_MESSAGE_BUS_ROUTER_ADDRESS_HPP
11 
12 #include "../application_config.hpp"
13 #include "../main_ctx_object.hpp"
14 #include <vector>
15 
16 namespace eagine::msgbus {
17 //------------------------------------------------------------------------------
21 public:
24  : main_ctx_object{EAGINE_ID(RouterAddr), parent} {
25  if(app_config().fetch("msg_bus.router.address", _addrs)) {
26  log_debug("configured router address(es) ${addr}")
27  .arg_func([&](logger_backend& backend) {
28  for(auto& addr : _addrs) {
29  backend.add_string(
30  EAGINE_ID(address), EAGINE_ID(string), addr);
31  }
32  });
33  }
34  }
35 
37  explicit operator bool() const noexcept {
38  return !_addrs.empty();
39  }
40 
42  operator string_view() const noexcept {
43  if(_addrs.empty()) {
44  return {};
45  }
46  return {_addrs.front()};
47  }
48 
50  auto count() const noexcept -> span_size_t {
51  return span_size(_addrs.size());
52  }
53 
55  auto begin() const noexcept {
56  return _addrs.cbegin();
57  }
58 
60  auto end() const noexcept {
61  return _addrs.cend();
62  }
63 
64 private:
65  std::vector<std::string> _addrs{};
66 };
67 //------------------------------------------------------------------------------
68 } // namespace eagine::msgbus
69 
70 #endif // EAGINE_MESSAGE_BUS_ROUTER_ADDRESS_HPP
auto log_debug(string_view format) noexcept
Create a log message entry for debugging, with specified format.
Definition: logger.hpp:341
Helper class used to initialize main context objects.
Definition: main_ctx_object.hpp:45
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
Base class for main context objects.
Definition: main_ctx_object.hpp:71
basic_address< false > address
Type alias for non-const memory address values.
Definition: address.hpp:203
auto backend() noexcept
Returns a pointer to the backend of this logger object.
Definition: logger.hpp:55
auto count() const noexcept -> span_size_t
Returns the number of addresses stored in this instance.
Definition: router_address.hpp:50
router_address(main_ctx_parent parent)
Construction from parent main context object.
Definition: router_address.hpp:23
auto begin() const noexcept
Returns a const iterator to the start of the range of addresses.
Definition: router_address.hpp:55
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
auto app_config() const noexcept -> application_config &
Returns a reference to the application config object.
Class loading and managing message bus router address(es).
Definition: router_address.hpp:20
Interface for logging backend implementations.
Definition: backend.hpp:60
auto end() const noexcept
Returns a const iterator past the end of the range of addresses.
Definition: router_address.hpp:60
auto front() const noexcept -> const value_type &
Returns a const reference to value at the front of the span.
Definition: span.hpp:338

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).