libROM  v1.0
Data-driven physical simulation library
ParallelBuffer.h
1 
11 // Description: A simple I/O stream class that intercepts output from an
12 // ostream and redirects the output as necessary for parallel
13 // I/O.
14 
15 #ifndef included_ParallelBuffer_h
16 #define included_ParallelBuffer_h
17 
18 #include "CAROM_config.h"
19 
20 #include <iostream>
21 #include <string>
22 
23 namespace CAROM {
24 
30 class ParallelBuffer : public std::streambuf
31 {
32 public:
40 
48 
57  void
59  const std::string& text)
60  {
61  outputString(text, static_cast<int>(text.length()));
62  }
63 
73  void
75  const std::string& text,
76  int length);
77 
83  int
84  sync();
85 
86 #if !defined(__INTEL_COMPILER) && (defined(__GNUG__))
96  std::streamsize
97  xsputn(
98  const std::string& text,
99  std::streamsize n);
100 #endif
101 
110  int
111  overflow(
112  int ch);
113 
114 #ifdef _MSC_VER
124  int
125  underflow()
126  {
127  return EOF;
128  }
129 #endif
130 
131 private:
141  void
142  copyToBuffer(
143  const std::string& text,
144  int length);
145 
149  void
150  outputBuffer();
151 
155  std::string d_prefix;
156 
160  std::ostream* d_ostream;
161 
165  char* d_buffer;
166 
170  int d_buffer_size;
171 
175  int d_buffer_ptr;
176 
180  static const int DEFAULT_BUFFER_SIZE;
181 };
182 
183 }
184 
185 #endif
int overflow(int ch)
Write an overflow character into the parallel buffer (called from streambuf).
int sync()
Synchronize the parallel buffer (called from streambuf).
~ParallelBuffer()
Destructor.
ParallelBuffer()
Default constructor.
void outputString(const std::string &text)
Write a text string to the output stream.