diff options
Diffstat (limited to 'Swiften/Parser/Tree')
-rw-r--r-- | Swiften/Parser/Tree/NullParserElement.cpp | 4 | ||||
-rw-r--r-- | Swiften/Parser/Tree/NullParserElement.h | 15 | ||||
-rw-r--r-- | Swiften/Parser/Tree/ParserElement.cpp | 30 | ||||
-rw-r--r-- | Swiften/Parser/Tree/ParserElement.h | 69 | ||||
-rw-r--r-- | Swiften/Parser/Tree/TreeReparser.cpp | 60 | ||||
-rw-r--r-- | Swiften/Parser/Tree/TreeReparser.h | 12 |
6 files changed, 96 insertions, 94 deletions
diff --git a/Swiften/Parser/Tree/NullParserElement.cpp b/Swiften/Parser/Tree/NullParserElement.cpp index 4a2db8f..7b52926 100644 --- a/Swiften/Parser/Tree/NullParserElement.cpp +++ b/Swiften/Parser/Tree/NullParserElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,6 +8,6 @@ namespace Swift { -boost::shared_ptr<NullParserElement> NullParserElement::element = boost::make_shared<NullParserElement>(); +std::shared_ptr<NullParserElement> NullParserElement::element = std::make_shared<NullParserElement>(); } diff --git a/Swiften/Parser/Tree/NullParserElement.h b/Swiften/Parser/Tree/NullParserElement.h index 60d8353..320e098 100644 --- a/Swiften/Parser/Tree/NullParserElement.h +++ b/Swiften/Parser/Tree/NullParserElement.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,16 +7,17 @@ #pragma once #include <string> + #include <Swiften/Base/API.h> #include <Swiften/Parser/Tree/ParserElement.h> namespace Swift { - class SWIFTEN_API NullParserElement : public ParserElement { - public: - NullParserElement() : ParserElement("", "", AttributeMap()) {} + class SWIFTEN_API NullParserElement : public ParserElement { + public: + NullParserElement() : ParserElement("", "", AttributeMap()) {} - virtual operator bool() { return false; } + virtual operator bool() { return false; } - static boost::shared_ptr<NullParserElement> element; - }; + static std::shared_ptr<NullParserElement> element; + }; } diff --git a/Swiften/Parser/Tree/ParserElement.cpp b/Swiften/Parser/Tree/ParserElement.cpp index 392029b..5415945 100644 --- a/Swiften/Parser/Tree/ParserElement.cpp +++ b/Swiften/Parser/Tree/ParserElement.cpp @@ -1,16 +1,16 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/ParserElement.h> -#include <Swiften/Parser/Tree/NullParserElement.h> -#include <iostream> -#include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> +#include <boost/lambda/lambda.hpp> + +#include <Swiften/Parser/Tree/NullParserElement.h> namespace lambda = boost::lambda; @@ -23,26 +23,26 @@ ParserElement::~ParserElement() { } ParserElement::ref ParserElement::addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes) { - ParserElement::ref child = boost::make_shared<ParserElement>(name, xmlns, attributes); - children_.push_back(child); - return child; + ParserElement::ref child = std::make_shared<ParserElement>(name, xmlns, attributes); + children_.push_back(child); + return child; } void ParserElement::appendCharacterData(const std::string& data) { - text_ += data; + text_ += data; } std::vector<ParserElement::ref> ParserElement::getChildren(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> result; - std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), - lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns); - return result; + std::vector<ParserElement::ref> result; + std::remove_copy_if(children_.begin(), children_.end(), std::back_inserter(result), + lambda::bind(&ParserElement::getName, *lambda::_1) != name || lambda::bind(&ParserElement::getNamespace, *lambda::_1) != xmlns); + return result; } ParserElement::ref ParserElement::getChild(const std::string& name, const std::string& xmlns) const { - std::vector<ParserElement::ref> results = getChildren(name, xmlns); - ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; - return result; + std::vector<ParserElement::ref> results = getChildren(name, xmlns); + ParserElement::ref result = results.empty() ? NullParserElement::element : results[0]; + return result; } } diff --git a/Swiften/Parser/Tree/ParserElement.h b/Swiften/Parser/Tree/ParserElement.h index 07cc153..38f2dee 100644 --- a/Swiften/Parser/Tree/ParserElement.h +++ b/Swiften/Parser/Tree/ParserElement.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,43 +7,44 @@ #pragma once +#include <memory> #include <string> #include <vector> + +#include <boost/signals2.hpp> + #include <Swiften/Base/API.h> -#include <Swiften/Base/boost_bsignals.h> #include <Swiften/Parser/AttributeMap.h> -#include <boost/shared_ptr.hpp> -#include <boost/smart_ptr/make_shared.hpp> namespace Swift { - class SWIFTEN_API ParserElement { - public: - typedef boost::shared_ptr<ParserElement> ref; - - ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - virtual ~ParserElement(); - - const std::string& getText() const { return text_; } - const std::string& getName() const { return name_; } - const std::string& getNamespace() const { return xmlns_; } - const AttributeMap& getAttributes() const { return attributes_; } - - ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); - void appendCharacterData(const std::string& data); - - std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; - const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} - ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; - - virtual operator bool() { - return true; - } - - private: - std::vector<ParserElement::ref> children_; - std::string name_; - std::string xmlns_; - AttributeMap attributes_; - std::string text_; - }; + class SWIFTEN_API ParserElement { + public: + typedef std::shared_ptr<ParserElement> ref; + + ParserElement(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + virtual ~ParserElement(); + + const std::string& getText() const { return text_; } + const std::string& getName() const { return name_; } + const std::string& getNamespace() const { return xmlns_; } + const AttributeMap& getAttributes() const { return attributes_; } + + ParserElement::ref addChild(const std::string& name, const std::string& xmlns, const AttributeMap& attributes); + void appendCharacterData(const std::string& data); + + std::vector<ParserElement::ref> getChildren(const std::string& name, const std::string& xmlns) const; + const std::vector<ParserElement::ref>& getAllChildren() const {return children_;} + ParserElement::ref getChild(const std::string& name, const std::string& xmlns) const; + + virtual operator bool() { + return true; + } + + private: + std::vector<ParserElement::ref> children_; + std::string name_; + std::string xmlns_; + AttributeMap attributes_; + std::string text_; + }; } diff --git a/Swiften/Parser/Tree/TreeReparser.cpp b/Swiften/Parser/Tree/TreeReparser.cpp index ac3ad0e..6993d73 100644 --- a/Swiften/Parser/Tree/TreeReparser.cpp +++ b/Swiften/Parser/Tree/TreeReparser.cpp @@ -1,48 +1,48 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/Parser/Tree/TreeReparser.h> -#include <boost/lexical_cast.hpp> -#include <utility> #include <deque> +#include <utility> + +#include <boost/lexical_cast.hpp> -#include <Swiften/Parser/PayloadParserFactoryCollection.h> -#include <Swiften/Parser/PayloadParserFactory.h> -#include <Swiften/Parser/PayloadParser.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Elements/MUCOccupant.h> +#include <Swiften/Parser/PayloadParser.h> +#include <Swiften/Parser/PayloadParserFactory.h> +#include <Swiften/Parser/PayloadParserFactoryCollection.h> namespace Swift { typedef std::pair<ParserElement::ref, bool> ElementState; -boost::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { - PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); - std::deque<ElementState > stack; - stack.push_back(ElementState(root, true)); - while (!stack.empty()) { - ElementState current = stack.back(); - stack.pop_back(); - if (current.second) { - stack.push_back(ElementState(current.first, false)); - parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); - foreach(ParserElement::ref child, current.first->getAllChildren()) { - stack.push_back(ElementState(child, true)); - } - } else { - parser->handleCharacterData(current.first->getText()); - parser->handleEndElement(current.first->getName(), current.first->getNamespace()); - } - - } - - boost::shared_ptr<Payload> payload = parser->getPayload(); - delete parser; - return payload; +std::shared_ptr<Payload> TreeReparser::parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection) { + PayloadParser* parser = collection->getPayloadParserFactory(root->getName(), root->getNamespace(), root->getAttributes())->createPayloadParser(); + std::deque<ElementState > stack; + stack.push_back(ElementState(root, true)); + while (!stack.empty()) { + ElementState current = stack.back(); + stack.pop_back(); + if (current.second) { + stack.push_back(ElementState(current.first, false)); + parser->handleStartElement(current.first->getName(), current.first->getNamespace(), current.first->getAttributes()); + for (const auto& child : current.first->getAllChildren()) { + stack.push_back(ElementState(child, true)); + } + } else { + parser->handleCharacterData(current.first->getText()); + parser->handleEndElement(current.first->getName(), current.first->getNamespace()); + } + + } + + std::shared_ptr<Payload> payload = parser->getPayload(); + delete parser; + return payload; } } diff --git a/Swiften/Parser/Tree/TreeReparser.h b/Swiften/Parser/Tree/TreeReparser.h index 80a326b..435922b 100644 --- a/Swiften/Parser/Tree/TreeReparser.h +++ b/Swiften/Parser/Tree/TreeReparser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -11,10 +11,10 @@ #include <Swiften/Parser/PayloadParsers/MUCItemParser.h> namespace Swift { - class PayloadParserFactoryCollection; - class SWIFTEN_API TreeReparser { - public: - static boost::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); + class PayloadParserFactoryCollection; + class SWIFTEN_API TreeReparser { + public: + static std::shared_ptr<Payload> parseTree(ParserElement::ref root, PayloadParserFactoryCollection* collection); - }; + }; } |