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