Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cheprep::DeflateOutputStreamBuffer Class Reference

#include <DeflateOutputStreamBuffer.h>

Inheritance diagram for cheprep::DeflateOutputStreamBuffer:
Collaboration diagram for cheprep::DeflateOutputStreamBuffer:

Public Member Functions

 DeflateOutputStreamBuffer (std::streambuf *buffer)
 
void init (bool compress)
 
void finish ()
 
virtual ~DeflateOutputStreamBuffer ()
 

Protected Member Functions

int overflow (int c=EOF)
 
bool flushOut ()
 
void putUI (unsigned int ui)
 
void putUS (unsigned short us)
 
void putUB (unsigned char ub)
 
void putS (const std::string s)
 
std::streampos pos ()
 
unsigned int getSize ()
 
unsigned int getCRC ()
 

Detailed Description

Definition at line 20 of file DeflateOutputStreamBuffer.h.

Constructor & Destructor Documentation

cheprep::DeflateOutputStreamBuffer::DeflateOutputStreamBuffer ( std::streambuf *  buffer)

Definition at line 80 of file DeflateOutputStreamBuffer.cc.

81  : buffer(aBuffer)
82  , crc(0)
83  , size(0)
84 #ifndef CHEPREP_NO_ZLIB
85  , zStreamOpen(false)
86  , in(inSize)
87  , out(outSize)
88 #endif // CHEPREP_NO_ZLIB
89  {
90 
91 #ifndef CHEPREP_NO_ZLIB
92  zStream.zalloc = Z_NULL;
93  zStream.zfree = Z_NULL;
94  zStream.opaque = Z_NULL;
95  zStream.msg = 0;
96  zStream.next_in = 0;
97  zStream.next_out = 0;
98  zStream.state = 0;
99 #endif // CHEPREP_NO_ZLIB
100  }
voidpf opaque
Definition: zlib.h:99
struct internal_state FAR * state
Definition: zlib.h:95
free_func zfree
Definition: zlib.h:98
z_const char * msg
Definition: zlib.h:94
alloc_func zalloc
Definition: zlib.h:97
Bytef * next_out
Definition: zlib.h:90
z_const Bytef * next_in
Definition: zlib.h:86
#define Z_NULL
Definition: zlib.h:208
cheprep::DeflateOutputStreamBuffer::~DeflateOutputStreamBuffer ( )
virtual

Definition at line 162 of file DeflateOutputStreamBuffer.cc.

162  {
163  }

Member Function Documentation

void cheprep::DeflateOutputStreamBuffer::finish ( )

Definition at line 129 of file DeflateOutputStreamBuffer.cc.

129  {
130 
131 #ifndef CHEPREP_NO_ZLIB
132  if (zStreamOpen) {
133 
134  overflow() ;
135 
136  zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
137  zStream.avail_out = outSize;
138 
139  int err = Z_OK ;
140  while ( err == Z_OK ) {
141  if (zStream.avail_out == 0) {
142  flushOut();
143  }
144  err = deflate(&zStream, Z_FINISH);
145  }
146 
147  flushOut() ;
148 
149  if (err != Z_STREAM_END) {
150  cerr << "ERROR: deflation failed" << endl;
151  }
152 
153  if (deflateEnd(&zStream) != Z_OK) {
154  cerr << "ERROR: deflateEnd failed" << endl;
155  }
156 
157  zStreamOpen = false ;
158  }
159 #endif // CHEPREP_NO_ZLIB
160  }
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.cc:939
#define Z_FINISH
Definition: zlib.h:168
#define Z_STREAM_END
Definition: zlib.h:174
Bytef * next_out
Definition: zlib.h:90
int ZEXPORT deflate(z_streamp strm, int flush)
Definition: deflate.cc:627
uInt avail_out
Definition: zlib.h:91
#define Z_OK
Definition: zlib.h:173

Here is the call graph for this function:

Here is the caller graph for this function:

bool cheprep::DeflateOutputStreamBuffer::flushOut ( )
protected

Definition at line 234 of file DeflateOutputStreamBuffer.cc.

234  {
235  int deflatedCount = outSize - zStream.avail_out;
236  int byteCount = buffer->sputn(&(out[0]), deflatedCount);
237 
238  zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
239  zStream.avail_out = outSize ;
240 
241  return deflatedCount == byteCount ;
242  }
Bytef * next_out
Definition: zlib.h:90
uInt avail_out
Definition: zlib.h:91

Here is the caller graph for this function:

unsigned int cheprep::DeflateOutputStreamBuffer::getCRC ( )
inlineprotected

Definition at line 72 of file DeflateOutputStreamBuffer.h.

72  {
73  return crc;
74  }

Here is the caller graph for this function:

unsigned int cheprep::DeflateOutputStreamBuffer::getSize ( )
inlineprotected

Definition at line 68 of file DeflateOutputStreamBuffer.h.

68  {
69  return size;
70  }

Here is the caller graph for this function:

void cheprep::DeflateOutputStreamBuffer::init ( bool  compress)

Definition at line 103 of file DeflateOutputStreamBuffer.cc.

103  {
104 
105  if (compress) {
106  if (zStreamOpen) return;
107 
108  zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
109  zStream.avail_in = 0 ;
110 
111  zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
112  zStream.avail_out = out.size();
113 
114  if (deflateInit2(&zStream, 6, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY ) != Z_OK) {
115  cerr << "ERROR: deflateInit2 failed" << endl;
116  } else {
117  zStreamOpen = true;
118  setp(&(in[0]), &(in[0])+inSize);
119  }
120  }
121 #else
122  void DeflateOutputStreamBuffer::init(bool /*compress*/) {
123 #endif // CHEPREP_NO_ZLIB
124 
125  crc = 0;
126  size = 0;
127  }
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
Definition: zlib.h:1651
uInt avail_in
Definition: zlib.h:87
#define Z_DEFLATED
Definition: zlib.h:205
Bytef * next_out
Definition: zlib.h:90
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.cc:57
uInt avail_out
Definition: zlib.h:91
z_const Bytef * next_in
Definition: zlib.h:86
#define Z_OK
Definition: zlib.h:173
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:196

Here is the caller graph for this function:

int cheprep::DeflateOutputStreamBuffer::overflow ( int  c = EOF)
protected

Definition at line 172 of file DeflateOutputStreamBuffer.cc.

172  {
173 
174 #ifndef CHEPREP_NO_ZLIB
175  if (zStreamOpen) {
176  zStream.avail_in = pptr() - pbase() ;
177  zStream.next_in = reinterpret_cast<unsigned char *>(&(in[0]));
178 
179  int len = zStream.avail_in;
180  unsigned char* buf = zStream.next_in;
181 
182  crc = crc ^ 0xffffffffUL;
183  while (len >= 8) {
184  DO8;
185  len -= 8;
186  }
187  if (len) do {
188  DO1;
189  } while (--len);
190  crc = crc ^ 0xffffffffUL;
191 
192  size += zStream.avail_in;
193 
194  zStream.next_out = reinterpret_cast<unsigned char *>(&(out[0]));
195  zStream.avail_out = outSize ;
196 
197  int err = Z_OK ;
198  while ((zStream.avail_in > 0 || zStream.avail_out == 0) && err == Z_OK) {
199  if (zStream.avail_out == 0 ) {
200  flushOut();
201  }
202  err = deflate(&zStream, Z_NO_FLUSH);
203  }
204 
205  flushOut();
206 
207  setp(&(in[0]), &(in[0]) + inSize);
208 
209  if ((err != Z_OK) && (err != Z_STREAM_END)) {
210  cerr << "ERROR: deflation failed" << endl;
211  return EOF ;
212  }
213 
214  if ( c != EOF ) {
215  *pptr() = c ;
216  pbump(1);
217  }
218 
219  return 0 ;
220  } else {
221 #endif // CHEPREP_NO_ZLIB
222  crc = crc ^ 0xffffffffUL;
223  crc = crctable[(crc ^ c) & 0xff] ^ (crc >> 8);
224  crc = crc ^ 0xffffffffUL;
225  size++;
226  return buffer->sputc((char)c);
227 #ifndef CHEPREP_NO_ZLIB
228  }
229 #endif // CHEPREP_NO_ZLIB
230  }
const XML_Char int len
Definition: expat.h:262
#define Z_NO_FLUSH
Definition: zlib.h:164
uInt avail_in
Definition: zlib.h:87
#define Z_STREAM_END
Definition: zlib.h:174
Bytef * next_out
Definition: zlib.h:90
int ZEXPORT deflate(z_streamp strm, int flush)
Definition: deflate.cc:627
uInt avail_out
Definition: zlib.h:91
z_const Bytef * next_in
Definition: zlib.h:86
#define Z_OK
Definition: zlib.h:173

Here is the call graph for this function:

Here is the caller graph for this function:

std::streampos cheprep::DeflateOutputStreamBuffer::pos ( )
inlineprotected

Definition at line 63 of file DeflateOutputStreamBuffer.h.

63  {
64  std::ostream os(buffer);
65  return os.tellp();
66  }

Here is the caller graph for this function:

void cheprep::DeflateOutputStreamBuffer::putS ( const std::string  s)
inlineprotected

Definition at line 59 of file DeflateOutputStreamBuffer.h.

59  {
60  buffer->sputn(s.c_str(), s.length());
61  }
const XML_Char * s
Definition: expat.h:262

Here is the caller graph for this function:

void cheprep::DeflateOutputStreamBuffer::putUB ( unsigned char  ub)
inlineprotected

Definition at line 55 of file DeflateOutputStreamBuffer.h.

55  {
56  buffer->sputc(ub);
57  }
void cheprep::DeflateOutputStreamBuffer::putUI ( unsigned int  ui)
inlineprotected

Definition at line 39 of file DeflateOutputStreamBuffer.h.

39  {
40  unsigned char* ucp = reinterpret_cast<unsigned char *>(&ui);
41  unsigned int i = (static_cast<unsigned int>(ucp[ 3 ]) << 24) +
42  (static_cast<unsigned int>(ucp[ 2 ]) << 16) +
43  (static_cast<unsigned int>(ucp[ 1 ]) << 8 ) +
44  (static_cast<unsigned int>(ucp[ 0 ]));
45  buffer->sputn(reinterpret_cast<char *>(&i), sizeof(unsigned int));
46  }

Here is the caller graph for this function:

void cheprep::DeflateOutputStreamBuffer::putUS ( unsigned short  us)
inlineprotected

Definition at line 48 of file DeflateOutputStreamBuffer.h.

48  {
49  unsigned char* ucp = reinterpret_cast<unsigned char *>(&us);
50  unsigned short s = (static_cast<unsigned short>(ucp[ 1 ]) << 8 ) +
51  (static_cast<unsigned short>(ucp[ 0 ]));
52  buffer->sputn(reinterpret_cast<char *>(&s), sizeof(unsigned short));
53  }
static constexpr double us
Definition: G4SIunits.hh:171
const XML_Char * s
Definition: expat.h:262

Here is the caller graph for this function:


The documentation for this class was generated from the following files: