From 1a188eff533fe10218eaec174755abe1f19dfdde Mon Sep 17 00:00:00 2001 From: Gert van Valkenhoef Date: Fri, 12 Aug 2011 18:24:22 +0200 Subject: [PATCH] Show internal structure of StdTextModel --- alien.cc | 5 ++++- textmodel.cc | 43 +++++++++++++++++++++++++++++++++++-------- textmodel.h | 10 +++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/alien.cc b/alien.cc index d82a33c..49d19fe 100644 --- a/alien.cc +++ b/alien.cc @@ -11,7 +11,10 @@ std::string AlienPiece::toString() { AlienPart::AlienPart(Store * const _store): store(_store) {} std::string AlienPart::toString() { - return store->toString(); + if (store != 0) + return store->toString(); + else + return "NULL"; } Alien::Alien(INTEGER id, const TypePath &path): Store(id), d_path(path), d_comps() {} diff --git a/textmodel.cc b/textmodel.cc index 6ecd89e..2028c2e 100644 --- a/textmodel.cc +++ b/textmodel.cc @@ -4,6 +4,9 @@ #include #include +//#include +//#include + namespace odc { const std::string TextModel::TYPENAME("TextModels.Model^"); @@ -32,7 +35,7 @@ void TextModel::internalize(Reader &reader) { const std::string StdTextModel::TYPENAME("TextModels.StdModel^"); const TypeProxy StdTextModel::PROXY; -StdTextModel::StdTextModel(INTEGER id) : TextModel(id) {} +StdTextModel::StdTextModel(INTEGER id) : TextModel(id), d_pieces() {} const std::string &StdTextModel::getType() { return TYPENAME; @@ -60,7 +63,6 @@ void StdTextModel::internalize(Reader &reader) { if (reader.isCancelled()) return; std::vector dict; - std::vector pieces; INTEGER len = reader.readInt(); BYTE ano = reader.readByte(); std::cout << "len " << len << " ano " << (int)ano << std::endl; @@ -73,14 +75,14 @@ void StdTextModel::internalize(Reader &reader) { INTEGER pieceLen = reader.readInt(); if (pieceLen > 0) { // shortchar piece std::cout << "Found SChar piece" << std::endl; - pieces.push_back(new ShortPiece(pieceLen)); + d_pieces.push_back(new ShortPiece(pieceLen)); // NEW(sp); sp.len := len; sp.attr := attr; // sp.file := rd.rider.Base(); sp.org := org; un := sp; // INC(org, len) -- increment org by len ? } else if (pieceLen < 0) { // longchar piece std::cout << "Found LChar piece" << std::endl; assert(pieceLen % 2 == 0); - pieces.push_back(new LongPiece(pieceLen / 2)); + d_pieces.push_back(new LongPiece(pieceLen / 2)); // len := -len; ASSERT(~ODD(len), 100); // NEW(lp); lp.len := len DIV 2; lp.attr := attr; // lp.file := rd.rider.Base(); lp.org := org; un := lp; @@ -93,13 +95,13 @@ void StdTextModel::internalize(Reader &reader) { // rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view); // v.view.InitContext(NewContext(v, t)); // un := v; INC(org) -- increment org by one?? WTH? - pieces.push_back(new ViewPiece()); + d_pieces.push_back(new ViewPiece(view)); ++skip; } ano = reader.readByte(); } - for (int i = 0; i < pieces.size(); ++i) { - pieces[i]->read(reader); + for (int i = 0; i < d_pieces.size(); ++i) { + d_pieces[i]->read(reader); } // rd.SetPos(org); } @@ -147,6 +149,14 @@ void StdTextModel::internalize(Reader &reader) { // END Internalize; // +std::string StdTextModel::toString() { + std::string sofar = "StdTextModel { "; + for (int i = 0; i < d_pieces.size(); ++i) { + sofar += d_pieces[i]->toString() + " "; + } + return sofar + "}"; +} + TextPiece::TextPiece(size_t len): d_len(len) {} LongPiece::LongPiece(size_t len): TextPiece(len) {} @@ -157,19 +167,36 @@ void LongPiece::read(Reader &reader) { delete buf; } +std::string LongPiece::toString() { + return std::string("LongPiece"); +} + ShortPiece::ShortPiece(size_t len): TextPiece(len) {} void ShortPiece::read(Reader &reader) { +// static char piece[] = "pieceA"; SHORTCHAR *buf = new SHORTCHAR[d_len + 1]; reader.readSChar(buf, d_len); buf[d_len] = 0; +// std::ofstream ofs(piece, std::ios::out); +// ofs.write(buf, d_len); +// ofs.close(); +// ++piece[5]; delete buf; } -ViewPiece::ViewPiece(): TextPiece(0) {} +std::string ShortPiece::toString() { + return std::string("ShortPiece"); +} + +ViewPiece::ViewPiece(Store *view): TextPiece(0), d_view(view) {} void ViewPiece::read(Reader &reader) { reader.readByte(); } +std::string ViewPiece::toString() { + return std::string("ViewPiece { ") + d_view->toString() + " }"; +} + } // namespace odc diff --git a/textmodel.h b/textmodel.h index 93fa5b7..bc14808 100644 --- a/textmodel.h +++ b/textmodel.h @@ -25,30 +25,36 @@ namespace odc { const size_t d_len; TextPiece(size_t len); virtual void read(Reader &reader) = 0; + virtual std::string toString() = 0; }; class LongPiece : public TextPiece { public: LongPiece(size_t len); virtual void read(Reader &reader); + virtual std::string toString(); }; class ShortPiece : public TextPiece { public: ShortPiece(size_t len); virtual void read(Reader &reader); + virtual std::string toString(); }; class ViewPiece : public TextPiece { + Store *d_view; public: - ViewPiece(); + ViewPiece(Store *view); virtual void read(Reader &reader); + virtual std::string toString(); }; class StdTextModel : public TextModel { private: static const std::string TYPENAME; static const TypeProxy PROXY; + std::vector d_pieces; public: StdTextModel(INTEGER id); @@ -56,6 +62,8 @@ namespace odc { static const std::string *getSuper(); virtual const std::string &getTypeName() const; virtual void internalize(Reader &reader); + + virtual std::string toString(); }; } // namespace odc -- 2.29.2