X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=odcread.cc;h=e790fdd36bcdc3b211d3c4d277cf9462ee6db3dd;hb=20254ed23eb75d8c3832b807ea97616fd684976e;hp=4ba36802c058412591472bd9fb6c4af470c6a41f;hpb=d7f2452e20b04d1559b7bdd3aa49b6fbf7d0abaf;p=odcread.git diff --git a/odcread.cc b/odcread.cc index 4ba3680..e790fdd 100644 --- a/odcread.cc +++ b/odcread.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -52,40 +53,41 @@ namespace odc { class MyVisitor : public Visitor { private: - std::vector d_context; + std::stack d_context; void terminateContext() { - Context *c = *(d_context.end() - 1); - d_context.erase(d_context.end() - 1); - if (d_context.size() == 0) { + Context *c = d_context.top(); + d_context.pop(); + if (d_context.empty()) { std::cout << c->getPlainText() << std::endl; } else { std::string text = c->getPlainText(); - (*(d_context.end() - 1))->addPiece(text); + d_context.top()->addPiece(text); } delete c; } public: virtual void partStart() { - d_context.push_back(new PartContext()); + d_context.push(new PartContext()); } virtual void partEnd() { terminateContext(); } virtual void foldLeft(bool collapsed) { - d_context.push_back(new FoldContext(collapsed)); + d_context.push(new FoldContext(collapsed)); } virtual void foldRight() { terminateContext(); } virtual void textShortPiece(const ShortPiece *piece) { std::string text = piece->getText(); - (*(d_context.end() - 1))->addPiece(text); + d_context.top()->addPiece(text); } virtual void textLongPiece(const LongPiece *piece) { - std::string text = piece->getText(); - (*(d_context.end() - 1))->addPiece(text); + throw "Long Piece not handled"; + //std::string text = piece->getText(); + //d_context.top()->addPiece(text); } };