00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <map>
00010 #include <string>
00011
00012 #include <Swiften/Base/ByteArray.h>
00013 #include <Swiften/Avatars/AvatarStorage.h>
00014 #include <Swiften/JID/JID.h>
00015
00016 namespace Swift {
00017 class AvatarMemoryStorage : public AvatarStorage {
00018 public:
00019 virtual bool hasAvatar(const std::string& hash) const { return avatars.find(hash) != avatars.end(); }
00020 virtual void addAvatar(const std::string& hash, const ByteArray& avatar) { avatars[hash] = avatar; }
00021 virtual ByteArray getAvatar(const std::string& hash) const {
00022 std::map<std::string, ByteArray>::const_iterator i = avatars.find(hash);
00023 return i == avatars.end() ? ByteArray() : i->second;
00024 }
00025
00026 virtual boost::filesystem::path getAvatarPath(const std::string& hash) const {
00027 return boost::filesystem::path("/avatars") / hash;
00028 }
00029
00030 virtual void setAvatarForJID(const JID& jid, const std::string& hash) {
00031 jidAvatars[jid] = hash;
00032 }
00033
00034 virtual std::string getAvatarForJID(const JID& jid) const {
00035 std::map<JID, std::string>::const_iterator i = jidAvatars.find(jid);
00036 return i == jidAvatars.end() ? "" : i->second;
00037 }
00038
00039 private:
00040 std::map<std::string, ByteArray> avatars;
00041 std::map<JID, std::string> jidAvatars;
00042 };
00043 }