3 /// Non-intrusive versions of serialization functions for the
4 /// record classes. These template functions make it possible
5 /// to use the record classes with the Boost::Serialization
10 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU General Public License in the COPYING file at the
22 root directory of this project for more details.
25 #ifndef __BARRY_S11N_BOOST_H__
26 #define __BARRY_S11N_BOOST_H__
30 #include <boost/serialization/vector.hpp>
32 ///////////////////////////////////////////////////////////////////////////////
35 // BARRY_BASE_S11N_VERSION - the base version where all record data is
36 // stored so it can be fully retrieved and
37 // uploaded to the handheld device later.
38 // BARRY_POD_MAP_VERSION - if these templates are called with a version
39 // equal or greater than this, only mappable,
40 // POD data is included in the serialization
42 #define BARRY_BASE_S11N_VERSION 0
43 #define BARRY_POD_MAP_VERSION 1000
45 // namespace boost::serialization, for the non-intrusive version
47 namespace serialization
{
49 template <class ArchiveT
>
50 void serialize(ArchiveT
&ar
, Barry::UnknownField
&uf
, const unsigned int ver
)
52 ar
& make_nvp("type", uf
.type
);
53 ar
& make_nvp("data", uf
.data
.raw_data
);
56 template <class ArchiveT
>
57 void serialize(ArchiveT
&ar
, Barry::Contact::GroupLink
&g
, const unsigned int ver
)
59 ar
& make_nvp("Link", g
.Link
);
60 ar
& make_nvp("Unknown", g
.Unknown
);
63 template <class ArchiveT
>
64 void serialize(ArchiveT
&ar
, Barry::CategoryList
&cl
, const unsigned int ver
)
66 std::vector
<std::string
> &sl
= cl
;
67 ar
& make_nvp("CategoryList", sl
);
70 template <class ArchiveT
>
71 void serialize(ArchiveT
&ar
, Barry::Contact
&c
, const unsigned int ver
)
73 ar
& make_nvp("RecType", c
.RecType
);
74 ar
& make_nvp("RecordId", c
.RecordId
);
76 ar
& make_nvp("EmailAddresses", c
.EmailAddresses
);
77 ar
& make_nvp("Phone", c
.Phone
);
78 ar
& make_nvp("Fax", c
.Fax
);
79 ar
& make_nvp("WorkPhone", c
.WorkPhone
);
80 ar
& make_nvp("HomePhone", c
.HomePhone
);
81 ar
& make_nvp("MobilePhone", c
.MobilePhone
);
82 ar
& make_nvp("Pager", c
.Pager
);
83 ar
& make_nvp("PIN", c
.PIN
);
84 ar
& make_nvp("Radio", c
.Radio
);
85 ar
& make_nvp("WorkPhone2", c
.WorkPhone2
);
86 ar
& make_nvp("HomePhone2", c
.HomePhone2
);
87 ar
& make_nvp("OtherPhone", c
.OtherPhone
);
88 ar
& make_nvp("FirstName", c
.FirstName
);
89 ar
& make_nvp("LastName", c
.LastName
);
90 ar
& make_nvp("Company", c
.Company
);
91 ar
& make_nvp("DefaultCommunicationsMethod", c
.DefaultCommunicationsMethod
);
92 ar
& make_nvp("Address1", c
.WorkAddress
.Address1
);
93 ar
& make_nvp("Address2", c
.WorkAddress
.Address2
);
94 ar
& make_nvp("Address3", c
.WorkAddress
.Address3
);
95 ar
& make_nvp("City", c
.WorkAddress
.City
);
96 ar
& make_nvp("Province", c
.WorkAddress
.Province
);
97 ar
& make_nvp("PostalCode", c
.WorkAddress
.PostalCode
);
98 ar
& make_nvp("Country", c
.WorkAddress
.Country
);
99 ar
& make_nvp("JobTitle", c
.JobTitle
);
100 ar
& make_nvp("PublicKey", c
.PublicKey
);
101 ar
& make_nvp("URL", c
.URL
);
102 ar
& make_nvp("Prefix", c
.Prefix
);
103 ar
& make_nvp("Categories", c
.Categories
);
104 ar
& make_nvp("HomeAddress1", c
.HomeAddress
.Address1
);
105 ar
& make_nvp("HomeAddress2", c
.HomeAddress
.Address2
);
106 ar
& make_nvp("HomeAddress3", c
.HomeAddress
.Address3
);
107 ar
& make_nvp("Notes", c
.Notes
);
108 ar
& make_nvp("UserDefined1", c
.UserDefined1
);
109 ar
& make_nvp("UserDefined2", c
.UserDefined2
);
110 ar
& make_nvp("UserDefined3", c
.UserDefined3
);
111 ar
& make_nvp("UserDefined4", c
.UserDefined4
);
112 ar
& make_nvp("HomeCity", c
.HomeAddress
.City
);
113 ar
& make_nvp("HomeProvince", c
.HomeAddress
.Province
);
114 ar
& make_nvp("HomePostalCode", c
.HomeAddress
.PostalCode
);
115 ar
& make_nvp("HomeCountry", c
.HomeAddress
.Country
);
116 ar
& make_nvp("Image", c
.Image
);
118 if( ver
< BARRY_POD_MAP_VERSION
) {
119 ar
& make_nvp("GroupLinks", c
.GroupLinks
);
120 ar
& make_nvp("Unknowns", c
.Unknowns
);
124 template <class ArchiveT
>
125 void serialize(ArchiveT
&ar
, Barry::EmailAddress
&a
, const unsigned int ver
)
127 ar
& make_nvp("Name", a
.Name
);
128 ar
& make_nvp("Email", a
.Email
);
131 template <class ArchiveT
>
132 void serialize(ArchiveT
&ar
, Barry::Message
&m
, const unsigned int ver
)
134 ar
& make_nvp("From", m
.From
);
135 ar
& make_nvp("To", m
.To
);
136 ar
& make_nvp("Cc", m
.Cc
);
137 ar
& make_nvp("Sender", m
.Sender
);
138 ar
& make_nvp("ReplyTo", m
.ReplyTo
);
139 ar
& make_nvp("Subject", m
.Subject
);
140 ar
& make_nvp("Body", m
.Body
);
141 ar
& make_nvp("Attachment", m
.Attachment
);
142 ar
& make_nvp("MessageRecordId", m
.MessageRecordId
);
143 ar
& make_nvp("MessageReplyTo", m
.MessageReplyTo
);
144 ar
& make_nvp("MessageDateSent", m
.MessageDateSent
);
145 ar
& make_nvp("MessageDateReceived", m
.MessageDateReceived
);
147 ar
& make_nvp("MessageTruncated", m
.MessageTruncated
);
148 ar
& make_nvp("MessageRead", m
.MessageRead
);
149 ar
& make_nvp("MessageReply", m
.MessageReply
);
150 ar
& make_nvp("MessageSaved", m
.MessageSaved
);
151 ar
& make_nvp("MessageSavedDeleted", m
.MessageSavedDeleted
);
153 ar
& make_nvp("MessagePriority", m
.Priority
);
154 ar
& make_nvp("MessageSensitivity", m
.Sensitivity
);
156 if( ver
< BARRY_POD_MAP_VERSION
) {
157 ar
& make_nvp("Unknowns", m
.Unknowns
);
161 template <class ArchiveT
>
162 void serialize(ArchiveT
&ar
, Barry::Calendar
&c
, const unsigned int ver
)
164 ar
& make_nvp("RecType", c
.RecType
);
165 ar
& make_nvp("RecordId", c
.RecordId
);
167 ar
& make_nvp("AllDayEvent", c
.AllDayEvent
);
169 ar
& make_nvp("Subject", c
.Subject
);
170 ar
& make_nvp("Notes", c
.Notes
);
171 ar
& make_nvp("Location", c
.Location
);
173 ar
& make_nvp("NotificationTime", c
.NotificationTime
);
174 ar
& make_nvp("StartTime", c
.StartTime
);
175 ar
& make_nvp("EndTime", c
.EndTime
);
177 ar
& make_nvp("Organizer", c
.Organizer
);
178 ar
& make_nvp("AcceptedBy", c
.AcceptedBy
);
179 ar
& make_nvp("Invited", c
.Invited
);
181 ar
& make_nvp("FreeBusyFlag", c
.FreeBusyFlag
);
182 ar
& make_nvp("ClassFlag", c
.ClassFlag
);
184 ar
& make_nvp("Recurring", c
.Recurring
);
185 ar
& make_nvp("RecurringType", c
.RecurringType
);
186 ar
& make_nvp("Interval", c
.Interval
);
187 ar
& make_nvp("RecurringEndTime", c
.RecurringEndTime
);
188 ar
& make_nvp("Perpetual", c
.Perpetual
);
189 ar
& make_nvp("CalendarID", c
.CalendarID
);
190 ar
& make_nvp("TimeZoneCode", c
.TimeZoneCode
);
191 ar
& make_nvp("TimeZoneValid", c
.TimeZoneValid
);
193 ar
& make_nvp("DayOfWeek", c
.DayOfWeek
);
194 ar
& make_nvp("WeekOfMonth", c
.WeekOfMonth
);
195 ar
& make_nvp("DayOfMonth", c
.DayOfMonth
);
196 ar
& make_nvp("MonthOfYear", c
.MonthOfYear
);
197 ar
& make_nvp("WeekDays", c
.WeekDays
);
199 if( ver
< BARRY_POD_MAP_VERSION
) {
200 ar
& make_nvp("Unknowns", c
.Unknowns
);
204 template <class ArchiveT
>
205 void serialize(ArchiveT
&ar
, Barry::CalendarAll
&c
, const unsigned int ver
)
207 serialize(ar
, static_cast<Barry::Calendar
&>(c
), ver
);
209 ar
& make_nvp("MailAccount", c
.MailAccount
);
212 template <class ArchiveT
>
213 void serialize(ArchiveT
&ar
, Barry::CallLog
&c
, const unsigned int ver
)
215 ar
& make_nvp("RecType", c
.RecType
);
216 ar
& make_nvp("RecordId", c
.RecordId
);
218 ar
& make_nvp("Duration", c
.Duration
);
219 ar
& make_nvp("Timestamp", c
.Timestamp
);
220 ar
& make_nvp("ContactName", c
.ContactName
);
221 ar
& make_nvp("PhoneNumber", c
.PhoneNumber
);
223 ar
& make_nvp("DirectionFlag", c
.DirectionFlag
);
224 ar
& make_nvp("StatusFlag", c
.StatusFlag
);
225 ar
& make_nvp("PhoneTypeFlag", c
.PhoneTypeFlag
);
226 ar
& make_nvp("PhoneInfoFlag", c
.PhoneInfoFlag
);
228 if( ver
< BARRY_POD_MAP_VERSION
) {
229 ar
& make_nvp("Unknowns", c
.Unknowns
);
233 template <class ArchiveT
>
234 void serialize(ArchiveT
&ar
, Barry::Bookmark
&c
, const unsigned int ver
)
236 ar
& make_nvp("RecType", c
.RecType
);
237 ar
& make_nvp("RecordId", c
.RecordId
);
238 ar
& make_nvp("Index", c
.Index
);
240 ar
& make_nvp("Name", c
.Name
);
241 ar
& make_nvp("Icon", c
.Icon
);
242 ar
& make_nvp("Url", c
.Url
);
244 ar
& make_nvp("BrowserIdentity", c
.BrowserIdentity
);
245 ar
& make_nvp("DisplayMode", c
.DisplayMode
);
246 ar
& make_nvp("JavaScriptMode", c
.JavaScriptMode
);
248 if( ver
< BARRY_POD_MAP_VERSION
) {
249 ar
& make_nvp("Unknowns", c
.Unknowns
);
253 template <class ArchiveT
>
254 void serialize(ArchiveT
&ar
, Barry::ServiceBookConfig
&c
, const unsigned int ver
)
256 ar
& make_nvp("Format", c
.Format
);
258 if( ver
< BARRY_POD_MAP_VERSION
) {
259 ar
& make_nvp("Unknowns", c
.Unknowns
);
263 template <class ArchiveT
>
264 void serialize(ArchiveT
&ar
, Barry::ServiceBook
&c
, const unsigned int ver
)
266 ar
& make_nvp("RecType", c
.RecType
);
267 ar
& make_nvp("RecordId", c
.RecordId
);
269 ar
& make_nvp("Name", c
.Name
);
270 ar
& make_nvp("HiddenName", c
.HiddenName
);
271 ar
& make_nvp("Description", c
.Description
);
272 ar
& make_nvp("DSID", c
.DSID
);
273 ar
& make_nvp("BesDomain", c
.BesDomain
);
274 ar
& make_nvp("UniqueId", c
.UniqueId
);
275 ar
& make_nvp("ContentId", c
.ContentId
);
276 ar
& make_nvp("Config", c
.Config
);
278 if( ver
< BARRY_POD_MAP_VERSION
) {
279 ar
& make_nvp("Unknowns", c
.Unknowns
);
283 template <class ArchiveT
>
284 void serialize(ArchiveT
&ar
, Barry::Memo
&m
, const unsigned int ver
)
286 ar
& make_nvp("RecType", m
.RecType
);
287 ar
& make_nvp("RecordId", m
.RecordId
);
289 ar
& make_nvp("Title", m
.Title
);
290 ar
& make_nvp("Body", m
.Body
);
291 ar
& make_nvp("Categories", m
.Categories
);
293 if( ver
< BARRY_POD_MAP_VERSION
) {
294 ar
& make_nvp( "Unknowns", m
.Unknowns
);
298 template <class ArchiveT
>
299 void serialize(ArchiveT
&ar
, Barry::Task
&t
, const unsigned int ver
)
301 ar
& make_nvp("RecType", t
.RecType
);
302 ar
& make_nvp("RecordId", t
.RecordId
);
304 ar
& make_nvp("Summary", t
.Summary
);
305 ar
& make_nvp("Notes", t
.Notes
);
306 ar
& make_nvp("Categories", t
.Categories
);
307 ar
& make_nvp("UID", t
.UID
);
309 ar
& make_nvp("StartTime", t
.StartTime
);
310 ar
& make_nvp("DueTime", t
.DueTime
);
311 ar
& make_nvp("AlarmTime", t
.AlarmTime
);
313 ar
& make_nvp("TimeZoneCode", t
.TimeZoneCode
);
314 ar
& make_nvp("TimeZoneValid", t
.TimeZoneValid
);
316 ar
& make_nvp("AlarmType", t
.AlarmType
);
317 ar
& make_nvp("Interval", t
.Interval
);
318 ar
& make_nvp("RecurringType", t
.RecurringType
);
319 ar
& make_nvp("RecurringEndTime", t
.RecurringEndTime
);
320 ar
& make_nvp("DayOfWeek", t
.DayOfWeek
);
321 ar
& make_nvp("WeekOfMonth", t
.WeekOfMonth
);
322 ar
& make_nvp("DayOfMonth", t
.DayOfMonth
);
323 ar
& make_nvp("MonthOfYear", t
.MonthOfYear
);
324 ar
& make_nvp("WeekDays", t
.WeekDays
);
326 ar
& make_nvp("PriorityFlag", t
.PriorityFlag
);
327 ar
& make_nvp("StatusFlag", t
.StatusFlag
);
328 ar
& make_nvp("Recurring", t
.Recurring
);
329 ar
& make_nvp("Perpetual", t
.Perpetual
);
330 ar
& make_nvp("DueDateFlag", t
.DueDateFlag
);
332 if( ver
< BARRY_POD_MAP_VERSION
) {
333 ar
& make_nvp( "Unknowns", t
.Unknowns
);
337 template<class ArchiveT
>
338 void serialize(ArchiveT
&ar
, Barry::PINMessage
&p
, const unsigned int ver
)
340 ar
& make_nvp("RecType", p
.RecType
);
341 ar
& make_nvp("RecordId", p
.RecordId
);
343 ar
& make_nvp("From", p
.From
);
344 ar
& make_nvp("To", p
.To
);
345 ar
& make_nvp("Cc", p
.Cc
);
346 ar
& make_nvp("Bcc", p
.Bcc
);
347 ar
& make_nvp("Subject", p
.Subject
);
348 ar
& make_nvp("Body", p
.Body
);
349 ar
& make_nvp("MessageRecordId", p
.MessageRecordId
);
350 ar
& make_nvp("MessageReplyTo", p
.MessageReplyTo
);
351 ar
& make_nvp("MessageDateSent", p
.MessageDateSent
);
352 ar
& make_nvp("MessageDateReceived", p
.MessageDateReceived
);
354 ar
& make_nvp("MessageTruncated", p
.MessageTruncated
);
355 ar
& make_nvp("MessageRead", p
.MessageRead
);
356 ar
& make_nvp("MessageReply", p
.MessageReply
);
357 ar
& make_nvp("MessageSaved", p
.MessageSaved
);
358 ar
& make_nvp("MessageSavedDeleted", p
.MessageSavedDeleted
);
360 ar
& make_nvp("MessagePriority", p
.Priority
);
361 ar
& make_nvp("MessageSensitivity", p
.Sensitivity
);
363 if(ver
< BARRY_POD_MAP_VERSION
) {
364 ar
& make_nvp("Unknowns", p
.Unknowns
);
368 template <class ArchiveT
>
369 void serialize(ArchiveT
&ar
, Barry::SavedMessage
&m
, const unsigned int ver
)
371 ar
& make_nvp("RecType", m
.RecType
);
372 ar
& make_nvp("RecordId", m
.RecordId
);
374 ar
& make_nvp("From", m
.From
);
375 ar
& make_nvp("To", m
.To
);
376 ar
& make_nvp("Cc", m
.Cc
);
377 ar
& make_nvp("Bcc", m
.Bcc
);
378 ar
& make_nvp("Sender", m
.Sender
);
379 ar
& make_nvp("ReplyTo", m
.ReplyTo
);
380 ar
& make_nvp("Subject", m
.Subject
);
381 ar
& make_nvp("Body", m
.Body
);
382 ar
& make_nvp("Attachment", m
.Attachment
);
383 ar
& make_nvp("MessageRecordId", m
.MessageRecordId
);
384 ar
& make_nvp("MessageReplyTo", m
.MessageReplyTo
);
385 ar
& make_nvp("MessageDateSent", m
.MessageDateSent
);
386 ar
& make_nvp("MessageDateReceived", m
.MessageDateReceived
);
388 ar
& make_nvp("MessageTruncated", m
.MessageTruncated
);
389 ar
& make_nvp("MessageRead", m
.MessageRead
);
390 ar
& make_nvp("MessageReply", m
.MessageReply
);
391 ar
& make_nvp("MessageSaved", m
.MessageSaved
);
392 ar
& make_nvp("MessageSavedDeleted", m
.MessageSavedDeleted
);
394 ar
& make_nvp("MessagePriority", m
.Priority
);
395 ar
& make_nvp("MessageSensitivity", m
.Sensitivity
);
397 if( ver
< BARRY_POD_MAP_VERSION
) {
398 ar
& make_nvp("Unknowns", m
.Unknowns
);
402 template <class ArchiveT
>
403 void serialize(ArchiveT
&ar
, Barry::Sms
&m
, const unsigned int ver
)
405 ar
& make_nvp("RecType", m
.RecType
);
406 ar
& make_nvp("RecordId", m
.RecordId
);
408 ar
& make_nvp("MessageStatus", m
.MessageStatus
);
409 ar
& make_nvp("DeliveryStatus", m
.DeliveryStatus
);
411 ar
& make_nvp("IsNew", m
.IsNew
);
412 ar
& make_nvp("NewConversation", m
.NewConversation
);
413 ar
& make_nvp("Saved", m
.Saved
);
414 ar
& make_nvp("Deleted", m
.Deleted
);
415 ar
& make_nvp("Opened", m
.Opened
);
417 ar
& make_nvp("Timestamp", m
.Timestamp
);
418 ar
& make_nvp("ServiceCenterTimestamp", m
.ServiceCenterTimestamp
);
420 ar
& make_nvp("DataCodingScheme", m
.DataCodingScheme
);
421 ar
& make_nvp("ErrorId", m
.ErrorId
);
423 ar
& make_nvp("Addresses", m
.Addresses
);
424 ar
& make_nvp("Body", m
.Body
);
426 if( ver
< BARRY_POD_MAP_VERSION
) {
427 ar
& make_nvp("Unknowns", m
.Unknowns
);
431 template <class ArchiveT
>
432 void serialize(ArchiveT
&ar
, Barry::Folder
&f
, const unsigned int ver
)
434 ar
& make_nvp("RecType", f
.RecType
);
435 ar
& make_nvp("RecordId", f
.RecordId
);
437 ar
& make_nvp("FolderName", f
.Name
);
438 ar
& make_nvp("FolderNumber", f
.Number
);
439 ar
& make_nvp("FolderLevel", f
.Level
);
440 ar
& make_nvp("FolderType", f
.Type
);
442 if( ver
< BARRY_POD_MAP_VERSION
) {
443 ar
& make_nvp( "Unknowns", f
.Unknowns
);
447 template <class ArchiveT
>
448 void serialize(ArchiveT
&ar
, Barry::Timezone
&t
, const unsigned int ver
)
450 ar
& make_nvp("RecType", t
.RecType
);
451 ar
& make_nvp("RecordId", t
.RecordId
);
453 ar
& make_nvp("TZType", t
.TZType
);
454 ar
& make_nvp("DSTOffset", t
.DSTOffset
);
455 ar
& make_nvp("Index", t
.Index
);
456 ar
& make_nvp("Offset", t
.Offset
);
457 ar
& make_nvp("OffsetFraction", t
.OffsetFraction
);
458 ar
& make_nvp("StartMonth", t
.StartMonth
);
459 ar
& make_nvp("EndMonth", t
.EndMonth
);
460 ar
& make_nvp("Left", t
.Left
);
461 ar
& make_nvp("UseDST", t
.UseDST
);
463 ar
& make_nvp("TimeZoneName", t
.TimeZoneName
);
465 if( ver
< BARRY_POD_MAP_VERSION
) {
466 ar
& make_nvp("Unknowns", t
.Unknowns
);
470 template <class ArchiveT
>
471 void serialize(ArchiveT
&ar
, Barry::ContentStore
&c
, const unsigned int ver
)
473 ar
& make_nvp("RecType", c
.RecType
);
474 ar
& make_nvp("RecordId", c
.RecordId
);
476 ar
& make_nvp("Filename", c
.Filename
);
477 ar
& make_nvp("FolderFlag", c
.FolderFlag
);
478 ar
& make_nvp("FileContent", c
.FileContent
);
479 ar
& make_nvp("FileDescriptor", c
.FileDescriptor
);
481 // FileSize is not used for building, so no need to save it here
483 if( ver
< BARRY_POD_MAP_VERSION
) {
484 ar
& make_nvp("Unknowns", c
.Unknowns
);
488 }} // namespace boost::serialization
491 //////////////////////////////////////////////////////////////////////////////
492 // Helper wrapper templates for loading and saving records to an iostream
496 // Can be used as a Storage class for RecordBuilder<>
497 template <class RecordT
>
501 typedef RecordT rec_type
;
502 typedef std::vector
<rec_type
> list_type
;
506 typename
list_type::iterator rec_it
;
509 explicit BoostLoader(std::istream
&is
)
511 boost::archive::text_iarchive
ia(is
);
513 rec_it
= m_records
.begin();
516 list_type
& GetRecords() { return m_records
; }
517 const list_type
& GetRecords() const { return m_records
; }
519 // retrieval operator
520 bool operator()(RecordT
&rec
, Builder
&builder
)
522 if( rec_it
== m_records
.end() )
530 // Can be used as a Storage class for RecordParser<>
531 template <class RecordT
>
535 typedef RecordT rec_type
;
536 typedef std::vector
<rec_type
> list_type
;
541 typename
list_type::iterator rec_it
;
544 explicit BoostSaver(std::ostream
&os
)
554 void WriteArchive() const
556 // write dbname first, so parsing is possible
557 m_os
<< RecordT::GetDBName() << std::endl
;
559 // write boost archive of all records
560 boost::archive::text_oarchive
oa(m_os
);
562 // boost is fussy that the vector must be const
563 // we do this explicitly, for documentation's sake
564 const list_type
&recs
= m_records
;
569 list_type
& GetRecords() { return m_records
; }
570 const list_type
& GetRecords() const { return m_records
; }
573 void operator()(const RecordT
&rec
)
575 m_records
.push_back(rec
);
582 /// This Parser turns incoming records (which can be of any record type
583 /// included in ALL_KNOWN_PARSER_TYPES) into a Boost Serialization stream
584 /// on the given iostream.
586 /// This class is defined completely in the header, so that it is
587 /// optional for applications to link against the boost libraries.
589 class BXEXPORT BoostParser
: public Barry::Parser
591 std::auto_ptr
<Barry::Parser
> m_parser
;
592 std::ofstream
*m_ofs
;
593 std::ostream
&m_os
; // references either an external object,
594 // or *m_ifs... this is the reference to
595 // use in the entire class... the constructor
598 std::string m_current_db
;
601 explicit BoostParser(const std::string
&filename
)
602 : m_ofs( new std::ofstream(filename
.c_str()) )
607 explicit BoostParser(std::ostream
&os
)
615 // flush any remaining parser output
616 // (note this still potentially uses m_ofs, so do this first)
619 // cleanup the stream
623 void StartDB(const std::string
&dbname
)
625 // done with current parser, flush it's output
629 #define HANDLE_PARSER(tname) \
630 if( dbname == tname::GetDBName() ) { \
632 new RecordParser<tname, BoostSaver<tname> >( \
633 new BoostSaver<tname>(m_os) ) ); \
637 ALL_KNOWN_PARSER_TYPES
639 // if we make it here, we don't have a record parser
640 // for this dbname, so just dump it to stderr (not stdout,
641 // since the user might be sending normal output there)
642 m_parser
.reset( new HexDumpParser(std::cerr
) );
645 void ParseRecord(const DBData
&data
, const IConverter
*ic
)
647 if( m_current_db
!= data
.GetDBName() ) {
648 StartDB(data
.GetDBName());
649 m_current_db
= data
.GetDBName();
652 m_parser
->ParseRecord(data
, ic
);
659 /// This Builder class reads a boost serialization stream, and converts
660 /// them into DBData records. Can only produce records for record types
661 /// in ALL_KNOWN_BUILDER_TYPES.
663 class BXEXPORT BoostBuilder
: public Barry::Builder
665 std::auto_ptr
<Builder
> m_builder
;
666 std::ifstream
*m_ifs
;
668 std::istream
&m_is
; // references either an external object,
669 // or *m_ifs... this is the reference to
670 // use in the entire class... the constructor
674 explicit BoostBuilder(const std::string
&filename
)
675 : m_ifs( new std::ifstream(filename
.c_str()) )
681 explicit BoostBuilder(std::istream
&is
)
695 // done with current builder
698 // read the next DBName
700 while( getline(m_is
, dbName
) ) {
702 #undef HANDLE_BUILDER
703 #define HANDLE_BUILDER(tname) \
704 if( dbName == tname::GetDBName() ) { \
706 new RecordBuilder<tname, BoostLoader<tname> >( \
707 new BoostLoader<tname>(m_is) ) ); \
711 ALL_KNOWN_BUILDER_TYPES
715 bool BuildRecord(DBData
&data
, size_t &offset
, const IConverter
*ic
)
717 if( !m_builder
.get() )
720 bool ret
= m_builder
->BuildRecord(data
, offset
, ic
);
726 bool FetchRecord(DBData
&data
, const IConverter
*ic
)
728 if( !m_builder
.get() )
731 bool ret
= m_builder
->FetchRecord(data
, ic
);
737 bool EndOfFile() const
739 return m_builder
.get() ? false : true;