Main Page   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 Type getType() const = 0;
00040   };
00041 
00042   class UserInfoCacheValue : public RequestIDCacheValue {
00043    private:
00044     Contact *m_contact;
00045 
00046    public:
00047     UserInfoCacheValue(Contact *c) : m_contact(c) { }
00048     unsigned int getUIN() const { return m_contact->getUIN(); }
00049     Contact* getContact() const { return m_contact; }
00050 
00051     Type getType() const { return UserInfo; }
00052   };
00053 
00054   class SMSEventCacheValue : public RequestIDCacheValue {
00055    private:
00056     SMSMessageEvent *m_ev;
00057 
00058    public:
00059     SMSEventCacheValue( SMSMessageEvent *ev ) : m_ev(ev) { }
00060     ~SMSEventCacheValue() { delete m_ev; }
00061     SMSMessageEvent* getEvent() const { return m_ev; }
00062     Contact* getContact() const { return m_ev->getContact(); }
00063 
00064     Type getType() const { return SMSMessage; }
00065   };
00066 
00067   class SearchCacheValue : public RequestIDCacheValue {
00068    private:
00069     SearchResultEvent *m_ev;
00070 
00071    public:
00072     SearchCacheValue( SearchResultEvent *ev ) : m_ev(ev) { }
00073     SearchResultEvent* getEvent() const { return m_ev; }
00074     Type getType() const { return Search; }
00075   };
00076 
00077   class RequestIDCache : public Cache<unsigned int, RequestIDCacheValue*> {
00078    public:
00079     RequestIDCache() { }
00080 
00081     SigC::Signal1<void,RequestIDCacheValue*> expired;
00082     
00083     void expireItem(const RequestIDCache::literator& l) {
00084       expired.emit( (*l).getValue() );
00085       Cache<unsigned int, RequestIDCacheValue*>::expireItem(l);
00086     }
00087 
00088     void removeItem(const RequestIDCache::literator& l) {
00089       delete ((*l).getValue());
00090       Cache<unsigned int, RequestIDCacheValue*>::removeItem(l);
00091     }
00092 
00093     void removeContact(Contact *c) {
00094       literator curr = m_list.begin();
00095       literator next = curr;
00096       while ( curr != m_list.end() ) {
00097         ++next;
00098         RequestIDCacheValue *cv = (*curr).getValue();
00099         if ( cv->getType() == RequestIDCacheValue::UserInfo ) {
00100           UserInfoCacheValue *ccv = static_cast<UserInfoCacheValue*>(cv);
00101           if (ccv->getContact() == c) removeItem(curr);
00102         } else if (cv->getType() == RequestIDCacheValue::SMSMessage ) {
00103           SMSEventCacheValue *ccv = static_cast<SMSEventCacheValue*>(cv);
00104           if (ccv->getContact() == c) removeItem(curr);
00105         }
00106         
00107         curr = next;
00108       }
00109     }
00110 
00111   };
00112   
00113 }
00114 
00115 #endif

Generated on Tue Jan 15 12:24:35 2002 for libicq2000 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001