source: trunk/source/global/management/include/G4strstreambuf.icc @ 1347

Last change on this file since 1347 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 4.6 KB
Line 
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//
27// $Id: G4strstreambuf.icc,v 1.13 2006/06/29 19:03:49 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29// ====================================================================
30//   G4strstreambuf.icc
31//
32// ====================================================================
33
34///////////////////////////////////////
35inline G4strstreambuf::G4strstreambuf()
36  : std::basic_streambuf<char>(),
37    count(0), destination(0)
38///////////////////////////////////////
39{
40  size= 4095;
41  buffer= new char[size+1];
42}
43
44
45////////////////////////////////////////
46inline G4strstreambuf::~G4strstreambuf()
47////////////////////////////////////////
48{
49  // flushing buffer...
50  // std::cout is used because destination object may not be alive.
51  if(count !=0) std::cout << buffer;
52
53  delete [] buffer;
54}
55
56
57//////////////////////////////////////////////////////////////////
58inline G4strstreambuf::G4strstreambuf(const G4strstreambuf& right)
59  : std::basic_streambuf<char>(),
60    buffer(right.buffer),
61    count(right.count), size(right.size),
62    destination(right.destination)
63//////////////////////////////////////////////////////////////////
64{
65}
66
67
68/////////////////////////////////////////////////////////////////////////////
69inline G4strstreambuf& G4strstreambuf::operator=(const G4strstreambuf& right)
70/////////////////////////////////////////////////////////////////////////////
71{
72  if(&right==this) return *this;
73 
74  destination= right.destination;
75  buffer= right.buffer;
76  count= right.count;
77  size= right.size;
78
79  return *this;
80}
81
82
83//////////////////////////////////////////////
84inline G4int G4strstreambuf::overflow(G4int c)
85//////////////////////////////////////////////
86{
87  G4int result= 0;
88  if(count>=size) result= sync();
89
90  buffer[count]= c;
91  count++;
92
93  return result;
94}
95
96///////////////////////////////////
97inline G4int G4strstreambuf::sync()
98///////////////////////////////////
99{
100  buffer[count] = '\0';
101  count= 0;
102  return ReceiveString();
103}
104
105
106#ifdef WIN32
107////////////////////////////////////////
108inline G4int G4strstreambuf::underflow()
109////////////////////////////////////////
110{
111  return 0;
112}
113#endif
114
115
116///////////////////////////////////////////////////////////////////
117inline void G4strstreambuf::SetDestination(G4coutDestination* dest)
118///////////////////////////////////////////////////////////////////
119{
120  destination= dest;
121}
122
123
124/////////////////////////////////////////////
125inline G4int G4strstreambuf::ReceiveString ()
126/////////////////////////////////////////////
127{
128  G4String stringToSend(buffer);
129  G4int result= 0;
130
131  if(this == &G4coutbuf && destination != 0) {
132    result=  destination-> ReceiveG4cout(stringToSend);
133
134  } else if(this == &G4cerrbuf && destination != 0) {
135    result=  destination-> ReceiveG4cerr(stringToSend);
136
137  } else if(this == &G4coutbuf && destination == 0) {
138    std::cout << stringToSend << std::flush;
139    result= 0;
140
141  } else if(this == &G4cerrbuf && destination == 0) {
142    std::cerr << stringToSend << std::flush;
143    result= 0;
144  }
145
146  return result;
147}
148
Note: See TracBrowser for help on using the repository browser.