Reorganized sample ppp options files
[barry/pauldeden.git] / src / r_contact.h
blobbfd78e3099f98e359d161c38fba73d0dc1dc6acb
1 ///
2 /// \file r_contact.h
3 /// Blackberry database record parser class for contact records.
4 ///
6 /*
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__
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 {
36 // NOTE: All classes here must be container-safe! Perhaps add sorting
37 // operators in the future.
40 struct BXEXPORT ContactGroupLink
42 uint32_t Link;
43 uint16_t Unknown;
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
54 /// @{
56 class BXEXPORT Contact
58 public:
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
65 uint8_t RecType;
66 uint32_t RecordId;
67 std::string
68 Email,
69 Phone,
70 Fax,
71 WorkPhone,
72 HomePhone,
73 MobilePhone,
74 Pager,
75 PIN,
76 Radio,
77 WorkPhone2,
78 HomePhone2,
79 OtherPhone,
80 FirstName,
81 LastName,
82 Company,
83 DefaultCommunicationsMethod,
84 JobTitle,
85 PublicKey,
86 URL,
87 Prefix,
88 Notes,
89 UserDefined1,
90 UserDefined2,
91 UserDefined3,
92 UserDefined4,
93 Image;
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
101 // device itself.
102 CategoryList Categories;
104 GroupLinksType GroupLinks;
105 UnknownsType Unknowns;
107 private:
108 bool m_FirstNameSeen;
110 //protected:
111 public:
112 const unsigned char* ParseField(const unsigned char *begin,
113 const unsigned char *end);
115 public:
116 Contact();
117 ~Contact();
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;
142 // database name
143 static const char * GetDBName() { return "Address Book"; }
144 static uint8_t GetDefaultRecType() { return 0; }
146 // helpers
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) {
153 contact.Dump(os);
154 return os;
157 /// @}
159 } // namespace Barry
161 #endif