Additional macros.
[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 a generic XML child object.
473  * 
474  * @param proper    the proper name of the child
475  */
476 #define IMPL_XMLOBJECT_CHILD(proper) \
477     protected: \
478         xmltooling::XMLObject* m_##proper; \
479         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
480     public: \
481         xmltooling::XMLObject* get##proper() const { \
482             return m_##proper; \
483         } \
484         void set##proper(xmltooling::XMLObject* child) { \
485             prepareForAssignment(m_##proper,child); \
486             *m_pos_##proper = m_##proper = child; \
487         }
488
489 /**
490  * Declares abstract get/set methods for a typed XML child collection.
491  * 
492  * @param proper    the proper name of the child type
493  */
494 #define DECL_TYPED_CHILDREN(proper) \
495     public: \
496         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
497         virtual VectorOf(proper) get##proper##s()=0; \
498         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
499         virtual const std::vector<proper*>& get##proper##s() const=0
500
501 /**
502  * Declares abstract get/set methods for a typed XML child collection in a foreign namespace.
503  * 
504  * @param proper    the proper name of the child type
505  * @param ns        the C++ namespace for the type
506  */
507 #define DECL_TYPED_FOREIGN_CHILDREN(proper,ns) \
508     public: \
509         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
510         virtual VectorOf(ns::proper) get##proper##s()=0; \
511         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
512         virtual const std::vector<ns::proper*>& get##proper##s() const=0
513
514 /**
515  * Declares abstract get/set methods for a generic XML child collection.
516  * 
517  * @param proper    the proper name of the child
518  */
519 #define DECL_XMLOBJECT_CHILDREN(proper) \
520     public: \
521         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
522         virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
523         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
524         virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
525
526 /**
527  * Implements get method and a private vector member for a typed XML child collection.
528  * 
529  * @param proper    the proper name of the child type
530  * @param fence     insertion fence for new objects of the child collection in backing list
531  */
532 #define IMPL_TYPED_CHILDREN(proper,fence) \
533     protected: \
534         std::vector<proper*> m_##proper##s; \
535     public: \
536         VectorOf(proper) get##proper##s() { \
537             return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
538         } \
539         const std::vector<proper*>& get##proper##s() const { \
540             return m_##proper##s; \
541         } 
542
543 /**
544  * Implements get method and a private vector member for a generic XML child collection.
545  * 
546  * @param proper    the proper name of the child
547  * @param fence     insertion fence for new objects of the child collection in backing list
548  */
549 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
550     protected: \
551         std::vector<xmltooling::XMLObject*> m_##proper##s; \
552     public: \
553         VectorOf(xmltooling::XMLObject) get##proper##s() { \
554             return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
555         } \
556         const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
557             return m_##proper##s; \
558         } 
559
560 /**
561  * Implements marshalling for a string attribute
562  * 
563  * @param proper        the proper name of the attribute
564  * @param ucase         the upcased name of the attribute
565  * @param namespaceURI  the XML namespace of the attribute
566  */
567 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
568     if(get##proper()) { \
569         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
570     }
571
572 /**
573  * Implements marshalling for a DateTime attribute
574  * 
575  * @param proper        the proper name of the attribute
576  * @param ucase         the upcased name of the attribute
577  * @param namespaceURI  the XML namespace of the attribute
578  */
579 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
580     if(get##proper()) { \
581         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()->getRawData()); \
582     }
583
584 /**
585  * Implements marshalling for an integer attribute
586  * 
587  * @param proper        the proper name of the attribute
588  * @param ucase         the upcased name of the attribute
589  * @param namespaceURI  the XML namespace of the attribute
590  */
591 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
592     char buf##proper[64]; \
593     sprintf(buf##proper,"%d",get##proper()); \
594     auto_ptr_XMLCh wide##proper(buf##proper); \
595     domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, wide##proper.get())
596
597 /**
598  * Implements marshalling for a boolean attribute
599  * 
600  * @param proper        the proper name of the attribute
601  * @param ucase         the upcased name of the attribute
602  * @param namespaceURI  the XML namespace of the attribute
603  */
604 #define MARSHALL_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
605     XMLCh flag##proper[2]; \
606     flag##proper[0]=m_##proper ? chDigit_1 : chDigit_0; \
607     flag##proper[1]=chNull; \
608     domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, flag##proper)
609
610 /**
611  * Implements marshalling for a QName attribute
612  * 
613  * @param proper        the proper name of the attribute
614  * @param ucase         the upcased name of the attribute
615  * @param namespaceURI  the XML namespace of the attribute
616  */
617 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
618     if(get##proper()) { \
619         auto_ptr_XMLCh qstr(get##proper()->toString().c_str()); \
620         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
621     }
622
623 /**
624  * Implements marshalling for an ID 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_ID_ATTRIB(proper,ucase,namespaceURI) \
631     if(get##proper()) { \
632         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
633         domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
634     }
635
636 /**
637  * Implements unmarshalling process branch for a string 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 PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
644     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
645         set##proper(attribute->getValue()); \
646         return; \
647     }
648
649 /**
650  * Implements unmarshalling process branch for an ID 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 PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
657     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
658         set##proper(attribute->getValue()); \
659         attribute->getOwnerElement()->setIdAttributeNode(attribute); \
660         return; \
661     }
662
663 /**
664  * Implements unmarshalling process branch for a DateTime attribute
665  * 
666  * @param proper        the proper name of the attribute
667  * @param ucase         the upcased name of the attribute
668  * @param namespaceURI  the XML namespace of the attribute
669  */
670 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
671     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
672
673 /**
674  * Implements unmarshalling process branch for a DateTime attribute
675  * 
676  * @param proper        the proper name of the attribute
677  * @param ucase         the upcased name of the attribute
678  * @param namespaceURI  the XML namespace of the attribute
679  */
680 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
681     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
682         set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
683         return; \
684     }
685
686 /**
687  * Implements unmarshalling process branch for an integer attribute
688  * 
689  * @param proper        the proper name of the attribute
690  * @param ucase         the upcased name of the attribute
691  * @param namespaceURI  the XML namespace of the attribute
692  */
693 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
694     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
695         set##proper(XMLString::parseInt(attribute->getValue())); \
696         return; \
697     }
698
699 /**
700  * Implements unmarshalling process branch for a boolean attribute
701  * 
702  * @param proper        the proper name of the attribute
703  * @param ucase         the upcased name of the attribute
704  * @param namespaceURI  the XML namespace of the attribute
705  */
706 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
707     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
708         const XMLCh* value=attribute->getValue(); \
709         if (value) { \
710             if (*value==chLatin_t || *value==chDigit_1) \
711                 m_##proper=true; \
712             else if (*value==chLatin_f || *value==chDigit_0) \
713                 m_##proper=false; \
714         } \
715         return; \
716     }
717
718 /**
719  * Implements unmarshalling process branch for typed child collection element
720  * 
721  * @param proper        the proper name of the child type
722  * @param namespaceURI  the XML namespace of the child element
723  * @param force         bypass use of hint and just cast down to check child
724  */
725 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
726     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
727         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
728         if (typesafe) { \
729             get##proper##s().push_back(typesafe); \
730             return; \
731         } \
732     }
733
734 /**
735  * Implements unmarshalling process branch for typed child singleton element
736  * 
737  * @param proper        the proper name of the child type
738  * @param namespaceURI  the XML namespace of the child element
739  * @param force         bypass use of hint and just cast down to check child
740  */
741 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
742     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
743         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
744         if (typesafe) { \
745             set##proper(typesafe); \
746             return; \
747         } \
748     }
749
750 /**
751  * Implements unmarshalling process branch for a generic child singleton element
752  * 
753  * @param proper        the proper name of the child type
754  * @param namespaceURI  the XML namespace of the child element
755  */
756 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
757     if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
758         set##proper(childXMLObject); \
759         return; \
760     }
761
762 /**
763  * Declares aliased get/set methods for named XML element content.
764  * 
765  * @param proper    the proper name to label the element's content
766  */
767 #define DECL_XMLOBJECT_CONTENT(proper) \
768     XMLTOOLING_DOXYGEN(Returns proper.) \
769     const XMLCh* get##proper() const { \
770         return getTextContent(); \
771     } \
772     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
773     void set##proper(const XMLCh* proper) { \
774         setTextContent(proper); \
775     }
776
777 /**
778  * Declares aliased get/set methods for named integer XML element content.
779  * 
780  * @param proper    the proper name to label the element's content
781  */
782 #define DECL_INTEGER_CONTENT(proper) \
783     XMLTOOLING_DOXYGEN(Returns proper.) \
784     int get##proper() const { \
785         return XMLString::parseInt(getTextContent()); \
786     } \
787     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
788     void set##proper(int proper) { \
789         char buf[64]; \
790         sprintf(buf,"%d",proper); \
791         xmltooling::auto_ptr_XMLCh widebuf(buf); \
792         setTextContent(widebuf.get()); \
793     }
794
795 /**
796  * Implements marshalling/unmarshalling for element content.
797  */
798 #define IMPL_XMLOBJECT_CONTENT \
799     protected: \
800         void marshallElementContent(DOMElement* domElement) const { \
801             if(getTextContent()) { \
802                 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
803             } \
804         } \
805         void processElementContent(const XMLCh* elementContent) { \
806             setTextContent(elementContent); \
807         }
808
809
810 /**
811  * Implements cloning methods for an XMLObject specialization implementation class.
812  * 
813  * @param cname    the name of the XMLObject specialization
814  */
815 #define IMPL_XMLOBJECT_CLONE(cname) \
816     cname* clone##cname() const { \
817         return clone(); \
818     } \
819     cname* clone() const { \
820         std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
821         cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
822         if (ret) { \
823             domClone.release(); \
824             return ret; \
825         } \
826         return new cname##Impl(*this); \
827     }
828
829 /**
830  * Declares an XMLObject specialization with a simple content model and type,
831  * handling it as string data.
832  * 
833  * @param linkage   linkage specifier for the class
834  * @param cname     the name of the XMLObject specialization
835  * @param proper    the proper name to label the element's content
836  * @param desc      documentation for class
837  */
838 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
839     BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
840         DECL_XMLOBJECT_CONTENT(proper); \
841     END_XMLOBJECT
842
843 /**
844  * Declares and defines an implementation class for an XMLObject with
845  * a simple content model and type, handling it as string data.
846  * 
847  * @param linkage   linkage specifier for the class
848  * @param cname     the name of the XMLObject specialization
849  */
850 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
851     class linkage cname##Impl \
852         : public virtual cname, \
853             public xmltooling::AbstractSimpleElement, \
854             public xmltooling::AbstractChildlessElement, \
855             public xmltooling::AbstractDOMCachingXMLObject, \
856             public xmltooling::AbstractValidatingXMLObject, \
857             public xmltooling::AbstractXMLObjectMarshaller, \
858             public xmltooling::AbstractXMLObjectUnmarshaller \
859     { \
860     public: \
861         virtual ~cname##Impl() {} \
862         cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
863             : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
864         } \
865         cname##Impl(const cname##Impl& src) \
866             : xmltooling::AbstractXMLObject(src), \
867                 xmltooling::AbstractSimpleElement(src), \
868                 xmltooling::AbstractDOMCachingXMLObject(src), \
869                 xmltooling::AbstractValidatingXMLObject(src) {} \
870         IMPL_XMLOBJECT_CLONE(cname) \
871         IMPL_XMLOBJECT_CONTENT \
872     }
873     
874 /**
875  * Begins the declaration of an XMLObjectBuilder specialization.
876  * Basic boilerplate includes an empty virtual destructor, and
877  * a default builder that defaults the element name.
878  * 
879  * @param linkage           linkage specifier for the class
880  * @param cname             the name of the XMLObject specialization
881  * @param namespaceURI      the XML namespace of the default associated element
882  * @param namespacePrefix   the XML namespace prefix of the default associated element
883  */
884 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
885     XMLTOOLING_DOXYGEN(Builder for cname objects.) \
886     class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
887     public: \
888         virtual ~cname##Builder() {} \
889         XMLTOOLING_DOXYGEN(Default builder.) \
890         virtual cname* buildObject() const { \
891             return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
892         } \
893         XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
894         virtual cname* buildObject( \
895             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
896             ) const
897
898 /**
899  * Ends the declaration of an XMLObjectBuilder specialization.
900  */
901 #define END_XMLOBJECTBUILDER }
902
903 /**
904  * Declares a generic XMLObjectBuilder specialization.
905  * 
906  * @param linkage           linkage specifier for the class
907  * @param cname             the name of the XMLObject specialization
908  * @param namespaceURI      the XML namespace of the default associated element
909  * @param namespacePrefix   the XML namespace prefix of the default associated element
910  */
911  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
912     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
913     XMLTOOLING_DOXYGEN(Singleton builder.) \
914     static cname* build##cname() { \
915         const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
916             XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
917             ); \
918         if (b) \
919             return b->buildObject(); \
920         throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
921     } \
922     END_XMLOBJECTBUILDER
923
924 /**
925  * Implements the standard XMLObjectBuilder specialization function. 
926  * 
927  * @param cname the name of the XMLObject specialization
928  */
929 #define IMPL_XMLOBJECTBUILDER(cname) \
930     cname* cname##Builder::buildObject( \
931         const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
932         ) const \
933     { \
934         return new cname##Impl(nsURI,localName,prefix,schemaType); \
935     }
936
937 /**
938  * Begins the declaration of a Schema Validator specialization.
939  * 
940  * @param linkage           linkage specifier for the class
941  * @param cname the base name of the Validator specialization
942  */
943  #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
944     class linkage cname##SchemaValidator : public xmltooling::Validator \
945     { \
946     public: \
947         virtual ~cname##SchemaValidator() {} \
948         virtual cname##SchemaValidator* clone() const { \
949             return new cname##SchemaValidator(); \
950         } \
951         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
952             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
953             if (!ptr) \
954                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
955
956 /**
957  * Ends the declaration of a Validator specialization.
958  */
959 #define END_XMLOBJECTVALIDATOR } }
960
961 /**
962  * Validator code that checks the object type.
963  * 
964  * @param cname     the name of the XMLObject specialization
965  */
966 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
967     const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
968     if (!ptr) \
969         throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
970
971 /**
972  * Validator code that checks for a required attribute, content, or singleton.
973  * 
974  * @param cname     the name of the XMLObject specialization
975  * @param proper    the proper name of the attribute, content, or singleton member 
976  */
977 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
978     if (!ptr->get##proper()) \
979         throw xmltooling::ValidationException(#cname" must have "#proper".")
980
981 /**
982  * Validator code that checks for one of a pair of
983  * required attributes, content, or singletons.
984  * 
985  * @param cname     the name of the XMLObject specialization
986  * @param proper1   the proper name of the first attribute, content, or singleton member 
987  * @param proper2   the proper name of the second attribute, content, or singleton member 
988  */
989 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
990     if (!ptr->get##proper1() && !ptr->get##proper2()) \
991         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
992
993 /**
994  * Validator code that checks for one of a pair of
995  * required attributes, content, or singletons, but disallows both.
996  * 
997  * @param cname     the name of the XMLObject specialization
998  * @param proper1   the proper name of the first attribute, content, or singleton member 
999  * @param proper2   the proper name of the second attribute, content, or singleton member 
1000  */
1001 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1002     if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1003         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1004
1005 /**
1006  * Validator code that checks for one of a set of three
1007  * required attributes, content, or singletons.
1008  * 
1009  * @param cname     the name of the XMLObject specialization
1010  * @param proper1   the proper name of the first attribute, content, or singleton member
1011  * @param proper2   the proper name of the second attribute, content, or singleton member
1012  * @param proper3   the proper name of the third attribute, content, or singleton member
1013  */
1014 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1015     if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1016         throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1017
1018 /**
1019  * Validator code that checks for one of a set of three
1020  * required attributes, content, or singletons but disallows more than one.
1021  * 
1022  * @param cname     the name of the XMLObject specialization
1023  * @param proper1   the proper name of the first attribute, content, or singleton member
1024  * @param proper2   the proper name of the second attribute, content, or singleton member
1025  * @param proper3   the proper name of the third attribute, content, or singleton member
1026  */
1027 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1028     int c##proper1##proper2##proper3=0; \
1029     if (ptr->get##proper1()!=NULL) \
1030         c##proper1##proper2##proper3++; \
1031     if (ptr->get##proper2()!=NULL) \
1032         c##proper1##proper2##proper3++; \
1033     if (ptr->get##proper3()!=NULL) \
1034         c##proper1##proper2##proper3++; \
1035     if (c##proper1##proper2##proper3 != 1) \
1036         throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1037
1038 /**
1039  * Validator code that checks a co-constraint (if one present, the other must be)
1040  * between a pair of attributes, content, or singletons.
1041  * 
1042  * @param cname     the name of the XMLObject specialization
1043  * @param proper1   the proper name of the first attribute, content, or singleton member 
1044  * @param proper2   the proper name of the second attribute, content, or singleton member 
1045  */
1046 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1047     if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1048         throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1049
1050 /**
1051  * Validator code that checks for a non-empty collection.
1052  * 
1053  * @param cname     the name of the XMLObject specialization
1054  * @param proper    the proper name of the collection item 
1055  */
1056 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1057     if (ptr->get##proper##s().empty()) \
1058         throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1059
1060 /**
1061  * Declares/defines a Validator specialization that checks object type and
1062  * a non-empty simple content model.
1063  * 
1064  * @param linkage   linkage specifier for the class
1065  * @param cname     the name of the XMLObject specialization
1066  */
1067 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1068     BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1069         XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1070     END_XMLOBJECTVALIDATOR
1071
1072 #include <utility>
1073
1074 /**
1075  * @namespace xmltooling
1076  * Public namespace of XML Tooling library
1077  */
1078 namespace xmltooling {
1079
1080     /**
1081      * Template function for cloning a sequence of XMLObjects.
1082      * Invokes the clone() member on each element of the input sequence and adds the copy to
1083      * the output sequence. Order is preserved.
1084      * 
1085      * @param in    input sequence to clone
1086      * @param out   output sequence to copy cloned pointers into
1087      */
1088     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1089         for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1090             if (*i)
1091                 out.push_back((*i)->clone());
1092             else
1093                 out.push_back(*i);
1094         }
1095     }
1096
1097     /**
1098      * Functor for cleaning up heap objects in containers.
1099      */
1100     template<class T> struct cleanup
1101     {
1102         /**
1103          * Function operator to delete an object.
1104          * 
1105          * @param ptr   object to delete
1106          */
1107         void operator()(T* ptr) {delete ptr;}
1108         
1109         /**
1110          * Function operator to delete an object stored as const.
1111          * 
1112          * @param ptr   object to delete after casting away const
1113          */
1114         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1115     };
1116
1117     /**
1118      * Functor for cleaning up heap objects in key/value containers.
1119      */
1120     template<class A,class B> struct cleanup_pair
1121     {
1122         /**
1123          * Function operator to delete an object.
1124          * 
1125          * @param p   a pair in which the second component is the object to delete
1126          */
1127         void operator()(const std::pair<A,B*>& p) {delete p.second;}
1128     };
1129 };
1130
1131 #endif /* __xmltooling_base_h__ */