~mc.../inkscape/inkscape

« back to all changes in this revision

Viewing changes to src/streams-zlib.h

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * IO layer : zlib streambuf
 
3
 *
 
4
 * Authors:
 
5
 *   Johan Ceuppens <jceuppen at easynet dot be>
 
6
 *
 
7
 * Copyright (C) 2004 Johan Ceuppens
 
8
 *
 
9
 * Released under GNU LGPL, read the file 'COPYING.LIB' for more information
 
10
 */
 
11
 
 
12
#ifndef __STREAMS_ZLIB_H_
 
13
#define __STREAMS_ZLIB_H_
 
14
 
 
15
#include "streams-handles.h"
 
16
 
 
17
#include <glib/gtypes.h>
 
18
#include <glib/garray.h>
 
19
#include <zlib.h>
 
20
#include <iostream>
 
21
 
 
22
namespace Inkscape {
 
23
 
 
24
class ZlibBufferException : public std::exception {};
 
25
 
 
26
// This is the initial buffersize for the stream and
 
27
// zipbuffers (the streambuffers expand as needed).
 
28
const unsigned int BUFSIZE_STREAM = 4096; 
 
29
 
 
30
/**
 
31
 * ZlibBuffer
 
32
 */ 
 
33
 
 
34
//TODO: unbuffered IO
 
35
class ZlibBuffer : public std::streambuf
 
36
{
 
37
public:
 
38
 
 
39
    ZlibBuffer(URIHandle& urih);
 
40
    virtual ~ZlibBuffer() {}
 
41
    
 
42
protected:
 
43
 
 
44
    virtual int allocate_buffers();
 
45
    virtual int reallocate_buffers(int new_getsize, int new_putsize);
 
46
    virtual int underflow();
 
47
    virtual int overflow(int c = EOF);
 
48
    virtual int flush_output();
 
49
 
 
50
    virtual void init_inflation() throw(ZlibBufferException);
 
51
    virtual void reset_inflation() throw(ZlibBufferException);
 
52
    virtual int consume_and_inflate();
 
53
    virtual int do_consume_and_inflate(int nbytes);
 
54
    virtual int consume(guint8 *buf, int nbytes);
 
55
    virtual int do_consume(guint8 *buf, int nbytes);
 
56
    virtual GByteArray *inflate(guint8 *in_buffer, int nbytes);
 
57
    virtual GByteArray *do_inflate(guint8 *in_buffer, int nbytes);
 
58
    virtual int copy_to_get(guint8 *data, int nbytes);
 
59
    virtual int do_copy_to_get(guint8 *data, int nbytes);
 
60
 
 
61
    URIHandle *_urihandle;
 
62
 
 
63
private:
 
64
 
 
65
    ZlibBuffer& operator=(ZlibBuffer const& rhs);
 
66
    ZlibBuffer(ZlibBuffer const& rhs);
 
67
 
 
68
    z_stream _zs;
 
69
    int _putsize, _getsize;//sizes of in and out buffers
 
70
    
 
71
};
 
72
 
 
73
class izstream : public std::istream {
 
74
public:
 
75
 
 
76
    explicit izstream(std::streambuf& sb) : std::istream(&sb) {}
 
77
    ~izstream() { std::ios::init(0); }
 
78
    
 
79
    std::streambuf *rdbuf() { return std::ios::rdbuf(); }
 
80
    std::streambuf *operator ->() { return rdbuf(); }
 
81
 
 
82
};
 
83
 
 
84
}
 
85
 
 
86
#endif
 
87
 
 
88
/*
 
89
  Local Variables:
 
90
  mode:c++
 
91
  c-file-style:"stroustrup"
 
92
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
93
  indent-tabs-mode:nil
 
94
  fill-column:99
 
95
  End:
 
96
*/
 
97
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :