#include <HumanStream.h>
Inheritance diagram for ers::HumanStream:
Public Member Functions | |
HumanStream () | |
HumanStream (const HumanStream &other) | |
~HumanStream () | |
std::string | to_string () |
void | clear () |
virtual void | send (const Issue *ptr) |
Sends an issue into the stream. | |
virtual void | print_to (std::ostream &stream) const |
operator std::string () const | |
virtual Issue * | receive () |
Receives an issue from the stream. | |
Static Public Member Functions | |
static std::string | to_string (const Issue *issue) throw () |
Static Public Attributes | |
static const char *const | KEY = "human" |
static const char *const | NULL_STREAM_KEY = "null" |
Protected Attributes | |
std::ostringstream | m_out_stream |
This class streams an issue into an human readable string. It is uses by the issue class to display itself. This stream can be specified for other uses, but the user is then responsible for reading data from the stream and clearing it.
Definition at line 27 of file HumanStream.h.
ers::HumanStream::HumanStream | ( | ) |
ers::HumanStream::HumanStream | ( | const HumanStream & | other | ) |
ers::HumanStream::~HumanStream | ( | ) |
void ers::HumanStream::clear | ( | ) |
Clears the content of the stream
Definition at line 61 of file HumanStream.cxx.
References m_out_stream.
00061 { 00062 m_out_stream.str(""); 00063 } // clear
ers::Stream::operator std::string | ( | ) | const [inherited] |
Definition at line 35 of file Stream.cxx.
References ers::Stream::print_to().
00035 { 00036 std::ostringstream stream ; 00037 print_to(stream); 00038 return stream.str(); 00039 } // to string
void ers::HumanStream::print_to | ( | std::ostream & | stream | ) | const [virtual] |
Reimplemented from ers::Stream.
Definition at line 65 of file HumanStream.cxx.
References KEY.
00065 { 00066 stream << ers::HumanStream::KEY << ':' ; 00067 } // print_to
ers::Issue * ers::Stream::receive | ( | ) | [virtual, inherited] |
Receives an issue from the stream.
Reads an isssue on the stream
Reimplemented in ers::FIFOStream.
Definition at line 55 of file Stream.cxx.
void ers::HumanStream::send | ( | const Issue * | ptr | ) | [virtual] |
Sends an issue into the stream.
Sends the issue to the stream.
i | the issue to send |
Reimplemented from ers::Stream.
Definition at line 69 of file HumanStream.cxx.
References ers::error, ERS_HERE, ERS_PRE_CHECK_PTR, false, first, ers::Issue::get_value(), ers::Issue::get_value_table(), if(), key, m_out_stream, ers::Issue::MESSAGE_KEY, boss::pos, ers::Issue::SEVERITY_KEY, deljobs::string, and true.
Referenced by to_string().
00069 { 00070 ERS_PRE_CHECK_PTR(issue_ptr); 00071 if (m_out_stream) { 00072 try { 00073 const string_map_type *table = issue_ptr->get_value_table(); 00074 const std::string message_str = issue_ptr->get_value(Issue::MESSAGE_KEY) ; 00075 const std::string severity_str = issue_ptr->get_value(Issue::SEVERITY_KEY) ; 00076 m_out_stream << "issue: " << message_str << "(" << severity_str << ")[" ; 00077 bool first = true ; 00078 for(string_map_type::const_iterator pos = table->begin();pos!=table->end();++pos) { 00079 const std::string &key = pos->first ; 00080 const std::string &value = pos->second ; 00081 if (first) { 00082 first = false ; 00083 } else { 00084 m_out_stream << ", " ; 00085 } // first or not 00086 m_out_stream << key << "=\"" << value << '\"'; 00087 } // for 00088 m_out_stream << "]" ; 00089 } catch (std::ios_base::failure &ex) { 00090 throw ers::Issue(ERS_HERE,ers::error,&ex); 00091 } // catch generic I/O errors 00092 } // if m_out_stream 00093 } // send
std::string ers::HumanStream::to_string | ( | ) |
Definition at line 54 of file HumanStream.cxx.
References m_out_stream.
Referenced by ers::Issue::human_description().
00054 { 00055 return m_out_stream.str(); 00056 } // to_string
std::string ers::HumanStream::to_string | ( | const Issue * | issue_ptr | ) | throw () [static] |
Dumps the content of an issue into a string This class is used internally by the Issue class to produce then description field.
issue_ptr | the Issue to serialise |
Definition at line 35 of file HumanStream.cxx.
References send(), deljobs::string, and to_string().
Referenced by to_string().
00035 { 00036 try { 00037 HumanStream ers_stream ; 00038 ers_stream.send(issue_ptr) ; 00039 std::string str = ers_stream.to_string(); 00040 return str ; 00041 } catch (std::exception &ex) { 00042 std::string msg = "error while building message " + std::string(ex.what()) ; 00043 return msg; 00044 } // 00045 } // to_string
const char *const ers::HumanStream::KEY = "human" [static] |
std::ostringstream ers::HumanStream::m_out_stream [protected] |
const char *const ers::Stream::NULL_STREAM_KEY = "null" [static, inherited] |
Key for discard stream
Definition at line 39 of file Stream.h.
Referenced by create_stream(), and ers::Stream::print_to().