3 /// Virtual protocol packet builder wrapper
7 Copyright (C) 2005, 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_BUILDER_H__
23 #define __BARRY_BUILDER_H__
26 //#include "protocol.h"
34 /// Base class for the builder functor hierarchy.
42 virtual bool operator()(Data
&data
, unsigned int databaseId
) = 0;
47 // RecordBuilder template class
49 /// Template class for easy creation of specific protocol packet builder
50 /// objects. This template takes the following template arguments:
52 /// - Record: One of the record classes in record.h
53 /// - Storage: A custom storage functor class. An object of this type
54 /// will be called as a function with empty Record as an
55 /// argument. This happens on the fly as the data is sent
56 /// to the device over USB, so it should not block forever.
58 /// Example SaveDatabase() call:
62 /// struct StoreContact
64 /// const std::vector<Contact> &array;
65 /// std::vector<Contact>::const_iterator ci;
66 /// StoreContact(const std::vector<Contact> &a)
67 /// : array(a), ci(array.begin()) {}
68 /// bool operator() (Contact &c)
70 /// if( ci != array.end() ) {
79 /// Controller con(probeResult);
80 /// con.OpenMode(Controller::Desktop);
81 /// std::vector<Contact> contactList;
82 /// StoreContact storage(contactList);
83 /// RecordBuilder<Contact, StoreContact> builder(storage);
84 /// con.SaveDatabase(con.GetDBID("Address Book"), builder);
87 template <class Record
, class Storage
>
88 class RecordBuilder
: public Builder
94 /// Constructor that references an externally managed storage object.
95 RecordBuilder(Storage
&storage
)
96 : m_store(&storage
), m_owned(false) {}
98 /// Constructor that references a locally managed storage object.
99 /// The pointer passed in will be stored, and freed when this class
100 /// is destroyed. It is safe to call this constructor with
101 /// a 'new'ly created storage object.
102 RecordBuilder(Storage
*storage
)
103 : m_store(storage
), m_owned(true) {}
111 /// Functor member called by Controller::SaveDatabase() during
113 virtual bool operator()(Data
&data
, unsigned int databaseId
)
116 if( !(*m_storage
)(rec
) )
118 rec
.Build(data
, databaseId
);