ers::HumanStream Class Reference

Single line, human readable format stream. More...

#include <HumanStream.h>

Inheritance diagram for ers::HumanStream:

ers::Stream List of all members.

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 Issuereceive ()
 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

Detailed Description

Single line, human readable format 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.

Author:
Matthias Wiesmann
Version:
1.0

Definition at line 27 of file HumanStream.h.


Constructor & Destructor Documentation

ers::HumanStream::HumanStream (  ) 

Definition at line 47 of file HumanStream.cxx.

00047 : ers::Stream() {} // HumanStream

ers::HumanStream::HumanStream ( const HumanStream other  ) 

Definition at line 48 of file HumanStream.cxx.

00048 : ers::Stream(other) {} 

ers::HumanStream::~HumanStream (  ) 

Definition at line 49 of file HumanStream.cxx.

00049 {} 


Member Function Documentation

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

Returns:
the issue that has been read
Note:
This implementation always returns a null pointer

Reimplemented in ers::FIFOStream.

Definition at line 55 of file Stream.cxx.

00055                              {
00056     return 0 ; 
00057 } // receive

void ers::HumanStream::send ( const Issue ptr  )  [virtual]

Sends an issue into the stream.

Sends the issue to the stream.

Parameters:
i the issue to send
Note:
This implementation silently discards the Issue

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 (  ) 

Returns:
the content of the stream as a 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.

Parameters:
issue_ptr the Issue to serialise
Returns:
string description

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


Member Data Documentation

const char *const ers::HumanStream::KEY = "human" [static]

Definition at line 32 of file HumanStream.h.

Referenced by create_stream(), and print_to().

std::ostringstream ers::HumanStream::m_out_stream [protected]

Definition at line 29 of file HumanStream.h.

Referenced by clear(), send(), and to_string().

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().


Generated on Tue Nov 29 23:36:31 2016 for BOSS_7.0.2 by  doxygen 1.4.7