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

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