/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include #include namespace Swift { Stanza::Stanza() { } Stanza::~Stanza() { payloads_.clear(); } void Stanza::updatePayload(std::shared_ptr payload) { foreach (std::shared_ptr& i, payloads_) { if (typeid(*i.get()) == typeid(*payload.get())) { i = payload; return; } } addPayload(payload); } static bool sameType(std::shared_ptr a, std::shared_ptr b) { return typeid(*a.get()) == typeid(*b.get()); } void Stanza::removePayloadOfSameType(std::shared_ptr payload) { payloads_.erase(std::remove_if(payloads_.begin(), payloads_.end(), boost::bind(&sameType, payload, _1)), payloads_.end()); } std::shared_ptr Stanza::getPayloadOfSameType(std::shared_ptr payload) const { foreach (const std::shared_ptr& i, payloads_) { if (typeid(*i.get()) == typeid(*payload.get())) { return i; } } return std::shared_ptr(); } boost::optional Stanza::getTimestamp() const { std::shared_ptr delay = getPayload(); return delay ? delay->getStamp() : boost::optional(); } boost::optional Stanza::getTimestampFrom(const JID& jid) const { std::vector< std::shared_ptr > delays = getPayloads(); for (size_t i = 0; i < delays.size(); ++i) { if (delays[i]->getFrom() == jid) { return delays[i]->getStamp(); } } return getTimestamp(); } }