diff options
author | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
---|---|---|
committer | Vasudev Kamath <vasudev@copyninja.info> | 2016-10-23 21:09:40 +0530 |
commit | eda4b75b1cff83336e87da90efca9fd6b4ced2c7 (patch) | |
tree | 491317ce50b5d19bc434ccc4b448d1bc70520177 /louloulibs/xmpp/roster.hpp | |
parent | 716c40e4ec45f8d538695225f4f06d541d959084 (diff) | |
parent | 0f14fe83ef53b08bd8fa09670c82f4996c329bdc (diff) | |
download | biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.gz biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.bz2 biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.tar.xz biboumi-eda4b75b1cff83336e87da90efca9fd6b4ced2c7.zip |
New upstream version 3.0upstream/3.0
Diffstat (limited to 'louloulibs/xmpp/roster.hpp')
-rw-r--r-- | louloulibs/xmpp/roster.hpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/louloulibs/xmpp/roster.hpp b/louloulibs/xmpp/roster.hpp new file mode 100644 index 0000000..aa1b449 --- /dev/null +++ b/louloulibs/xmpp/roster.hpp @@ -0,0 +1,71 @@ +#pragma once + + +#include <algorithm> +#include <string> +#include <vector> + +class RosterItem +{ +public: + RosterItem(const std::string& jid, const std::string& name, + std::vector<std::string>& groups); + RosterItem(const std::string& jid, const std::string& name); + RosterItem() = default; + ~RosterItem() = default; + RosterItem(const RosterItem&) = default; + RosterItem(RosterItem&&) = default; + RosterItem& operator=(const RosterItem&) = default; + RosterItem& operator=(RosterItem&&) = default; + + std::string jid; + std::string name; + std::vector<std::string> groups; + +private: +}; + +/** + * Keep track of the last known stat of a JID's roster + */ +class Roster +{ +public: + Roster() = default; + ~Roster() = default; + + void clear(); + + template <typename... ArgsType> + RosterItem* add_item(ArgsType&&... args) + { + this->items.emplace_back(std::forward<ArgsType>(args)...); + auto it = this->items.end() - 1; + return &*it; + } + RosterItem* get_item(const std::string& jid) + { + auto it = std::find_if(this->items.begin(), this->items.end(), + [this, &jid](const auto& item) + { + return item.jid == jid; + }); + if (it != this->items.end()) + return &*it; + return nullptr; + } + const std::vector<RosterItem>& get_items() const + { + return this->items; + } + +private: + std::vector<RosterItem> items; + + Roster(const Roster&) = delete; + Roster(Roster&&) = delete; + Roster& operator=(const Roster&) = delete; + Roster& operator=(Roster&&) = delete; +}; + + |