Utilities#

constellation::utils Namespace#

using constellation::utils::Port = std::uint16_t#

Port number for a network connection.

Note that most ports in Constellation are ephemeral ports, meaning that the port numbers are allocated dynamically. See also https://en.wikipedia.org/wiki/Ephemeral_port.

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 T>
inline const char *constellation::utils::to_char_ptr(const T *data)#
template<typename T>
inline char *constellation::utils::to_char_ptr(T *data)#
template<typename T>
inline const void *constellation::utils::to_void_ptr(const T *data)#
template<typename T>
inline void *constellation::utils::to_void_ptr(T *data)#
template<typename T>
inline const std::byte *constellation::utils::to_byte_ptr(const T *data)#
template<typename T>
inline std::byte *constellation::utils::to_byte_ptr(T *data)#
template<typename R>
inline std::span<const std::byte> constellation::utils::to_byte_span(const R &range)#
template<typename R>
inline std::span<std::byte> constellation::utils::to_byte_span(R &range)#
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

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_#
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.

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.

class StopwatchTimer#
#include <constellation/core/utils/timers.hpp>

Timer that can be used as a stopwatch

Public Functions

inline StopwatchTimer()#
inline void start()#
inline void stop()#
inline std::chrono::nanoseconds duration() const#
struct string_hash#
#include <constellation/core/utils/string_hash_map.hpp>

Hash for std::unorderd_map

Public Types

using hash_type = std::hash<std::string_view>#
using is_transparent = void#

Public Functions

inline std::size_t operator()(const char *str) const#
inline std::size_t operator()(std::string_view str) const#
inline std::size_t operator()(const std::string &str) const#
class TimeoutTimer#
#include <constellation/core/utils/timers.hpp>

Timer that can be used to wait for timeouts

Public Functions

inline TimeoutTimer(std::chrono::nanoseconds timeout)#
inline void start()#
inline bool timeoutReached() const#