00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <vector>
00010 #include <string>
00011 #include <boost/shared_ptr.hpp>
00012 #include <boost/optional/optional_fwd.hpp>
00013 #include <boost/date_time/posix_time/ptime.hpp>
00014
00015 #include <Swiften/Base/API.h>
00016 #include <Swiften/Elements/Element.h>
00017 #include <Swiften/JID/JID.h>
00018
00019 namespace Swift {
00020 class Payload;
00021
00022 class SWIFTEN_API Stanza : public Element {
00023 public:
00024 typedef boost::shared_ptr<Stanza> ref;
00025
00026 Stanza();
00027 virtual ~Stanza();
00028
00029 template<typename T>
00030 boost::shared_ptr<T> getPayload() const {
00031 for (size_t i = 0; i < payloads_.size(); ++i) {
00032 boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i]));
00033 if (result) {
00034 return result;
00035 }
00036 }
00037 return boost::shared_ptr<T>();
00038 }
00039
00040 template<typename T>
00041 std::vector< boost::shared_ptr<T> > getPayloads() const {
00042 std::vector< boost::shared_ptr<T> > results;
00043 for (size_t i = 0; i < payloads_.size(); ++i) {
00044 boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(payloads_[i]));
00045 if (result) {
00046 results.push_back(result);
00047 }
00048 }
00049 return results;
00050 }
00051
00052
00053 const std::vector< boost::shared_ptr<Payload> >& getPayloads() const {
00054 return payloads_;
00055 }
00056
00057 void addPayload(boost::shared_ptr<Payload> payload) {
00058 payloads_.push_back(payload);
00059 }
00060
00061 void updatePayload(boost::shared_ptr<Payload> payload);
00062
00063 boost::shared_ptr<Payload> getPayloadOfSameType(boost::shared_ptr<Payload>) const;
00064
00065 const JID& getFrom() const { return from_; }
00066 void setFrom(const JID& from) { from_ = from; }
00067
00068 const JID& getTo() const { return to_; }
00069 void setTo(const JID& to) { to_ = to; }
00070
00071 const std::string& getID() const { return id_; }
00072 void setID(const std::string& id) { id_ = id; }
00073
00074 boost::optional<boost::posix_time::ptime> getTimestamp() const;
00075
00076
00077 boost::optional<boost::posix_time::ptime> getTimestampFrom(const JID& jid) const;
00078
00079 private:
00080 std::string id_;
00081 JID from_;
00082 JID to_;
00083 std::vector< boost::shared_ptr<Payload> > payloads_;
00084 };
00085 }