X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=textmodel.h;h=e6faa6ec8ee2a25d792f6fd451ca2f29d61fd43e;hb=149d7ca4cf84c3c9b7eb55b02d6b152fb00894bf;hp=93fa5b7aeba80aabbbddad13534b784484322f11;hpb=63b438eb6e7c0e06bf37614c5de3c03f25301af5;p=odcread.git diff --git a/textmodel.h b/textmodel.h index 93fa5b7..e6faa6e 100644 --- a/textmodel.h +++ b/textmodel.h @@ -9,53 +9,116 @@ namespace odc { class TextModel : public ContainerModel { private: - static const std::string TYPENAME; - static const TypeProxy PROXY; + static const TypeProxy PROXY; public: - TextModel(INTEGER id); - static const std::string &getType(); - static const std::string *getSuper(); + static const std::string TYPENAME; virtual const std::string &getTypeName() const; + + TextModel(INTEGER id); + /** + * Just calls super and reads the version and checks that its in the allowed range. + */ virtual void internalize(Reader &reader); }; + /** + * A TextPiece is just a component of an StdTextModel. + * It has a certain length in bytes, which is known construction time (due + * to meta-data in the StdTextModel header) and contents which are read + * later. + */ class TextPiece { public: + /** + * The number of bytes that will be read. + */ const size_t d_len; TextPiece(size_t len); virtual void read(Reader &reader) = 0; + virtual std::string toString() const = 0; + virtual void accept(Visitor &visitor) const = 0; + /** + * Size in bytes, excluding the null-character that terminates the string (i.e. the size that is read from file). + */ + unsigned size() const; }; + /** + * TextPiece consisting of 16-bit unicode characters. + * Not sure if the encoding is UCS-2 or UTF-16. + */ class LongPiece : public TextPiece { + private: + CHAR *d_buf; public: LongPiece(size_t len); + ~LongPiece(); virtual void read(Reader &reader); + virtual std::string toString() const; + virtual void accept(Visitor &visitor) const; + + /** + * Get the buffer contents as 16-bit (UCS-2 or UTF-16 I don't know) unicode. + */ + CHAR *getBuffer() const; }; + /** + * TextPiece consisting of 8-bit characters in the Latin-1 extension of ASCII. + */ class ShortPiece : public TextPiece { + private: + SHORTCHAR *d_buf; public: ShortPiece(size_t len); + ~ShortPiece(); virtual void read(Reader &reader); + virtual std::string toString() const; + virtual void accept(Visitor &visitor) const; + + /** + * Get the buffer contents as 8-bit (Latin-1) characters. + */ + SHORTCHAR *getBuffer() const; }; + /** + * TextPiece that embeds a View. + */ class ViewPiece : public TextPiece { + Store *d_view; public: - ViewPiece(); + ViewPiece(Store *view); + ~ViewPiece(); virtual void read(Reader &reader); + virtual std::string toString() const; + virtual void accept(Visitor &visitor) const; }; + /** + * Default implementation of a TextModel. + * Essentially it is a series of TextPieces. + */ class StdTextModel : public TextModel { private: - static const std::string TYPENAME; - static const TypeProxy PROXY; + static const TypeProxy PROXY; + std::vector d_pieces; public: - StdTextModel(INTEGER id); - static const std::string &getType(); - static const std::string *getSuper(); + static const std::string TYPENAME; virtual const std::string &getTypeName() const; + + StdTextModel(INTEGER id); + /** + * Calls super and reads the version and checks that its in the allowed range. + * Then the text model meta-data is read, including information on all the pieces. + * After reading the meta-data, the pieces themselves are read. + */ virtual void internalize(Reader &reader); + + virtual std::string toString(); + virtual void accept(Visitor &visitor) const; }; } // namespace odc