LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
gd_io_stream.h
Go to the documentation of this file.
1/* *****************************************************************************
2** Initial file written and documented by:
3** Kevin Shepherd <kshepherd@php.net> December 2007
4** of Scarlet Line http://www.scarletline.com/
5*******************************************************************************/
29#ifndef _gd_io_stream_h
30#define _gd_io_stream_h
31#ifdef __cplusplus
32
33#include "gd.h"
34#include <iostream>
35
38class BGD_EXPORT_DATA_IMPL istreamIOCtx : public gdIOCtx {
39 public:
40 typedef std::istream stream_type;
47 istreamIOCtx(stream_type &__stream) { init(&__stream); }
48
49 static int Getbuf(gdIOCtxPtr ctx, void *buf, int size);
50 static int Putbuf(gdIOCtxPtr, const void *, int);
51 static void Putchar(gdIOCtxPtr, int);
52 static int Getchar(gdIOCtxPtr ctx);
53 static int Seek(gdIOCtxPtr ctx, const int pos);
54 static long Tell(gdIOCtxPtr ctx);
55 static void FreeCtx(gdIOCtxPtr ctx);
56
57 void init(stream_type *__stream)
58 {
59 getC = Getchar;
60 putC = Putchar;
61 getBuf = Getbuf;
62 putBuf = Putbuf;
63 tell = Tell;
64 seek = Seek;
65 gd_free = FreeCtx;
66 _M_stream = __stream;
67 }
68
69 private:
70 stream_type *_M_stream;
71};
74inline gdIOCtxPtr gdNewIstreamCtx(std::istream *__stream) { return new istreamIOCtx(*__stream); }
75
78class BGD_EXPORT_DATA_IMPL ostreamIOCtx : public gdIOCtx {
79 public:
80 typedef std::ostream stream_type;
87 ostreamIOCtx(stream_type &__stream) { init(&__stream); }
88
89 static int Getbuf(gdIOCtxPtr, void *, int);
90 static int Putbuf(gdIOCtxPtr ctx, const void *buf, int size);
91 static int Getchar(gdIOCtxPtr);
92 static void Putchar(gdIOCtxPtr ctx, int a);
93 static int Seek(gdIOCtxPtr ctx, const int pos);
94 static long Tell(gdIOCtxPtr ctx);
95 static void FreeCtx(gdIOCtxPtr ctx);
96
97 void init(stream_type *__stream)
98 {
99 getC = Getchar;
100 putC = Putchar;
101 getBuf = Getbuf;
102 putBuf = Putbuf;
103 tell = Tell;
104 seek = Seek;
105 gd_free = FreeCtx;
106 _M_stream = __stream;
107 }
108
109 private:
110 stream_type *_M_stream;
111};
114inline gdIOCtxPtr gdNewOstreamCtx(std::ostream *__stream) { return new ostreamIOCtx(*__stream); }
115
116#endif /* __cplusplus */
117#endif /* _gd_io_stream_h */