3 /// Blackberry database record classes. Help translate data
4 /// from data packets to useful structurs, and back.
5 /// This header provides the common types and classes
6 /// used by the general record parser classes in the
7 /// r_*.h files. Only application-safe API stuff goes in
8 /// here. Internal library types go in record-internal.h
12 Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 See the GNU General Public License in the COPYING file at the
24 root directory of this project for more details.
27 #ifndef __BARRY_RECORD_H__
28 #define __BARRY_RECORD_H__
37 // forward declarations
38 namespace Barry
{ class Data
; }
43 // NOTE: All classes here must be container-safe! Perhaps add sorting
44 // operators in the future.
49 struct BXEXPORT CommandTableCommand
55 class BXEXPORT CommandTable
58 typedef CommandTableCommand Command
;
59 typedef std::vector
<Command
> CommandArrayType
;
61 CommandArrayType Commands
;
64 BXLOCAL
const unsigned char* ParseField(const unsigned char *begin
,
65 const unsigned char *end
);
70 void Parse(const Data
&data
, size_t offset
);
73 // returns 0 if unable to find command name, which is safe, since
74 // 0 is a special command that shouldn't be in the table anyway
75 unsigned int GetCommand(const std::string
&name
) const;
77 void Dump(std::ostream
&os
) const;
80 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const CommandTable
&command
) {
87 struct BXEXPORT RecordStateTableState
96 class BXEXPORT RecordStateTable
99 typedef RecordStateTableState State
;
100 typedef unsigned int IndexType
;
101 typedef std::map
<IndexType
, State
> StateMapType
;
103 StateMapType StateMap
;
106 mutable IndexType m_LastNewRecordId
;
109 BXLOCAL
const unsigned char* ParseField(const unsigned char *begin
,
110 const unsigned char *end
);
116 void Parse(const Data
&data
);
119 bool GetIndex(uint32_t RecordId
, IndexType
*pFoundIndex
= 0) const;
120 uint32_t MakeNewRecordId() const;
122 void Dump(std::ostream
&os
) const;
125 BXEXPORT
inline std::ostream
& operator<< (std::ostream
&os
, const RecordStateTable
&rst
) {
132 struct BXEXPORT DatabaseItem
135 unsigned int RecordCount
;
139 class BXEXPORT DatabaseDatabase
142 typedef DatabaseItem Database
;
143 typedef std::vector
<Database
> DatabaseArrayType
;
145 DatabaseArrayType Databases
;
148 template <class RecordType
, class FieldType
>
149 void ParseRec(const RecordType
&rec
, const unsigned char *end
);
151 template <class FieldType
>
152 const unsigned char* ParseField(const unsigned char *begin
,
153 const unsigned char *end
);
159 void Parse(const Data
&data
);
162 // returns true on success, and fills target
163 bool GetDBNumber(const std::string
&name
, unsigned int &number
) const;
164 bool GetDBName(unsigned int number
, std::string
&name
) const;
166 void Dump(std::ostream
&os
) const;
169 BXEXPORT
inline std::ostream
& operator<<(std::ostream
&os
, const DatabaseDatabase
&dbdb
) {
176 std::string raw_data
;
178 const std::string::value_type
* data() const { return raw_data
.data(); }
179 std::string::size_type
size() const { return raw_data
.size(); }
180 void assign(const std::string::value_type
*s
, std::string::size_type n
)
181 { raw_data
.assign(s
, n
); }
184 struct BXEXPORT UnknownField
189 BXEXPORT
std::ostream
& operator<< (std::ostream
&os
, const std::vector
<UnknownField
> &unknowns
);
191 struct BXEXPORT EmailAddress
204 return Name
.size() + Email
.size();
207 BXEXPORT
std::ostream
& operator<<(std::ostream
&os
, const EmailAddress
&msga
);
209 typedef std::vector
<EmailAddress
> EmailAddressList
;
210 BXEXPORT
std::ostream
& operator<<(std::ostream
&os
, const EmailAddressList
&elist
);
212 struct BXEXPORT PostalAddress
223 std::string
GetLabel() const;
226 bool HasData() const { return Address1
.size() || Address2
.size() ||
227 Address3
.size() || City
.size() || Province
.size() ||
228 PostalCode
.size() || Country
.size(); }
230 BXEXPORT
std::ostream
& operator<<(std::ostream
&os
, const PostalAddress
&msga
);
234 int Month
; // 0 to 11
236 int Year
; // exact number, eg. 2008
238 Date() : Month(0), Day(0), Year(0) {}
239 explicit Date(const struct tm
*timep
);
241 bool HasData() const { return Month
|| Day
|| Year
; }
244 void ToTm(struct tm
*timep
) const;
245 std::string
ToYYYYMMDD() const;
246 std::string
ToBBString() const; // converts to Blackberry string
247 // format of DD/MM/YYYY
249 bool FromTm(const struct tm
*timep
);
250 bool FromBBString(const std::string
&str
);
251 bool FromYYYYMMDD(const std::string
&str
);
253 BXEXPORT
std::ostream
& operator<<(std::ostream
&os
, const Date
&date
);
255 class BXEXPORT CategoryList
: public std::vector
<std::string
>
258 /// Parses the given comma delimited category string into
259 /// this CategoryList object, appending each token to the vector.
260 /// Will clear vector beforehand.
261 void CategoryStr2List(const std::string
&str
);
263 /// Turns the current vectory into a comma delimited category
264 /// string suitable for use in Calendar, Task, and Memo
266 void CategoryList2Str(std::string
&str
) const;
268 using std::vector
<std::string
>::operator=;
272 /// \addtogroup RecordParserClasses
273 /// Parser and data storage classes. These classes take a
274 /// Database Database record and convert them into C++ objects.
275 /// Each of these classes are safe to be used in standard
276 /// containers, and are meant to be used in conjunction with the
277 /// RecordParser<> template when calling Controller::LoadDatabase().
283 #ifndef __BARRY_LIBRARY_BUILD__
284 // Include all parser classes, to make it easy for the application to use.
285 #include "r_calendar.h"
286 #include "r_calllog.h"
287 #include "r_contact.h"
289 #include "r_message.h"
290 #include "r_servicebook.h"
292 #include "r_pin_message.h"
293 #include "r_saved_message.h"
295 #include "r_folder.h"
296 #include "r_timezone.h"