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
-
using constellation::utils::string_hash_set = std::unordered_set<std::string, string_hash, std::equal_to<>>#
Unordered string set 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_insensitive = true) noexcept#
-
template<typename E>
auto constellation::utils::enum_names() noexcept#
-
template<typename S, typename T>
inline void constellation::utils::msgpack_pack(S &stream, const T &object)# MsgPack helper function to pack value to a stream.
- Throws:
MsgpackPackError – if packing fails
- Template Parameters:
S – Reference to target stream
T – Value to be packed
-
template<typename R, typename ...Args>
inline R constellation::utils::msgpack_unpack_to(Args&&... args)# MsgPack helper to unpack a value to target type.
- Throws:
MsgpackUnpackError – if unpacking fails
- Template Parameters:
R – Target return type
Args – Variadic arguments
- Returns:
Unpacked value in target type
-
template<typename R, typename ...Args>
inline R constellation::utils::msgpack_unpack_to_enum(Args&&... args)# MsgPack helper to unpack an enum.
- Throws:
MsgpackUnpackError – if unpacking fails
- Template Parameters:
R – Target return type
Args – Variadic arguments
- Returns:
Unpacked value in target type
-
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
-
template<typename T>
inline void constellation::utils::set_thread_name(T &thread, const std::string &name)#
-
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 demangle (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
Subclassed by constellation::metrics::InvalidMetricValueException
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 ManagerLocator#
- #include <constellation/core/utils/ManagerLocator.hpp>
Manager locator.
This class is a singleton that manages the access, creation and destruction of various managers. It acts as a single global instance to avoid issues with static order initialization when managers have dependencies on each other.
Public Functions
-
inline ~ManagerLocator()#
Public Static Functions
-
static inline ManagerLocator &getInstance()#
-
static inline log::SinkManager &getSinkManager()#
Return the sink manager.
-
static inline metrics::MetricsManager &getMetricsManager()#
Return the metrics manager.
-
static inline chirp::Manager *getCHIRPManager()#
Return the CHIRP manager.
-
static inline void setDefaultCHIRPManager(std::unique_ptr<chirp::Manager> manager)#
Create the default CHIRP manager.
-
inline ~ManagerLocator()#
-
class MsgpackError : public constellation::utils::RuntimeError#
- #include <constellation/core/utils/exceptions.hpp>
Error in encoding or decoding MsgPack data.
Issues in treating incoming or outgoing MsgPack-encoded data
Subclassed by constellation::utils::MsgpackPackError, constellation::utils::MsgpackUnpackError
Public Functions
-
inline explicit MsgpackError(const std::string &type, const std::string &reason)#
-
inline explicit MsgpackError(const std::string &type, const std::string &reason)#
-
class MsgpackPackError : public constellation::utils::MsgpackError#
Public Functions
-
inline explicit MsgpackPackError(const std::string &type, const std::string &reason)#
-
inline explicit MsgpackPackError(const std::string &type, const std::string &reason)#
-
class MsgpackUnpackError : public constellation::utils::MsgpackError#
Public Functions
-
inline explicit MsgpackUnpackError(const std::string &type, const std::string &reason)#
-
inline explicit MsgpackUnpackError(const std::string &type, const std::string &reason)#
-
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::networking::NetworkError, constellation::satellite::FSMError, constellation::satellite::SatelliteError, constellation::satellite::UserCommandError, constellation::utils::MsgpackError
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::unordered_map
-
class TimeoutTimer#
- #include <constellation/core/utils/timers.hpp>
Timer that can be used to wait for timeouts