File: Synopsis/Buffer.hh 1
2
3
4
5
6
7
8#ifndef Synopsis_Buffer_hh_
9#define Synopsis_Buffer_hh_
10
11#include <streambuf>
12#include <vector>
13
14namespace Synopsis
15{
16
17
18
19
20
21
22class Buffer
23{
24public:
25 Buffer(std::streambuf *, const std::string & = std::string("unknown"));
26
27
28 unsigned long size() const { return my_buffer.size();}
29
30
31 char get() { return my_cursor < my_buffer.size() ? my_buffer[my_cursor++] : '\0';}
32
33 void unget() { --my_cursor;}
34
35 void reset(unsigned long c = 0) { my_cursor = c;}
36
37
38 unsigned long position() const { return my_cursor - 1;}
39
40 char at(unsigned long p) const { return my_buffer[p];}
41
42 const char *ptr(unsigned long p = 0) const { return my_buffer.c_str() + p;}
43
44
45
46 void replace(const char *from, const char *to,
47 const char *begin, unsigned long length);
48
49
50 unsigned long origin(const char *, std::string &) const;
51
52
53
54 void write(std::ostream &, const std::string &) const;
55
56private:
57 struct Replacement
58 {
59 Replacement(const char *from, const char *to,
60 const char *begin, unsigned long length);
61 static bool smaller(Replacement const &r1, Replacement const &r2)
62 { return r1.from < r2.from;}
63 const char *from;
64 const char *to;
65 const char *begin;
66 unsigned long length;
67 };
68 typedef std::vector<Replacement> Replacements;
69
70
71
72
73
74
75 long read_line_directive(unsigned long cursor, long line,
76 unsigned long &begin, unsigned long &end) const;
77
78 std::string my_filename;
79 std::string my_buffer;
80 unsigned long my_cursor;
81 Replacements my_replacements;
82};
83
84}
85
86#endif
Generated on Thu Apr 16 16:28:04 2009 by
synopsis (version devel)