2// ********************************************************************
3// * License and Disclaimer *
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. *
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. *
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// ********************************************************************
26// G4strstreambuf inline methods implementation
28// Authors: H.Yoshida, M.Nagamatu - November 1998
29// Revisions: G.Cosmo, 1998-2013
30// --------------------------------------------------------------------
32// --------------------------------------------------------------------
33inline G4strstreambuf::G4strstreambuf()
34 : std::basic_streambuf<char>()
37 buffer = new char[size + 1];
40// --------------------------------------------------------------------
41inline G4strstreambuf::~G4strstreambuf()
44 // std::cout is used because destination object may not be alive.
54// --------------------------------------------------------------------
55inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
56 : std::basic_streambuf<char>()
57 , buffer(right.buffer)
60 , destination(right.destination)
63// --------------------------------------------------------------------
64inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
69 destination = right.destination;
70 buffer = right.buffer;
77// --------------------------------------------------------------------
78inline G4int G4strstreambuf::overflow(G4int c)
90// --------------------------------------------------------------------
91inline G4int G4strstreambuf::sync()
95 return ReceiveString();
99// --------------------------------------------------------------------
100inline G4int G4strstreambuf::underflow() { return 0; }
103// --------------------------------------------------------------------
104inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
109inline G4coutDestination* G4strstreambuf::GetDestination() const
114// --------------------------------------------------------------------
115inline G4int G4strstreambuf::ReceiveString()
117 G4String stringToSend(buffer);
120 if(this == &G4coutbuf && destination != nullptr)
122 result = destination->ReceiveG4cout_(stringToSend);
124 else if(this == &G4cerrbuf && destination != nullptr)
126 result = destination->ReceiveG4cerr_(stringToSend);
128 else if(this == &G4coutbuf && destination == nullptr)
130 std::cout << stringToSend << std::flush;
133 else if(this == &G4cerrbuf && destination == nullptr)
135 std::cerr << stringToSend << std::flush;