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