From daf513a6567100322d3c51733ea0c449ca6adb1b Mon Sep 17 00:00:00 2001 From: Tim Robbings Date: Mon, 9 Mar 2015 16:11:32 +0000 Subject: Tidy XEP-0141 code This change addresses some feedback the previous XEP-0141 commit (a39d650). Test-information: Ran the CPPUnit tests, these completed successfully. Change-Id: I2caf1eb1349f7527bd9af8ce8adfb194391253e4 diff --git a/Swiften/Elements/FormPage.cpp b/Swiften/Elements/FormPage.cpp index 1a9bd32..db7979f 100644 --- a/Swiften/Elements/FormPage.cpp +++ b/Swiften/Elements/FormPage.cpp @@ -7,7 +7,7 @@ namespace Swift { -FormPage::FormPage() : xmlns_("http://jabber.org/protocol/xdata-layout") { +FormPage::FormPage() { } FormPage::~FormPage() { @@ -21,11 +21,7 @@ const std::string& FormPage::getLabel() const { return label_; } -const std::string& FormPage::getXMLNS() const { - return xmlns_; -} - -void FormPage::addChildSection(boost::shared_ptr& section) { +void FormPage::addChildSection(boost::shared_ptr section) { childSections_.push_back(section); } @@ -33,7 +29,7 @@ const std::vector >& FormPage::getChildSections() return childSections_; } -void FormPage::addTextElement(boost::shared_ptr& textElement) { +void FormPage::addTextElement(boost::shared_ptr textElement) { textElements_.push_back(textElement); } @@ -41,7 +37,7 @@ const std::vector >& FormPage::getTextElements() con return textElements_; } -void FormPage::addReportedRef(boost::shared_ptr& reportedRef) { +void FormPage::addReportedRef(boost::shared_ptr reportedRef) { reportedRefs_.push_back(reportedRef); } @@ -49,7 +45,7 @@ const std::vector >& FormPage::getReportedRef return reportedRefs_; } -void FormPage::addField(boost::shared_ptr& field) { +void FormPage::addField(boost::shared_ptr field) { fields_.push_back(field); } diff --git a/Swiften/Elements/FormPage.h b/Swiften/Elements/FormPage.h index e5ecda2..0e66549 100644 --- a/Swiften/Elements/FormPage.h +++ b/Swiften/Elements/FormPage.h @@ -23,20 +23,18 @@ namespace Swift { ~FormPage(); void setLabel(const std::string& label); const std::string& getLabel() const; - const std::string& getXMLNS() const; - void addChildSection(boost::shared_ptr& section); + void addChildSection(boost::shared_ptr section); const std::vector >& getChildSections() const; - void addTextElement(boost::shared_ptr& textElement); + void addTextElement(boost::shared_ptr textElement); const std::vector >& getTextElements() const; - void addReportedRef(boost::shared_ptr& reportedRef); + void addReportedRef(boost::shared_ptr reportedRef); const std::vector >& getReportedRefs() const; - void addField(boost::shared_ptr& field); + void addField(boost::shared_ptr field); const std::vector >& getFields() const; void addFieldRef(std::string ref); const std::vector getFieldRefs() const; private: - std::string xmlns_; std::string label_; std::vector > textElements_; std::vector > childSections_; diff --git a/Swiften/Elements/FormSection.cpp b/Swiften/Elements/FormSection.cpp index 46005a0..7b254df 100644 --- a/Swiften/Elements/FormSection.cpp +++ b/Swiften/Elements/FormSection.cpp @@ -21,7 +21,7 @@ const std::string& FormSection::getLabel() const { return label_; } -void FormSection::addTextElement(boost::shared_ptr& textElement) { +void FormSection::addTextElement(boost::shared_ptr textElement) { textElements_.push_back(textElement); } @@ -29,7 +29,7 @@ const std::vector >& FormSection::getTextElements() return textElements_; } -void FormSection::addReportedRef(boost::shared_ptr& reportedRef) { +void FormSection::addReportedRef(boost::shared_ptr reportedRef) { reportedRefs_.push_back(reportedRef); } @@ -37,7 +37,7 @@ const std::vector >& FormSection::getReported return reportedRefs_; } -void FormSection::addChildSection(boost::shared_ptr& childSection) { +void FormSection::addChildSection(boost::shared_ptr childSection) { childSections_.push_back(childSection); } @@ -45,7 +45,7 @@ const std::vector >& FormSection::getChildSection return childSections_; } -void FormSection::addField(boost::shared_ptr& field) { +void FormSection::addField(boost::shared_ptr field) { fields_.push_back(field); } diff --git a/Swiften/Elements/FormSection.h b/Swiften/Elements/FormSection.h index f799062..22af67b 100644 --- a/Swiften/Elements/FormSection.h +++ b/Swiften/Elements/FormSection.h @@ -22,13 +22,13 @@ namespace Swift { ~FormSection(); void setLabel(const std::string& label); const std::string& getLabel() const; - void addTextElement(boost::shared_ptr& textElement); + void addTextElement(boost::shared_ptr textElement); const std::vector >& getTextElements() const; - void addReportedRef(boost::shared_ptr& reportedRef); + void addReportedRef(boost::shared_ptr reportedRef); const std::vector >& getReportedRefs() const; - void addChildSection(boost::shared_ptr& childSection); + void addChildSection(boost::shared_ptr childSection); const std::vector >& getChildSections() const; - void addField(boost::shared_ptr& field); + void addField(boost::shared_ptr field); const std::vector >& getFields() const; void addFieldRef(std::string ref); const std::vector getFieldRefs() const; diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index d400c4c..bc48fcb 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -4,18 +4,17 @@ * See the COPYING file for more information. */ #include -#include #include #include +#include namespace Swift { -FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(false), parseStarted_(false), hasReportedRef_(false){ +FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(false), hasReportedRef_(false){ } void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level_ == TopLevel) { - parseStarted_ = true; std::string type = attributes.getAttribute("type"); if (type == "form") { getPayloadInternal()->setType(Form::FormType); @@ -191,15 +190,15 @@ void FormParser::handleEndElement(const std::string& element, const std::string& else { if (currentPages_.size() > 0) { foreach (boost::shared_ptr page, currentPages_) { - foreach (std::string pRef, page->getFieldRefs()) { - if (pRef == currentField_->getName()) { + foreach (std::string pageRef, page->getFieldRefs()) { + if (pageRef == currentField_->getName()) { page->addField(currentField_); } } } foreach (boost::shared_ptr section, currentSections_) { - foreach (std::string sRef, section->getFieldRefs()) { - if (sRef == currentField_->getName()) { + foreach (std::string sectionRef, section->getFieldRefs()) { + if (sectionRef == currentField_->getName()) { section->addField(currentField_); } } @@ -219,7 +218,7 @@ void FormParser::handleEndElement(const std::string& element, const std::string& sectionStack_.pop_back(); } else if (sectionStack_.size() == 1) { - // Add the remaining section on the stack to it's parent page + // Add the remaining section on the stack to its parent page currentPage_->addChildSection(sectionStack_.at(sectionStack_.size()-1)); sectionStack_.pop_back(); } diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index a3b7556..c8c2294 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -32,7 +32,6 @@ namespace Swift { bool parsingItem_; bool parsingReported_; bool parsingOption_; - bool parseStarted_; bool hasReportedRef_; FormField::ref currentField_; std::vector currentFields_; diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp index 633ead6..a4ec52e 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp @@ -101,7 +101,7 @@ boost::shared_ptr FormSerializer::fieldRefToXML(const std::string& r boost::shared_ptr FormSerializer::pageToXML(boost::shared_ptr page) const { boost::shared_ptr pageElement(new XMLElement("page")); - pageElement->setAttribute("xmlns", page->getXMLNS()); + pageElement->setAttribute("xmlns", "http://jabber.org/protocol/xdata-layout"); if (!page->getLabel().empty()) { pageElement->setAttribute("label", page->getLabel()); } -- cgit v0.10.2-6-g49f6