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

ContactList.h

00001 /*
00002  * ContactList (model)
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 CONTACTLIST_H
00023 #define CONTACTLIST_H
00024 
00025 #include <list>
00026 #include <string>
00027 #include <map>
00028 
00029 #include <libicq2000/Contact.h>
00030 #include <sigc++/signal_system.h>
00031 
00032 using std::list;
00033 using std::string;
00034 using std::map;
00035 
00036 namespace ICQ2000 {
00037 
00038   class ContactListEvent;
00039 
00040   class _ContactList_iterator {
00041   private:
00042     map<unsigned int,ContactRef>::iterator iter;
00043   
00044   public:
00045     _ContactList_iterator(map<unsigned int,ContactRef>::iterator i)
00046       : iter(i) { }
00047   
00048     _ContactList_iterator& operator++() { ++iter; return *this; }
00049     _ContactList_iterator operator++(int) { return _ContactList_iterator(iter++); }
00050     bool operator==(const _ContactList_iterator& x) const { return iter == x.iter; }
00051     bool operator!=(const _ContactList_iterator& x) const { return iter != x.iter; }
00052     ContactRef& operator*() { return (*iter).second; }
00053   };
00054 
00055   class _ContactList_const_iterator {
00056    private:
00057     map<unsigned int,ContactRef>::const_iterator iter;
00058   
00059    public:
00060     _ContactList_const_iterator(map<unsigned int,ContactRef>::const_iterator i)
00061       : iter(i) { }
00062   
00063     _ContactList_const_iterator& operator++() { ++iter; return *this; }
00064     _ContactList_const_iterator operator++(int) { return _ContactList_const_iterator(iter++); }
00065     bool operator==(const _ContactList_const_iterator& x) const { return iter == x.iter; }
00066     bool operator!=(const _ContactList_const_iterator& x) const { return iter != x.iter; }
00067     const ContactRef& operator*() { return (*iter).second; }
00068   };
00069 
00070   class ContactList {
00071    private:
00072     map<unsigned int,ContactRef> m_cmap;
00073 
00074     /*
00075      * Mobile contacts are implemented as
00076      * Contact's and should still have UINs.
00077      * Purely Mobile contacts will have imaginary UINs
00078      * (ones counting down from -1), this is the best I could
00079      * do to keep this consistent across board.
00080      *
00081      * It would be nice to have a hash off mobile# to contact
00082      * but this was proving tricky to ensure consistency.
00083      */
00084 
00085 
00086    public:
00087     typedef _ContactList_iterator iterator;
00088     typedef _ContactList_const_iterator const_iterator;
00089 
00090     ContactList();
00091     ContactList(const ContactList& cl);
00092 
00093     ContactRef operator[](unsigned int uin);
00094     ContactRef lookup_uin(unsigned int uin);
00095     ContactRef lookup_mobile(const std::string& m);
00096     ContactRef lookup_email(const std::string& em);
00097     ContactRef add(ContactRef ct);
00098     void remove(unsigned int uin);
00099 
00100     unsigned int size() const;
00101     bool empty() const;
00102 
00103     bool exists(unsigned int uin);
00104     bool mobile_exists(const string& m);
00105     bool email_exists(const string& em);
00106 
00107     iterator begin();
00108     iterator end();
00109     const_iterator begin() const;
00110     const_iterator end() const;
00111 
00112     SigC::Signal1<void,ContactListEvent*> contactlist_signal;
00113   };
00114 
00115 }
00116 
00117 #endif

Generated on Fri Apr 26 23:48:14 2002 for libicq2000 by doxygen1.2.15