Multi-line svn commit, see body.
[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),(m_##proper!=NULL ? XMLString::parseInt(m_##proper): NULL)); \
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         case XMLConstants::XML_BOOL_NULL: \
692             break; \
693     }
694
695 /**
696  * Implements marshalling for a QName attribute
697  * 
698  * @param proper        the proper name of the attribute
699  * @param ucase         the upcased name of the attribute
700  * @param namespaceURI  the XML namespace of the attribute
701  */
702 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
703     if (m_##proper) { \
704         auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \
705         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
706     }
707
708 /**
709  * Implements marshalling for an ID attribute
710  * 
711  * @param proper        the proper name of the attribute
712  * @param ucase         the upcased name of the attribute
713  * @param namespaceURI  the XML namespace of the attribute
714  */
715 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
716     if (m_##proper) { \
717         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
718         domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
719     }
720
721 /**
722  * Implements unmarshalling process branch for a string attribute
723  * 
724  * @param proper        the proper name of the attribute
725  * @param ucase         the upcased name of the attribute
726  * @param namespaceURI  the XML namespace of the attribute
727  */
728 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
729     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
730         set##proper(attribute->getValue()); \
731         return; \
732     }
733
734 /**
735  * Implements unmarshalling process branch for an ID attribute
736  * 
737  * @param proper        the proper name of the attribute
738  * @param ucase         the upcased name of the attribute
739  * @param namespaceURI  the XML namespace of the attribute
740  */
741 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
742     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
743         set##proper(attribute->getValue()); \
744         attribute->getOwnerElement()->setIdAttributeNode(attribute); \
745         return; \
746     }
747
748 /**
749  * Implements unmarshalling process branch for a DateTime attribute
750  * 
751  * @param proper        the proper name of the attribute
752  * @param ucase         the upcased name of the attribute
753  * @param namespaceURI  the XML namespace of the attribute
754  */
755 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
756     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
757
758 /**
759  * Implements unmarshalling process branch for a DateTime attribute
760  * 
761  * @param proper        the proper name of the attribute
762  * @param ucase         the upcased name of the attribute
763  * @param namespaceURI  the XML namespace of the attribute
764  */
765 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
766     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
767         set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
768         return; \
769     }
770
771 /**
772  * Implements unmarshalling process branch for an integer attribute
773  * 
774  * @param proper        the proper name of the attribute
775  * @param ucase         the upcased name of the attribute
776  * @param namespaceURI  the XML namespace of the attribute
777  */
778 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
779     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
780
781 /**
782  * Implements unmarshalling process branch for a boolean attribute
783  * 
784  * @param proper        the proper name of the attribute
785  * @param ucase         the upcased name of the attribute
786  * @param namespaceURI  the XML namespace of the attribute
787  */
788 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
789     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
790
791 /**
792  * Implements unmarshalling process branch for typed child collection element
793  * 
794  * @param proper        the proper name of the child type
795  * @param namespaceURI  the XML namespace of the child element
796  * @param force         bypass use of hint and just cast down to check child
797  */
798 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
799     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
800         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
801         if (typesafe) { \
802             get##proper##s().push_back(typesafe); \
803             return; \
804         } \
805     }
806
807 /**
808  * Implements unmarshalling process branch for typed child collection element
809  * in a foreign namespace.
810  * 
811  * @param proper        the proper name of the child type
812  * @param ns            the C++ namespace for the type
813  * @param namespaceURI  the XML namespace of the child element
814  * @param force         bypass use of hint and just cast down to check child
815  */
816 #define PROC_TYPED_FOREIGN_CHILDREN(proper,ns,namespaceURI,force) \
817     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
818         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
819         if (typesafe) { \
820             get##proper##s().push_back(typesafe); \
821             return; \
822         } \
823     }
824
825 /**
826  * Implements unmarshalling process branch for typed child singleton element
827  * 
828  * @param proper        the proper name of the child type
829  * @param namespaceURI  the XML namespace of the child element
830  * @param force         bypass use of hint and just cast down to check child
831  */
832 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
833     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
834         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
835         if (typesafe) { \
836             set##proper(typesafe); \
837             return; \
838         } \
839     }
840
841 /**
842  * Implements unmarshalling process branch for typed child singleton element
843  * in a foreign namespace.
844  * 
845  * @param proper        the proper name of the child type
846  * @param ns            the C++ namespace for the type
847  * @param namespaceURI  the XML namespace of the child element
848  * @param force         bypass use of hint and just cast down to check child
849  */
850 #define PROC_TYPED_FOREIGN_CHILD(proper,ns,namespaceURI,force) \
851     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
852         ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
853         if (typesafe) { \
854             set##proper(typesafe); \
855             return; \
856         } \
857     }
858
859 /**
860  * Implements unmarshalling process branch for a generic child singleton element
861  * 
862  * @param proper        the proper name of the child type
863  * @param namespaceURI  the XML namespace of the child element
864  */
865 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
866     if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
867         set##proper(childXMLObject); \
868         return; \
869     }
870
871 /**
872  * Declares aliased get/set methods for named XML element content.
873  * 
874  * @param proper    the proper name to label the element's content
875  */
876 #define DECL_XMLOBJECT_CONTENT(proper) \
877     XMLTOOLING_DOXYGEN(Returns proper.) \
878     const XMLCh* get##proper() const { \
879         return getTextContent(); \
880     } \
881     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
882     void set##proper(const XMLCh* proper) { \
883         setTextContent(proper); \
884     }
885
886 /**
887  * Declares aliased get/set methods for named integer XML element content.
888  * 
889  * @param proper    the proper name to label the element's content
890  */
891 #define DECL_INTEGER_CONTENT(proper) \
892     XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \
893     std::pair<bool,int> get##proper() const { \
894         return std::make_pair((getTextContent()!=NULL), (getTextContent()!=NULL ? XMLString::parseInt(getTextContent()) : NULL)); \
895     } \
896     XMLTOOLING_DOXYGEN(Sets proper.) \
897     void set##proper(int proper) { \
898         char buf[64]; \
899         sprintf(buf,"%d",proper); \
900         xmltooling::auto_ptr_XMLCh widebuf(buf); \
901         setTextContent(widebuf.get()); \
902     } \
903     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
904     void set##proper(const XMLCh* proper) { \
905         setTextContent(proper); \
906     }
907
908 /**
909  * Implements marshalling/unmarshalling for element content.
910  */
911 #define IMPL_XMLOBJECT_CONTENT \
912     protected: \
913         void marshallElementContent(DOMElement* domElement) const { \
914             if(getTextContent()) { \
915                 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
916             } \
917         } \
918         void processElementContent(const XMLCh* elementContent) { \
919             setTextContent(elementContent); \
920         }
921
922
923 /**
924  * Implements cloning methods for an XMLObject specialization implementation class.
925  * 
926  * @param cname    the name of the XMLObject specialization
927  */
928 #define IMPL_XMLOBJECT_CLONE(cname) \
929     cname* clone##cname() const { \
930         return clone(); \
931     } \
932     cname* clone() const { \
933         std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
934         cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
935         if (ret) { \
936             domClone.release(); \
937             return ret; \
938         } \
939         return new cname##Impl(*this); \
940     }
941
942 /**
943  * Declares an XMLObject specialization with a simple content model and type,
944  * handling it as string data.
945  * 
946  * @param linkage   linkage specifier for the class
947  * @param cname     the name of the XMLObject specialization
948  * @param proper    the proper name to label the element's content
949  * @param desc      documentation for class
950  */
951 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
952     BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
953         DECL_XMLOBJECT_CONTENT(proper); \
954     END_XMLOBJECT
955
956 /**
957  * Declares and defines an implementation class for an XMLObject with
958  * a simple content model and type, handling it as string data.
959  * 
960  * @param linkage   linkage specifier for the class
961  * @param cname     the name of the XMLObject specialization
962  */
963 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
964     class linkage cname##Impl \
965         : public virtual cname, \
966             public xmltooling::AbstractSimpleElement, \
967             public xmltooling::AbstractChildlessElement, \
968             public xmltooling::AbstractDOMCachingXMLObject, \
969             public xmltooling::AbstractValidatingXMLObject, \
970             public xmltooling::AbstractXMLObjectMarshaller, \
971             public xmltooling::AbstractXMLObjectUnmarshaller \
972     { \
973     public: \
974         virtual ~cname##Impl() {} \
975         cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
976             : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
977         } \
978         cname##Impl(const cname##Impl& src) \
979             : xmltooling::AbstractXMLObject(src), \
980                 xmltooling::AbstractSimpleElement(src), \
981                 xmltooling::AbstractDOMCachingXMLObject(src), \
982                 xmltooling::AbstractValidatingXMLObject(src) {} \
983         IMPL_XMLOBJECT_CLONE(cname) \
984         IMPL_XMLOBJECT_CONTENT \
985     }
986     
987 /**
988  * Begins the declaration of an XMLObjectBuilder specialization.
989  * Basic boilerplate includes an empty virtual destructor, and
990  * a default builder that defaults the element name.
991  * 
992  * @param linkage           linkage specifier for the class
993  * @param cname             the name of the XMLObject specialization
994  * @param namespaceURI      the XML namespace of the default associated element
995  * @param namespacePrefix   the XML namespace prefix of the default associated element
996  */
997 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
998     XMLTOOLING_DOXYGEN(Builder for cname objects.) \
999     class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
1000     public: \
1001         virtual ~cname##Builder() {} \
1002         XMLTOOLING_DOXYGEN(Default builder.) \
1003         virtual cname* buildObject() const { \
1004             return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
1005         } \
1006         XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
1007         virtual cname* buildObject( \
1008             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
1009             ) const
1010
1011 /**
1012  * Ends the declaration of an XMLObjectBuilder specialization.
1013  */
1014 #define END_XMLOBJECTBUILDER }
1015
1016 /**
1017  * Declares a generic XMLObjectBuilder specialization.
1018  * 
1019  * @param linkage           linkage specifier for the class
1020  * @param cname             the name of the XMLObject specialization
1021  * @param namespaceURI      the XML namespace of the default associated element
1022  * @param namespacePrefix   the XML namespace prefix of the default associated element
1023  */
1024  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
1025     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
1026     XMLTOOLING_DOXYGEN(Singleton builder.) \
1027     static cname* build##cname() { \
1028         const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
1029             XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
1030             ); \
1031         if (b) \
1032             return b->buildObject(); \
1033         throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
1034     } \
1035     END_XMLOBJECTBUILDER
1036
1037 /**
1038  * Implements the standard XMLObjectBuilder specialization function. 
1039  * 
1040  * @param cname the name of the XMLObject specialization
1041  */
1042 #define IMPL_XMLOBJECTBUILDER(cname) \
1043     cname* cname##Builder::buildObject( \
1044         const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
1045         ) const \
1046     { \
1047         return new cname##Impl(nsURI,localName,prefix,schemaType); \
1048     }
1049
1050 /**
1051  * Begins the declaration of a Schema Validator specialization.
1052  * 
1053  * @param linkage           linkage specifier for the class
1054  * @param cname the base name of the Validator specialization
1055  */
1056  #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
1057     class linkage cname##SchemaValidator : public xmltooling::Validator \
1058     { \
1059     public: \
1060         virtual ~cname##SchemaValidator() {} \
1061         virtual cname##SchemaValidator* clone() const { \
1062             return new cname##SchemaValidator(); \
1063         } \
1064         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1065             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1066             if (!ptr) \
1067                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1068
1069 /**
1070  * Begins the declaration of a Schema Validator specialization subclass.
1071  * 
1072  * @param linkage   linkage specifier for the class
1073  * @param cname     the base name of the Validator specialization
1074  * @param base      base class for the validator
1075  */
1076  #define BEGIN_XMLOBJECTVALIDATOR_SUB(linkage,cname,base) \
1077     class linkage cname##SchemaValidator : public base##SchemaValidator \
1078     { \
1079     public: \
1080         virtual ~cname##SchemaValidator() {} \
1081         virtual cname##SchemaValidator* clone() const { \
1082             return new cname##SchemaValidator(); \
1083         } \
1084         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1085             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1086             if (!ptr) \
1087                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1088
1089 /**
1090  * Ends the declaration of a Validator specialization.
1091  */
1092 #define END_XMLOBJECTVALIDATOR } }
1093
1094 /**
1095  * Validator code that checks the object type.
1096  * 
1097  * @param cname     the name of the XMLObject specialization
1098  */
1099 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
1100     const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1101     if (!ptr) \
1102         throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1103
1104 /**
1105  * Validator code that checks for a required attribute, content, or singleton.
1106  * 
1107  * @param cname     the name of the XMLObject specialization
1108  * @param proper    the proper name of the attribute, content, or singleton member 
1109  */
1110 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
1111     if (!ptr->get##proper()) \
1112         throw xmltooling::ValidationException(#cname" must have "#proper".")
1113
1114 /**
1115  * Validator code that checks for a required integer attribute
1116  * 
1117  * @param cname     the name of the XMLObject specialization
1118  * @param proper    the proper name of the attribute, content, or singleton member 
1119  */
1120 #define XMLOBJECTVALIDATOR_REQUIRE_INTEGER(cname,proper) \
1121     if (!ptr->get##proper().first) \
1122         throw xmltooling::ValidationException(#cname" must have "#proper".")
1123
1124 /**
1125  * Validator code that checks for one of a pair of
1126  * required attributes, content, or singletons.
1127  * 
1128  * @param cname     the name of the XMLObject specialization
1129  * @param proper1   the proper name of the first attribute, content, or singleton member 
1130  * @param proper2   the proper name of the second attribute, content, or singleton member 
1131  */
1132 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
1133     if (!ptr->get##proper1() && !ptr->get##proper2()) \
1134         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
1135
1136 /**
1137  * Validator code that checks for one of a pair of
1138  * required attributes, content, or singletons, but disallows both.
1139  * 
1140  * @param cname     the name of the XMLObject specialization
1141  * @param proper1   the proper name of the first attribute, content, or singleton member 
1142  * @param proper2   the proper name of the second attribute, content, or singleton member 
1143  */
1144 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1145     if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1146         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1147
1148 /**
1149  * Validator code that checks for one of a set of three
1150  * required attributes, content, or singletons.
1151  * 
1152  * @param cname     the name of the XMLObject specialization
1153  * @param proper1   the proper name of the first attribute, content, or singleton member
1154  * @param proper2   the proper name of the second attribute, content, or singleton member
1155  * @param proper3   the proper name of the third attribute, content, or singleton member
1156  */
1157 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1158     if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1159         throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1160
1161 /**
1162  * Validator code that checks for one of a set of three
1163  * required attributes, content, or singletons but disallows more than one.
1164  * 
1165  * @param cname     the name of the XMLObject specialization
1166  * @param proper1   the proper name of the first attribute, content, or singleton member
1167  * @param proper2   the proper name of the second attribute, content, or singleton member
1168  * @param proper3   the proper name of the third attribute, content, or singleton member
1169  */
1170 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1171     int c##proper1##proper2##proper3=0; \
1172     if (ptr->get##proper1()!=NULL) \
1173         c##proper1##proper2##proper3++; \
1174     if (ptr->get##proper2()!=NULL) \
1175         c##proper1##proper2##proper3++; \
1176     if (ptr->get##proper3()!=NULL) \
1177         c##proper1##proper2##proper3++; \
1178     if (c##proper1##proper2##proper3 != 1) \
1179         throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1180
1181 /**
1182  * Validator code that checks a co-constraint (if one present, the other must be)
1183  * between a pair of attributes, content, or singletons.
1184  * 
1185  * @param cname     the name of the XMLObject specialization
1186  * @param proper1   the proper name of the first attribute, content, or singleton member 
1187  * @param proper2   the proper name of the second attribute, content, or singleton member 
1188  */
1189 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1190     if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1191         throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1192
1193 /**
1194  * Validator code that checks for a non-empty collection.
1195  * 
1196  * @param cname     the name of the XMLObject specialization
1197  * @param proper    the proper name of the collection item 
1198  */
1199 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1200     if (ptr->get##proper##s().empty()) \
1201         throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1202
1203 /**
1204  * Declares/defines a Validator specialization that checks object type and
1205  * a non-empty simple content model.
1206  * 
1207  * @param linkage   linkage specifier for the class
1208  * @param cname     the name of the XMLObject specialization
1209  */
1210 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1211     BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1212         XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1213     END_XMLOBJECTVALIDATOR
1214
1215 #include <utility>
1216
1217 /**
1218  * @namespace xmltooling
1219  * Public namespace of XML Tooling library
1220  */
1221 namespace xmltooling {
1222
1223     /**
1224      * Template function for cloning a sequence of XMLObjects.
1225      * Invokes the clone() member on each element of the input sequence and adds the copy to
1226      * the output sequence. Order is preserved.
1227      * 
1228      * @param in    input sequence to clone
1229      * @param out   output sequence to copy cloned pointers into
1230      */
1231     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1232         for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1233             if (*i)
1234                 out.push_back((*i)->clone());
1235             else
1236                 out.push_back(*i);
1237         }
1238     }
1239
1240     /**
1241      * Functor for cleaning up heap objects in containers.
1242      */
1243     template<class T> struct cleanup
1244     {
1245         /**
1246          * Function operator to delete an object.
1247          * 
1248          * @param ptr   object to delete
1249          */
1250         void operator()(T* ptr) {delete ptr;}
1251         
1252         /**
1253          * Function operator to delete an object stored as const.
1254          * 
1255          * @param ptr   object to delete after casting away const
1256          */
1257         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1258     };
1259
1260     /**
1261      * Functor for cleaning up heap objects in key/value containers.
1262      */
1263     template<class A,class B> struct cleanup_pair
1264     {
1265         /**
1266          * Function operator to delete an object.
1267          * 
1268          * @param p   a pair in which the second component is the object to delete
1269          */
1270         void operator()(const std::pair<A,B*>& p) {delete p.second;}
1271     };
1272 };
1273
1274 #endif /* __xmltooling_base_h__ */