3 /// Compile-time test to make sure all FieldHandle<> templates
4 /// and classes are complete.
8 Copyright (C) 2012, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <barry/barry.h>
27 using namespace Barry
;
29 void DumpId(const FieldIdentity
&id
)
31 cout
<< " sub = " << (id
.HasSubfields
? "true" : "false")
33 << (id
.ParentName
? id
.ParentName
: "NULL") << endl
;
34 cout
<< " FieldTypeCode = " << id
.FieldTypeCode
<< endl
;
35 cout
<< " Ldif = " << (id
.Ldif
? id
.Ldif
: "NULL")
37 << (id
.ObjectClass
? id
.ObjectClass
: "NULL")
39 cout
<< " Iconv = " << (id
.IconvNeeded
? "true" : "false")
43 void DumpEnumConstants(const EnumConstants
*ec
)
45 cout
<< " Available constants:" << endl
;
47 EnumConstants::EnumConstantList::const_iterator
48 b
= ec
->GetConstantList().begin(),
49 e
= ec
->GetConstantList().end();
50 for( ; b
!= e
; ++b
) {
51 cout
<< " " << b
->DisplayName
52 << " (" << b
->Name
<< ")"
53 << " = " << b
->Value
<< endl
;
58 std::ostream
& operator<<(std::ostream
&os
, const EmailList
&el
)
61 for( EmailList::const_iterator b
= el
.begin(); b
!= el
.end(); ++b
) {
72 template <class RecordT
>
77 FieldHandler(const RecordT
&obj
)
82 void operator()(EnumFieldBase
<RecordT
> *ep
,
83 const FieldIdentity
&id
) const
85 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
86 << ep
->GetName(ep
->GetValue(m_rec
))
87 << " (" << ep
->GetValue(m_rec
) << ")"
90 DumpEnumConstants(ep
);
93 void operator()(typename FieldHandle
<RecordT
>::PostalPointer pp
,
94 const FieldIdentity
&id
) const
96 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
97 << m_rec
.*(pp
.m_PostalAddress
).*(pp
.m_PostalField
)
102 template <class TypeT
>
103 void operator()(TypeT
RecordT::* mp
, const FieldIdentity
&id
) const
105 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
106 << m_rec
.*mp
<< endl
;
111 class VirtualFieldHandler
: public FieldValueHandlerBase
114 /// For type std::string
115 virtual void operator()(const std::string
&v
,
116 const FieldIdentity
&id
) const
118 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
122 /// For type EmailAddressList
123 virtual void operator()(const EmailAddressList
&v
,
124 const FieldIdentity
&id
) const
126 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
131 virtual void operator()(const time_t &v
,
132 const FieldIdentity
&id
) const
134 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
139 virtual void operator()(const uint8_t &v
,
140 const FieldIdentity
&id
) const
142 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
143 << (unsigned int) v
<< endl
;
146 /// For type uint16_t
147 virtual void operator()(const uint16_t &v
,
148 const FieldIdentity
&id
) const
150 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
154 /// For type uint32_t
155 virtual void operator()(const uint32_t &v
,
156 const FieldIdentity
&id
) const
158 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
162 /// For type uint64_t
163 virtual void operator()(const uint64_t &v
,
164 const FieldIdentity
&id
) const
166 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
171 virtual void operator()(const bool &v
,
172 const FieldIdentity
&id
) const
174 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
179 virtual void operator()(const int32_t &v
,
180 const FieldIdentity
&id
) const
182 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
186 /// For type EmailList
187 virtual void operator()(const EmailList
&v
,
188 const FieldIdentity
&id
) const
190 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
195 virtual void operator()(const Date
&v
,
196 const FieldIdentity
&id
) const
198 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
202 /// For type CategoryList
203 virtual void operator()(const CategoryList
&v
,
204 const FieldIdentity
&id
) const
206 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
210 /// For type PostalAddress
211 virtual void operator()(const PostalAddress
&v
,
212 const FieldIdentity
&id
) const
214 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
218 /// For type UnknownsType
219 virtual void operator()(const UnknownsType
&v
,
220 const FieldIdentity
&id
) const
222 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
232 contact
.RecordId
= 100000;
233 contact
.EmailAddresses
.push_back("cdfrey@foursquare.net");
234 contact
.EmailAddresses
.push_back("cdfrey@netdirect.ca");
235 contact
.Phone
= "519-555-1212";
236 contact
.Fax
= "no fax";
237 contact
.HomeFax
= "home fax";
238 contact
.WorkPhone
= "work 51235";
239 contact
.WorkPhone2
= "work2 12351234";
240 contact
.HomePhone
= "home 12341234";
241 contact
.HomePhone2
= "home2 4234234";
242 contact
.MobilePhone
= "mobile 88888";
243 contact
.MobilePhone2
= "mobile2 23424";
244 contact
.Pager
= "pager 123412342";
245 contact
.PIN
= "PIN 1234";
246 contact
.Radio
= "CBC";
247 contact
.OtherPhone
= "other 12341234";
248 contact
.FirstName
= "Chris";
249 contact
.LastName
= "Frey";
250 contact
.Company
= "Company naaaaaaaaaaame";
251 contact
.DefaultCommunicationsMethod
= "E";
252 contact
.JobTitle
= "Programmer";
253 contact
.PublicKey
= "seeeecrit";
254 contact
.URL
= "http://netdirect.ca/~cdfrey/";
255 contact
.Prefix
= "nothing";
256 contact
.Notes
= "This is a notes field that can hold mega data";
257 contact
.UserDefined1
= "user 1";
258 contact
.UserDefined2
= "user 2";
259 contact
.UserDefined3
= "user 3";
260 contact
.UserDefined4
= "user 4";
261 contact
.Image
= "no image available";
262 contact
.Nickname
= "LRU";
264 d
.FromYYYYMMDD("20120101");
265 contact
.Birthday
= d
;
266 contact
.WorkAddress
.Address1
= "work address 1";
267 contact
.WorkAddress
.Address2
= "work address 2";
268 contact
.WorkAddress
.Address3
= "work address 3";
269 contact
.WorkAddress
.City
= "work city";
270 contact
.WorkAddress
.Province
= "work Province";
271 contact
.WorkAddress
.PostalCode
= "work PostalCode";
272 contact
.WorkAddress
.Country
= "work Country";
273 contact
.HomeAddress
.Address1
= "home address 1";
274 contact
.HomeAddress
.Address2
= "home address 2";
275 contact
.HomeAddress
.Address3
= "home address 3";
276 contact
.HomeAddress
.City
= "home city";
277 contact
.HomeAddress
.Province
= "home Province";
278 contact
.HomeAddress
.PostalCode
= "home PostalCode";
279 contact
.HomeAddress
.Country
= "home Country";
280 contact
.Categories
.push_back("office");
281 contact
.Categories
.push_back("entertainment");
283 FieldHandler
<Contact
> handler(contact
);
284 ForEachField(Contact::GetFieldHandles(), handler
);
286 cout
<< "================================================" << endl
;
288 VirtualFieldHandler vhandler
;
289 ForEachFieldValue(contact
, vhandler
);
294 VirtualFieldHandler vhandler
;
296 cout
<< "All parsers......" << endl
;
299 #define HANDLE_PARSER(tname) \
300 cout << "Record: " << #tname << endl; \
301 cout << "===================================================" << endl;\
303 FieldHandler<tname> fh##tname(obj##tname); \
304 cout << "By member pointer..." << endl; \
305 ForEachField(tname::GetFieldHandles(), fh##tname); \
306 cout << "\nBy value..." << endl; \
307 ForEachFieldValue(obj##tname, vhandler); \
310 ALL_KNOWN_PARSER_TYPES
313 cout
<< "All builders........" << endl
;
315 #undef HANDLE_BUILDER
316 #define HANDLE_BUILDER(tname) \
317 cout << "Record: " << #tname << endl; \
318 cout << "===================================================" << endl;\
320 FieldHandler<tname> bfh##tname(bobj##tname); \
321 cout << "By member pointer..." << endl; \
322 ForEachField(tname::GetFieldHandles(), bfh##tname); \
323 cout << "\nBy value..." << endl; \
324 ForEachFieldValue(bobj##tname, vhandler); \
327 ALL_KNOWN_BUILDER_TYPES