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 // ********************************************************************
 
   27 // $Id: G4strstreambuf.icc 67970 2013-03-13 10:10:06Z gcosmo $
 
   28 // ====================================================================
 
   31 // ====================================================================
 
   33 ///////////////////////////////////////
 
   34 inline G4strstreambuf::G4strstreambuf()
 
   35   : std::basic_streambuf<char>(),
 
   36     count(0), destination(0)
 
   37 ///////////////////////////////////////
 
   40   buffer= new char[size+1];
 
   44 ////////////////////////////////////////
 
   45 inline G4strstreambuf::~G4strstreambuf()
 
   46 ////////////////////////////////////////
 
   49   // std::cout is used because destination object may not be alive.
 
   50   if(count !=0) std::cout << buffer;
 
   56 //////////////////////////////////////////////////////////////////
 
   57 inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
 
   58   : std::basic_streambuf<char>(), 
 
   60     count(right.count), size(right.size),
 
   61     destination(right.destination)
 
   62 //////////////////////////////////////////////////////////////////
 
   67 /////////////////////////////////////////////////////////////////////////////
 
   68 inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
 
   69 /////////////////////////////////////////////////////////////////////////////
 
   71   if(&right==this) return *this;
 
   73   destination= right.destination;
 
   82 //////////////////////////////////////////////
 
   83 inline G4int G4strstreambuf::overflow(G4int c)
 
   84 //////////////////////////////////////////////
 
   87   if(count>=size) result= sync();
 
   95 ///////////////////////////////////
 
   96 inline G4int G4strstreambuf::sync()
 
   97 ///////////////////////////////////
 
  101   return ReceiveString();
 
  106 ////////////////////////////////////////
 
  107 inline G4int G4strstreambuf::underflow()
 
  108 ////////////////////////////////////////
 
  115 ///////////////////////////////////////////////////////////////////
 
  116 inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
 
  117 ///////////////////////////////////////////////////////////////////
 
  123 /////////////////////////////////////////////
 
  124 inline G4int G4strstreambuf::ReceiveString ()
 
  125 /////////////////////////////////////////////
 
  127   G4String stringToSend(buffer);
 
  130   if(this == &G4coutbuf && destination != 0) {
 
  131     result=  destination-> ReceiveG4cout(stringToSend);
 
  133   } else if(this == &G4cerrbuf && destination != 0) {
 
  134     result=  destination-> ReceiveG4cerr(stringToSend);
 
  136   } else if(this == &G4coutbuf && destination == 0) {
 
  137     std::cout << stringToSend << std::flush;
 
  140   } else if(this == &G4cerrbuf && destination == 0) {
 
  141     std::cerr << stringToSend << std::flush;