Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

RequestIDCache.h

00001 /*
00002  * RequestIDCache
00003  *
00004  * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef REQUESTIDCACHE_H
00023 #define REQUESTIDCACHE_H
00024 
00025 #include <libicq2000/Cache.h>
00026 
00027 #include <sigc++/signal_system.h>
00028 
00029 namespace ICQ2000 {
00030 
00031   class RequestIDCacheValue {
00032    public:
00033     enum Type {
00034       UserInfo,
00035       SMSMessage,
00036       Search
00037     };
00038 
00039     virtual ~RequestIDCacheValue() { }
00040 
00041     virtual Type getType() const = 0;
00042   };
00043 
00044   class UserInfoCacheValue : public RequestIDCacheValue {
00045    private:
00046     ContactRef m_contact;
00047 
00048    public:
00049     UserInfoCacheValue(ContactRef c) : m_contact(c) { }
00050     unsigned int getUIN() const { return m_contact->getUIN(); }
00051     ContactRef getContact() const { return m_contact; }
00052 
00053     Type getType() const { return UserInfo; }
00054   };
00055 
00056   class SMSEventCacheValue : public RequestIDCacheValue {
00057    private:
00058     SMSMessageEvent *m_ev;
00059 
00060    public:
00061     SMSEventCacheValue( SMSMessageEvent *ev ) : m_ev(ev) { }
00062     virtual ~SMSEventCacheValue() { delete m_ev; }
00063     SMSMessageEvent* getEvent() const { return m_ev; }
00064     ContactRef getContact() const { return m_ev->getContact(); }
00065 
00066     Type getType() const { return SMSMessage; }
00067   };
00068 
00069   class SearchCacheValue : public RequestIDCacheValue {
00070    private:
00071     SearchResultEvent *m_ev;
00072 
00073    public:
00074     SearchCacheValue( SearchResultEvent *ev ) : m_ev(ev) { }
00075     SearchResultEvent* getEvent() const { return m_ev; }
00076     Type getType() const { return Search; }
00077   };
00078 
00079   class RequestIDCache : public Cache<unsigned int, RequestIDCacheValue*> {
00080    public:
00081     RequestIDCache() { }
00082     ~RequestIDCache()
00083     {
00084       removeAll();
00085     }
00086 
00087     SigC::Signal1<void,RequestIDCacheValue*> expired;
00088     
00089     void expireItem(const RequestIDCache::literator& l) {
00090       expired.emit( (*l).getValue() );
00091       Cache<unsigned int, RequestIDCacheValue*>::expireItem(l);
00092     }
00093 
00094     void removeItem(const RequestIDCache::literator& l) {
00095       delete ((*l).getValue());
00096       Cache<unsigned int, RequestIDCacheValue*>::removeItem(l);
00097     }
00098 
00099   };
00100   
00101 }
00102 
00103 #endif

Generated on Sun Jul 21 10:57:32 2002 for libicq2000 by doxygen1.2.16