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.
57 typedef std::vector
<Command
> CommandArrayType
;
59 CommandArrayType Commands
;
62 const unsigned char* ParseField(const unsigned char *begin
,
63 const unsigned char *end
);
68 void Parse(const Data
&data
, size_t offset
);
71 // returns 0 if unable to find command name, which is safe, since
72 // 0 is a special command that shouldn't be in the table anyway
73 unsigned int GetCommand(const std::string
&name
) const;
75 void Dump(std::ostream
&os
) const;
78 inline std::ostream
& operator<< (std::ostream
&os
, const CommandTable
&command
) {
85 class RecordStateTable
97 typedef unsigned int IndexType
;
98 typedef std::map
<IndexType
, State
> StateMapType
;
100 StateMapType StateMap
;
103 mutable IndexType m_LastNewRecordId
;
106 const unsigned char* ParseField(const unsigned char *begin
,
107 const unsigned char *end
);
113 void Parse(const Data
&data
);
116 bool GetIndex(uint32_t RecordId
, IndexType
*pFoundIndex
= 0) const;
117 uint32_t MakeNewRecordId() const;
119 void Dump(std::ostream
&os
) const;
122 inline std::ostream
& operator<< (std::ostream
&os
, const RecordStateTable
&rst
) {
129 class DatabaseDatabase
135 unsigned int RecordCount
;
139 typedef std::vector
<Database
> DatabaseArrayType
;
141 DatabaseArrayType Databases
;
144 template <class RecordType
, class FieldType
>
145 void ParseRec(const RecordType
&rec
, const unsigned char *end
);
147 template <class FieldType
>
148 const unsigned char* ParseField(const unsigned char *begin
,
149 const unsigned char *end
);
155 void Parse(const Data
&data
);
158 // returns true on success, and fills target
159 bool GetDBNumber(const std::string
&name
, unsigned int &number
) const;
160 bool GetDBName(unsigned int number
, std::string
&name
) const;
162 void Dump(std::ostream
&os
) const;
165 inline std::ostream
& operator<<(std::ostream
&os
, const DatabaseDatabase
&dbdb
) {
175 std::ostream
& operator<< (std::ostream
&os
, const std::vector
<UnknownField
> &unknowns
);
188 std::ostream
& operator<<(std::ostream
&os
, const Address
&msga
);
191 /// \addtogroup RecordParserClasses
192 /// Parser and data storage classes. These classes take a
193 /// Database Database record and convert them into C++ objects.
194 /// Each of these classes are safe to be used in standard
195 /// containers, and are meant to be used in conjunction with the
196 /// RecordParser<> template when calling Controller::LoadDatabase().
202 // Include all parser classes, to make it easy for the application to use.
203 #include "r_calendar.h"
204 #include "r_contact.h"
206 #include "r_message.h"
207 #include "r_servicebook.h"
209 #include "r_pin_message.h"
210 #include "r_saved_message.h"