tzwrapper.cc: fixed use of iterator after erase
[barry.git] / src / r_contact.h
blobf866833ce243d153c9d1e9b1bc57c5bc04f56bf6
1 ///
2 /// \file r_contact.h
3 /// Blackberry database record parser class for contact records.
4 ///
6 /*
7 Copyright (C) 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_RECORD_CONTACT_H__
23 #define __BARRY_RECORD_CONTACT_H__
25 #include "dll.h"
26 #include "record.h"
27 #include <iosfwd>
28 #include <string>
29 #include <vector>
30 #include <map>
31 #include <stdint.h>
33 namespace Barry {
35 // forward declarations
36 class IConverter;
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 struct BXEXPORT ContactGroupLink
45 uint32_t Link;
46 uint16_t Unknown;
48 ContactGroupLink() : Link(0), Unknown(0) {}
49 ContactGroupLink(uint32_t link, uint16_t unknown)
50 : Link(link), Unknown(unknown)
54 /// \addtogroup RecordParserClasses
55 /// @{
58 // Contact record class
60 /// Represents a single record in the Address Book Blackberry database.
61 ///
62 class BXEXPORT Contact
64 public:
65 typedef Barry::CategoryList CategoryList;
66 typedef ContactGroupLink GroupLink;
67 typedef std::vector<GroupLink> GroupLinksType;
68 typedef Barry::UnknownsType UnknownsType;
69 typedef Barry::EmailType EmailType;
70 typedef Barry::EmailList EmailList;
73 // Record fields
76 // contact specific data
77 uint8_t RecType;
78 uint32_t RecordId;
79 EmailList EmailAddresses;
81 /// This field, Phone, is deprecated. It is possible
82 /// to write to this field to the Blackberry,
83 /// but modern devices won't let you add it
84 /// through their GUIs. This field only seems
85 /// to exist on the 7750. While other devices
86 /// accept the field and display it, it is
87 /// not accessible by default.
88 std::string Phone;
90 std::string
91 Fax,
92 HomeFax,
93 WorkPhone,
94 HomePhone,
95 MobilePhone,
96 MobilePhone2,
97 Pager,
98 PIN,
99 Radio,
100 WorkPhone2,
101 HomePhone2,
102 OtherPhone,
103 FirstName,
104 LastName,
105 Company,
106 DefaultCommunicationsMethod,
107 JobTitle,
108 PublicKey,
109 URL,
110 Prefix,
111 Notes,
112 UserDefined1,
113 UserDefined2,
114 UserDefined3,
115 UserDefined4,
116 Image,
117 Nickname;
119 Date Birthday;
120 Date Anniversary;
122 PostalAddress WorkAddress;
123 PostalAddress HomeAddress;
125 // Categories are not allowed to have commas in them.
126 // A category name containing a comma will be split into
127 // two categories, not only by this library, but by the
128 // device itself.
129 CategoryList Categories;
131 GroupLinksType GroupLinks;
132 UnknownsType Unknowns;
134 private:
135 bool m_FirstNameSeen;
137 public:
138 const unsigned char* ParseField(const unsigned char *begin,
139 const unsigned char *end, const IConverter *ic = 0);
141 public:
142 Contact();
143 ~Contact();
145 uint32_t GetID() const { return RecordId; }
146 std::string GetFullName() const;
147 const std::string& GetEmail(unsigned int index = 0) const;
149 // Parser / Builder API (see parser.h / builder.h)
150 void Validate() const;
151 uint8_t GetRecType() const { return RecType; }
152 uint32_t GetUniqueId() const { return RecordId; }
153 void SetIds(uint8_t Type, uint32_t Id) { RecType = Type; RecordId = Id; }
154 void ParseHeader(const Data &data, size_t &offset);
155 void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0);
156 void BuildHeader(Data &data, size_t &offset) const;
157 void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const;
159 // operations (common among record classes)
160 void Clear(); // erase everything
161 void Dump(std::ostream &os) const;
162 std::string GetDescription() const;
164 // Sorting - use enough data to make the sorting as
165 // consistent as possible
166 bool operator<(const Contact &other) const;
168 // database name
169 static const char * GetDBName() { return "Address Book"; }
170 static uint8_t GetDefaultRecType() { return 0; }
172 // helpers
173 static void SplitName(const std::string &full, std::string &first, std::string &last);
174 static std::string Email2CommaString(const EmailList &list);
175 static void CommaString2Email(const std::string &list, EmailList &result);
177 // Generic Field Handle support
178 static const FieldHandle<Contact>::ListT& GetFieldHandles();
181 BXEXPORT inline std::ostream& operator<< (std::ostream &os, const Contact &contact) {
182 contact.Dump(os);
183 return os;
186 /// @}
188 } // namespace Barry
190 #endif