3 /// Compile-time test to make sure all FieldHandle<> templates
4 /// and classes are complete.
8 Copyright (C) 2012-2013, 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 template <class RecordT
>
63 FieldHandler(const RecordT
&obj
)
68 void operator()(EnumFieldBase
<RecordT
> *ep
,
69 const FieldIdentity
&id
) const
71 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
72 << ep
->GetName(ep
->GetValue(m_rec
))
73 << " (" << ep
->GetValue(m_rec
) << ")"
76 DumpEnumConstants(ep
);
79 void operator()(typename FieldHandle
<RecordT
>::PostalPointer pp
,
80 const FieldIdentity
&id
) const
82 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
83 << m_rec
.*(pp
.m_PostalAddress
).*(pp
.m_PostalField
)
88 template <class TypeT
>
89 void operator()(TypeT
RecordT::* mp
, const FieldIdentity
&id
) const
91 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
97 class VirtualFieldHandler
: public FieldValueHandlerBase
100 /// For type std::string
101 virtual void operator()(const std::string
&v
,
102 const FieldIdentity
&id
) const
104 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
108 /// For type EmailAddressList
109 virtual void operator()(const EmailAddressList
&v
,
110 const FieldIdentity
&id
) const
112 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
116 /// For type Barry::TimeT
117 virtual void operator()(const Barry::TimeT
&v
,
118 const FieldIdentity
&id
) const
120 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
125 virtual void operator()(const uint8_t &v
,
126 const FieldIdentity
&id
) const
128 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
129 << (unsigned int) v
<< endl
;
132 /// For type uint16_t
133 virtual void operator()(const uint16_t &v
,
134 const FieldIdentity
&id
) const
136 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
140 /// For type uint32_t
141 virtual void operator()(const uint32_t &v
,
142 const FieldIdentity
&id
) const
144 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
148 /// For type uint64_t
149 virtual void operator()(const uint64_t &v
,
150 const FieldIdentity
&id
) const
152 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
157 virtual void operator()(const bool &v
,
158 const FieldIdentity
&id
) const
160 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
165 virtual void operator()(const int32_t &v
,
166 const FieldIdentity
&id
) const
168 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
172 /// For type EmailList
173 virtual void operator()(const EmailList
&v
,
174 const FieldIdentity
&id
) const
176 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
181 virtual void operator()(const Date
&v
,
182 const FieldIdentity
&id
) const
184 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
188 /// For type CategoryList
189 virtual void operator()(const CategoryList
&v
,
190 const FieldIdentity
&id
) const
192 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
196 /// For type PostalAddress
197 virtual void operator()(const PostalAddress
&v
,
198 const FieldIdentity
&id
) const
200 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
204 /// For type UnknownsType
205 virtual void operator()(const UnknownsType
&v
,
206 const FieldIdentity
&id
) const
208 cout
<< id
.DisplayName
<< " (" << id
.Name
<< "): "
218 contact
.RecordId
= 100000;
219 contact
.EmailAddresses
.push_back("cdfrey@foursquare.net");
220 contact
.EmailAddresses
.push_back("cdfrey@netdirect.ca");
221 contact
.Phone
= "519-555-1212";
222 contact
.Fax
= "no fax";
223 contact
.HomeFax
= "home fax";
224 contact
.WorkPhone
= "work 51235";
225 contact
.WorkPhone2
= "work2 12351234";
226 contact
.HomePhone
= "home 12341234";
227 contact
.HomePhone2
= "home2 4234234";
228 contact
.MobilePhone
= "mobile 88888";
229 contact
.MobilePhone2
= "mobile2 23424";
230 contact
.Pager
= "pager 123412342";
231 contact
.PIN
= "PIN 1234";
232 contact
.Radio
= "CBC";
233 contact
.OtherPhone
= "other 12341234";
234 contact
.FirstName
= "Chris";
235 contact
.LastName
= "Frey";
236 contact
.Company
= "Company naaaaaaaaaaame";
237 contact
.DefaultCommunicationsMethod
= "E";
238 contact
.JobTitle
= "Programmer";
239 contact
.PublicKey
= "seeeecrit";
240 contact
.URL
= "http://netdirect.ca/~cdfrey/";
241 contact
.Prefix
= "nothing";
242 contact
.Notes
= "This is a notes field that can hold mega data";
243 contact
.UserDefined1
= "user 1";
244 contact
.UserDefined2
= "user 2";
245 contact
.UserDefined3
= "user 3";
246 contact
.UserDefined4
= "user 4";
247 contact
.Image
= "no image available";
248 contact
.Nickname
= "LRU";
250 d
.FromYYYYMMDD("20120101");
251 contact
.Birthday
= d
;
252 contact
.WorkAddress
.Address1
= "work address 1";
253 contact
.WorkAddress
.Address2
= "work address 2";
254 contact
.WorkAddress
.Address3
= "work address 3";
255 contact
.WorkAddress
.City
= "work city";
256 contact
.WorkAddress
.Province
= "work Province";
257 contact
.WorkAddress
.PostalCode
= "work PostalCode";
258 contact
.WorkAddress
.Country
= "work Country";
259 contact
.HomeAddress
.Address1
= "home address 1";
260 contact
.HomeAddress
.Address2
= "home address 2";
261 contact
.HomeAddress
.Address3
= "home address 3";
262 contact
.HomeAddress
.City
= "home city";
263 contact
.HomeAddress
.Province
= "home Province";
264 contact
.HomeAddress
.PostalCode
= "home PostalCode";
265 contact
.HomeAddress
.Country
= "home Country";
266 contact
.Categories
.push_back("office");
267 contact
.Categories
.push_back("entertainment");
269 FieldHandler
<Contact
> handler(contact
);
270 ForEachField(Contact::GetFieldHandles(), handler
);
272 cout
<< "================================================" << endl
;
274 VirtualFieldHandler vhandler
;
275 ForEachFieldValue(contact
, vhandler
);
280 VirtualFieldHandler vhandler
;
282 cout
<< "All parsers......" << endl
;
285 #define HANDLE_PARSER(tname) \
286 cout << "Record: " << #tname << endl; \
287 cout << "===================================================" << endl;\
289 FieldHandler<tname> fh##tname(obj##tname); \
290 cout << "By member pointer..." << endl; \
291 ForEachField(tname::GetFieldHandles(), fh##tname); \
292 cout << "\nBy value..." << endl; \
293 ForEachFieldValue(obj##tname, vhandler); \
296 ALL_KNOWN_PARSER_TYPES
299 cout
<< "All builders........" << endl
;
301 #undef HANDLE_BUILDER
302 #define HANDLE_BUILDER(tname) \
303 cout << "Record: " << #tname << endl; \
304 cout << "===================================================" << endl;\
306 FieldHandler<tname> bfh##tname(bobj##tname); \
307 cout << "By member pointer..." << endl; \
308 ForEachField(tname::GetFieldHandles(), bfh##tname); \
309 cout << "\nBy value..." << endl; \
310 ForEachFieldValue(bobj##tname, vhandler); \
313 ALL_KNOWN_BUILDER_TYPES