DEADSOFTWARE

Testing odcread against a bunch of existing .odc files
[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 };
43 /**
44 * TextPiece consisting of 16-bit characters.
45 * Not sure of the encoding.
46 */
47 class LongPiece : public TextPiece {
48 private:
49 CHAR *d_buf;
50 public:
51 LongPiece(size_t len);
52 ~LongPiece();
53 virtual void read(Reader &reader);
54 virtual std::string toString() const;
55 /**
56 * Return the text contained in this piece.
57 * Currently just casting the buffer to wchar_t* and hoping for the best.
58 */
59 virtual std::wstring getText() const;
60 virtual void accept(Visitor &visitor) const;
61 };
63 /**
64 * TextPiece consisting of 8-bit characters.
65 */
66 class ShortPiece : public TextPiece {
67 private:
68 SHORTCHAR *d_buf;
69 public:
70 ShortPiece(size_t len);
71 ~ShortPiece();
72 virtual void read(Reader &reader);
73 virtual std::string toString() const;
74 virtual std::string getText() const;
75 virtual void accept(Visitor &visitor) const;
76 };
78 /**
79 * TextPiece that embeds a View.
80 */
81 class ViewPiece : public TextPiece {
82 Store *d_view;
83 public:
84 ViewPiece(Store *view);
85 ~ViewPiece();
86 virtual void read(Reader &reader);
87 virtual std::string toString() const;
88 virtual void accept(Visitor &visitor) const;
89 };
91 /**
92 * Default implementation of a TextModel.
93 * Essentially it is a series of TextPieces.
94 */
95 class StdTextModel : public TextModel {
96 private:
97 static const TypeProxy<StdTextModel, TextModel> PROXY;
98 std::vector<TextPiece *> d_pieces;
100 public:
101 static const std::string TYPENAME;
102 virtual const std::string &getTypeName() const;
104 StdTextModel(INTEGER id);
105 /**
106 * Calls super and reads the version and checks that its in the allowed range.
107 * Then the text model meta-data is read, including information on all the pieces.
108 * After reading the meta-data, the pieces themselves are read.
109 */
110 virtual void internalize(Reader &reader);
112 virtual std::string toString();
113 virtual void accept(Visitor &visitor) const;
114 };
116 } // namespace odc
118 #endif // _TEXTMODEL_H_