From: Gert van Valkenhoef Date: Wed, 9 Nov 2011 08:59:50 +0000 (+0000) Subject: Use STL stack instead of vector. X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=3c4f1fe68ac495544031117a347b22711c99d72b;p=odcread.git Use STL stack instead of vector. --- diff --git a/odcread.cc b/odcread.cc index 4ba3680..24bb51e 100644 --- a/odcread.cc +++ b/odcread.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -52,40 +53,40 @@ 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); + d_context.top()->addPiece(text); } };