BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::HumanStream Class Reference

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

#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
 
- Public Member Functions inherited from ers::Stream
 Stream ()
 
 Stream (const Stream &other)
 
 operator std::string () const
 
virtual ~Stream ()
 
virtual void send (const Issue *i)
 Sends an issue into the stream.
 
virtual Issuereceive ()
 Receives an issue from the stream.
 
virtual void print_to (std::ostream &stream) const
 

Static Public Member Functions

static std::string to_string (const Issue *issue) throw ()
 

Static Public Attributes

static const char *const KEY = "human"
 
- Static Public Attributes inherited from ers::Stream
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

◆ HumanStream() [1/2]

ers::HumanStream::HumanStream ( )

Definition at line 47 of file HumanStream.cxx.

47: ers::Stream() {} // HumanStream
Root/Null issue stream.
Definition: Stream.h:35

◆ HumanStream() [2/2]

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

Definition at line 48 of file HumanStream.cxx.

48: ers::Stream(other) {}

◆ ~HumanStream()

ers::HumanStream::~HumanStream ( )

Definition at line 49 of file HumanStream.cxx.

49{}

Member Function Documentation

◆ clear()

void ers::HumanStream::clear ( )

Clears the content of the stream

Definition at line 61 of file HumanStream.cxx.

61 {
62 m_out_stream.str("");
63} // clear
std::ostringstream m_out_stream
Definition: HumanStream.h:29

◆ print_to()

void ers::HumanStream::print_to ( std::ostream &  stream) const
virtual

Reimplemented from ers::Stream.

Definition at line 65 of file HumanStream.cxx.

65 {
66 stream << ers::HumanStream::KEY << ':' ;
67} // print_to
static const char *const KEY
Definition: HumanStream.h:32

◆ send()

void ers::HumanStream::send ( const Issue i)
virtual

Sends an issue into the stream.

Sends the issue to the stream.

Parameters
ithe issue to send
Note
This implementation silently discards the Issue

Reimplemented from ers::Stream.

Definition at line 69 of file HumanStream.cxx.

69 {
70 ERS_PRE_CHECK_PTR(issue_ptr);
71 if (m_out_stream) {
72 try {
73 const string_map_type *table = issue_ptr->get_value_table();
74 const std::string message_str = issue_ptr->get_value(Issue::MESSAGE_KEY) ;
75 const std::string severity_str = issue_ptr->get_value(Issue::SEVERITY_KEY) ;
76 m_out_stream << "issue: " << message_str << "(" << severity_str << ")[" ;
77 bool first = true ;
78 for(string_map_type::const_iterator pos = table->begin();pos!=table->end();++pos) {
79 const std::string &key = pos->first ;
80 const std::string &value = pos->second ;
81 if (first) {
82 first = false ;
83 } else {
84 m_out_stream << ", " ;
85 } // first or not
86 m_out_stream << key << "=\"" << value << '\"';
87 } // for
88 m_out_stream << "]" ;
89 } catch (std::ios_base::failure &ex) {
90 throw ers::Issue(ERS_HERE,ers::error,&ex);
91 } // catch generic I/O errors
92 } // if m_out_stream
93} // send
#define ERS_HERE
Definition: Context.h:119
#define ERS_PRE_CHECK_PTR(p)
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
Definition: Taupair.h:42
Root Issue class.
static const char *const MESSAGE_KEY
key for human readable
static const char *const SEVERITY_KEY
key for the severity_t of the issue
Index first(Pair i)
Definition: EvtCyclic3.cc:195
@ error
Definition: Core.h:24
std::map< std::string, std::string > string_map_type
Definition: Core.h:26

Referenced by to_string().

◆ to_string() [1/2]

std::string ers::HumanStream::to_string ( )
Returns
the content of the stream as a string

Definition at line 54 of file HumanStream.cxx.

54 {
55 return m_out_stream.str();
56} // to_string

Referenced by ers::Issue::human_description().

◆ to_string() [2/2]

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_ptrthe Issue to serialise
Returns
string description

Definition at line 35 of file HumanStream.cxx.

35 {
36 try {
37 HumanStream ers_stream ;
38 ers_stream.send(issue_ptr) ;
39 std::string str = ers_stream.to_string();
40 return str ;
41 } catch (std::exception &ex) {
42 std::string msg = "error while building message " + std::string(ex.what()) ;
43 return msg;
44 } //
45} // to_string

Referenced by to_string().

Member Data Documentation

◆ KEY

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

Definition at line 32 of file HumanStream.h.

Referenced by print_to().

◆ m_out_stream

std::ostringstream ers::HumanStream::m_out_stream
protected

Definition at line 29 of file HumanStream.h.


The documentation for this class was generated from the following files: