Message

Forward declaration of the Message template class.

Defined in Rodin/Alert/Message.h

template <
  class Prefix>
class Message;
Template parameters
Prefix The prefix type for the message.

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;
Direct inheritance by class family
Message
↓

Derived classes

Derived classDescription
PrefixedMessage<Prefix>public
Full type
PrefixedMessage< Prefix >
Convenience message for custom Alert prefixes.

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& tag) -> Message&
Stream insertion operator for NewLine tag.
void operator<<(const RaiseT& tag)
Stream insertion operator for Raise tag.
void raise() const virtual
Raises (outputs) the message to the user.
void setOutputStream(std::ostream& os)
Sets the output stream for this message.

Function documentation

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.

Message(const Message& other)

Copy constructor.

Parameters
other Object to copy.

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

Message(Message&& other) defaulted

Move constructor.

Parameters
other Object to move.

const char* 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> template<class T>
std::enable_if_t<Internal::CanBeOutput<T>::Value, Message&> 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.

Message& operator<<(const NewLineT& tag)

Stream insertion operator for NewLine tag.

Parameters
tag Formatting or action tag selected through its type.
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.

void operator<<(const RaiseT& tag)

Stream insertion operator for Raise tag.

Parameters
tag Formatting or action tag selected through its type.

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

void 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 throws after writing the diagnostic).

void 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.