OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimGzStream.h
Go to the documentation of this file.
1 // ============================================================================
2 // gzstream, C++ iostream classes wrapping the zlib compression library.
3 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ============================================================================
19 //
20 // File : gzstream.h
21 // Revision : $Revision: 13050 $
22 // Revision_date : $Date: 2008-06-19 14:07:35 -0400 (Thu, 19 Jun 2008) $
23 // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
24 //
25 // Standard streambuf implementation following Nicolai Josuttis, "The
26 // Standard C++ Library".
27 // ============================================================================
28 
29 #ifndef ossimGzStream_HEADER
30 #define ossimGzStream_HEADER
31 
32 // standard C++ with new header file names and std:: namespace
35 #include <ossim/ossimConfig.h>
36 #include <iostream>
37 #include <fstream>
39 
40 #if OSSIM_HAS_LIBZ
41 // ----------------------------------------------------------------------------
42 // Internal classes to implement gzstream. See below for user classes.
43 // ----------------------------------------------------------------------------
44 
45 class OSSIM_DLL ossimGzStreamBuf : public std::streambuf
46 {
47 
48 public:
49  ossimGzStreamBuf();
50 
51  virtual ~ossimGzStreamBuf();
52 
53  bool is_open()const;
54  ossimGzStreamBuf* open( const char* name, int open_mode);
55  ossimGzStreamBuf* close();
56 
57  virtual int overflow( int c = EOF);
58 
59  // will not use buffer for get.
60  virtual std::streamsize xsgetn(char_type* __s, std::streamsize n);
61  virtual int underflow();
62  virtual int sync();
63  virtual pos_type seekoff(off_type t, std::ios_base::seekdir dir,
64  std::ios_base::openmode omode = std::ios_base::in |
65  std::ios_base::out);
66 /* virtual pos_type seekpos(pos_type posType, */
67 /* std::ios_base::openmode __mode = std::ios_base::in | */
68 /* std::ios_base::out); */
69 
70 private:
71  struct PrivateData;
72  int flush_buffer();
73 
74  static const int bufferSize = 303; // 47+256 size of data buff
75  // totals 512 bytes under g++ for igzstream at the end.
76  PrivateData* prvtData;
77  char buffer[bufferSize]; // data buffer
78  bool opened; // open/close state of stream
79  int mode; // I/O mode
80 
81 }; // End of class ossimGzStreamBuf
82 
83 /* class OSSIM_DLL ossimGzStreamBase : virtual public ossimProtocolStream */
84 /* { */
85 /* protected: */
86 /* ossimGzStreamBuf buf; */
87 
88 /* public: */
89 /* ossimGzStreamBase():ossimProtocolStream(&buf) { } */
90 /* ossimGzStreamBase( const char* name, int open_mode); */
91 /* virtual ~ossimGzStreamBase(); */
92 /* virtual void open( const char* name, int open_mode); */
93 /* virtual void close(); */
94 /* ossimGzStreamBuf* rdbuf() { return &buf; } */
95 
96 /* TYPE_DATA */
97 /* }; */
98 
99 //class OSSIM_DLL ossimIgzStream : public ossimGzStreamBase, public std::istream
100 class OSSIM_DLL ossimIgzStream : public ossimIFStream
101 {
102 public:
103  ossimIgzStream();
104  ossimIgzStream( const char* name,
105  std::ios_base::openmode mode = std::ios_base::in);
106  virtual ~ossimIgzStream();
107  ossimGzStreamBuf* rdbuf();
108 
109  virtual void open( const char* name,
110  std::ios_base::openmode mode = std::ios_base::in);
111 
112  virtual void close();
113  virtual bool is_open()const;
114  virtual bool isCompressed()const;
115 
116 protected:
117  ossimGzStreamBuf buf;
118 
119 }; // End of class ossimIgzStream
120 
121 class OSSIM_DLL ossimOgzStream : public ossimOFStream
122 {
123 public:
124  ossimOgzStream();
125  ossimOgzStream( const char* name,
126  std::ios_base::openmode mode =
127  std::ios_base::out|std::ios_base::trunc );
128  virtual ~ossimOgzStream();
129 
130  ossimGzStreamBuf* rdbuf();
131  void open( const char* name,
132  std::ios_base::openmode mode =
133  std::ios_base::out|std::ios_base::trunc );
134  virtual void close();
135  virtual bool is_open()const;
136  virtual bool isCompressed()const;
137 
138 protected:
139  ossimGzStreamBuf buf;
140 
141 }; // End of class ossimOgzStream
142 
143 #endif /* #if OSSIM_HAS_LIBZ */
144 
145 #endif /* #define ossimGzStream_HEADER */
os2<< "> n<< " > nendobj n
#define OSSIM_DLL
virtual bool isCompressed() const
isCompressed method.