X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=textmodel.h;h=8eb26eb47d419c2a2d2b7d5e30765161e4898d91;hb=20254ed23eb75d8c3832b807ea97616fd684976e;hp=38eb7c55b73d0546c5884263a98e2ec01d53b474;hpb=cf035fa1849a5e65c0d636ce2718bc2c85994680;p=odcread.git diff --git a/textmodel.h b/textmodel.h index 38eb7c5..8eb26eb 100644 --- a/textmodel.h +++ b/textmodel.h @@ -9,26 +9,41 @@ 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() = 0; - virtual std::string toPlainText() = 0; + virtual std::string toString() const = 0; + virtual void accept(Visitor &visitor) const = 0; }; + /** + * TextPiece consisting of 16-bit characters. + * Not sure of the encoding. + */ class LongPiece : public TextPiece { private: CHAR *d_buf; @@ -36,10 +51,18 @@ namespace odc { LongPiece(size_t len); ~LongPiece(); virtual void read(Reader &reader); - virtual std::string toString(); - virtual std::string toPlainText(); + virtual std::string toString() const; + /** + * Return the text contained in this piece. + * Currently just casting the buffer to wchar_t* and hoping for the best. + */ + virtual std::wstring getText() const; + virtual void accept(Visitor &visitor) const; }; + /** + * TextPiece consisting of 8-bit characters. + */ class ShortPiece : public TextPiece { private: SHORTCHAR *d_buf; @@ -47,34 +70,47 @@ namespace odc { ShortPiece(size_t len); ~ShortPiece(); virtual void read(Reader &reader); - virtual std::string toString(); - virtual std::string toPlainText(); + virtual std::string toString() const; + virtual std::string getText() const; + virtual void accept(Visitor &visitor) const; }; + /** + * TextPiece that embeds a View. + */ class ViewPiece : public TextPiece { Store *d_view; public: ViewPiece(Store *view); + ~ViewPiece(); virtual void read(Reader &reader); - virtual std::string toString(); - virtual std::string toPlainText(); + 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 std::string toPlainText(); + virtual void accept(Visitor &visitor) const; }; } // namespace odc