Revise boolean attribute methods to handle defaults.
[shibboleth/cpp-xmltooling.git] / xmltooling / base.h
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file base.h
19  * 
20  * Base header file definitions
21  * Must be included prior to including any other header
22  */
23
24 #ifndef __xmltooling_base_h__
25 #define __xmltooling_base_h__
26
27 #if defined (_MSC_VER) || defined(__BORLANDC__)
28   #include <xmltooling/config_pub_win32.h>
29 #else
30   #include <xmltooling/config_pub.h>
31 #endif
32
33 // Windows and GCC4 Symbol Visibility Macros
34 #ifdef WIN32
35   #define XMLTOOL_IMPORT __declspec(dllimport)
36   #define XMLTOOL_EXPORT __declspec(dllexport)
37   #define XMLTOOL_DLLLOCAL
38   #define XMLTOOL_DLLPUBLIC
39 #else
40   #define XMLTOOL_IMPORT
41   #ifdef GCC_HASCLASSVISIBILITY
42     #define XMLTOOL_EXPORT __attribute__ ((visibility("default")))
43     #define XMLTOOL_DLLLOCAL __attribute__ ((visibility("hidden")))
44     #define XMLTOOL_DLLPUBLIC __attribute__ ((visibility("default")))
45   #else
46     #define XMLTOOL_EXPORT
47     #define XMLTOOL_DLLLOCAL
48     #define XMLTOOL_DLLPUBLIC
49   #endif
50 #endif
51
52 // Define XMLTOOL_API for DLL builds
53 #ifdef XMLTOOLING_EXPORTS
54   #define XMLTOOL_API XMLTOOL_EXPORT
55 #else
56   #define XMLTOOL_API XMLTOOL_IMPORT
57 #endif
58
59 // Throwable classes must always be visible on GCC in all binaries
60 #ifdef WIN32
61   #define XMLTOOL_EXCEPTIONAPI(api) api
62 #elif defined(GCC_HASCLASSVISIBILITY)
63   #define XMLTOOL_EXCEPTIONAPI(api) XMLTOOL_EXPORT
64 #else
65   #define XMLTOOL_EXCEPTIONAPI(api)
66 #endif
67
68 #ifdef _MSC_VER
69     #define XMLTOOLING_DOXYGEN(desc) /##** desc */
70 #else
71     #define XMLTOOLING_DOXYGEN(desc)
72 #endif
73
74 /**
75  * Blocks copy c'tor and assignment operator for a class.
76  */
77 #define MAKE_NONCOPYABLE(type) \
78     private: \
79         type(const type&); \
80         type& operator=(const type&);
81
82 #ifndef DOXYGEN_SKIP
83 #ifndef NULL
84 #define NULL    0
85 #endif
86 #define UNICODE_LITERAL_1(a) {chLatin_##a, chNull}
87 #define UNICODE_LITERAL_2(a,b) {chLatin_##a, chLatin_##b, chNull}
88 #define UNICODE_LITERAL_3(a,b,c) {chLatin_##a, chLatin_##b, chLatin_##c, chNull}
89 #define UNICODE_LITERAL_4(a,b,c,d) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chNull}
90 #define UNICODE_LITERAL_5(a,b,c,d,e) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chNull}
91 #define UNICODE_LITERAL_6(a,b,c,d,e,f) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chNull}
92 #define UNICODE_LITERAL_7(a,b,c,d,e,f,g) \
93     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chNull}
94 #define UNICODE_LITERAL_8(a,b,c,d,e,f,g,h) \
95     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chNull}
96 #define UNICODE_LITERAL_9(a,b,c,d,e,f,g,h,i) \
97     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, chNull}
98 #define UNICODE_LITERAL_10(a,b,c,d,e,f,g,h,i,j) \
99     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
100         chLatin_##j, chNull}
101 #define UNICODE_LITERAL_11(a,b,c,d,e,f,g,h,i,j,k) \
102     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
103         chLatin_##j, chLatin_##k, chNull}
104 #define UNICODE_LITERAL_12(a,b,c,d,e,f,g,h,i,j,k,l) \
105     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
106         chLatin_##j, chLatin_##k, chLatin_##l, chNull}
107 #define UNICODE_LITERAL_13(a,b,c,d,e,f,g,h,i,j,k,l,m) \
108     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
109         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chNull}
110 #define UNICODE_LITERAL_14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) \
111     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
112         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chNull}
113 #define UNICODE_LITERAL_15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \
114     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
115         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chNull}
116 #define UNICODE_LITERAL_16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
117     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
118         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chNull}
119 #define UNICODE_LITERAL_17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) \
120     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
121         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chNull}
122 #define UNICODE_LITERAL_18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) \
123     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
124         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, chNull}
125 #define UNICODE_LITERAL_19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) \
126     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
127         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
128         chLatin_##s, chNull}
129 #define UNICODE_LITERAL_20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) \
130     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
131         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
132         chLatin_##s, chLatin_##t, chNull}
133 #define UNICODE_LITERAL_21(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) \
134     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
135         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
136         chLatin_##s, chLatin_##t, chLatin_##u, chNull}
137 #define UNICODE_LITERAL_22(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v) \
138     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
139         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
140         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chNull}
141 #define UNICODE_LITERAL_23(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) \
142     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
143         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
144         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chNull}
145 #define UNICODE_LITERAL_24(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x) \
146     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
147         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
148         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chNull}
149 #define UNICODE_LITERAL_25(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y) \
150     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
151         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
152         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chNull}
153 #define UNICODE_LITERAL_26(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) \
154     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
155         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
156         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, chNull}
157 #define UNICODE_LITERAL_27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa) \
158     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
159         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
160         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
161         chLatin_##aa, chNull}
162 #define UNICODE_LITERAL_28(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb) \
163     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
164         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
165         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
166         chLatin_##aa, chLatin_##bb, chNull}
167 #define UNICODE_LITERAL_29(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc) \
168     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
169         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
170         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
171         chLatin_##aa, chLatin_##bb, chLatin_##cc, chNull}
172 #define UNICODE_LITERAL_30(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd) \
173     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
174         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
175         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
176         chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chNull}
177 #define UNICODE_LITERAL_31(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee) \
178     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
179         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
180         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
181         chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chNull}
182 #define UNICODE_LITERAL_32(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff) \
183     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
184         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
185         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
186         chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chLatin_##ff, chNull}
187 #define UNICODE_LITERAL_33(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg) \
188     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
189         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
190         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
191         chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chLatin_##ff, chLatin_##gg, chNull}
192 #define UNICODE_LITERAL_34(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh) \
193     {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \
194         chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \
195         chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, \
196         chLatin_##aa, chLatin_##bb, chLatin_##cc, chLatin_##dd, chLatin_##ee, chLatin_##ff, chLatin_##gg, chLatin_##hh, chNull}
197 #endif /* DOXYGEN_SKIP */
198
199 /**
200  * Begins the declaration of an XMLObject specialization for an abstract element/type.
201  * Basic boilerplate includes a protected constructor, empty virtual destructor,
202  * and Unicode constants for the default associated element's name and prefix.
203  * 
204  * @param linkage   linkage specifier for the class
205  * @param cname     the name of the class to declare
206  * @param base      the base class to derive from using public virtual inheritance
207  * @param desc      documentation comment for class
208  */
209 #define DECL_XMLOBJECT_ABSTRACT(linkage,cname,base,desc) \
210     XMLTOOLING_DOXYGEN(desc) \
211     class linkage cname : public virtual base { \
212     protected: \
213         cname() {} \
214     public: \
215         virtual ~cname() {} \
216         XMLTOOLING_DOXYGEN(Element local name) \
217         static const XMLCh LOCAL_NAME[]; \
218     }
219
220 /**
221  * Begins the declaration of an XMLObject specialization.
222  * Basic boilerplate includes a protected constructor, empty virtual destructor,
223  * and Unicode constants for the default associated element's name and prefix.
224  * 
225  * @param linkage   linkage specifier for the class
226  * @param cname     the name of the class to declare
227  * @param base      the base class to derive from using public virtual inheritance
228  * @param desc      documentation comment for class
229  */
230 #define BEGIN_XMLOBJECT(linkage,cname,base,desc) \
231     XMLTOOLING_DOXYGEN(desc) \
232     class linkage cname : public virtual base { \
233     protected: \
234         cname() {} \
235     public: \
236         virtual ~cname() {} \
237         XMLTOOLING_DOXYGEN(Type-specific clone method.) \
238         virtual cname* clone##cname() const=0; \
239         XMLTOOLING_DOXYGEN(Element local name) \
240         static const XMLCh LOCAL_NAME[]
241
242 /**
243  * Begins the declaration of an XMLObject specialization with two base classes.
244  * Basic boilerplate includes a protected constructor, empty virtual destructor,
245  * and Unicode constants for the default associated element's name and prefix.
246  * 
247  * @param linkage   linkage specifier for the class
248  * @param cname     the name of the class to declare
249  * @param base      the first base class to derive from using public virtual inheritance
250  * @param base2     the second base class to derive from using public virtual inheritance
251  * @param desc      documentation comment for class
252  */
253 #define BEGIN_XMLOBJECT2(linkage,cname,base,base2,desc) \
254     XMLTOOLING_DOXYGEN(desc) \
255     class linkage cname : public virtual base, public virtual base2 { \
256     protected: \
257         cname() {} \
258     public: \
259         virtual ~cname() {} \
260         XMLTOOLING_DOXYGEN(Type-specific clone method.) \
261         virtual cname* clone##cname() const=0; \
262         XMLTOOLING_DOXYGEN(Element local name) \
263         static const XMLCh LOCAL_NAME[]
264
265 /**
266  * Begins the declaration of an XMLObject specialization with three base classes.
267  * Basic boilerplate includes a protected constructor, empty virtual destructor,
268  * and Unicode constants for the default associated element's name and prefix.
269  * 
270  * @param linkage   linkage specifier for the class
271  * @param cname     the name of the class to declare
272  * @param base      the first base class to derive from using public virtual inheritance
273  * @param base2     the second base class to derive from using public virtual inheritance
274  * @param base3     the third base class to derive from using public virtual inheritance
275  * @param desc      documentation comment for class
276  */
277 #define BEGIN_XMLOBJECT3(linkage,cname,base,base2,base3,desc) \
278     XMLTOOLING_DOXYGEN(desc) \
279     class linkage cname : public virtual base, public virtual base2, public virtual base3 { \
280     protected: \
281         cname() {} \
282     public: \
283         virtual ~cname() {} \
284         XMLTOOLING_DOXYGEN(Type-specific clone method.) \
285         virtual cname* clone##cname() const=0; \
286         XMLTOOLING_DOXYGEN(Element local name) \
287         static const XMLCh LOCAL_NAME[]
288
289 /**
290  * Begins the declaration of an XMLObject specialization with four base classes.
291  * Basic boilerplate includes a protected constructor, empty virtual destructor,
292  * and Unicode constants for the default associated element's name and prefix.
293  * 
294  * @param linkage   linkage specifier for the class
295  * @param cname     the name of the class to declare
296  * @param base      the first base class to derive from using public virtual inheritance
297  * @param base2     the second base class to derive from using public virtual inheritance
298  * @param base3     the third base class to derive from using public virtual inheritance
299  * @param base4     the fourth base class to derive from using public virtual inheritance
300  * @param desc      documentation comment for class
301  */
302 #define BEGIN_XMLOBJECT4(linkage,cname,base,base2,base3,base4,desc) \
303     XMLTOOLING_DOXYGEN(desc) \
304     class linkage cname : public virtual base, public virtual base2, public virtual base3, public virtual base4 { \
305     protected: \
306         cname() {} \
307     public: \
308         virtual ~cname() {} \
309         XMLTOOLING_DOXYGEN(Type-specific clone method.) \
310         virtual cname* clone##cname() const=0; \
311         XMLTOOLING_DOXYGEN(Element local name) \
312         static const XMLCh LOCAL_NAME[]
313
314 /**
315  * Ends the declaration of an XMLObject specialization.
316  */
317 #define END_XMLOBJECT }
318
319 /**
320  * Declares abstract get/set methods for a typed XML attribute.
321  * 
322  * @param proper    the proper name of the attribute
323  * @param upcased   the upcased name of the attribute
324  * @param type      the attribute's data type
325  */
326 #define DECL_XMLOBJECT_ATTRIB(proper,upcased,type) \
327     public: \
328         XMLTOOLING_DOXYGEN(proper attribute name) \
329         static const XMLCh upcased##_ATTRIB_NAME[]; \
330         XMLTOOLING_DOXYGEN(Returns the proper attribute.) \
331         virtual const type* get##proper() const=0; \
332         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
333         virtual void set##proper(const type* proper)=0
334
335 /**
336  * Declares abstract get/set methods for a string XML attribute.
337  * 
338  * @param proper    the proper name of the attribute
339  * @param upcased   the upcased name of the attribute
340  */
341 #define DECL_STRING_ATTRIB(proper,upcased) \
342     DECL_XMLOBJECT_ATTRIB(proper,upcased,XMLCh)
343
344 /**
345  * Declares abstract get/set methods for a string XML attribute.
346  * 
347  * @param proper    the proper name of the attribute
348  * @param upcased   the upcased name of the attribute
349  */
350 #define DECL_DATETIME_ATTRIB(proper,upcased) \
351     DECL_XMLOBJECT_ATTRIB(proper,upcased,xmltooling::DateTime); \
352     XMLTOOLING_DOXYGEN(Returns the proper attribute in epoch form.) \
353     virtual time_t get##proper##Epoch() const=0; \
354     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
355     virtual void set##proper(time_t proper)=0; \
356     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
357     virtual void set##proper(const XMLCh* proper)=0
358
359 /**
360  * Declares abstract get/set methods for an integer XML attribute.
361  * 
362  * @param proper    the proper name of the attribute
363  * @param upcased   the upcased name of the attribute
364  */
365 #define DECL_INTEGER_ATTRIB(proper,upcased) \
366     public: \
367         XMLTOOLING_DOXYGEN(proper attribute name) \
368         static const XMLCh upcased##_ATTRIB_NAME[]; \
369         XMLTOOLING_DOXYGEN(Returns the proper attribute after a NULL indicator.) \
370         virtual std::pair<bool,int> get##proper() const=0; \
371         XMLTOOLING_DOXYGEN(Sets the proper attribute using a string value.) \
372         virtual void set##proper(const XMLCh* proper)=0; \
373         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
374         virtual void set##proper(int proper)=0
375
376 /**
377  * Declares abstract get/set methods for a boolean XML attribute.
378  * 
379  * @param proper    the proper name of the attribute
380  * @param upcased   the upcased name of the attribute
381  * @param def       the default/presumed value, if no explicit value has been set
382  */
383 #define DECL_BOOLEAN_ATTRIB(proper,upcased,def) \
384     public: \
385         XMLTOOLING_DOXYGEN(proper attribute name) \
386         static const XMLCh upcased##_ATTRIB_NAME[]; \
387         XMLTOOLING_DOXYGEN(Returns the proper attribute or def if not set.) \
388         bool proper() const { \
389             switch (get##proper()) { \
390                 case xmltooling::XMLConstants::XML_BOOL_TRUE: \
391                 case xmltooling::XMLConstants::XML_BOOL_ONE: \
392                     return true; \
393                 case xmltooling::XMLConstants::XML_BOOL_FALSE: \
394                 case xmltooling::XMLConstants::XML_BOOL_ZERO: \
395                     return false; \
396                 default: \
397                     return def; \
398             } \
399         } \
400         XMLTOOLING_DOXYGEN(Returns the proper attribute as an explicit enumerated value.) \
401         virtual xmltooling::XMLConstants::xmltooling_bool_t get##proper() const=0; \
402         XMLTOOLING_DOXYGEN(Sets the proper attribute using an enumerated value.) \
403         virtual void proper(xmltooling::XMLConstants::xmltooling_bool_t value)=0; \
404         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
405         void proper(bool value) { \
406             proper(value ? xmltooling::XMLConstants::XML_BOOL_ONE : xmltooling::XMLConstants::XML_BOOL_ZERO); \
407         } \
408         XMLTOOLING_DOXYGEN(Sets the proper attribute using a string constant.) \
409         void set##proper(const XMLCh* value) { \
410             if (value) { \
411                 switch (*value) { \
412                     case chLatin_t: \
413                         proper(xmltooling::XMLConstants::XML_BOOL_TRUE); \
414                         break; \
415                     case chLatin_f: \
416                         proper(xmltooling::XMLConstants::XML_BOOL_FALSE); \
417                         break; \
418                     case chDigit_1: \
419                         proper(xmltooling::XMLConstants::XML_BOOL_ONE); \
420                         break; \
421                     case chDigit_0: \
422                         proper(xmltooling::XMLConstants::XML_BOOL_ZERO); \
423                         break; \
424                     default: \
425                         proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
426                 } \
427             } \
428             else \
429                 proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
430         }
431
432 /**
433  * Implements get/set methods and a private member for a typed XML attribute.
434  * 
435  * @param proper    the proper name of the attribute
436  * @param type      the attribute's data type
437  */
438 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
439     protected: \
440         type* m_##proper; \
441     public: \
442         const type* get##proper() const { \
443             return m_##proper; \
444         } \
445         void set##proper(const type* proper) { \
446             m_##proper = prepareForAssignment(m_##proper,proper); \
447         }
448
449 /**
450  * Implements get/set methods and a private member for a string XML attribute.
451  * 
452  * @param proper    the proper name of the attribute
453  */
454 #define IMPL_STRING_ATTRIB(proper) \
455     IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
456
457 /**
458  * Implements get/set methods and a private member for a DateTime XML attribute.
459  * 
460  * @param proper    the proper name of the attribute
461  * @param fallback  epoch to return when attribute is NULL
462  */
463 #define IMPL_DATETIME_ATTRIB(proper,fallback) \
464     protected: \
465         DateTime* m_##proper; \
466         time_t m_##proper##Epoch; \
467     public: \
468         const DateTime* get##proper() const { \
469             return m_##proper; \
470         } \
471         time_t get##proper##Epoch() const { \
472             return m_##proper ? m_##proper##Epoch : fallback; \
473         } \
474         void set##proper(const DateTime* proper) { \
475             m_##proper = prepareForAssignment(m_##proper,proper); \
476             if (m_##proper) \
477                 m_##proper##Epoch=m_##proper->getEpoch(); \
478         } \
479         void set##proper(time_t proper) { \
480             m_##proper = prepareForAssignment(m_##proper,proper); \
481             m_##proper##Epoch = proper; \
482         } \
483         void set##proper(const XMLCh* proper) { \
484             m_##proper = prepareForAssignment(m_##proper,proper); \
485             if (m_##proper) \
486                 m_##proper##Epoch=m_##proper->getEpoch(); \
487         }
488
489 /**
490  * Implements get/set methods and a private member for an integer XML attribute.
491  * 
492  * @param proper    the proper name of the attribute
493  */
494 #define IMPL_INTEGER_ATTRIB(proper) \
495     protected: \
496         XMLCh* m_##proper; \
497     public: \
498         pair<bool,int> get##proper() const { \
499             return make_pair((m_##proper!=NULL),(m_##proper!=NULL ? XMLString::parseInt(m_##proper): 0)); \
500         } \
501         void set##proper(const XMLCh* proper) { \
502             m_##proper = prepareForAssignment(m_##proper,proper); \
503         } \
504         void set##proper(int proper) { \
505             char buf##proper[64]; \
506             sprintf(buf##proper,"%d",proper); \
507             auto_ptr_XMLCh wide##proper(buf##proper); \
508             set##proper(wide##proper.get()); \
509         }
510
511 /**
512  * Implements get/set methods and a private member for a boolean XML attribute.
513  * 
514  * @param proper    the proper name of the attribute
515  */
516 #define IMPL_BOOLEAN_ATTRIB(proper) \
517     protected: \
518         XMLConstants::xmltooling_bool_t m_##proper; \
519     public: \
520         XMLConstants::xmltooling_bool_t get##proper() const { \
521             return m_##proper; \
522         } \
523         void proper(XMLConstants::xmltooling_bool_t value) { \
524             if (m_##proper != value) { \
525                 releaseThisandParentDOM(); \
526                 m_##proper = value; \
527             } \
528         }
529
530 /**
531  * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
532  * 
533  * @param proper    the proper name of the child type
534  * @param ns        the C++ namespace for the type
535  */
536 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
537     public: \
538         XMLTOOLING_DOXYGEN(Returns the proper child.) \
539         virtual ns::proper* get##proper() const=0; \
540         XMLTOOLING_DOXYGEN(Sets the proper child.) \
541         virtual void set##proper(ns::proper* child)=0
542
543 /**
544  * Declares abstract get/set methods for a typed XML child object.
545  * 
546  * @param proper    the proper name of the child type
547  */
548 #define DECL_TYPED_CHILD(proper) \
549     public: \
550         XMLTOOLING_DOXYGEN(Returns the proper child.) \
551         virtual proper* get##proper() const=0; \
552         XMLTOOLING_DOXYGEN(Sets the proper child.) \
553         virtual void set##proper(proper* child)=0
554
555 /**
556  * Declares abstract get/set methods for a generic XML child object.
557  * 
558  * @param proper    the proper name of the child
559  */
560 #define DECL_XMLOBJECT_CHILD(proper) \
561     public: \
562         XMLTOOLING_DOXYGEN(Returns the proper child.) \
563         virtual xmltooling::XMLObject* get##proper() const=0; \
564         XMLTOOLING_DOXYGEN(Sets the proper child.) \
565         virtual void set##proper(xmltooling::XMLObject* child)=0
566
567
568 /**
569  * Implements get/set methods and a private list iterator member for a typed XML child object.
570  * 
571  * @param proper    the proper name of the child type
572  */
573 #define IMPL_TYPED_CHILD(proper) \
574     protected: \
575         proper* m_##proper; \
576         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
577     public: \
578         proper* get##proper() const { \
579             return m_##proper; \
580         } \
581         void set##proper(proper* child) { \
582             prepareForAssignment(m_##proper,child); \
583             *m_pos_##proper = m_##proper = child; \
584         }
585
586 /**
587  * Implements get/set methods and a private list iterator member for
588  * a typed XML child object in a foreign namespace
589  * 
590  * @param proper    the proper name of the child type
591  * @param ns        the C++ namespace for the type
592  */
593 #define IMPL_TYPED_FOREIGN_CHILD(proper,ns) \
594     protected: \
595         ns::proper* m_##proper; \
596         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
597     public: \
598         ns::proper* get##proper() const { \
599             return m_##proper; \
600         } \
601         void set##proper(ns::proper* child) { \
602             prepareForAssignment(m_##proper,child); \
603             *m_pos_##proper = m_##proper = child; \
604         }
605
606 /**
607  * Implements get/set methods and a private list iterator member for a generic XML child object.
608  * 
609  * @param proper    the proper name of the child
610  */
611 #define IMPL_XMLOBJECT_CHILD(proper) \
612     protected: \
613         xmltooling::XMLObject* m_##proper; \
614         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
615     public: \
616         xmltooling::XMLObject* get##proper() const { \
617             return m_##proper; \
618         } \
619         void set##proper(xmltooling::XMLObject* child) { \
620             prepareForAssignment(m_##proper,child); \
621             *m_pos_##proper = m_##proper = child; \
622         }
623
624 /**
625  * Declares abstract get/set methods for a typed XML child collection.
626  * 
627  * @param proper    the proper name of the child type
628  */
629 #define DECL_TYPED_CHILDREN(proper) \
630     public: \
631         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
632         virtual VectorOf(proper) get##proper##s()=0; \
633         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
634         virtual const std::vector<proper*>& get##proper##s() const=0
635
636 /**
637  * Declares abstract get/set methods for a typed XML child collection in a foreign namespace.
638  * 
639  * @param proper    the proper name of the child type
640  * @param ns        the C++ namespace for the type
641  */
642 #define DECL_TYPED_FOREIGN_CHILDREN(proper,ns) \
643     public: \
644         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
645         virtual VectorOf(ns::proper) get##proper##s()=0; \
646         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
647         virtual const std::vector<ns::proper*>& get##proper##s() const=0
648
649 /**
650  * Declares abstract get/set methods for a generic XML child collection.
651  * 
652  * @param proper    the proper name of the child
653  */
654 #define DECL_XMLOBJECT_CHILDREN(proper) \
655     public: \
656         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
657         virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
658         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
659         virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
660
661 /**
662  * Implements get method and a private vector member for a typed XML child collection.
663  * 
664  * @param proper    the proper name of the child type
665  * @param fence     insertion fence for new objects of the child collection in backing list
666  */
667 #define IMPL_TYPED_CHILDREN(proper,fence) \
668     protected: \
669         std::vector<proper*> m_##proper##s; \
670     public: \
671         VectorOf(proper) get##proper##s() { \
672             return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
673         } \
674         const std::vector<proper*>& get##proper##s() const { \
675             return m_##proper##s; \
676         } 
677
678 /**
679  * Implements get method and a private vector member for a typed XML child collection
680  * in a foreign namespace.
681  * 
682  * @param proper    the proper name of the child type
683  * @param ns        the C++ namespace for the type
684  * @param fence     insertion fence for new objects of the child collection in backing list
685  */
686 #define IMPL_TYPED_FOREIGN_CHILDREN(proper,ns,fence) \
687     protected: \
688         std::vector<ns::proper*> m_##proper##s; \
689     public: \
690         VectorOf(ns::proper) get##proper##s() { \
691             return VectorOf(ns::proper)(this, m_##proper##s, &m_children, fence); \
692         } \
693         const std::vector<ns::proper*>& get##proper##s() const { \
694             return m_##proper##s; \
695         } 
696
697 /**
698  * Implements get method and a private vector member for a generic XML child collection.
699  * 
700  * @param proper    the proper name of the child
701  * @param fence     insertion fence for new objects of the child collection in backing list
702  */
703 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
704     protected: \
705         std::vector<xmltooling::XMLObject*> m_##proper##s; \
706     public: \
707         VectorOf(xmltooling::XMLObject) get##proper##s() { \
708             return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
709         } \
710         const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
711             return m_##proper##s; \
712         } 
713
714 /**
715  * Implements marshalling for a string attribute
716  * 
717  * @param proper        the proper name of the attribute
718  * @param ucase         the upcased name of the attribute
719  * @param namespaceURI  the XML namespace of the attribute
720  */
721 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
722     if (m_##proper) { \
723         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
724     }
725
726 /**
727  * Implements marshalling for a DateTime attribute
728  * 
729  * @param proper        the proper name of the attribute
730  * @param ucase         the upcased name of the attribute
731  * @param namespaceURI  the XML namespace of the attribute
732  */
733 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
734     if (m_##proper) { \
735         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper->getRawData()); \
736     }
737
738 /**
739  * Implements marshalling for an integer attribute
740  * 
741  * @param proper        the proper name of the attribute
742  * @param ucase         the upcased name of the attribute
743  * @param namespaceURI  the XML namespace of the attribute
744  */
745 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
746     if (m_##proper) { \
747         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
748     }
749
750 /**
751  * Implements marshalling for a boolean attribute
752  * 
753  * @param proper        the proper name of the attribute
754  * @param ucase         the upcased name of the attribute
755  * @param namespaceURI  the XML namespace of the attribute
756  */
757 #define MARSHALL_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
758     switch (m_##proper) { \
759         case XMLConstants::XML_BOOL_TRUE: \
760             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_TRUE); \
761             break; \
762         case XMLConstants::XML_BOOL_ONE: \
763             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ONE); \
764             break; \
765         case XMLConstants::XML_BOOL_FALSE: \
766             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_FALSE); \
767             break; \
768         case XMLConstants::XML_BOOL_ZERO: \
769             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ZERO); \
770             break; \
771         case XMLConstants::XML_BOOL_NULL: \
772             break; \
773     }
774
775 /**
776  * Implements marshalling for a QName attribute
777  * 
778  * @param proper        the proper name of the attribute
779  * @param ucase         the upcased name of the attribute
780  * @param namespaceURI  the XML namespace of the attribute
781  */
782 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
783     if (m_##proper) { \
784         auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \
785         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
786     }
787
788 /**
789  * Implements marshalling for an ID attribute
790  * 
791  * @param proper        the proper name of the attribute
792  * @param ucase         the upcased name of the attribute
793  * @param namespaceURI  the XML namespace of the attribute
794  */
795 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
796     if (m_##proper) { \
797         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
798         domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
799     }
800
801 /**
802  * Implements unmarshalling process branch for a string attribute
803  * 
804  * @param proper        the proper name of the attribute
805  * @param ucase         the upcased name of the attribute
806  * @param namespaceURI  the XML namespace of the attribute
807  */
808 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
809     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
810         set##proper(attribute->getValue()); \
811         return; \
812     }
813
814 /**
815  * Implements unmarshalling process branch for an ID attribute
816  * 
817  * @param proper        the proper name of the attribute
818  * @param ucase         the upcased name of the attribute
819  * @param namespaceURI  the XML namespace of the attribute
820  */
821 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
822     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
823         set##proper(attribute->getValue()); \
824         attribute->getOwnerElement()->setIdAttributeNode(attribute); \
825         return; \
826     }
827
828 /**
829  * Implements unmarshalling process branch for a DateTime attribute
830  * 
831  * @param proper        the proper name of the attribute
832  * @param ucase         the upcased name of the attribute
833  * @param namespaceURI  the XML namespace of the attribute
834  */
835 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
836     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
837
838 /**
839  * Implements unmarshalling process branch for a DateTime attribute
840  * 
841  * @param proper        the proper name of the attribute
842  * @param ucase         the upcased name of the attribute
843  * @param namespaceURI  the XML namespace of the attribute
844  */
845 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
846     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
847         set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
848         return; \
849     }
850
851 /**
852  * Implements unmarshalling process branch for an integer attribute
853  * 
854  * @param proper        the proper name of the attribute
855  * @param ucase         the upcased name of the attribute
856  * @param namespaceURI  the XML namespace of the attribute
857  */
858 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
859     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
860
861 /**
862  * Implements unmarshalling process branch for a boolean attribute
863  * 
864  * @param proper        the proper name of the attribute
865  * @param ucase         the upcased name of the attribute
866  * @param namespaceURI  the XML namespace of the attribute
867  */
868 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
869     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
870
871 /**
872  * Implements unmarshalling process branch for typed child collection element
873  * 
874  * @param proper        the proper name of the child type
875  * @param namespaceURI  the XML namespace of the child element
876  * @param force         bypass use of hint and just cast down to check child
877  */
878 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
879     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
880         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
881         if (typesafe) { \
882             get##proper##s().push_back(typesafe); \
883             return; \
884         } \
885     }
886
887 /**
888  * Implements unmarshalling process branch for typed child collection element
889  * in a foreign namespace.
890  * 
891  * @param proper        the proper name of the child type
892  * @param ns            the C++ namespace for the type
893  * @param namespaceURI  the XML namespace of the child element
894  * @param force         bypass use of hint and just cast down to check child
895  */
896 #define PROC_TYPED_FOREIGN_CHILDREN(proper,ns,namespaceURI,force) \
897     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
898         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
899         if (typesafe) { \
900             get##proper##s().push_back(typesafe); \
901             return; \
902         } \
903     }
904
905 /**
906  * Implements unmarshalling process branch for typed child singleton element
907  * 
908  * @param proper        the proper name of the child type
909  * @param namespaceURI  the XML namespace of the child element
910  * @param force         bypass use of hint and just cast down to check child
911  */
912 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
913     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
914         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
915         if (typesafe) { \
916             set##proper(typesafe); \
917             return; \
918         } \
919     }
920
921 /**
922  * Implements unmarshalling process branch for typed child singleton element
923  * in a foreign namespace.
924  * 
925  * @param proper        the proper name of the child type
926  * @param ns            the C++ namespace for the type
927  * @param namespaceURI  the XML namespace of the child element
928  * @param force         bypass use of hint and just cast down to check child
929  */
930 #define PROC_TYPED_FOREIGN_CHILD(proper,ns,namespaceURI,force) \
931     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
932         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
933         if (typesafe) { \
934             set##proper(typesafe); \
935             return; \
936         } \
937     }
938
939 /**
940  * Implements unmarshalling process branch for a generic child singleton element
941  * 
942  * @param proper        the proper name of the child type
943  * @param namespaceURI  the XML namespace of the child element
944  */
945 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
946     if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
947         set##proper(childXMLObject); \
948         return; \
949     }
950
951 /**
952  * Declares aliased get/set methods for named XML element content.
953  * 
954  * @param proper    the proper name to label the element's content
955  */
956 #define DECL_XMLOBJECT_CONTENT(proper) \
957     XMLTOOLING_DOXYGEN(Returns proper.) \
958     const XMLCh* get##proper() const { \
959         return getTextContent(); \
960     } \
961     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
962     void set##proper(const XMLCh* proper) { \
963         setTextContent(proper); \
964     }
965
966 /**
967  * Declares aliased get/set methods for named integer XML element content.
968  * 
969  * @param proper    the proper name to label the element's content
970  */
971 #define DECL_INTEGER_CONTENT(proper) \
972     XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \
973     std::pair<bool,int> get##proper() const { \
974         return std::make_pair((getTextContent()!=NULL), (getTextContent()!=NULL ? XMLString::parseInt(getTextContent()) : NULL)); \
975     } \
976     XMLTOOLING_DOXYGEN(Sets proper.) \
977     void set##proper(int proper) { \
978         char buf[64]; \
979         sprintf(buf,"%d",proper); \
980         xmltooling::auto_ptr_XMLCh widebuf(buf); \
981         setTextContent(widebuf.get()); \
982     } \
983     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
984     void set##proper(const XMLCh* proper) { \
985         setTextContent(proper); \
986     }
987
988 /**
989  * Implements marshalling/unmarshalling for element content.
990  */
991 #define IMPL_XMLOBJECT_CONTENT \
992     protected: \
993         void marshallElementContent(DOMElement* domElement) const { \
994             if(getTextContent()) { \
995                 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
996             } \
997         } \
998         void processElementContent(const XMLCh* elementContent) { \
999             setTextContent(elementContent); \
1000         }
1001
1002
1003 /**
1004  * Implements cloning methods for an XMLObject specialization implementation class.
1005  * 
1006  * @param cname    the name of the XMLObject specialization
1007  */
1008 #define IMPL_XMLOBJECT_CLONE(cname) \
1009     cname* clone##cname() const { \
1010         return clone(); \
1011     } \
1012     cname* clone() const { \
1013         std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
1014         cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
1015         if (ret) { \
1016             domClone.release(); \
1017             return ret; \
1018         } \
1019         return new cname##Impl(*this); \
1020     }
1021
1022 /**
1023  * Declares an XMLObject specialization with a simple content model and type,
1024  * handling it as string data.
1025  * 
1026  * @param linkage   linkage specifier for the class
1027  * @param cname     the name of the XMLObject specialization
1028  * @param proper    the proper name to label the element's content
1029  * @param desc      documentation for class
1030  */
1031 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
1032     BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
1033         DECL_XMLOBJECT_CONTENT(proper); \
1034     END_XMLOBJECT
1035
1036 /**
1037  * Declares and defines an implementation class for an XMLObject with
1038  * a simple content model and type, handling it as string data.
1039  * 
1040  * @param linkage   linkage specifier for the class
1041  * @param cname     the name of the XMLObject specialization
1042  */
1043 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
1044     class linkage cname##Impl \
1045         : public virtual cname, \
1046             public xmltooling::AbstractSimpleElement, \
1047             public xmltooling::AbstractChildlessElement, \
1048             public xmltooling::AbstractDOMCachingXMLObject, \
1049             public xmltooling::AbstractXMLObjectMarshaller, \
1050             public xmltooling::AbstractXMLObjectUnmarshaller \
1051     { \
1052     public: \
1053         virtual ~cname##Impl() {} \
1054         cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
1055             : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
1056         } \
1057         cname##Impl(const cname##Impl& src) \
1058             : xmltooling::AbstractXMLObject(src), \
1059                 xmltooling::AbstractSimpleElement(src), \
1060                 xmltooling::AbstractDOMCachingXMLObject(src) {} \
1061         IMPL_XMLOBJECT_CLONE(cname) \
1062         IMPL_XMLOBJECT_CONTENT \
1063     }
1064     
1065 /**
1066  * Begins the declaration of an XMLObjectBuilder specialization.
1067  * Basic boilerplate includes an empty virtual destructor, and
1068  * a default builder that defaults the element name.
1069  * 
1070  * @param linkage           linkage specifier for the class
1071  * @param cname             the name of the XMLObject specialization
1072  * @param namespaceURI      the XML namespace of the default associated element
1073  * @param namespacePrefix   the XML namespace prefix of the default associated element
1074  */
1075 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
1076     XMLTOOLING_DOXYGEN(Builder for cname objects.) \
1077     class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
1078     public: \
1079         virtual ~cname##Builder() {} \
1080         XMLTOOLING_DOXYGEN(Default builder.) \
1081         virtual cname* buildObject() const { \
1082             return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
1083         } \
1084         XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
1085         virtual cname* buildObject( \
1086             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
1087             ) const
1088
1089 /**
1090  * Ends the declaration of an XMLObjectBuilder specialization.
1091  */
1092 #define END_XMLOBJECTBUILDER }
1093
1094 /**
1095  * Declares a generic XMLObjectBuilder specialization.
1096  * 
1097  * @param linkage           linkage specifier for the class
1098  * @param cname             the name of the XMLObject specialization
1099  * @param namespaceURI      the XML namespace of the default associated element
1100  * @param namespacePrefix   the XML namespace prefix of the default associated element
1101  */
1102  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
1103     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
1104     XMLTOOLING_DOXYGEN(Singleton builder.) \
1105     static cname* build##cname() { \
1106         const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
1107             XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
1108             ); \
1109         if (b) \
1110             return b->buildObject(); \
1111         throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
1112     } \
1113     END_XMLOBJECTBUILDER
1114
1115 /**
1116  * Implements the standard XMLObjectBuilder specialization function. 
1117  * 
1118  * @param cname the name of the XMLObject specialization
1119  */
1120 #define IMPL_XMLOBJECTBUILDER(cname) \
1121     cname* cname##Builder::buildObject( \
1122         const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
1123         ) const \
1124     { \
1125         return new cname##Impl(nsURI,localName,prefix,schemaType); \
1126     }
1127
1128 /**
1129  * Begins the declaration of a Schema Validator specialization.
1130  * 
1131  * @param linkage           linkage specifier for the class
1132  * @param cname the base name of the Validator specialization
1133  */
1134  #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
1135     class linkage cname##SchemaValidator : public xmltooling::Validator \
1136     { \
1137     public: \
1138         virtual ~cname##SchemaValidator() {} \
1139         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1140             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1141             if (!ptr) \
1142                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1143
1144 /**
1145  * Begins the declaration of a Schema Validator specialization subclass.
1146  * 
1147  * @param linkage   linkage specifier for the class
1148  * @param cname     the base name of the Validator specialization
1149  * @param base      base class for the validator
1150  */
1151  #define BEGIN_XMLOBJECTVALIDATOR_SUB(linkage,cname,base) \
1152     class linkage cname##SchemaValidator : public base##SchemaValidator \
1153     { \
1154     public: \
1155         virtual ~cname##SchemaValidator() {} \
1156         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1157             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1158             if (!ptr) \
1159                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1160
1161 /**
1162  * Ends the declaration of a Validator specialization.
1163  */
1164 #define END_XMLOBJECTVALIDATOR } }
1165
1166 /**
1167  * Validator code that checks the object type.
1168  * 
1169  * @param cname     the name of the XMLObject specialization
1170  */
1171 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
1172     const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1173     if (!ptr) \
1174         throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1175
1176 /**
1177  * Validator code that checks for a required attribute, content, or singleton.
1178  * 
1179  * @param cname     the name of the XMLObject specialization
1180  * @param proper    the proper name of the attribute, content, or singleton member 
1181  */
1182 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
1183     if (!ptr->get##proper()) \
1184         throw xmltooling::ValidationException(#cname" must have "#proper".")
1185
1186 /**
1187  * Validator code that checks for a required integer attribute
1188  * 
1189  * @param cname     the name of the XMLObject specialization
1190  * @param proper    the proper name of the attribute, content, or singleton member 
1191  */
1192 #define XMLOBJECTVALIDATOR_REQUIRE_INTEGER(cname,proper) \
1193     if (!ptr->get##proper().first) \
1194         throw xmltooling::ValidationException(#cname" must have "#proper".")
1195
1196 /**
1197  * Validator code that checks for one of a pair of
1198  * required attributes, content, or singletons.
1199  * 
1200  * @param cname     the name of the XMLObject specialization
1201  * @param proper1   the proper name of the first attribute, content, or singleton member 
1202  * @param proper2   the proper name of the second attribute, content, or singleton member 
1203  */
1204 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
1205     if (!ptr->get##proper1() && !ptr->get##proper2()) \
1206         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
1207
1208 /**
1209  * Validator code that checks for one of a pair of
1210  * required attributes, content, or singletons, but disallows both.
1211  * 
1212  * @param cname     the name of the XMLObject specialization
1213  * @param proper1   the proper name of the first attribute, content, or singleton member 
1214  * @param proper2   the proper name of the second attribute, content, or singleton member 
1215  */
1216 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1217     if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1218         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1219
1220 /**
1221  * Validator code that checks for one of a set of three
1222  * required attributes, content, or singletons.
1223  * 
1224  * @param cname     the name of the XMLObject specialization
1225  * @param proper1   the proper name of the first attribute, content, or singleton member
1226  * @param proper2   the proper name of the second attribute, content, or singleton member
1227  * @param proper3   the proper name of the third attribute, content, or singleton member
1228  */
1229 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1230     if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1231         throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1232
1233 /**
1234  * Validator code that checks for one of a set of three
1235  * required attributes, content, or singletons but disallows more than one.
1236  * 
1237  * @param cname     the name of the XMLObject specialization
1238  * @param proper1   the proper name of the first attribute, content, or singleton member
1239  * @param proper2   the proper name of the second attribute, content, or singleton member
1240  * @param proper3   the proper name of the third attribute, content, or singleton member
1241  */
1242 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1243     int c##proper1##proper2##proper3=0; \
1244     if (ptr->get##proper1()!=NULL) \
1245         c##proper1##proper2##proper3++; \
1246     if (ptr->get##proper2()!=NULL) \
1247         c##proper1##proper2##proper3++; \
1248     if (ptr->get##proper3()!=NULL) \
1249         c##proper1##proper2##proper3++; \
1250     if (c##proper1##proper2##proper3 != 1) \
1251         throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1252
1253 /**
1254  * Validator code that checks a co-constraint (if one present, the other must be)
1255  * between a pair of attributes, content, or singletons.
1256  * 
1257  * @param cname     the name of the XMLObject specialization
1258  * @param proper1   the proper name of the first attribute, content, or singleton member 
1259  * @param proper2   the proper name of the second attribute, content, or singleton member 
1260  */
1261 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1262     if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1263         throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1264
1265 /**
1266  * Validator code that checks for a non-empty collection.
1267  * 
1268  * @param cname     the name of the XMLObject specialization
1269  * @param proper    the proper name of the collection item 
1270  */
1271 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1272     if (ptr->get##proper##s().empty()) \
1273         throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1274
1275 /**
1276  * Declares/defines a Validator specialization that checks object type and
1277  * a non-empty simple content model.
1278  * 
1279  * @param linkage   linkage specifier for the class
1280  * @param cname     the name of the XMLObject specialization
1281  */
1282 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1283     BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1284         XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1285     END_XMLOBJECTVALIDATOR
1286
1287 #include <utility>
1288
1289 /**
1290  * @namespace xmltooling
1291  * Public namespace of XML Tooling library
1292  */
1293 namespace xmltooling {
1294
1295     /**
1296      * Template function for cloning a sequence of XMLObjects.
1297      * Invokes the clone() member on each element of the input sequence and adds the copy to
1298      * the output sequence. Order is preserved.
1299      * 
1300      * @param in    input sequence to clone
1301      * @param out   output sequence to copy cloned pointers into
1302      */
1303     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1304         for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1305             if (*i)
1306                 out.push_back((*i)->clone());
1307             else
1308                 out.push_back(*i);
1309         }
1310     }
1311
1312     /**
1313      * Functor for cleaning up heap objects in containers.
1314      */
1315     template<class T> struct cleanup
1316     {
1317         /**
1318          * Function operator to delete an object.
1319          * 
1320          * @param ptr   object to delete
1321          */
1322         void operator()(T* ptr) {delete ptr;}
1323         
1324         /**
1325          * Function operator to delete an object stored as const.
1326          * 
1327          * @param ptr   object to delete after casting away const
1328          */
1329         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1330     };
1331
1332     /**
1333      * Functor for cleaning up heap objects in key/value containers.
1334      */
1335     template<class A,class B> struct cleanup_pair
1336     {
1337         /**
1338          * Function operator to delete an object.
1339          * 
1340          * @param p   a pair in which the second component is the object to delete
1341          */
1342         void operator()(const std::pair<A,B*>& p) {delete p.second;}
1343     };
1344 };
1345
1346 #endif /* __xmltooling_base_h__ */