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