template<class Prefix>
Rodin::Alert::Message class

Forward declaration of the Message template class.

Base template class for formatted message output.

Base template class for formatted message output with customizable prefixes.

Base class for creating formatted messages with customizable prefixes, colors, and styles. Messages support stream-like insertion operators for building content incrementally. This class is used as the base for Exception, Warning, Info, and Success message types.

The Message class handles:

  • Formatted output with colored prefixes
  • Automatic indentation for multi-line messages
  • Stream-like insertion operators for content
  • Integration with the Alert tag types (NewLine, Raise, etc.)

Example usage (through derived classes):

Exception() << "Error in function: " << funcName << NewLine
            << "Invalid parameter value: " << value << Raise;

Constructors, destructors, conversion operators

Message(std::ostream& os, const Prefix& prefix) noexcept
Constructs a message with output stream and prefix.
Message(const Message& other)
Copy constructor.
Message(Message&& other) defaulted
Move constructor.
~Message() defaulted virtual
Virtual destructor.

Public functions

auto what() const -> const char* noexcept
Gets the message content as a C-string.
template<class T>
auto operator<<(const T& v) -> std::enable_if_t<Internal::CanBeOutput<T>::Value, Message&> noexcept
Stream insertion operator for arbitrary streamable types.
auto operator<<(const NewLineT&) -> Message&
Stream insertion operator for NewLine tag.
auto operator<<(const RaiseT&) -> void
Stream insertion operator for Raise tag.
auto raise() const -> void virtual
Raises (outputs) the message to the user.
auto setOutputStream(std::ostream& os) -> void
Sets the output stream for this message.

Function documentation

template<class Prefix _1>
Rodin::Alert::Message<_1>::Message(std::ostream& os, const Prefix& prefix) noexcept

Constructs a message with output stream and prefix.

Parameters
os The output stream to write the message to.
prefix The message prefix object.

template<class Prefix _1>
Rodin::Alert::Message<_1>::Message(const Message& other)

Copy constructor.

Parameters
other Object to copy.

Performs a copy of the message's state including the accumulated message content.

template<class Prefix _1>
Rodin::Alert::Message<_1>::Message(Message&& other) defaulted

Move constructor.

Parameters
other Object to move.

template<class Prefix _1>
const char* Rodin::Alert::Message<_1>::what() const noexcept

Gets the message content as a C-string.

Returns Null-terminated string containing the message.

Returns the accumulated message content without formatting or color codes. Useful for logging or storing the message text.

template<class Prefix _1> template<class T>
std::enable_if_t<Internal::CanBeOutput<T>::Value, Message&> Rodin::Alert::Message<_1>::operator<<(const T& v) noexcept

Stream insertion operator for arbitrary streamable types.

Template parameters
T The type to insert (must be streamable).
Parameters
v The value to insert into the message.
Returns Reference to this Message object for method chaining.

Appends content to the message. Handles automatic indentation when content follows a newline. Only enabled for types that can be output to an ostream.

template<class Prefix _1>
Message& Rodin::Alert::Message<_1>::operator<<(const NewLineT&)

Stream insertion operator for NewLine tag.

Returns Reference to this Message object for method chaining.

Inserts a newline character and marks the next insertion for automatic indentation to align with the message prefix.

template<class Prefix _1>
void Rodin::Alert::Message<_1>::operator<<(const RaiseT&)

Stream insertion operator for Raise tag.

Triggers the raise() method to output the message and perform any associated actions (such as program termination for exceptions).

template<class Prefix _1>
void Rodin::Alert::Message<_1>::raise() const virtual

Raises (outputs) the message to the user.

Default behavior outputs the formatted message to the configured output stream. Derived classes may override this to add additional behavior (e.g., Exception terminates the program).

template<class Prefix _1>
void Rodin::Alert::Message<_1>::setOutputStream(std::ostream& os)

Sets the output stream for this message.

Parameters
os The new output stream.

Changes where the message will be output when raised.