G4strstreambuf.icc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 // ====================================================================
00029 //   G4strstreambuf.icc
00030 //
00031 // ====================================================================
00032 
00034 inline G4strstreambuf::G4strstreambuf()
00035   : std::basic_streambuf<char>(),
00036     count(0), destination(0)
00038 {
00039   size= 4095;
00040   buffer= new char[size+1];
00041 }
00042 
00043 
00045 inline G4strstreambuf::~G4strstreambuf()
00047 {
00048   // flushing buffer...
00049   // std::cout is used because destination object may not be alive.
00050   if(count !=0) std::cout << buffer;
00051 
00052   delete [] buffer;
00053 }
00054 
00055 
00057 inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
00058   : std::basic_streambuf<char>(), 
00059     buffer(right.buffer), 
00060     count(right.count), size(right.size),
00061     destination(right.destination)
00063 {
00064 }
00065 
00066 
00068 inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
00070 {
00071   if(&right==this) return *this;
00072   
00073   destination= right.destination;
00074   buffer= right.buffer;
00075   count= right.count;
00076   size= right.size;
00077 
00078   return *this;
00079 }
00080 
00081 
00083 inline G4int G4strstreambuf::overflow(G4int c)
00085 {
00086   G4int result= 0;
00087   if(count>=size) result= sync();
00088 
00089   buffer[count]= c;
00090   count++;
00091 
00092   return result;
00093 }
00094 
00096 inline G4int G4strstreambuf::sync()
00098 {
00099   buffer[count] = '\0';
00100   count= 0;
00101   return ReceiveString();
00102 }
00103 
00104 
00105 #ifdef WIN32
00107 inline G4int G4strstreambuf::underflow()
00109 {
00110   return 0;
00111 }
00112 #endif
00113 
00114 
00116 inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
00118 {
00119   destination= dest;
00120 }
00121 
00122 
00124 inline G4int G4strstreambuf::ReceiveString ()
00126 {
00127   G4String stringToSend(buffer);
00128   G4int result= 0;
00129 
00130   if(this == &G4coutbuf && destination != 0) {
00131     result=  destination-> ReceiveG4cout(stringToSend);
00132 
00133   } else if(this == &G4cerrbuf && destination != 0) {
00134     result=  destination-> ReceiveG4cerr(stringToSend);
00135 
00136   } else if(this == &G4coutbuf && destination == 0) {
00137     std::cout << stringToSend << std::flush;
00138     result= 0;
00139 
00140   } else if(this == &G4cerrbuf && destination == 0) {
00141     std::cerr << stringToSend << std::flush;
00142     result= 0;
00143   }
00144 
00145   return result;
00146 }
00147 

Generated on Mon May 27 17:49:55 2013 for Geant4 by  doxygen 1.4.7