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-2007, 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__
36 // forward declarations
37 namespace Barry
{ class Data
; }
42 // NOTE: All classes here must be container-safe! Perhaps add sorting
43 // operators in the future.
48 struct CommandTableCommand
57 typedef CommandTableCommand Command
;
58 typedef std::vector
<Command
> CommandArrayType
;
60 CommandArrayType Commands
;
63 const unsigned char* ParseField(const unsigned char *begin
,
64 const unsigned char *end
);
69 void Parse(const Data
&data
, size_t offset
);
72 // returns 0 if unable to find command name, which is safe, since
73 // 0 is a special command that shouldn't be in the table anyway
74 unsigned int GetCommand(const std::string
&name
) const;
76 void Dump(std::ostream
&os
) const;
79 inline std::ostream
& operator<< (std::ostream
&os
, const CommandTable
&command
) {
86 struct RecordStateTableState
95 class RecordStateTable
98 typedef RecordStateTableState State
;
99 typedef unsigned int IndexType
;
100 typedef std::map
<IndexType
, State
> StateMapType
;
102 StateMapType StateMap
;
105 mutable IndexType m_LastNewRecordId
;
108 const unsigned char* ParseField(const unsigned char *begin
,
109 const unsigned char *end
);
115 void Parse(const Data
&data
);
118 bool GetIndex(uint32_t RecordId
, IndexType
*pFoundIndex
= 0) const;
119 uint32_t MakeNewRecordId() const;
121 void Dump(std::ostream
&os
) const;
124 inline std::ostream
& operator<< (std::ostream
&os
, const RecordStateTable
&rst
) {
134 unsigned int RecordCount
;
138 class DatabaseDatabase
141 typedef DatabaseItem Database
;
142 typedef std::vector
<Database
> DatabaseArrayType
;
144 DatabaseArrayType Databases
;
147 template <class RecordType
, class FieldType
>
148 void ParseRec(const RecordType
&rec
, const unsigned char *end
);
150 template <class FieldType
>
151 const unsigned char* ParseField(const unsigned char *begin
,
152 const unsigned char *end
);
158 void Parse(const Data
&data
);
161 // returns true on success, and fills target
162 bool GetDBNumber(const std::string
&name
, unsigned int &number
) const;
163 bool GetDBName(unsigned int number
, std::string
&name
) const;
165 void Dump(std::ostream
&os
) const;
168 inline std::ostream
& operator<<(std::ostream
&os
, const DatabaseDatabase
&dbdb
) {
178 std::ostream
& operator<< (std::ostream
&os
, const std::vector
<UnknownField
> &unknowns
);
191 std::ostream
& operator<<(std::ostream
&os
, const EmailAddress
&msga
);
204 std::string
GetLabel() const;
207 bool HasData() const { return Address1
.size() || Address2
.size() ||
208 Address3
.size() || City
.size() || Province
.size() ||
209 PostalCode
.size() || Country
.size(); }
211 std::ostream
& operator<<(std::ostream
&os
, const PostalAddress
&msga
);
214 /// \addtogroup RecordParserClasses
215 /// Parser and data storage classes. These classes take a
216 /// Database Database record and convert them into C++ objects.
217 /// Each of these classes are safe to be used in standard
218 /// containers, and are meant to be used in conjunction with the
219 /// RecordParser<> template when calling Controller::LoadDatabase().
225 // Include all parser classes, to make it easy for the application to use.
226 #include "r_calendar.h"
227 #include "r_contact.h"
229 #include "r_message.h"
230 #include "r_servicebook.h"
232 #include "r_pin_message.h"
233 #include "r_saved_message.h"
234 #include "r_folder.h"