3 /// Blackberry database record parser class for contact records.
7 Copyright (C) 2005-2008, 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__
36 // NOTE: All classes here must be container-safe! Perhaps add sorting
37 // operators in the future.
40 struct BXEXPORT ContactGroupLink
45 ContactGroupLink() : Link(0), Unknown(0) {}
46 ContactGroupLink(uint32_t link
, uint16_t unknown
)
47 : Link(link
), Unknown(unknown
)
51 typedef std::vector
<std::string
> CategoryList
;
53 /// \addtogroup RecordParserClasses
56 class BXEXPORT Contact
59 typedef Barry::CategoryList CategoryList
;
60 typedef ContactGroupLink GroupLink
;
61 typedef std::vector
<GroupLink
> GroupLinksType
;
62 typedef std::vector
<UnknownField
> UnknownsType
;
64 // contact specific data
83 DefaultCommunicationsMethod
,
95 PostalAddress WorkAddress
;
96 PostalAddress HomeAddress
;
98 // Categories are not allowed to have commas in them.
99 // A category name containing a comma will be split into
100 // two categories, not only by this library, but by the
102 CategoryList Categories
;
104 GroupLinksType GroupLinks
;
105 UnknownsType Unknowns
;
108 bool m_FirstNameSeen
;
112 const unsigned char* ParseField(const unsigned char *begin
,
113 const unsigned char *end
);
119 uint32_t GetID() const { return RecordId
; }
120 std::string
GetFullName() const;
122 // Parser / Builder API (see parser.h / builder.h)
123 uint8_t GetRecType() const { return RecType
; }
124 uint32_t GetUniqueId() const { return RecordId
; }
125 void SetIds(uint8_t Type
, uint32_t Id
) { RecType
= Type
; RecordId
= Id
; }
126 void ParseHeader(const Data
&data
, size_t &offset
);
127 void ParseFields(const Data
&data
, size_t &offset
);
128 void BuildHeader(Data
&data
, size_t &offset
) const;
129 void BuildFields(Data
&data
, size_t &offset
) const;
131 void Clear(); // erase everything
133 void Dump(std::ostream
&os
) const;
135 // sorting - put group links at the end
136 bool operator<(const Contact
&other
) const {
137 return GroupLinks
.size() == 0 && other
.GroupLinks
.size() > 0;
138 // // testing - put group links at the top
139 // return GroupLinks.size() > 0 && other.GroupLinks.size() == 0;
143 static const char * GetDBName() { return "Address Book"; }
144 static uint8_t GetDefaultRecType() { return 0; }
147 static void SplitName(const std::string
&full
, std::string
&first
, std::string
&last
);
148 static void CategoryStr2List(const std::string
&str
, Barry::CategoryList
&list
);
149 static void CategoryList2Str(const Barry::CategoryList
&list
, std::string
&str
);
152 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const Contact
&contact
) {