From: Gert van Valkenhoef Date: Mon, 7 Nov 2011 18:54:24 +0000 (+0000) Subject: Disable debug output, read TextPieces into memory X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=bfa2551119497089b987c2bce3e2f512f9e2130f;p=odcread.git Disable debug output, read TextPieces into memory --- diff --git a/odcread.cc b/odcread.cc index 27117dd..6d50668 100644 --- a/odcread.cc +++ b/odcread.cc @@ -30,11 +30,13 @@ int main(int argc, char *argv[]) { } std::ifstream in(argv[1], std::ios::in | std::ios::binary); odc::Store* s = odc::importDocument(in); - //std::cout << s->toString() << std::endl; - //std::cout << in.tellg() << " " << in.eof() << std::endl; + std::cout << std::endl << std::endl; + + std::cout << s->toString() << std::endl; + std::cout << in.tellg() << " " << in.eof() << std::endl; odc::TypePath path; odc::ContainerModel(0).getTypePath(&path); - //std::cout << path.toString() << std::endl; + std::cout << path.toString() << std::endl; return 0; } diff --git a/textmodel.cc b/textmodel.cc index 2810420..81ac03d 100644 --- a/textmodel.cc +++ b/textmodel.cc @@ -89,8 +89,8 @@ void StdTextModel::internalize(Reader &reader) { // INC(org, len) -- increment org by len ? } else { // embedded view //std::cout << "Found View piece" << std::endl; - reader.readInt(); reader.readInt(); - Store *view = reader.readStore(); // fixme: save somewhere + reader.readInt(); reader.readInt(); // view width + height: ignore + Store *view = reader.readStore(); // NEW(v); v.len := 1; v.attr := attr; // rd.ReadInt(v.w); rd.ReadInt(v.h); Views.ReadView(rd, v.view); // v.view.InitContext(NewContext(v, t)); @@ -161,33 +161,40 @@ TextPiece::TextPiece(size_t len): d_len(len) {} LongPiece::LongPiece(size_t len): TextPiece(len) {} +LongPiece::~LongPiece() { + delete d_buf; +} + void LongPiece::read(Reader &reader) { - CHAR *buf = new CHAR[d_len]; - reader.readLChar(buf, d_len); - delete buf; + d_buf = new CHAR[d_len]; + reader.readLChar(d_buf, d_len); } std::string LongPiece::toString() { - return std::string("LongPiece"); + return std::string("LongPiece(FIXME)");// + std::wstring((wchar_t*)d_buf) + std::string(")"); } ShortPiece::ShortPiece(size_t len): TextPiece(len) {} +ShortPiece::~ShortPiece() { + delete d_buf; +} + 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::cout.write(buf, d_len); + d_buf = new SHORTCHAR[d_len + 1]; + reader.readSChar(d_buf, d_len); + d_buf[d_len] = 0; +// std::cout.write(buf, d_len); // std::ofstream ofs(piece, std::ios::out); // ofs.write(buf, d_len); // ofs.close(); // ++piece[5]; - delete buf; +// delete buf; } std::string ShortPiece::toString() { - return std::string("ShortPiece"); + return std::string("ShortPiece(") + std::string(d_buf) + std::string(")"); } ViewPiece::ViewPiece(Store *view): TextPiece(0), d_view(view) {} diff --git a/textmodel.h b/textmodel.h index bc14808..9cab44d 100644 --- a/textmodel.h +++ b/textmodel.h @@ -29,15 +29,21 @@ namespace odc { }; class LongPiece : public TextPiece { + private: + CHAR *d_buf; public: LongPiece(size_t len); + ~LongPiece(); virtual void read(Reader &reader); virtual std::string toString(); }; class ShortPiece : public TextPiece { + private: + SHORTCHAR *d_buf; public: ShortPiece(size_t len); + ~ShortPiece(); virtual void read(Reader &reader); virtual std::string toString(); };