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