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

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