3 /// Blackberry database record parser class for contact records.
7 Copyright (C) 2005-2010, 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__
35 // forward declarations
39 // NOTE: All classes here must be container-safe! Perhaps add sorting
40 // operators in the future.
43 struct BXEXPORT ContactGroupLink
48 ContactGroupLink() : Link(0), Unknown(0) {}
49 ContactGroupLink(uint32_t link
, uint16_t unknown
)
50 : Link(link
), Unknown(unknown
)
54 /// \addtogroup RecordParserClasses
58 // Contact record class
60 /// Represents a single record in the Address Book Blackberry database.
62 class BXEXPORT Contact
65 typedef Barry::CategoryList CategoryList
;
66 typedef ContactGroupLink GroupLink
;
67 typedef std::vector
<GroupLink
> GroupLinksType
;
68 typedef std::vector
<UnknownField
> UnknownsType
;
69 typedef std::string EmailType
;
70 typedef std::vector
<EmailType
> EmailList
;
76 // contact specific data
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.
104 DefaultCommunicationsMethod
,
119 PostalAddress WorkAddress
;
120 PostalAddress HomeAddress
;
122 // Categories are not allowed to have commas in them.
123 // A category name containing a comma will be split into
124 // two categories, not only by this library, but by the
126 CategoryList Categories
;
128 GroupLinksType GroupLinks
;
129 UnknownsType Unknowns
;
132 bool m_FirstNameSeen
;
135 const unsigned char* ParseField(const unsigned char *begin
,
136 const unsigned char *end
, const IConverter
*ic
= 0);
142 uint32_t GetID() const { return RecordId
; }
143 std::string
GetFullName() const;
144 const std::string
& GetEmail(unsigned int index
= 0) const;
146 // Parser / Builder API (see parser.h / builder.h)
147 uint8_t GetRecType() const { return RecType
; }
148 uint32_t GetUniqueId() const { return RecordId
; }
149 void SetIds(uint8_t Type
, uint32_t Id
) { RecType
= Type
; RecordId
= Id
; }
150 void ParseHeader(const Data
&data
, size_t &offset
);
151 void ParseFields(const Data
&data
, size_t &offset
, const IConverter
*ic
= 0);
152 void BuildHeader(Data
&data
, size_t &offset
) const;
153 void BuildFields(Data
&data
, size_t &offset
, const IConverter
*ic
= 0) const;
155 void Clear(); // erase everything
157 void Dump(std::ostream
&os
) const;
159 // Sorting - use enough data to make the sorting as
160 // consistent as possible
161 bool operator<(const Contact
&other
) const;
164 static const char * GetDBName() { return "Address Book"; }
165 static uint8_t GetDefaultRecType() { return 0; }
168 static void SplitName(const std::string
&full
, std::string
&first
, std::string
&last
);
171 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const Contact
&contact
) {