1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* IO layer : handles for URIs
*
* Authors:
* Johan Ceuppens <jceuppen at easynet dot be>
*
* Copyright (C) 2004 Johan Ceuppens
*
* Released under GNU LGPL, read the file 'COPYING.LIB' for more information
*/
#ifndef __STREAM_HANDLES_H_
#define __STREAM_HANDLES_H_
#include <stdio.h>
#include <exception>
#include "forward.h"
namespace Inkscape {
/**
* URIHandle (Abstract class)
*/
class URIHandle
{
public:
virtual ~URIHandle() {}
virtual int read (void *buf, int buflen) = 0;
virtual int write (void const *buf, int buflen) = 0;
virtual void close() = 0;
protected:
virtual int sys_read (void *buf, int buflen) = 0;
virtual int sys_write (void const *buf, int buflen) = 0;
virtual void sys_close() = 0;
virtual void error(char const *errstr) = 0;
};
/**
* FileHandle
*/
class IOException : public std::exception {};
class ReadException : public IOException
{
public:
const char *what() const throw() { return "error read"; }
};
class WriteException : public IOException
{
public:
const char *what() const throw() { return "error write"; }
};
class FileHandle : public URIHandle
{
public:
FileHandle() : fp(0) {}
virtual ~FileHandle() { if (fp) sys_close(); };
virtual int open(URI const& uri, char const* mode);
virtual void close();
virtual int read (void *buf, int buflen);
virtual int write (void const *buf, int buflen);
virtual int seek (long offset, int whence);
protected:
virtual FILE *sys_open(URI const& uri, char const* mode);
virtual void sys_close();
virtual int sys_read(void *buf, int buflen) throw(ReadException);
virtual int sys_write(void const *buf, int buflen) throw(WriteException);
virtual int sys_seek(long offset, int whence);
virtual void error(char const *errstr);
FILE *get_fp() { return fp; }
private:
FILE *fp;
};
/*
class SocketHandle : public URIHandle
{
// ...
};
*/
}
#endif
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|