• Main Page
  • Classes
  • Files
  • File List

Swiften/Avatars/AvatarMemoryStorage.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
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 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1