GNU CommonC++
zstream.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_ZSTREAM_H_
44 #define CCXX_ZSTREAM_H_
45 
46 #ifndef CCXX_MISSING_H_
47 #include <cc++/missing.h>
48 #endif
49 
50 #ifndef CCXX_THREAD_H_
51 #include <cc++/thread.h>
52 #endif
53 
54 #ifndef CCXX_STRING_H_
55 #include <cc++/string.h>
56 #endif
57 
58 #ifndef CCXX_EXCEPTION_H_
59 #include <cc++/exception.h>
60 #endif
61 
62 #include <zlib.h>
63 
64 #ifdef CCXX_NAMESPACES
65 namespace ost {
66 #endif
67 
68 #ifdef COMMON_STD_EXCEPTION
69 
70 class __EXPORT IOZException : public IOException
71 {
72 public:
73  IOZException(const String &str) : IOException(str) {};
74 };
75 
76 #endif
77 
78 class __EXPORT IZStream : protected std::streambuf, public std::istream
79 {
80 private:
81  gzFile fp;
82  int doallocate();
83  bool throwflag;
84 
85 protected:
86  size_t bufsize;
87  char *gbuf;
88 
89  void allocate(size_t size);
90 
91  int underflow();
92 
93  int uflow();
94 
95 public:
96  IZStream(bool throwflag = false);
97  IZStream(const char *name, size_t size = 512, bool tf = false);
98 
99  bool isOpen(void);
100 
101  void close(void);
102 
103  virtual ~IZStream();
104 
105  void open(const char *name, size_t size = 512);
106 
107  inline size_t getBufferSize(void)
108  {return bufsize;};
109 };
110 
111 class __EXPORT OZStream : protected std::streambuf, public std::ostream
112 {
113 private:
114  gzFile fp;
115  int doallocate();
116  bool throwflag;
117 
118 protected:
119  size_t bufsize;
120  char *pbuf;
121 
122  void allocate(size_t size);
123 
124  int overflow(int ch);
125 
126 public:
127  OZStream(bool throwflag = false);
128  OZStream(const char *name, int level = Z_DEFAULT_COMPRESSION, size_t size = 512, bool tf = false);
129 
130  bool isOpen(void);
131 
132  void close(void);
133 
134  virtual ~OZStream();
135 
136  void open(const char *name, int level = Z_DEFAULT_COMPRESSION, size_t size = 512);
137 
138  inline size_t getBufferSize(void)
139  {return bufsize;};
140 };
141 
142 #ifdef CCXX_NAMESPACES
143 }
144 #endif
145 
146 #endif
147