Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
DeflateOutputStreamBuffer.h
이 파일의 문서화 페이지로 가기
1 // Copyright FreeHEP, 2005.
2 #ifndef CHEPREP_DEFLATEOUTPUTSTREAMBUF_H
3 #define CHEPREP_DEFLATEOUTPUTSTREAMBUF_H
4 
5 #include <vector>
6 #include <iostream>
7 #include <string>
8 #include <cstdio>
9 
10 #ifndef CHEPREP_NO_ZLIB
11 #include <zlib.h>
12 #endif // CHEPREP_NO_ZLIB
13 
18 namespace cheprep {
19 
20  class DeflateOutputStreamBuffer : public std::streambuf {
21 
22  public:
23 
24  DeflateOutputStreamBuffer(std::streambuf *buffer);
25 
26  void init(bool compress);
27  void finish();
28 
30 
31 
32  protected:
33  int overflow(int c = EOF);
34 
35 #ifndef CHEPREP_NO_ZLIB
36  bool flushOut();
37 #endif // CHEPREP_NO_ZLIB
38 
39  inline void putUI(unsigned int ui) {
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  }
47 
48  inline void putUS(unsigned short us) {
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  }
54 
55  inline void putUB(unsigned char ub) {
56  buffer->sputc(ub);
57  }
58 
59  inline void putS(const std::string s) {
60  buffer->sputn(s.c_str(), s.length());
61  }
62 
63  inline std::streampos pos() {
64  std::ostream os(buffer);
65  return os.tellp();
66  }
67 
68  inline unsigned int getSize() {
69  return size;
70  }
71 
72  inline unsigned int getCRC() {
73  return crc;
74  }
75 
76  private:
77  static unsigned long crctable[256];
78  std::streambuf *buffer;
79 
80  unsigned int crc;
81  unsigned int size;
82 
83 #ifndef CHEPREP_NO_ZLIB
84  static const unsigned int inSize = 1000;
85  static const unsigned int outSize = 1000;
88 
89  std::vector<char> in;
90  std::vector<char> out;
91 #endif // CHEPREP_NO_ZLIB
92 };
93 
94 
95 } // cheprep
96 
97 
98 
99 #endif // CHEPREP_DEFLATEOUTPUTSTREAMBUF_H
static constexpr double us
Definition: G4SIunits.hh:171
const XML_Char * s
Definition: expat.h:262