Utilities#
constellation::utils
Namespace#
-
template<typename V>
using constellation::utils::string_hash_map = std::unordered_map<std::string, V, string_hash, std::equal_to<>># Unordered string map using hashes for fast lookup
-
template<typename R>
inline std::span<const std::byte> constellation::utils::to_byte_span(const R &range)#
-
template<typename E>
auto constellation::utils::enum_cast(std::string_view value, bool case_insesitive = true) noexcept#
-
template<typename E>
auto constellation::utils::enum_names() noexcept#
-
inline Port constellation::utils::bind_ephemeral_port(zmq::socket_t &socket)#
Bind ZeroMQ socket to wildcard address with ephemeral port.
See also https://libzmq.readthedocs.io/en/latest/zmq_tcp.html.
- Parameters:
socket – Reference to socket which should be bound
- Returns:
Ephemeral port assigned by operating system
-
inline std::shared_ptr<zmq::context_t> &constellation::utils::global_zmq_context()#
Return the global ZeroMQ context.
Note
Since the global ZeroMQ context is static, static classes need to store an instance of the shared pointer.
- Returns:
Shared pointer to the global ZeroMQ context
-
inline std::set<asio::ip::address_v4> constellation::utils::get_broadcast_addresses()#
-
template<typename F>
inline std::string constellation::utils::transform(std::string_view string, F operation)# Transforms a string with a given operation
-
template<typename S>
inline std::string constellation::utils::to_string(S string_like)# Converts a string-like object to a string
-
template<typename B>
inline std::string constellation::utils::to_string(B t)# Converts a bool to a string
-
template<typename A>
inline std::string constellation::utils::to_string(A t)# Converts a non-boolean arithmetic object to a string
-
template<typename T>
inline std::string constellation::utils::to_string(T tp)# Converts an std::chrono::system_clock::time_point to a string
-
template<typename D>
std::string constellation::utils::to_string(D d)# Convert a duration to a string
-
template<typename E>
inline std::string constellation::utils::to_string(E enum_val)# Converts an enum to a string
-
template<typename R, typename F>
inline std::string constellation::utils::range_to_string(const R &range, F to_string_func, const std::string &delim = ", ")# Converts a range to a string with custom to_string function and delimiter
-
template<typename R>
inline std::string constellation::utils::range_to_string(const R &range, const std::string &delim = ", ")# Converts a range to a string with custom delimiter
-
template<typename E>
inline std::string constellation::utils::list_enum_names()# List all possible enum values
-
inline std::string constellation::utils::char_to_hex_string(char c)#
Convert char as hex string
-
inline std::string constellation::utils::demangle(const std::type_info &type)#
Demangle type to human-readable form using cxxabi.
Note
This is not portable and potentially ugly, use
demangle<T>()
instead if possible.- Parameters:
type – Type info of type to demnalge (use
typeid
)- Returns:
String with demangled type or mangled name if demangling failed
-
template<typename T>
inline std::string constellation::utils::demangle()# Demangle type to human-readable form.
This function implements type demangling for common STL containers and falls back to the cxxabi
demangle()
method for other STL types and non-STL types.- Template Parameters:
T – Type to demangle
- Returns:
String with demangled type
-
inline std::string constellation::utils::to_platform_string(std::string string)#
-
inline std::string constellation::utils::to_std_string(std::string string)#
-
class Exception : public std::exception#
- #include <constellation/core/utils/exceptions.hpp>
Base class for all non-internal exceptions in framework.
Subclassed by constellation::utils::LogicError, constellation::utils::RuntimeError
Public Functions
-
inline explicit Exception(std::string what_arg)#
Creates exception with the specified problem.
- Parameters:
what_arg – Text describing the problem
-
inline const char *what() const noexcept override#
Return the error message.
- Returns:
Text describing the error
Protected Functions
-
Exception() = default#
Internal constructor for exceptions setting the error message indirectly.
Protected Attributes
-
std::string error_message_#
-
inline explicit Exception(std::string what_arg)#
-
class LogicError : public constellation::utils::Exception#
- #include <constellation/core/utils/exceptions.hpp>
Errors related to logical problems in the code structure.
Problems that could also have been detected at compile time by specialized software
Public Functions
-
inline explicit LogicError(std::string what_arg)#
Creates exception with the given logical problem.
- Parameters:
what_arg – Text describing the problem
Protected Functions
-
LogicError() = default#
Internal constructor for exceptions setting the error message indirectly.
-
inline explicit LogicError(std::string what_arg)#
-
class RuntimeError : public constellation::utils::Exception#
- #include <constellation/core/utils/exceptions.hpp>
Errors related to problems occurring at runtime.
Problems that could never have been detected at compile time
Subclassed by constellation::config::ConfigurationError, constellation::controller::ControllerError, constellation::exec::DSOLoaderError, constellation::message::IncorrectMessageType, constellation::message::MessageDecodingError, constellation::satellite::FSMError, constellation::satellite::SatelliteError, constellation::satellite::UserCommandError
Public Functions
-
inline explicit RuntimeError(std::string what_arg)#
Creates exception with the given runtime problem.
- Parameters:
what_arg – Text describing the problem
Protected Functions
-
RuntimeError() = default#
Internal constructor for exceptions setting the error message indirectly.
-
inline explicit RuntimeError(std::string what_arg)#
-
class StopwatchTimer#
- #include <constellation/core/utils/timers.hpp>
Timer that can be used as a stopwatch
-
struct string_hash#
- #include <constellation/core/utils/string_hash_map.hpp>
Hash for std::unorderd_map
-
class TimeoutTimer#
- #include <constellation/core/utils/timers.hpp>
Timer that can be used to wait for timeouts