From 6af3eb5576ae8475bcb1d545a563dcf059f9366f Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Tue, 20 Mar 2012 18:51:37 +0100 Subject: Serializer cleanup. More make_shared usage. diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index 2676a02..6c6201b 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -18,61 +18,39 @@ namespace Swift { -boost::shared_ptr createTextElement(const std::string& elementName, const std::string& text) { - boost::shared_ptr element = boost::make_shared(elementName); - element->addNode(boost::make_shared(text)); - return element; -} - VCardSerializer::VCardSerializer() : GenericPayloadSerializer() { } std::string VCardSerializer::serializePayload(boost::shared_ptr vcard) const { XMLElement queryElement("vCard", "vcard-temp"); if (!vcard->getVersion().empty()) { - boost::shared_ptr versionElement(new XMLElement("VERSION")); - versionElement->addNode(boost::make_shared(vcard->getVersion())); - queryElement.addNode(versionElement); + queryElement.addNode(boost::make_shared("VERSION", "", vcard->getVersion())); } if (!vcard->getFullName().empty()) { - boost::shared_ptr fullNameElement(new XMLElement("FN")); - fullNameElement->addNode(boost::make_shared(vcard->getFullName())); - queryElement.addNode(fullNameElement); + queryElement.addNode(boost::make_shared("FN", "", vcard->getFullName())); } if (!vcard->getGivenName().empty() || !vcard->getFamilyName().empty() || !vcard->getMiddleName().empty() || !vcard->getPrefix().empty() || !vcard->getSuffix().empty()) { boost::shared_ptr nameElement(new XMLElement("N")); if (!vcard->getFamilyName().empty()) { - boost::shared_ptr familyNameElement(new XMLElement("FAMILY")); - familyNameElement->addNode(boost::make_shared(vcard->getFamilyName())); - nameElement->addNode(familyNameElement); + nameElement->addNode(boost::make_shared("FAMILY", "", vcard->getFamilyName())); } if (!vcard->getGivenName().empty()) { - boost::shared_ptr givenNameElement(new XMLElement("GIVEN")); - givenNameElement->addNode(boost::make_shared(vcard->getGivenName())); - nameElement->addNode(givenNameElement); + nameElement->addNode(boost::make_shared("GIVEN", "", vcard->getGivenName())); } if (!vcard->getMiddleName().empty()) { - boost::shared_ptr middleNameElement(new XMLElement("MIDDLE")); - middleNameElement->addNode(boost::make_shared(vcard->getMiddleName())); - nameElement->addNode(middleNameElement); + nameElement->addNode(boost::make_shared("MIDDLE", "", vcard->getMiddleName())); } if (!vcard->getPrefix().empty()) { - boost::shared_ptr prefixElement(new XMLElement("PREFIX")); - prefixElement->addNode(boost::make_shared(vcard->getPrefix())); - nameElement->addNode(prefixElement); + nameElement->addNode(boost::make_shared("PREFIX", "", vcard->getPrefix())); } if (!vcard->getSuffix().empty()) { - boost::shared_ptr suffixElement(new XMLElement("SUFFIX")); - suffixElement->addNode(boost::make_shared(vcard->getSuffix())); - nameElement->addNode(suffixElement); + nameElement->addNode(boost::make_shared("SUFFIX", "", vcard->getSuffix())); } queryElement.addNode(nameElement); } foreach(const VCard::EMailAddress& emailAddress, vcard->getEMailAddresses()) { boost::shared_ptr emailElement(new XMLElement("EMAIL")); - boost::shared_ptr userIDElement(new XMLElement("USERID")); - userIDElement->addNode(boost::make_shared(emailAddress.address)); - emailElement->addNode(userIDElement); + emailElement->addNode(boost::make_shared("USERID", "", emailAddress.address)); if (emailAddress.isHome) { emailElement->addNode(boost::make_shared("HOME")); } @@ -91,99 +69,89 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr vcard) c queryElement.addNode(emailElement); } if (!vcard->getNickname().empty()) { - boost::shared_ptr nickElement(new XMLElement("NICKNAME")); - nickElement->addNode(boost::make_shared(vcard->getNickname())); - queryElement.addNode(nickElement); + queryElement.addNode(boost::make_shared("NICKNAME", "", vcard->getNickname())); } if (!vcard->getPhoto().empty() || !vcard->getPhotoType().empty()) { XMLElement::ref photoElement(new XMLElement("PHOTO")); if (!vcard->getPhotoType().empty()) { - XMLElement::ref typeElement(new XMLElement("TYPE")); - typeElement->addNode(XMLTextNode::ref(new XMLTextNode(vcard->getPhotoType()))); - photoElement->addNode(typeElement); + photoElement->addNode(boost::make_shared("TYPE", "", vcard->getPhotoType())); } if (!vcard->getPhoto().empty()) { - XMLElement::ref binvalElement(new XMLElement("BINVAL")); - binvalElement->addNode(XMLTextNode::ref(new XMLTextNode(Base64::encode(vcard->getPhoto())))); - photoElement->addNode(binvalElement); + photoElement->addNode(boost::make_shared("BINVAL", "", Base64::encode(vcard->getPhoto()))); } queryElement.addNode(photoElement); } if (!vcard->getBirthday().is_not_a_date_time()) { - XMLElement::ref bdayElement(new XMLElement("BDAY")); - bdayElement->addNode(boost::shared_ptr(new XMLTextNode(dateTimeToString(vcard->getBirthday())))); - queryElement.addNode(bdayElement); + queryElement.addNode(boost::make_shared("BDAY", "", dateTimeToString(vcard->getBirthday()))); } foreach(const VCard::Telephone& telephone, vcard->getTelephones()) { boost::shared_ptr telElement(new XMLElement("TEL")); - boost::shared_ptr numberElement(new XMLElement("NUMBER")); - numberElement->addNode(boost::shared_ptr(new XMLTextNode(telephone.number))); - telElement->addNode(numberElement); + telElement->addNode(boost::make_shared("NUMBER", "", telephone.number)); if (telephone.isHome) { - telElement->addNode(boost::shared_ptr(new XMLElement("HOME"))); + telElement->addNode(boost::make_shared("HOME")); } if (telephone.isWork) { - telElement->addNode(boost::shared_ptr(new XMLElement("WORK"))); + telElement->addNode(boost::make_shared("WORK")); } if (telephone.isVoice) { - telElement->addNode(boost::shared_ptr(new XMLElement("VOICE"))); + telElement->addNode(boost::make_shared("VOICE")); } if (telephone.isFax) { - telElement->addNode(boost::shared_ptr(new XMLElement("FAX"))); + telElement->addNode(boost::make_shared("FAX")); } if (telephone.isPager) { - telElement->addNode(boost::shared_ptr(new XMLElement("PAGER"))); + telElement->addNode(boost::make_shared("PAGER")); } if (telephone.isMSG) { - telElement->addNode(boost::shared_ptr(new XMLElement("MSG"))); + telElement->addNode(boost::make_shared("MSG")); } if (telephone.isCell) { - telElement->addNode(boost::shared_ptr(new XMLElement("CELL"))); + telElement->addNode(boost::make_shared("CELL")); } if (telephone.isVideo) { - telElement->addNode(boost::shared_ptr(new XMLElement("VIDEO"))); + telElement->addNode(boost::make_shared("VIDEO")); } if (telephone.isBBS) { - telElement->addNode(boost::shared_ptr(new XMLElement("BBS"))); + telElement->addNode(boost::make_shared("BBS")); } if (telephone.isModem) { - telElement->addNode(boost::shared_ptr(new XMLElement("MODEM"))); + telElement->addNode(boost::make_shared("MODEM")); } if (telephone.isISDN) { - telElement->addNode(boost::shared_ptr(new XMLElement("ISDN"))); + telElement->addNode(boost::make_shared("ISDN")); } if (telephone.isPCS) { - telElement->addNode(boost::shared_ptr(new XMLElement("PCS"))); + telElement->addNode(boost::make_shared("PCS")); } if (telephone.isPreferred) { - telElement->addNode(boost::shared_ptr(new XMLElement("PREF"))); + telElement->addNode(boost::make_shared("PREF")); } queryElement.addNode(telElement); } foreach(const VCard::Address& address, vcard->getAddresses()) { - boost::shared_ptr adrElement(new XMLElement("ADR")); + boost::shared_ptr adrElement = boost::make_shared("ADR"); if (!address.POBox.empty()) { - adrElement->addNode(createTextElement("POBOX", address.POBox)); + adrElement->addNode(boost::make_shared("POBOX", "", address.POBox)); } if (!address.addressExtension.empty()) { - adrElement->addNode(createTextElement("EXTADD", address.addressExtension)); + adrElement->addNode(boost::make_shared("EXTADD", "", address.addressExtension)); } if (!address.street.empty()) { - adrElement->addNode(createTextElement("STREET", address.street)); + adrElement->addNode(boost::make_shared("STREET", "", address.street)); } if (!address.locality.empty()) { - adrElement->addNode(createTextElement("LOCALITY", address.locality)); + adrElement->addNode(boost::make_shared("LOCALITY", "", address.locality)); } if (!address.region.empty()) { - adrElement->addNode(createTextElement("REGION", address.region)); + adrElement->addNode(boost::make_shared("REGION", "", address.region)); } if (!address.postalCode.empty()) { - adrElement->addNode(createTextElement("PCODE", address.postalCode)); + adrElement->addNode(boost::make_shared("PCODE", "", address.postalCode)); } if (!address.country.empty()) { - adrElement->addNode(createTextElement("CTRY", address.country)); + adrElement->addNode(boost::make_shared("CTRY", "", address.country)); } if (address.isHome) { @@ -211,10 +179,10 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr vcard) c } foreach(const VCard::AddressLabel& addressLabel, vcard->getAddressLabels()) { - boost::shared_ptr labelElement(new XMLElement("LABEL")); + boost::shared_ptr labelElement = boost::make_shared("LABEL"); foreach(const std::string& line, addressLabel.lines) { - labelElement->addNode(createTextElement("LINE", line)); + labelElement->addNode(boost::make_shared("LINE", "", line)); } if (addressLabel.isHome) { @@ -242,36 +210,36 @@ std::string VCardSerializer::serializePayload(boost::shared_ptr vcard) c } foreach(const JID& jid, vcard->getJIDs()) { - queryElement.addNode(createTextElement("JID", jid.toString())); + queryElement.addNode(boost::make_shared("JID", "", jid.toString())); } if (!vcard->getDescription().empty()) { - queryElement.addNode(createTextElement("DESC", vcard->getDescription())); + queryElement.addNode(boost::make_shared("DESC", "", vcard->getDescription())); } foreach(const VCard::Organization& org, vcard->getOrganizations()) { - boost::shared_ptr orgElement(new XMLElement("ORG")); + boost::shared_ptr orgElement = boost::make_shared("ORG"); if (!org.name.empty()) { - orgElement->addNode(createTextElement("ORGNAME", org.name)); + orgElement->addNode(boost::make_shared("ORGNAME", "", org.name)); } if (!org.units.empty()) { foreach(const std::string& unit, org.units) { - orgElement->addNode(createTextElement("ORGUNIT", unit)); + orgElement->addNode(boost::make_shared("ORGUNIT", "", unit)); } } queryElement.addNode(orgElement); } foreach(const std::string& title, vcard->getTitles()) { - queryElement.addNode(createTextElement("TITLE", title)); + queryElement.addNode(boost::make_shared("TITLE", "", title)); } foreach(const std::string& role, vcard->getRoles()) { - queryElement.addNode(createTextElement("ROLE", role)); + queryElement.addNode(boost::make_shared("ROLE", "", role)); } foreach(const std::string& url, vcard->getURLs()) { - queryElement.addNode(createTextElement("URL", url)); + queryElement.addNode(boost::make_shared("URL", "", url)); } if (!vcard->getUnknownContent().empty()) { -- cgit v0.10.2-6-g49f6