DEADSOFTWARE

Makefile: proper dependency management
[odcread.git] / textmodel.h
1 #ifndef _TEXTMODEL_H_
2 #define _TEXTMODEL_H_
4 #include <oberon.h>
5 #include <typeregister.h>
6 #include <store.h>
8 namespace odc {
10 class TextModel : public ContainerModel {
11 private:
12 static const TypeProxy<TextModel, ContainerModel> PROXY;
14 public:
15 static const std::string TYPENAME;
16 virtual const std::string &getTypeName() const;
18 TextModel(INTEGER id);
19 /**
20 * Just calls super and reads the version and checks that its in the allowed range.
21 */
22 virtual void internalize(Reader &reader);
23 };
25 /**
26 * A TextPiece is just a component of an StdTextModel.
27 * It has a certain length in bytes, which is known construction time (due
28 * to meta-data in the StdTextModel header) and contents which are read
29 * later.
30 */
31 class TextPiece {
32 public:
33 /**
34 * The number of bytes that will be read.
35 */
36 const size_t d_len;
37 TextPiece(size_t len);
38 virtual void read(Reader &reader) = 0;
39 virtual std::string toString() const = 0;
40 virtual void accept(Visitor &visitor) const = 0;
41 /**
42 * Size in bytes, excluding the null-character that terminates the string (i.e. the size that is read from file).
43 */
44 unsigned size() const;
45 };
47 /**
48 * TextPiece consisting of 16-bit unicode characters.
49 * Not sure if the encoding is UCS-2 or UTF-16.
50 */
51 class LongPiece : public TextPiece {
52 private:
53 CHAR *d_buf;
54 public:
55 LongPiece(size_t len);
56 ~LongPiece();
57 virtual void read(Reader &reader);
58 virtual std::string toString() const;
59 virtual void accept(Visitor &visitor) const;
61 /**
62 * Get the buffer contents as 16-bit (UCS-2 or UTF-16 I don't know) unicode.
63 */
64 CHAR *getBuffer() const;
65 };
67 /**
68 * TextPiece consisting of 8-bit characters in the Latin-1 extension of ASCII.
69 */
70 class ShortPiece : public TextPiece {
71 private:
72 SHORTCHAR *d_buf;
73 public:
74 ShortPiece(size_t len);
75 ~ShortPiece();
76 virtual void read(Reader &reader);
77 virtual std::string toString() const;
78 virtual void accept(Visitor &visitor) const;
80 /**
81 * Get the buffer contents as 8-bit (Latin-1) characters.
82 */
83 SHORTCHAR *getBuffer() const;
84 };
86 /**
87 * TextPiece that embeds a View.
88 */
89 class ViewPiece : public TextPiece {
90 Store *d_view;
91 public:
92 ViewPiece(Store *view);
93 ~ViewPiece();
94 virtual void read(Reader &reader);
95 virtual std::string toString() const;
96 virtual void accept(Visitor &visitor) const;
97 };
99 /**
100 * Default implementation of a TextModel.
101 * Essentially it is a series of TextPieces.
102 */
103 class StdTextModel : public TextModel {
104 private:
105 static const TypeProxy<StdTextModel, TextModel> PROXY;
106 std::vector<TextPiece *> d_pieces;
108 public:
109 static const std::string TYPENAME;
110 virtual const std::string &getTypeName() const;
112 StdTextModel(INTEGER id);
113 /**
114 * Calls super and reads the version and checks that its in the allowed range.
115 * Then the text model meta-data is read, including information on all the pieces.
116 * After reading the meta-data, the pieces themselves are read.
117 */
118 virtual void internalize(Reader &reader);
120 virtual std::string toString();
121 virtual void accept(Visitor &visitor) const;
122 };
124 } // namespace odc
126 #endif // _TEXTMODEL_H_