ROSE
0.11.96.11
|
Converts text to messages.
A message stream is a subclass of std::ostream
and therefore allows all the usual stream insertion operators (<<
). A stream converts each line of output text to a single message, creating the message with properties defined for the stream and sending the results to a specified destination. Streams typically impart a facility name and importance level to each message via the stream's properties.
#include <Message.h>
Public Member Functions | |
Stream (const std::string facilityName, Importance imp, const DestinationPtr &destination) | |
Construct a stream and initialize its name and importance properties. | |
Stream (const MesgProps &props, const DestinationPtr &destination) | |
Construct a stream and initialize its properties as specified. | |
Stream (const Stream &other) | |
Construct a new stream from an existing stream. More... | |
Stream & | operator= (const Stream &other) |
Initialize this stream from another stream. More... | |
Stream (const std::ostream &other_) | |
Copy constructor with dynamic cast. More... | |
Stream & | operator= (const std::ostream &other_) |
Assignment with dynamic cast. More... | |
void | incrementRefCount () |
size_t | decrementRefCount () |
SProxy | dup () const |
Used for partial messages when std::move is missing. More... | |
bool | enabled () const |
Returns true if a stream is enabled. More... | |
bool | operator! () const |
Returns false if this stream is enabled. | |
MesgProps | properties () const |
Return the default properties for this stream. More... | |
operator void * () const | |
Returns true if this stream is enabled. More... | |
operator bool () const | |
Returns true if this stream is enabled. More... | |
void | enable (bool b=true) |
Enable or disable a stream. More... | |
void | disable () |
Enable or disable a stream. More... | |
void | completionString (const std::string &s, bool asDefault=true) |
Set message or stream property. More... | |
void | interruptionString (const std::string &s, bool asDefault=true) |
Set message or stream property. More... | |
void | cancelationString (const std::string &s, bool asDefault=true) |
Set message or stream property. More... | |
void | facilityName (const std::string &s, bool asDefault=true) |
Set message or stream property. More... | |
DestinationPtr | destination () const |
Property: message destination. More... | |
Stream & | destination (const DestinationPtr &d) |
Property: message destination. More... | |
Protected Member Functions | |
void | initFromNS (const Stream &other) |
Initiaize this stream from other . More... | |
Sawyer::Message::Stream::Stream | ( | const Stream & | other | ) |
Construct a new stream from an existing stream.
If other
has a pending message then ownership of that message is moved to this new stream.
Thread safety: This method is thread-safe.
Sawyer::Message::Stream::Stream | ( | const std::ostream & | other_ | ) |
Copy constructor with dynamic cast.
Same as Stream(const Stream&)
but declared so we can do things like this:
Thread safety: This method is thread-safe.
Initialize this stream from another stream.
If other
has a pending message then ownership of that message is moved to this stream.
Thread safety: This method is thread-safe.
Stream& Sawyer::Message::Stream::operator= | ( | const std::ostream & | other_ | ) |
Assignment with dynamic cast.
Same as operator=(const Stream&)
but declared so we can do things like this:
Thread safety: This method is thread-safe.
SProxy Sawyer::Message::Stream::dup | ( | ) | const |
Used for partial messages when std::move is missing.
Thread safety: This method is thread-safe.
|
protected |
Initiaize this stream from other
.
This stream will get its own StreamBuf (if it doesn't have one already), and any pending message from other
will be moved (not copied) to this stream.
Thread safety: This method is not thread-safe–the caller is expected to obtain the necessary locks.
bool Sawyer::Message::Stream::enabled | ( | ) | const |
Returns true if a stream is enabled.
Thread safety: This method is thread-safe.
|
inline |
Returns true if this stream is enabled.
This implicit conversion to bool can be used to conveniently avoid expensive insertion operations when a stream is disabled. For example, if printing MemoryMap
is an expensive operation then the logging can be written any of these ways to avoid formatting memorymap when logging is disabled:
The SAWYER_MESG_FIRST macro is similar in that it short circuits, but it prints to the first stream that's enabled For example, these two are equivalent:
Thread safety: This method is thread-safe.
|
inline |
Returns true if this stream is enabled.
This implicit conversion to bool can be used to conveniently avoid expensive insertion operations when a stream is disabled. For example, if printing MemoryMap
is an expensive operation then the logging can be written any of these ways to avoid formatting memorymap when logging is disabled:
The SAWYER_MESG_FIRST macro is similar in that it short circuits, but it prints to the first stream that's enabled For example, these two are equivalent:
Thread safety: This method is thread-safe.
void Sawyer::Message::Stream::enable | ( | bool | b = true | ) |
Enable or disable a stream.
A disabled stream buffers the latest partial message and enabling the stream will cause the entire accumulated message to be emitted–whether the partial message immediately appears on the output is up to the message sinks.
Thread safety: This method is thread-safe.
|
inline |
Enable or disable a stream.
A disabled stream buffers the latest partial message and enabling the stream will cause the entire accumulated message to be emitted–whether the partial message immediately appears on the output is up to the message sinks.
Thread safety: This method is thread-safe.
void Sawyer::Message::Stream::completionString | ( | const std::string & | s, |
bool | asDefault = true |
||
) |
Set message or stream property.
If asDefault
is false then the property is set only in the current message and the message must be empty (e.g., just after the previous message was completed). When asDefault
is true the new value becomes the default for all future messages. The default also affects the current message if the current message is empty.
Thread safety: This method is thread-safe.
void Sawyer::Message::Stream::interruptionString | ( | const std::string & | s, |
bool | asDefault = true |
||
) |
Set message or stream property.
If asDefault
is false then the property is set only in the current message and the message must be empty (e.g., just after the previous message was completed). When asDefault
is true the new value becomes the default for all future messages. The default also affects the current message if the current message is empty.
Thread safety: This method is thread-safe.
void Sawyer::Message::Stream::cancelationString | ( | const std::string & | s, |
bool | asDefault = true |
||
) |
Set message or stream property.
If asDefault
is false then the property is set only in the current message and the message must be empty (e.g., just after the previous message was completed). When asDefault
is true the new value becomes the default for all future messages. The default also affects the current message if the current message is empty.
Thread safety: This method is thread-safe.
void Sawyer::Message::Stream::facilityName | ( | const std::string & | s, |
bool | asDefault = true |
||
) |
Set message or stream property.
If asDefault
is false then the property is set only in the current message and the message must be empty (e.g., just after the previous message was completed). When asDefault
is true the new value becomes the default for all future messages. The default also affects the current message if the current message is empty.
Thread safety: This method is thread-safe.
DestinationPtr Sawyer::Message::Stream::destination | ( | ) | const |
Property: message destination.
This is the pointer to the top of the plumbing lattice.
Thread safety: This method is thread-safe.
Stream& Sawyer::Message::Stream::destination | ( | const DestinationPtr & | d | ) |
Property: message destination.
This is the pointer to the top of the plumbing lattice.
Thread safety: This method is thread-safe.
MesgProps Sawyer::Message::Stream::properties | ( | ) | const |
Return the default properties for this stream.
These are the properties of the stream itself before they are adjusted by the destination lattice. The default properties are used each time the stream creates a message.
Thread safety: This method is thread-safe.