Reworked int/bool attribute handling.
[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, public virtual xmltooling::ValidatingXMLObject { \
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, public virtual xmltooling::ValidatingXMLObject { \
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  * Ends the declaration of an XMLObject specialization.
267  */
268 #define END_XMLOBJECT }
269
270 /**
271  * Declares abstract get/set methods for a typed XML attribute.
272  * 
273  * @param proper    the proper name of the attribute
274  * @param upcased   the upcased name of the attribute
275  * @param type      the attribute's data type
276  */
277 #define DECL_XMLOBJECT_ATTRIB(proper,upcased,type) \
278     public: \
279         XMLTOOLING_DOXYGEN(proper attribute name) \
280         static const XMLCh upcased##_ATTRIB_NAME[]; \
281         XMLTOOLING_DOXYGEN(Returns the proper attribute.) \
282         virtual const type* get##proper() const=0; \
283         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
284         virtual void set##proper(const type* proper)=0
285
286 /**
287  * Declares abstract get/set methods for a string XML attribute.
288  * 
289  * @param proper    the proper name of the attribute
290  * @param upcased   the upcased name of the attribute
291  */
292 #define DECL_STRING_ATTRIB(proper,upcased) \
293     DECL_XMLOBJECT_ATTRIB(proper,upcased,XMLCh)
294
295 /**
296  * Declares abstract get/set methods for a string XML attribute.
297  * 
298  * @param proper    the proper name of the attribute
299  * @param upcased   the upcased name of the attribute
300  */
301 #define DECL_DATETIME_ATTRIB(proper,upcased) \
302     DECL_XMLOBJECT_ATTRIB(proper,upcased,xmltooling::DateTime); \
303     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
304     virtual void set##proper(time_t proper)=0; \
305     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
306     virtual void set##proper(const XMLCh* proper)=0
307
308 /**
309  * Declares abstract get/set methods for an integer XML attribute.
310  * 
311  * @param proper    the proper name of the attribute
312  * @param upcased   the upcased name of the attribute
313  */
314 #define DECL_INTEGER_ATTRIB(proper,upcased) \
315     public: \
316         XMLTOOLING_DOXYGEN(proper attribute name) \
317         static const XMLCh upcased##_ATTRIB_NAME[]; \
318         XMLTOOLING_DOXYGEN(Returns the proper attribute after a NULL indicator.) \
319         virtual std::pair<bool,int> get##proper() const=0; \
320         XMLTOOLING_DOXYGEN(Sets the proper attribute using a string value.) \
321         virtual void set##proper(const XMLCh* proper)=0; \
322         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
323         virtual void set##proper(int proper)=0
324
325 /**
326  * Declares abstract get/set methods for a boolean XML attribute.
327  * 
328  * @param proper    the proper name of the attribute
329  * @param upcased   the upcased name of the attribute
330  */
331 #define DECL_BOOLEAN_ATTRIB(proper,upcased) \
332     public: \
333         XMLTOOLING_DOXYGEN(proper attribute name) \
334         static const XMLCh upcased##_ATTRIB_NAME[]; \
335         XMLTOOLING_DOXYGEN(Returns the proper attribute after a NULL indicator.) \
336         virtual std::pair<bool,bool> proper() const=0; \
337         XMLTOOLING_DOXYGEN(Sets the proper attribute using an enumerated value.) \
338         virtual void proper(xmltooling::XMLConstants::xmltooling_bool_t value)=0; \
339         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
340         void proper(bool value) { \
341             proper(value ? xmltooling::XMLConstants::XML_BOOL_ONE : xmltooling::XMLConstants::XML_BOOL_ZERO); \
342         } \
343         XMLTOOLING_DOXYGEN(Sets the proper attribute using a string constant.) \
344         void set##proper(const XMLCh* value) { \
345             if (value) { \
346                 switch (*value) { \
347                     case chLatin_t: \
348                         proper(xmltooling::XMLConstants::XML_BOOL_TRUE); \
349                         break; \
350                     case chLatin_f: \
351                         proper(xmltooling::XMLConstants::XML_BOOL_FALSE); \
352                         break; \
353                     case chDigit_1: \
354                         proper(xmltooling::XMLConstants::XML_BOOL_ONE); \
355                         break; \
356                     case chDigit_0: \
357                         proper(xmltooling::XMLConstants::XML_BOOL_ZERO); \
358                         break; \
359                     default: \
360                         proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
361                 } \
362             } \
363             else \
364                 proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
365         }
366
367 /**
368  * Implements get/set methods and a private member for a typed XML attribute.
369  * 
370  * @param proper    the proper name of the attribute
371  * @param type      the attribute's data type
372  */
373 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
374     protected: \
375         type* m_##proper; \
376     public: \
377         const type* get##proper() const { \
378             return m_##proper; \
379         } \
380         void set##proper(const type* proper) { \
381             m_##proper = prepareForAssignment(m_##proper,proper); \
382         }
383
384 /**
385  * Implements get/set methods and a private member for a string XML attribute.
386  * 
387  * @param proper    the proper name of the attribute
388  */
389 #define IMPL_STRING_ATTRIB(proper) \
390     IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
391
392 /**
393  * Implements get/set methods and a private member for a DateTime XML attribute.
394  * 
395  * @param proper    the proper name of the attribute
396  */
397 #define IMPL_DATETIME_ATTRIB(proper) \
398     IMPL_XMLOBJECT_ATTRIB(proper,xmltooling::DateTime); \
399     void set##proper(time_t proper) { \
400         m_##proper = prepareForAssignment(m_##proper,proper); \
401     } \
402     void set##proper(const XMLCh* proper) { \
403         m_##proper = prepareForAssignment(m_##proper,proper); \
404     }
405
406 /**
407  * Implements get/set methods and a private member for an integer XML attribute.
408  * 
409  * @param proper    the proper name of the attribute
410  */
411 #define IMPL_INTEGER_ATTRIB(proper) \
412     protected: \
413         XMLCh* m_##proper; \
414     public: \
415         pair<bool,int> get##proper() const { \
416             return make_pair((m_##proper!=NULL),XMLString::parseInt(m_##proper)); \
417         } \
418         void set##proper(const XMLCh* proper) { \
419             m_##proper = prepareForAssignment(m_##proper,proper); \
420         } \
421         void set##proper(int proper) { \
422             char buf##proper[64]; \
423             sprintf(buf##proper,"%d",proper); \
424             auto_ptr_XMLCh wide##proper(buf##proper); \
425             set##proper(wide##proper.get()); \
426         }
427
428 /**
429  * Implements get/set methods and a private member for a boolean XML attribute.
430  * 
431  * @param proper    the proper name of the attribute
432  */
433 #define IMPL_BOOLEAN_ATTRIB(proper) \
434     protected: \
435         XMLConstants::xmltooling_bool_t m_##proper; \
436     public: \
437         pair<bool,bool> proper() const { \
438             return make_pair( \
439                 (m_##proper!=XMLConstants::XML_BOOL_NULL), \
440                 (m_##proper==XMLConstants::XML_BOOL_TRUE || m_##proper==XMLConstants::XML_BOOL_ONE) \
441                 ); \
442         } \
443         void proper(XMLConstants::xmltooling_bool_t value) { \
444             if (m_##proper != value) { \
445                 releaseThisandParentDOM(); \
446                 m_##proper = value; \
447             } \
448         }
449
450 /**
451  * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
452  * 
453  * @param proper    the proper name of the child type
454  * @param ns        the C++ namespace for the type
455  */
456 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
457     public: \
458         XMLTOOLING_DOXYGEN(Returns the proper child.) \
459         virtual ns::proper* get##proper() const=0; \
460         XMLTOOLING_DOXYGEN(Sets the proper child.) \
461         virtual void set##proper(ns::proper* child)=0
462
463 /**
464  * Declares abstract get/set methods for a typed XML child object.
465  * 
466  * @param proper    the proper name of the child type
467  */
468 #define DECL_TYPED_CHILD(proper) \
469     public: \
470         XMLTOOLING_DOXYGEN(Returns the proper child.) \
471         virtual proper* get##proper() const=0; \
472         XMLTOOLING_DOXYGEN(Sets the proper child.) \
473         virtual void set##proper(proper* child)=0
474
475 /**
476  * Declares abstract get/set methods for a generic XML child object.
477  * 
478  * @param proper    the proper name of the child
479  */
480 #define DECL_XMLOBJECT_CHILD(proper) \
481     public: \
482         XMLTOOLING_DOXYGEN(Returns the proper child.) \
483         virtual xmltooling::XMLObject* get##proper() const=0; \
484         XMLTOOLING_DOXYGEN(Sets the proper child.) \
485         virtual void set##proper(xmltooling::XMLObject* child)=0
486
487
488 /**
489  * Implements get/set methods and a private list iterator member for a typed XML child object.
490  * 
491  * @param proper    the proper name of the child type
492  */
493 #define IMPL_TYPED_CHILD(proper) \
494     protected: \
495         proper* m_##proper; \
496         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
497     public: \
498         proper* get##proper() const { \
499             return m_##proper; \
500         } \
501         void set##proper(proper* child) { \
502             prepareForAssignment(m_##proper,child); \
503             *m_pos_##proper = m_##proper = child; \
504         }
505
506 /**
507  * Implements get/set methods and a private list iterator member for
508  * a typed XML child object in a foreign namespace
509  * 
510  * @param proper    the proper name of the child type
511  * @param ns        the C++ namespace for the type
512  */
513 #define IMPL_TYPED_FOREIGN_CHILD(proper,ns) \
514     protected: \
515         ns::proper* m_##proper; \
516         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
517     public: \
518         ns::proper* get##proper() const { \
519             return m_##proper; \
520         } \
521         void set##proper(ns::proper* child) { \
522             prepareForAssignment(m_##proper,child); \
523             *m_pos_##proper = m_##proper = child; \
524         }
525
526 /**
527  * Implements get/set methods and a private list iterator member for a generic XML child object.
528  * 
529  * @param proper    the proper name of the child
530  */
531 #define IMPL_XMLOBJECT_CHILD(proper) \
532     protected: \
533         xmltooling::XMLObject* m_##proper; \
534         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
535     public: \
536         xmltooling::XMLObject* get##proper() const { \
537             return m_##proper; \
538         } \
539         void set##proper(xmltooling::XMLObject* child) { \
540             prepareForAssignment(m_##proper,child); \
541             *m_pos_##proper = m_##proper = child; \
542         }
543
544 /**
545  * Declares abstract get/set methods for a typed XML child collection.
546  * 
547  * @param proper    the proper name of the child type
548  */
549 #define DECL_TYPED_CHILDREN(proper) \
550     public: \
551         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
552         virtual VectorOf(proper) get##proper##s()=0; \
553         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
554         virtual const std::vector<proper*>& get##proper##s() const=0
555
556 /**
557  * Declares abstract get/set methods for a typed XML child collection in a foreign namespace.
558  * 
559  * @param proper    the proper name of the child type
560  * @param ns        the C++ namespace for the type
561  */
562 #define DECL_TYPED_FOREIGN_CHILDREN(proper,ns) \
563     public: \
564         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
565         virtual VectorOf(ns::proper) get##proper##s()=0; \
566         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
567         virtual const std::vector<ns::proper*>& get##proper##s() const=0
568
569 /**
570  * Declares abstract get/set methods for a generic XML child collection.
571  * 
572  * @param proper    the proper name of the child
573  */
574 #define DECL_XMLOBJECT_CHILDREN(proper) \
575     public: \
576         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
577         virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
578         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
579         virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
580
581 /**
582  * Implements get method and a private vector member for a typed XML child collection.
583  * 
584  * @param proper    the proper name of the child type
585  * @param fence     insertion fence for new objects of the child collection in backing list
586  */
587 #define IMPL_TYPED_CHILDREN(proper,fence) \
588     protected: \
589         std::vector<proper*> m_##proper##s; \
590     public: \
591         VectorOf(proper) get##proper##s() { \
592             return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
593         } \
594         const std::vector<proper*>& get##proper##s() const { \
595             return m_##proper##s; \
596         } 
597
598 /**
599  * Implements get method and a private vector member for a typed XML child collection
600  * in a foreign namespace.
601  * 
602  * @param proper    the proper name of the child type
603  * @param ns        the C++ namespace for the type
604  * @param fence     insertion fence for new objects of the child collection in backing list
605  */
606 #define IMPL_TYPED_FOREIGN_CHILDREN(proper,ns,fence) \
607     protected: \
608         std::vector<ns::proper*> m_##proper##s; \
609     public: \
610         VectorOf(ns::proper) get##proper##s() { \
611             return VectorOf(ns::proper)(this, m_##proper##s, &m_children, fence); \
612         } \
613         const std::vector<ns::proper*>& get##proper##s() const { \
614             return m_##proper##s; \
615         } 
616
617 /**
618  * Implements get method and a private vector member for a generic XML child collection.
619  * 
620  * @param proper    the proper name of the child
621  * @param fence     insertion fence for new objects of the child collection in backing list
622  */
623 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
624     protected: \
625         std::vector<xmltooling::XMLObject*> m_##proper##s; \
626     public: \
627         VectorOf(xmltooling::XMLObject) get##proper##s() { \
628             return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
629         } \
630         const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
631             return m_##proper##s; \
632         } 
633
634 /**
635  * Implements marshalling for a string attribute
636  * 
637  * @param proper        the proper name of the attribute
638  * @param ucase         the upcased name of the attribute
639  * @param namespaceURI  the XML namespace of the attribute
640  */
641 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
642     if (m_##proper) { \
643         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
644     }
645
646 /**
647  * Implements marshalling for a DateTime attribute
648  * 
649  * @param proper        the proper name of the attribute
650  * @param ucase         the upcased name of the attribute
651  * @param namespaceURI  the XML namespace of the attribute
652  */
653 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
654     if (m_##proper) { \
655         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper->getRawData()); \
656     }
657
658 /**
659  * Implements marshalling for an integer attribute
660  * 
661  * @param proper        the proper name of the attribute
662  * @param ucase         the upcased name of the attribute
663  * @param namespaceURI  the XML namespace of the attribute
664  */
665 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
666     if (m_##proper) { \
667         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
668     }
669
670 /**
671  * Implements marshalling for a boolean attribute
672  * 
673  * @param proper        the proper name of the attribute
674  * @param ucase         the upcased name of the attribute
675  * @param namespaceURI  the XML namespace of the attribute
676  */
677 #define MARSHALL_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
678     switch (m_##proper) { \
679         case XMLConstants::XML_BOOL_TRUE: \
680             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_TRUE); \
681             break; \
682         case XMLConstants::XML_BOOL_ONE: \
683             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ONE); \
684             break; \
685         case XMLConstants::XML_BOOL_FALSE: \
686             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_FALSE); \
687             break; \
688         case XMLConstants::XML_BOOL_ZERO: \
689             domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ZERO); \
690             break; \
691     }
692
693 /**
694  * Implements marshalling for a QName attribute
695  * 
696  * @param proper        the proper name of the attribute
697  * @param ucase         the upcased name of the attribute
698  * @param namespaceURI  the XML namespace of the attribute
699  */
700 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
701     if (m_##proper) { \
702         auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \
703         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
704     }
705
706 /**
707  * Implements marshalling for an ID attribute
708  * 
709  * @param proper        the proper name of the attribute
710  * @param ucase         the upcased name of the attribute
711  * @param namespaceURI  the XML namespace of the attribute
712  */
713 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
714     if (m_##proper) { \
715         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
716         domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
717     }
718
719 /**
720  * Implements unmarshalling process branch for a string attribute
721  * 
722  * @param proper        the proper name of the attribute
723  * @param ucase         the upcased name of the attribute
724  * @param namespaceURI  the XML namespace of the attribute
725  */
726 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
727     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
728         set##proper(attribute->getValue()); \
729         return; \
730     }
731
732 /**
733  * Implements unmarshalling process branch for an ID attribute
734  * 
735  * @param proper        the proper name of the attribute
736  * @param ucase         the upcased name of the attribute
737  * @param namespaceURI  the XML namespace of the attribute
738  */
739 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
740     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
741         set##proper(attribute->getValue()); \
742         attribute->getOwnerElement()->setIdAttributeNode(attribute); \
743         return; \
744     }
745
746 /**
747  * Implements unmarshalling process branch for a DateTime attribute
748  * 
749  * @param proper        the proper name of the attribute
750  * @param ucase         the upcased name of the attribute
751  * @param namespaceURI  the XML namespace of the attribute
752  */
753 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
754     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
755
756 /**
757  * Implements unmarshalling process branch for a DateTime attribute
758  * 
759  * @param proper        the proper name of the attribute
760  * @param ucase         the upcased name of the attribute
761  * @param namespaceURI  the XML namespace of the attribute
762  */
763 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
764     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
765         set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
766         return; \
767     }
768
769 /**
770  * Implements unmarshalling process branch for an integer attribute
771  * 
772  * @param proper        the proper name of the attribute
773  * @param ucase         the upcased name of the attribute
774  * @param namespaceURI  the XML namespace of the attribute
775  */
776 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
777     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
778
779 /**
780  * Implements unmarshalling process branch for a boolean attribute
781  * 
782  * @param proper        the proper name of the attribute
783  * @param ucase         the upcased name of the attribute
784  * @param namespaceURI  the XML namespace of the attribute
785  */
786 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
787     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
788
789 /**
790  * Implements unmarshalling process branch for typed child collection element
791  * 
792  * @param proper        the proper name of the child type
793  * @param namespaceURI  the XML namespace of the child element
794  * @param force         bypass use of hint and just cast down to check child
795  */
796 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
797     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
798         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
799         if (typesafe) { \
800             get##proper##s().push_back(typesafe); \
801             return; \
802         } \
803     }
804
805 /**
806  * Implements unmarshalling process branch for typed child collection element
807  * in a foreign namespace.
808  * 
809  * @param proper        the proper name of the child type
810  * @param ns            the C++ namespace for the type
811  * @param namespaceURI  the XML namespace of the child element
812  * @param force         bypass use of hint and just cast down to check child
813  */
814 #define PROC_TYPED_FOREIGN_CHILDREN(proper,ns,namespaceURI,force) \
815     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
816         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
817         if (typesafe) { \
818             get##proper##s().push_back(typesafe); \
819             return; \
820         } \
821     }
822
823 /**
824  * Implements unmarshalling process branch for typed child singleton element
825  * 
826  * @param proper        the proper name of the child type
827  * @param namespaceURI  the XML namespace of the child element
828  * @param force         bypass use of hint and just cast down to check child
829  */
830 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
831     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
832         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
833         if (typesafe) { \
834             set##proper(typesafe); \
835             return; \
836         } \
837     }
838
839 /**
840  * Implements unmarshalling process branch for typed child singleton element
841  * in a foreign namespace.
842  * 
843  * @param proper        the proper name of the child type
844  * @param ns            the C++ namespace for the type
845  * @param namespaceURI  the XML namespace of the child element
846  * @param force         bypass use of hint and just cast down to check child
847  */
848 #define PROC_TYPED_FOREIGN_CHILD(proper,ns,namespaceURI,force) \
849     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
850         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
851         if (typesafe) { \
852             set##proper(typesafe); \
853             return; \
854         } \
855     }
856
857 /**
858  * Implements unmarshalling process branch for a generic child singleton element
859  * 
860  * @param proper        the proper name of the child type
861  * @param namespaceURI  the XML namespace of the child element
862  */
863 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
864     if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
865         set##proper(childXMLObject); \
866         return; \
867     }
868
869 /**
870  * Declares aliased get/set methods for named XML element content.
871  * 
872  * @param proper    the proper name to label the element's content
873  */
874 #define DECL_XMLOBJECT_CONTENT(proper) \
875     XMLTOOLING_DOXYGEN(Returns proper.) \
876     const XMLCh* get##proper() const { \
877         return getTextContent(); \
878     } \
879     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
880     void set##proper(const XMLCh* proper) { \
881         setTextContent(proper); \
882     }
883
884 /**
885  * Declares aliased get/set methods for named integer XML element content.
886  * 
887  * @param proper    the proper name to label the element's content
888  */
889 #define DECL_INTEGER_CONTENT(proper) \
890     XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \
891     std::pair<bool,int> get##proper() const { \
892         return std::make_pair((getTextContent()!=NULL), XMLString::parseInt(getTextContent())); \
893     } \
894     XMLTOOLING_DOXYGEN(Sets proper.) \
895     void set##proper(int proper) { \
896         char buf[64]; \
897         sprintf(buf,"%d",proper); \
898         xmltooling::auto_ptr_XMLCh widebuf(buf); \
899         setTextContent(widebuf.get()); \
900     } \
901     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
902     void set##proper(const XMLCh* proper) { \
903         setTextContent(proper); \
904     }
905
906 /**
907  * Implements marshalling/unmarshalling for element content.
908  */
909 #define IMPL_XMLOBJECT_CONTENT \
910     protected: \
911         void marshallElementContent(DOMElement* domElement) const { \
912             if(getTextContent()) { \
913                 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
914             } \
915         } \
916         void processElementContent(const XMLCh* elementContent) { \
917             setTextContent(elementContent); \
918         }
919
920
921 /**
922  * Implements cloning methods for an XMLObject specialization implementation class.
923  * 
924  * @param cname    the name of the XMLObject specialization
925  */
926 #define IMPL_XMLOBJECT_CLONE(cname) \
927     cname* clone##cname() const { \
928         return clone(); \
929     } \
930     cname* clone() const { \
931         std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
932         cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
933         if (ret) { \
934             domClone.release(); \
935             return ret; \
936         } \
937         return new cname##Impl(*this); \
938     }
939
940 /**
941  * Declares an XMLObject specialization with a simple content model and type,
942  * handling it as string data.
943  * 
944  * @param linkage   linkage specifier for the class
945  * @param cname     the name of the XMLObject specialization
946  * @param proper    the proper name to label the element's content
947  * @param desc      documentation for class
948  */
949 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
950     BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
951         DECL_XMLOBJECT_CONTENT(proper); \
952     END_XMLOBJECT
953
954 /**
955  * Declares and defines an implementation class for an XMLObject with
956  * a simple content model and type, handling it as string data.
957  * 
958  * @param linkage   linkage specifier for the class
959  * @param cname     the name of the XMLObject specialization
960  */
961 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
962     class linkage cname##Impl \
963         : public virtual cname, \
964             public xmltooling::AbstractSimpleElement, \
965             public xmltooling::AbstractChildlessElement, \
966             public xmltooling::AbstractDOMCachingXMLObject, \
967             public xmltooling::AbstractValidatingXMLObject, \
968             public xmltooling::AbstractXMLObjectMarshaller, \
969             public xmltooling::AbstractXMLObjectUnmarshaller \
970     { \
971     public: \
972         virtual ~cname##Impl() {} \
973         cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
974             : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
975         } \
976         cname##Impl(const cname##Impl& src) \
977             : xmltooling::AbstractXMLObject(src), \
978                 xmltooling::AbstractSimpleElement(src), \
979                 xmltooling::AbstractDOMCachingXMLObject(src), \
980                 xmltooling::AbstractValidatingXMLObject(src) {} \
981         IMPL_XMLOBJECT_CLONE(cname) \
982         IMPL_XMLOBJECT_CONTENT \
983     }
984     
985 /**
986  * Begins the declaration of an XMLObjectBuilder specialization.
987  * Basic boilerplate includes an empty virtual destructor, and
988  * a default builder that defaults the element name.
989  * 
990  * @param linkage           linkage specifier for the class
991  * @param cname             the name of the XMLObject specialization
992  * @param namespaceURI      the XML namespace of the default associated element
993  * @param namespacePrefix   the XML namespace prefix of the default associated element
994  */
995 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
996     XMLTOOLING_DOXYGEN(Builder for cname objects.) \
997     class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
998     public: \
999         virtual ~cname##Builder() {} \
1000         XMLTOOLING_DOXYGEN(Default builder.) \
1001         virtual cname* buildObject() const { \
1002             return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
1003         } \
1004         XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
1005         virtual cname* buildObject( \
1006             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
1007             ) const
1008
1009 /**
1010  * Ends the declaration of an XMLObjectBuilder specialization.
1011  */
1012 #define END_XMLOBJECTBUILDER }
1013
1014 /**
1015  * Declares a generic XMLObjectBuilder specialization.
1016  * 
1017  * @param linkage           linkage specifier for the class
1018  * @param cname             the name of the XMLObject specialization
1019  * @param namespaceURI      the XML namespace of the default associated element
1020  * @param namespacePrefix   the XML namespace prefix of the default associated element
1021  */
1022  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
1023     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
1024     XMLTOOLING_DOXYGEN(Singleton builder.) \
1025     static cname* build##cname() { \
1026         const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
1027             XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
1028             ); \
1029         if (b) \
1030             return b->buildObject(); \
1031         throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
1032     } \
1033     END_XMLOBJECTBUILDER
1034
1035 /**
1036  * Implements the standard XMLObjectBuilder specialization function. 
1037  * 
1038  * @param cname the name of the XMLObject specialization
1039  */
1040 #define IMPL_XMLOBJECTBUILDER(cname) \
1041     cname* cname##Builder::buildObject( \
1042         const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
1043         ) const \
1044     { \
1045         return new cname##Impl(nsURI,localName,prefix,schemaType); \
1046     }
1047
1048 /**
1049  * Begins the declaration of a Schema Validator specialization.
1050  * 
1051  * @param linkage           linkage specifier for the class
1052  * @param cname the base name of the Validator specialization
1053  */
1054  #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
1055     class linkage cname##SchemaValidator : public xmltooling::Validator \
1056     { \
1057     public: \
1058         virtual ~cname##SchemaValidator() {} \
1059         virtual cname##SchemaValidator* clone() const { \
1060             return new cname##SchemaValidator(); \
1061         } \
1062         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1063             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1064             if (!ptr) \
1065                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1066
1067 /**
1068  * Begins the declaration of a Schema Validator specialization subclass.
1069  * 
1070  * @param linkage   linkage specifier for the class
1071  * @param cname     the base name of the Validator specialization
1072  * @param base      base class for the validator
1073  */
1074  #define BEGIN_XMLOBJECTVALIDATOR_SUB(linkage,cname,base) \
1075     class linkage cname##SchemaValidator : public base##SchemaValidator \
1076     { \
1077     public: \
1078         virtual ~cname##SchemaValidator() {} \
1079         virtual cname##SchemaValidator* clone() const { \
1080             return new cname##SchemaValidator(); \
1081         } \
1082         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1083             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1084             if (!ptr) \
1085                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1086
1087 /**
1088  * Ends the declaration of a Validator specialization.
1089  */
1090 #define END_XMLOBJECTVALIDATOR } }
1091
1092 /**
1093  * Validator code that checks the object type.
1094  * 
1095  * @param cname     the name of the XMLObject specialization
1096  */
1097 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
1098     const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1099     if (!ptr) \
1100         throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1101
1102 /**
1103  * Validator code that checks for a required attribute, content, or singleton.
1104  * 
1105  * @param cname     the name of the XMLObject specialization
1106  * @param proper    the proper name of the attribute, content, or singleton member 
1107  */
1108 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
1109     if (!ptr->get##proper()) \
1110         throw xmltooling::ValidationException(#cname" must have "#proper".")
1111
1112 /**
1113  * Validator code that checks for a required integer attribute
1114  * 
1115  * @param cname     the name of the XMLObject specialization
1116  * @param proper    the proper name of the attribute, content, or singleton member 
1117  */
1118 #define XMLOBJECTVALIDATOR_REQUIRE_INTEGER(cname,proper) \
1119     if (!ptr->get##proper().first) \
1120         throw xmltooling::ValidationException(#cname" must have "#proper".")
1121
1122 /**
1123  * Validator code that checks for one of a pair of
1124  * required attributes, content, or singletons.
1125  * 
1126  * @param cname     the name of the XMLObject specialization
1127  * @param proper1   the proper name of the first attribute, content, or singleton member 
1128  * @param proper2   the proper name of the second attribute, content, or singleton member 
1129  */
1130 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
1131     if (!ptr->get##proper1() && !ptr->get##proper2()) \
1132         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
1133
1134 /**
1135  * Validator code that checks for one of a pair of
1136  * required attributes, content, or singletons, but disallows both.
1137  * 
1138  * @param cname     the name of the XMLObject specialization
1139  * @param proper1   the proper name of the first attribute, content, or singleton member 
1140  * @param proper2   the proper name of the second attribute, content, or singleton member 
1141  */
1142 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1143     if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1144         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1145
1146 /**
1147  * Validator code that checks for one of a set of three
1148  * required attributes, content, or singletons.
1149  * 
1150  * @param cname     the name of the XMLObject specialization
1151  * @param proper1   the proper name of the first attribute, content, or singleton member
1152  * @param proper2   the proper name of the second attribute, content, or singleton member
1153  * @param proper3   the proper name of the third attribute, content, or singleton member
1154  */
1155 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1156     if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1157         throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1158
1159 /**
1160  * Validator code that checks for one of a set of three
1161  * required attributes, content, or singletons but disallows more than one.
1162  * 
1163  * @param cname     the name of the XMLObject specialization
1164  * @param proper1   the proper name of the first attribute, content, or singleton member
1165  * @param proper2   the proper name of the second attribute, content, or singleton member
1166  * @param proper3   the proper name of the third attribute, content, or singleton member
1167  */
1168 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1169     int c##proper1##proper2##proper3=0; \
1170     if (ptr->get##proper1()!=NULL) \
1171         c##proper1##proper2##proper3++; \
1172     if (ptr->get##proper2()!=NULL) \
1173         c##proper1##proper2##proper3++; \
1174     if (ptr->get##proper3()!=NULL) \
1175         c##proper1##proper2##proper3++; \
1176     if (c##proper1##proper2##proper3 != 1) \
1177         throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1178
1179 /**
1180  * Validator code that checks a co-constraint (if one present, the other must be)
1181  * between a pair of attributes, content, or singletons.
1182  * 
1183  * @param cname     the name of the XMLObject specialization
1184  * @param proper1   the proper name of the first attribute, content, or singleton member 
1185  * @param proper2   the proper name of the second attribute, content, or singleton member 
1186  */
1187 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1188     if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1189         throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1190
1191 /**
1192  * Validator code that checks for a non-empty collection.
1193  * 
1194  * @param cname     the name of the XMLObject specialization
1195  * @param proper    the proper name of the collection item 
1196  */
1197 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1198     if (ptr->get##proper##s().empty()) \
1199         throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1200
1201 /**
1202  * Declares/defines a Validator specialization that checks object type and
1203  * a non-empty simple content model.
1204  * 
1205  * @param linkage   linkage specifier for the class
1206  * @param cname     the name of the XMLObject specialization
1207  */
1208 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1209     BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1210         XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1211     END_XMLOBJECTVALIDATOR
1212
1213 #include <utility>
1214
1215 /**
1216  * @namespace xmltooling
1217  * Public namespace of XML Tooling library
1218  */
1219 namespace xmltooling {
1220
1221     /**
1222      * Template function for cloning a sequence of XMLObjects.
1223      * Invokes the clone() member on each element of the input sequence and adds the copy to
1224      * the output sequence. Order is preserved.
1225      * 
1226      * @param in    input sequence to clone
1227      * @param out   output sequence to copy cloned pointers into
1228      */
1229     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1230         for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1231             if (*i)
1232                 out.push_back((*i)->clone());
1233             else
1234                 out.push_back(*i);
1235         }
1236     }
1237
1238     /**
1239      * Functor for cleaning up heap objects in containers.
1240      */
1241     template<class T> struct cleanup
1242     {
1243         /**
1244          * Function operator to delete an object.
1245          * 
1246          * @param ptr   object to delete
1247          */
1248         void operator()(T* ptr) {delete ptr;}
1249         
1250         /**
1251          * Function operator to delete an object stored as const.
1252          * 
1253          * @param ptr   object to delete after casting away const
1254          */
1255         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1256     };
1257
1258     /**
1259      * Functor for cleaning up heap objects in key/value containers.
1260      */
1261     template<class A,class B> struct cleanup_pair
1262     {
1263         /**
1264          * Function operator to delete an object.
1265          * 
1266          * @param p   a pair in which the second component is the object to delete
1267          */
1268         void operator()(const std::pair<A,B*>& p) {delete p.second;}
1269     };
1270 };
1271
1272 #endif /* __xmltooling_base_h__ */