summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/FormSerializer.cpp')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FormSerializer.cpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
index cc6339c..9a05431 100644
--- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp
@@ -7,11 +7,9 @@
#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
#include <iostream>
+#include <memory>
#include <string>
-#include <boost/shared_ptr.hpp>
-#include <boost/smart_ptr/make_shared.hpp>
-
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/String.h>
#include <Swiften/Base/foreach.h>
@@ -21,10 +19,10 @@
using namespace Swift;
namespace {
- template<typename T> void serializeValueAsString(boost::shared_ptr<FormField> field, boost::shared_ptr<XMLElement> parent) {
- std::string value = boost::dynamic_pointer_cast<T>(field)->getValue();
+ template<typename T> void serializeValueAsString(std::shared_ptr<FormField> field, std::shared_ptr<XMLElement> parent) {
+ std::string value = std::dynamic_pointer_cast<T>(field)->getValue();
if (!value.empty()) {
- boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
+ std::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
valueElement->addNode(XMLTextNode::create(value));
parent->addNode(valueElement);
}
@@ -35,12 +33,12 @@ namespace Swift {
FormSerializer::FormSerializer() : GenericPayloadSerializer<Form>() {}
-std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) const {
+std::string FormSerializer::serializePayload(std::shared_ptr<Form> form) const {
if (!form) {
return "";
}
- boost::shared_ptr<XMLElement> formElement(new XMLElement("x", "jabber:x:data"));
+ std::shared_ptr<XMLElement> formElement(new XMLElement("x", "jabber:x:data"));
std::string type;
switch (form->getType()) {
case Form::FormType: type = "form"; break;
@@ -55,14 +53,14 @@ std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) cons
if (!form->getInstructions().empty()) {
multiLineify(form->getInstructions(), "instructions", formElement);
}
- foreach(boost::shared_ptr<FormPage> page, form->getPages()) {
+ foreach(std::shared_ptr<FormPage> page, form->getPages()) {
formElement->addNode(pageToXML(page));
}
- foreach(boost::shared_ptr<FormField> field, form->getFields()) {
+ foreach(std::shared_ptr<FormField> field, form->getFields()) {
formElement->addNode(fieldToXML(field, true));
}
if (!form->getReportedFields().empty()) {
- boost::shared_ptr<XMLElement> reportedElement(new XMLElement("reported"));
+ std::shared_ptr<XMLElement> reportedElement(new XMLElement("reported"));
foreach(FormField::ref field, form->getReportedFields()) {
reportedElement->addNode(fieldToXML(field, true));
}
@@ -70,7 +68,7 @@ std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) cons
}
foreach(Form::FormItem item, form->getItems()) {
- boost::shared_ptr<XMLElement> itemElement(new XMLElement("item"));
+ std::shared_ptr<XMLElement> itemElement(new XMLElement("item"));
foreach(FormField::ref field, item) {
itemElement->addNode(fieldToXML(field, false));
}
@@ -81,27 +79,27 @@ std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) cons
formElement->addNode(textToXML(text));
}
- foreach (boost::shared_ptr<FormField> field, fields_) {
+ foreach (std::shared_ptr<FormField> field, fields_) {
formElement->addNode(fieldToXML(field,true));
}
return formElement->serialize();
}
-boost::shared_ptr<XMLElement> FormSerializer::textToXML(boost::shared_ptr<FormText> text) const {
- boost::shared_ptr<XMLElement> textElement (new XMLElement("text"));
- textElement->addNode(boost::make_shared<XMLTextNode>(text->getTextString()));
+std::shared_ptr<XMLElement> FormSerializer::textToXML(std::shared_ptr<FormText> text) const {
+ std::shared_ptr<XMLElement> textElement (new XMLElement("text"));
+ textElement->addNode(std::make_shared<XMLTextNode>(text->getTextString()));
return textElement;
}
-boost::shared_ptr<XMLElement> FormSerializer::fieldRefToXML(const std::string& ref) const {
- boost::shared_ptr<XMLElement> fieldRefElement(new XMLElement("fieldref"));
+std::shared_ptr<XMLElement> FormSerializer::fieldRefToXML(const std::string& ref) const {
+ std::shared_ptr<XMLElement> fieldRefElement(new XMLElement("fieldref"));
fieldRefElement->setAttribute("var", ref);
return fieldRefElement;
}
-boost::shared_ptr<XMLElement> FormSerializer::pageToXML(boost::shared_ptr<FormPage> page) const {
- boost::shared_ptr<XMLElement> pageElement(new XMLElement("page"));
+std::shared_ptr<XMLElement> FormSerializer::pageToXML(std::shared_ptr<FormPage> page) const {
+ std::shared_ptr<XMLElement> pageElement(new XMLElement("page"));
pageElement->setAttribute("xmlns", "http://jabber.org/protocol/xdata-layout");
if (!page->getLabel().empty()) {
pageElement->setAttribute("label", page->getLabel());
@@ -109,12 +107,12 @@ boost::shared_ptr<XMLElement> FormSerializer::pageToXML(boost::shared_ptr<FormPa
foreach(const FormText::text text, page->getTextElements()) {
pageElement->addNode(textToXML(text));
}
- foreach (const boost::shared_ptr<FormField> field, page->getFields()) {
+ foreach (const std::shared_ptr<FormField> field, page->getFields()) {
pageElement->addNode(fieldRefToXML(field->getName()));
fields_.push_back(field);
}
foreach(const FormReportedRef::ref reportedRef, page->getReportedRefs()) {
- pageElement->addNode(boost::make_shared<XMLElement>("reportedref"));
+ pageElement->addNode(std::make_shared<XMLElement>("reportedref"));
}
foreach(const FormSection::section section, page->getChildSections()) {
pageElement->addNode(sectionToXML(section));
@@ -122,20 +120,20 @@ boost::shared_ptr<XMLElement> FormSerializer::pageToXML(boost::shared_ptr<FormPa
return pageElement;
}
-boost::shared_ptr<XMLElement> FormSerializer::sectionToXML(boost::shared_ptr<FormSection> section) const {
- boost::shared_ptr<XMLElement> sectionElement(new XMLElement("section"));
+std::shared_ptr<XMLElement> FormSerializer::sectionToXML(std::shared_ptr<FormSection> section) const {
+ std::shared_ptr<XMLElement> sectionElement(new XMLElement("section"));
if (!section->getLabel().empty()) {
sectionElement->setAttribute("label", section->getLabel());
}
foreach(const FormText::text text, section->getTextElements()) {
sectionElement->addNode(textToXML(text));
}
- foreach(const boost::shared_ptr<FormField> field, section->getFields()) {
+ foreach(const std::shared_ptr<FormField> field, section->getFields()) {
sectionElement->addNode(fieldRefToXML(field->getName()));
fields_.push_back(field);
}
foreach(const FormReportedRef::ref reportedRef, section->getReportedRefs()) {
- sectionElement->addNode(boost::make_shared<XMLElement>("reportedref"));
+ sectionElement->addNode(std::make_shared<XMLElement>("reportedref"));
}
foreach(const FormSection::section childSection, section->getChildSections()) {
sectionElement->addNode(sectionToXML(childSection));
@@ -143,8 +141,8 @@ boost::shared_ptr<XMLElement> FormSerializer::sectionToXML(boost::shared_ptr<For
return sectionElement;
}
-boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormField> field, bool withTypeAttribute) const {
- boost::shared_ptr<XMLElement> fieldElement(new XMLElement("field"));
+std::shared_ptr<XMLElement> FormSerializer::fieldToXML(std::shared_ptr<FormField> field, bool withTypeAttribute) const {
+ std::shared_ptr<XMLElement> fieldElement(new XMLElement("field"));
if (!field->getName().empty()) {
fieldElement->setAttribute("var", field->getName());
}
@@ -152,11 +150,11 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
fieldElement->setAttribute("label", field->getLabel());
}
if (field->getRequired()) {
- fieldElement->addNode(boost::make_shared<XMLElement>("required"));
+ fieldElement->addNode(std::make_shared<XMLElement>("required"));
}
if (!field->getDescription().empty()) {
- boost::shared_ptr<XMLElement> descriptionElement(new XMLElement("desc"));
- descriptionElement->addNode(boost::make_shared<XMLTextNode>(field->getDescription()));
+ std::shared_ptr<XMLElement> descriptionElement(new XMLElement("desc"));
+ descriptionElement->addNode(std::make_shared<XMLTextNode>(field->getDescription()));
fieldElement->addNode(descriptionElement);
}
@@ -179,18 +177,18 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
fieldElement->setAttribute("type", fieldType);
}
foreach (const std::string& value, field->getValues()) {
- boost::shared_ptr<XMLElement> valueElement = boost::make_shared<XMLElement>("value");
- valueElement->addNode(boost::make_shared<XMLTextNode>(value));
+ std::shared_ptr<XMLElement> valueElement = std::make_shared<XMLElement>("value");
+ valueElement->addNode(std::make_shared<XMLTextNode>(value));
fieldElement->addNode(valueElement);
}
foreach (const FormField::Option& option, field->getOptions()) {
- boost::shared_ptr<XMLElement> optionElement(new XMLElement("option"));
+ std::shared_ptr<XMLElement> optionElement(new XMLElement("option"));
if (!option.label.empty()) {
optionElement->setAttribute("label", option.label);
}
- boost::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
+ std::shared_ptr<XMLElement> valueElement(new XMLElement("value"));
valueElement->addNode(XMLTextNode::create(option.value));
optionElement->addNode(valueElement);
fieldElement->addNode(optionElement);
@@ -198,13 +196,13 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF
return fieldElement;
}
-void FormSerializer::multiLineify(const std::string& text, const std::string& elementName, boost::shared_ptr<XMLElement> element) const {
+void FormSerializer::multiLineify(const std::string& text, const std::string& elementName, std::shared_ptr<XMLElement> element) const {
std::string unRdText(text);
erase(unRdText, '\r');
std::vector<std::string> lines = String::split(unRdText, '\n');
foreach (std::string line, lines) {
- boost::shared_ptr<XMLElement> lineElement(new XMLElement(elementName));
- lineElement->addNode(boost::make_shared<XMLTextNode>(line));
+ std::shared_ptr<XMLElement> lineElement(new XMLElement(elementName));
+ lineElement->addNode(std::make_shared<XMLTextNode>(line));
element->addNode(lineElement);
}
}