Updated Changelog
[centerim/davrieb.git] / libicq2000 / libicq2000 / ContactList.h
bloba35da6191204301cb787353bb8bc5e332775e5e9
1 /*
2 * ContactList (model)
4 * Copyright (C) 2001 Barnaby Gray <barnaby@beedesign.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef CONTACTLIST_H
23 #define CONTACTLIST_H
25 #include <string>
26 #include <map>
28 #include <libicq2000/Contact.h>
29 #include <libicq2000/sigslot.h>
31 namespace ICQ2000 {
33 class ContactListEvent;
35 class _ContactList_iterator {
36 private:
37 std::map<unsigned int,ContactRef>::iterator iter;
39 public:
40 _ContactList_iterator(std::map<unsigned int,ContactRef>::iterator i)
41 : iter(i) { }
43 _ContactList_iterator& operator++() { ++iter; return *this; }
44 _ContactList_iterator operator++(int) { return _ContactList_iterator(iter++); }
45 bool operator==(const _ContactList_iterator& x) const { return iter == x.iter; }
46 bool operator!=(const _ContactList_iterator& x) const { return iter != x.iter; }
47 ContactRef& operator*() { return (*iter).second; }
50 class _ContactList_const_iterator {
51 private:
52 std::map<unsigned int,ContactRef>::const_iterator iter;
54 public:
55 _ContactList_const_iterator(std::map<unsigned int,ContactRef>::const_iterator i)
56 : iter(i) { }
58 _ContactList_const_iterator& operator++() { ++iter; return *this; }
59 _ContactList_const_iterator operator++(int) { return _ContactList_const_iterator(iter++); }
60 bool operator==(const _ContactList_const_iterator& x) const { return iter == x.iter; }
61 bool operator!=(const _ContactList_const_iterator& x) const { return iter != x.iter; }
62 const ContactRef& operator*() { return (*iter).second; }
65 class ContactList {
66 private:
67 std::map<unsigned int,ContactRef> m_cmap;
70 * Mobile contacts are implemented as
71 * Contact's and should still have UINs.
72 * Purely Mobile contacts will have imaginary UINs
73 * (ones counting down from -1), this is the best I could
74 * do to keep this consistent across board.
76 * It would be nice to have a hash off mobile# to contact
77 * but this was proving tricky to ensure consistency.
81 public:
82 typedef _ContactList_iterator iterator;
83 typedef _ContactList_const_iterator const_iterator;
85 ContactList();
86 ContactList(const ContactList& cl);
87 ContactList(ContactRef ct);
89 ContactRef operator[](unsigned int uin);
90 ContactRef lookup_uin(unsigned int uin);
91 ContactRef lookup_mobile(const std::string& m);
92 ContactRef lookup_email(const std::string& em);
93 ContactRef add(ContactRef ct);
94 void remove(unsigned int uin);
96 unsigned int size() const;
97 bool empty() const;
99 bool exists(unsigned int uin);
100 bool mobile_exists(const std::string& m);
101 bool email_exists(const std::string& em);
103 iterator begin();
104 iterator end();
105 const_iterator begin() const;
106 const_iterator end() const;
111 #endif