Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BuffercoutDestination.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4BuffercoutDestination
27//
28// Class Description:
29//
30// A cout destination that buffers received stream in a buffer and
31// dumps the buffer only when full.
32// Optionally allows for an infinite buffer.
33
34// ---------------- G4BuffercoutDestination ----------------
35//
36// Author: A.Dotti (SLAC), 14 April 2017
37// --------------------------------------------------------------------
38#ifndef G4BUFFERCOUTDESTINATION_HH
39#define G4BUFFERCOUTDESTINATION_HH
40
41#include <sstream>
42
43#include "G4coutDestination.hh"
44
46{
47 public:
48 explicit G4BuffercoutDestination(std::size_t maxSize = 0);
49 ~G4BuffercoutDestination() override;
50
51 G4int ReceiveG4cout(const G4String& msg) override;
52 G4int ReceiveG4cerr(const G4String& msg) override;
53 // Flush buffer to std output
54 virtual G4int FlushG4cout();
55 // Flush buffer to std error
56 virtual G4int FlushG4cerr();
57 // Flsuh both buffers
58
59 virtual void Finalize();
60
61 // Set maximum size of buffer, when buffer grows to specified size,
62 // it will trigger flush. Dimension in char
63 void SetMaxSize(std::size_t max) { m_maxSize = max; }
64 std::size_t GetMaxSize() const { return m_maxSize; }
65 std::size_t GetCurrentSizeOut() const { return m_currentSize_out; }
66 std::size_t GetCurrentSizeErr() const { return m_currentSize_err; }
67
68 protected:
69 void ResetCout();
70 void ResetCerr();
71
72 std::ostringstream m_buffer_out;
73 std::ostringstream m_buffer_err;
74 std::size_t m_currentSize_out = 0;
75 std::size_t m_currentSize_err = 0;
76 std::size_t m_maxSize = 0;
77};
78
79#endif
int G4int
Definition: G4Types.hh:85
void SetMaxSize(std::size_t max)
std::size_t GetCurrentSizeOut() const
G4int ReceiveG4cerr(const G4String &msg) override
std::size_t GetCurrentSizeErr() const
G4int ReceiveG4cout(const G4String &msg) override