Geant4-11
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
G4BuffercoutDestination Class Reference

#include <G4BuffercoutDestination.hh>

Inheritance diagram for G4BuffercoutDestination:
G4coutDestination

Public Types

using Transformer = std::function< G4bool(G4String &)>
 

Public Member Functions

void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
virtual void Finalize ()
 
virtual G4int FlushG4cerr ()
 
virtual G4int FlushG4cout ()
 
 G4BuffercoutDestination (std::size_t maxSize=0)
 
std::size_t GetCurrentSizeErr () const
 
std::size_t GetCurrentSizeOut () const
 
std::size_t GetMaxSize () const
 
virtual G4int ReceiveG4cerr (const G4String &msg) override
 
G4int ReceiveG4cerr_ (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &msg) override
 
G4int ReceiveG4cout_ (const G4String &msg)
 
virtual void ResetTransformers ()
 
void SetMaxSize (std::size_t max)
 
virtual ~G4BuffercoutDestination ()
 

Protected Member Functions

void ResetCerr ()
 
void ResetCout ()
 

Protected Attributes

std::ostringstream m_buffer_err
 
std::ostringstream m_buffer_out
 
std::size_t m_currentSize_err = 0
 
std::size_t m_currentSize_out = 0
 
std::size_t m_maxSize = 0
 
std::vector< TransformertransformersCerr
 
std::vector< TransformertransformersCout
 

Static Protected Attributes

static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Detailed Description

Definition at line 45 of file G4BuffercoutDestination.hh.

Member Typedef Documentation

◆ Transformer

Definition at line 61 of file G4coutDestination.hh.

Constructor & Destructor Documentation

◆ G4BuffercoutDestination()

G4BuffercoutDestination::G4BuffercoutDestination ( std::size_t  maxSize = 0)
explicit

Definition at line 37 of file G4BuffercoutDestination.cc.

38 : m_buffer_out("")
39 , m_buffer_err("")
40 , m_maxSize(max)
41{}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

◆ ~G4BuffercoutDestination()

G4BuffercoutDestination::~G4BuffercoutDestination ( )
virtual

Definition at line 44 of file G4BuffercoutDestination.cc.

44{ Finalize(); }

References Finalize().

Member Function Documentation

◆ AddCerrTransformer() [1/2]

void G4coutDestination::AddCerrTransformer ( const Transformer t)
inlineinherited

Definition at line 67 of file G4coutDestination.hh.

68 {
69 transformersCerr.push_back(t);
70 }
std::vector< Transformer > transformersCerr

References G4coutDestination::transformersCerr.

Referenced by G4MTcoutDestination::HandleFileCerr().

◆ AddCerrTransformer() [2/2]

void G4coutDestination::AddCerrTransformer ( Transformer &&  t)
inlineinherited

Definition at line 71 of file G4coutDestination.hh.

71{ transformersCerr.push_back(t); }

References G4coutDestination::transformersCerr.

◆ AddCoutTransformer() [1/2]

void G4coutDestination::AddCoutTransformer ( const Transformer t)
inlineinherited

◆ AddCoutTransformer() [2/2]

void G4coutDestination::AddCoutTransformer ( Transformer &&  t)
inlineinherited

Definition at line 66 of file G4coutDestination.hh.

66{ transformersCout.push_back(t); }

References G4coutDestination::transformersCout.

◆ Finalize()

void G4BuffercoutDestination::Finalize ( )
virtual

Definition at line 47 of file G4BuffercoutDestination.cc.

48{
51}

References FlushG4cerr(), and FlushG4cout().

Referenced by ~G4BuffercoutDestination().

◆ FlushG4cerr()

G4int G4BuffercoutDestination::FlushG4cerr ( )
virtual

Definition at line 96 of file G4BuffercoutDestination.cc.

97{
98 std::cerr << m_buffer_err.str() << std::flush;
99 ResetCerr();
100 return 0;
101}

References m_buffer_err, and ResetCerr().

Referenced by G4MTcoutDestination::DumpBuffer(), Finalize(), and ReceiveG4cerr().

◆ FlushG4cout()

G4int G4BuffercoutDestination::FlushG4cout ( )
virtual

Definition at line 80 of file G4BuffercoutDestination.cc.

81{
82 std::cout << m_buffer_out.str() << std::flush;
83 ResetCout();
84 return 0;
85}

References m_buffer_out, and ResetCout().

Referenced by G4MTcoutDestination::DumpBuffer(), Finalize(), and ReceiveG4cout().

◆ GetCurrentSizeErr()

std::size_t G4BuffercoutDestination::GetCurrentSizeErr ( ) const
inline

Definition at line 66 of file G4BuffercoutDestination.hh.

References m_currentSize_err.

◆ GetCurrentSizeOut()

std::size_t G4BuffercoutDestination::GetCurrentSizeOut ( ) const
inline

Definition at line 65 of file G4BuffercoutDestination.hh.

References m_currentSize_out.

◆ GetMaxSize()

std::size_t G4BuffercoutDestination::GetMaxSize ( ) const
inline

Definition at line 64 of file G4BuffercoutDestination.hh.

64{ return m_maxSize; }

References m_maxSize.

◆ ReceiveG4cerr()

G4int G4BuffercoutDestination::ReceiveG4cerr ( const G4String msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 67 of file G4BuffercoutDestination.cc.

68{
69 m_currentSize_err += msg.size();
70 m_buffer_err << msg;
71 // If there is a max size and it has been reached, flush
73 {
75 }
76 return 0;
77}

References FlushG4cerr(), m_buffer_err, m_currentSize_err, and m_maxSize.

◆ ReceiveG4cerr_()

G4int G4coutDestination::ReceiveG4cerr_ ( const G4String msg)
inherited

Definition at line 84 of file G4coutDestination.cc.

85{
86 if(transformersCout.size() > 0)
87 {
88 G4String m = msg;
89 std::for_each(transformersCerr.begin(), transformersCerr.end(),
90 [&m](const Transformer& t) { t(m); }
91 // Call transforming function on message
92 );
93 return ReceiveG4cerr(m);
94 }
95 else
96 {
97 return ReceiveG4cerr(msg);
98 }
99}
static constexpr double m
Definition: G4SIunits.hh:109
virtual G4int ReceiveG4cerr(const G4String &msg)
std::function< G4bool(G4String &)> Transformer

References m, G4coutDestination::ReceiveG4cerr(), G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cerr().

◆ ReceiveG4cout()

G4int G4BuffercoutDestination::ReceiveG4cout ( const G4String msg)
overridevirtual

Reimplemented from G4coutDestination.

Definition at line 54 of file G4BuffercoutDestination.cc.

55{
56 m_currentSize_out += msg.size();
57 m_buffer_out << msg;
58 // If there is a max size and it has been reached, flush
60 {
62 }
63 return 0;
64}

References FlushG4cout(), m_buffer_out, m_currentSize_out, and m_maxSize.

◆ ReceiveG4cout_()

G4int G4coutDestination::ReceiveG4cout_ ( const G4String msg)
inherited

Definition at line 62 of file G4coutDestination.cc.

63{
64 // Avoid copy of string if not necessary
65 if(transformersCout.size() > 0)
66 {
67 G4String m = msg;
68 G4bool result = true;
69 for(const auto& el : transformersCout)
70 {
71 result &= el(m);
72 if(!result)
73 break;
74 }
75 return (result ? ReceiveG4cout(m) : 0);
76 }
77 else
78 {
79 return ReceiveG4cout(msg);
80 }
81}
bool G4bool
Definition: G4Types.hh:86
virtual G4int ReceiveG4cout(const G4String &msg)

References m, G4coutDestination::ReceiveG4cout(), and G4coutDestination::transformersCout.

Referenced by G4MasterForwardcoutDestination::ReceiveG4cout().

◆ ResetCerr()

void G4BuffercoutDestination::ResetCerr ( )
protected

Definition at line 104 of file G4BuffercoutDestination.cc.

105{
106 m_buffer_err.str("");
107 m_buffer_err.clear();
109}

References m_buffer_err, and m_currentSize_err.

Referenced by FlushG4cerr().

◆ ResetCout()

void G4BuffercoutDestination::ResetCout ( )
protected

Definition at line 88 of file G4BuffercoutDestination.cc.

89{
90 m_buffer_out.str("");
91 m_buffer_out.clear();
93}

References m_buffer_out, and m_currentSize_out.

Referenced by FlushG4cout().

◆ ResetTransformers()

void G4coutDestination::ResetTransformers ( )
virtualinherited

Definition at line 41 of file G4coutDestination.cc.

42{
43 transformersCout.clear();
44 transformersCerr.clear();
45}

References G4coutDestination::transformersCerr, and G4coutDestination::transformersCout.

◆ SetMaxSize()

void G4BuffercoutDestination::SetMaxSize ( std::size_t  max)
inline

Definition at line 63 of file G4BuffercoutDestination.hh.

63{ m_maxSize = max; }

References m_maxSize, and G4INCL::Math::max().

Field Documentation

◆ m_buffer_err

std::ostringstream G4BuffercoutDestination::m_buffer_err
protected

Definition at line 73 of file G4BuffercoutDestination.hh.

Referenced by FlushG4cerr(), ReceiveG4cerr(), and ResetCerr().

◆ m_buffer_out

std::ostringstream G4BuffercoutDestination::m_buffer_out
protected

Definition at line 72 of file G4BuffercoutDestination.hh.

Referenced by FlushG4cout(), ReceiveG4cout(), and ResetCout().

◆ m_currentSize_err

std::size_t G4BuffercoutDestination::m_currentSize_err = 0
protected

Definition at line 75 of file G4BuffercoutDestination.hh.

Referenced by GetCurrentSizeErr(), ReceiveG4cerr(), and ResetCerr().

◆ m_currentSize_out

std::size_t G4BuffercoutDestination::m_currentSize_out = 0
protected

Definition at line 74 of file G4BuffercoutDestination.hh.

Referenced by GetCurrentSizeOut(), ReceiveG4cout(), and ResetCout().

◆ m_maxSize

std::size_t G4BuffercoutDestination::m_maxSize = 0
protected

Definition at line 76 of file G4BuffercoutDestination.hh.

Referenced by GetMaxSize(), ReceiveG4cerr(), ReceiveG4cout(), and SetMaxSize().

◆ masterG4coutDestination

G4coutDestination * G4coutDestination::masterG4coutDestination = nullptr
staticprotectedinherited

◆ transformersCerr

std::vector<Transformer> G4coutDestination::transformersCerr
protectedinherited

◆ transformersCout

std::vector<Transformer> G4coutDestination::transformersCout
protectedinherited

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