Missing doxygen comment.
[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  * Ends the declaration of an XMLObject specialization.
244  */
245 #define END_XMLOBJECT }
246
247 /**
248  * Declares abstract get/set methods for a typed XML attribute.
249  * 
250  * @param proper    the proper name of the attribute
251  * @param upcased   the upcased name of the attribute
252  * @param type      the attribute's data type
253  */
254 #define DECL_XMLOBJECT_ATTRIB(proper,upcased,type) \
255     public: \
256         XMLTOOLING_DOXYGEN(proper attribute name) \
257         static const XMLCh upcased##_ATTRIB_NAME[]; \
258         XMLTOOLING_DOXYGEN(Returns the proper attribute.) \
259         virtual const type* get##proper() const=0; \
260         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
261         virtual void set##proper(const type* proper)=0
262
263 /**
264  * Declares abstract get/set methods for a string XML attribute.
265  * 
266  * @param proper    the proper name of the attribute
267  * @param upcased   the upcased name of the attribute
268  */
269 #define DECL_STRING_ATTRIB(proper,upcased) \
270     DECL_XMLOBJECT_ATTRIB(proper,upcased,XMLCh)
271
272 /**
273  * Declares abstract get/set methods for a string XML attribute.
274  * 
275  * @param proper    the proper name of the attribute
276  * @param upcased   the upcased name of the attribute
277  */
278 #define DECL_DATETIME_ATTRIB(proper,upcased) \
279     DECL_XMLOBJECT_ATTRIB(proper,upcased,xmltooling::DateTime); \
280     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
281     virtual void set##proper(time_t proper)=0; \
282     XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
283     virtual void set##proper(const XMLCh* proper)=0
284
285 /**
286  * Declares abstract get/set methods for an integer XML attribute.
287  * 
288  * @param proper    the proper name of the attribute
289  * @param upcased   the upcased name of the attribute
290  */
291 #define DECL_INTEGER_ATTRIB(proper,upcased) \
292     public: \
293         XMLTOOLING_DOXYGEN(proper attribute name) \
294         static const XMLCh upcased##_ATTRIB_NAME[]; \
295         XMLTOOLING_DOXYGEN(Returns the proper attribute.) \
296         virtual int get##proper() const=0; \
297         XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
298         virtual void set##proper(int proper)=0
299
300 /**
301  * Implements get/set methods and a private member for a typed XML attribute.
302  * 
303  * @param proper    the proper name of the attribute
304  * @param type      the attribute's data type
305  */
306 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
307     protected: \
308         type* m_##proper; \
309     public: \
310         const type* get##proper() const { \
311             return m_##proper; \
312         } \
313         void set##proper(const type* proper) { \
314             m_##proper = prepareForAssignment(m_##proper,proper); \
315         }
316
317 /**
318  * Implements get/set methods and a private member for a string XML attribute.
319  * 
320  * @param proper    the proper name of the attribute
321  */
322 #define IMPL_STRING_ATTRIB(proper) \
323     IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
324
325 /**
326  * Implements get/set methods and a private member for a DateTime XML attribute.
327  * 
328  * @param proper    the proper name of the attribute
329  */
330 #define IMPL_DATETIME_ATTRIB(proper) \
331     IMPL_XMLOBJECT_ATTRIB(proper,xmltooling::DateTime); \
332     void set##proper(time_t proper) { \
333         m_##proper = prepareForAssignment(m_##proper,proper); \
334     } \
335     void set##proper(const XMLCh* proper) { \
336         m_##proper = prepareForAssignment(m_##proper,proper); \
337     }
338
339 /**
340  * Implements get/set methods and a private member for an integer XML attribute.
341  * 
342  * @param proper    the proper name of the attribute
343  */
344 #define IMPL_INTEGER_ATTRIB(proper) \
345     protected: \
346         int m_##proper; \
347     public: \
348         int get##proper() const { \
349             return m_##proper; \
350         } \
351         void set##proper(int proper) { \
352             if (m_##proper != proper) { \
353                 releaseThisandParentDOM(); \
354                 m_##proper = proper; \
355             } \
356         }
357
358 /**
359  * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
360  * 
361  * @param proper    the proper name of the child type
362  * @param ns        the C++ namespace for the type
363  */
364 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
365     public: \
366         XMLTOOLING_DOXYGEN(Returns the proper child.) \
367         virtual ns::proper* get##proper() const=0; \
368         XMLTOOLING_DOXYGEN(Sets the proper child.) \
369         virtual void set##proper(ns::proper* child)=0
370
371 /**
372  * Declares abstract get/set methods for a typed XML child object.
373  * 
374  * @param proper    the proper name of the child type
375  */
376 #define DECL_TYPED_CHILD(proper) \
377     public: \
378         XMLTOOLING_DOXYGEN(Returns the proper child.) \
379         virtual proper* get##proper() const=0; \
380         XMLTOOLING_DOXYGEN(Sets the proper child.) \
381         virtual void set##proper(proper* child)=0
382
383 /**
384  * Declares abstract get/set methods for a generic XML child object.
385  * 
386  * @param proper    the proper name of the child
387  */
388 #define DECL_XMLOBJECT_CHILD(proper) \
389     public: \
390         XMLTOOLING_DOXYGEN(Returns the proper child.) \
391         virtual xmltooling::XMLObject* get##proper() const=0; \
392         XMLTOOLING_DOXYGEN(Sets the proper child.) \
393         virtual void set##proper(xmltooling::XMLObject* child)=0
394
395
396 /**
397  * Implements get/set methods and a private list iterator member for a typed XML child object.
398  * 
399  * @param proper    the proper name of the child type
400  */
401 #define IMPL_TYPED_CHILD(proper) \
402     protected: \
403         proper* m_##proper; \
404         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
405     public: \
406         proper* get##proper() const { \
407             return m_##proper; \
408         } \
409         void set##proper(proper* child) { \
410             prepareForAssignment(m_##proper,child); \
411             *m_pos_##proper = m_##proper = child; \
412         }
413
414 /**
415  * Implements get/set methods and a private list iterator member for a generic XML child object.
416  * 
417  * @param proper    the proper name of the child
418  */
419 #define IMPL_XMLOBJECT_CHILD(proper) \
420     protected: \
421         xmltooling::XMLObject* m_##proper; \
422         std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
423     public: \
424         xmltooling::XMLObject* get##proper() const { \
425             return m_##proper; \
426         } \
427         void set##proper(xmltooling::XMLObject* child) { \
428             prepareForAssignment(m_##proper,child); \
429             *m_pos_##proper = m_##proper = child; \
430         }
431
432 /**
433  * Declares abstract get/set methods for a typed XML child collection.
434  * 
435  * @param proper    the proper name of the child type
436  */
437 #define DECL_TYPED_CHILDREN(proper) \
438     public: \
439         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
440         virtual VectorOf(proper) get##proper##s()=0; \
441         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
442         virtual const std::vector<proper*>& get##proper##s() const=0
443
444 /**
445  * Declares abstract get/set methods for a generic XML child collection.
446  * 
447  * @param proper    the proper name of the child
448  */
449 #define DECL_XMLOBJECT_CHILDREN(proper) \
450     public: \
451         XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
452         virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
453         XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
454         virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
455
456 /**
457  * Implements get method and a private vector member for a typed XML child collection.
458  * 
459  * @param proper    the proper name of the child type
460  * @param fence     insertion fence for new objects of the child collection in backing list
461  */
462 #define IMPL_TYPED_CHILDREN(proper,fence) \
463     protected: \
464         std::vector<proper*> m_##proper##s; \
465     public: \
466         VectorOf(proper) get##proper##s() { \
467             return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
468         } \
469         const std::vector<proper*>& get##proper##s() const { \
470             return m_##proper##s; \
471         } 
472
473 /**
474  * Implements get method and a private vector member for a generic XML child collection.
475  * 
476  * @param proper    the proper name of the child
477  * @param fence     insertion fence for new objects of the child collection in backing list
478  */
479 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
480     protected: \
481         std::vector<xmltooling::XMLObject*> m_##proper##s; \
482     public: \
483         VectorOf(xmltooling::XMLObject) get##proper##s() { \
484             return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
485         } \
486         const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
487             return m_##proper##s; \
488         } 
489
490 /**
491  * Implements marshalling for a string attribute
492  * 
493  * @param proper        the proper name of the attribute
494  * @param ucase         the upcased name of the attribute
495  * @param namespaceURI  the XML namespace of the attribute
496  */
497 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
498     if(get##proper()) { \
499         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
500     }
501
502 /**
503  * Implements marshalling for a DateTime attribute
504  * 
505  * @param proper        the proper name of the attribute
506  * @param ucase         the upcased name of the attribute
507  * @param namespaceURI  the XML namespace of the attribute
508  */
509 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
510     if(get##proper()) { \
511         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()->getRawData()); \
512     }
513
514 /**
515  * Implements marshalling for an integer attribute
516  * 
517  * @param proper        the proper name of the attribute
518  * @param ucase         the upcased name of the attribute
519  * @param namespaceURI  the XML namespace of the attribute
520  */
521 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
522     char buf##proper[64]; \
523     sprintf(buf##proper,"%d",get##proper()); \
524     auto_ptr_XMLCh wide##proper(buf##proper); \
525     domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, wide##proper.get())
526
527 /**
528  * Implements marshalling for a QName attribute
529  * 
530  * @param proper        the proper name of the attribute
531  * @param ucase         the upcased name of the attribute
532  * @param namespaceURI  the XML namespace of the attribute
533  */
534 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
535     if(get##proper()) { \
536         auto_ptr_XMLCh qstr(get##proper()->toString().c_str()); \
537         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
538     }
539
540 /**
541  * Implements marshalling for an ID attribute
542  * 
543  * @param proper        the proper name of the attribute
544  * @param ucase         the upcased name of the attribute
545  * @param namespaceURI  the XML namespace of the attribute
546  */
547 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
548     if(get##proper()) { \
549         domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
550         domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
551     }
552
553 /**
554  * Implements unmarshalling process branch for a string attribute
555  * 
556  * @param proper        the proper name of the attribute
557  * @param ucase         the upcased name of the attribute
558  * @param namespaceURI  the XML namespace of the attribute
559  */
560 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
561     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
562         set##proper(attribute->getValue()); \
563         return; \
564     }
565
566 /**
567  * Implements unmarshalling process branch for an ID attribute
568  * 
569  * @param proper        the proper name of the attribute
570  * @param ucase         the upcased name of the attribute
571  * @param namespaceURI  the XML namespace of the attribute
572  */
573 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
574     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
575         set##proper(attribute->getValue()); \
576         static_cast<DOMElement*>(attribute->getParentNode())->setIdAttributeNode(attribute); \
577         return; \
578     }
579
580 /**
581  * Implements unmarshalling process branch for a DateTime attribute
582  * 
583  * @param proper        the proper name of the attribute
584  * @param ucase         the upcased name of the attribute
585  * @param namespaceURI  the XML namespace of the attribute
586  */
587 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
588     PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
589
590 /**
591  * Implements unmarshalling process branch for a DateTime attribute
592  * 
593  * @param proper        the proper name of the attribute
594  * @param ucase         the upcased name of the attribute
595  * @param namespaceURI  the XML namespace of the attribute
596  */
597 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
598     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
599         set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
600         return; \
601     }
602
603 /**
604  * Implements unmarshalling process branch for an integer attribute
605  * 
606  * @param proper        the proper name of the attribute
607  * @param ucase         the upcased name of the attribute
608  * @param namespaceURI  the XML namespace of the attribute
609  */
610 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
611     if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
612         set##proper(XMLString::parseInt(attribute->getValue())); \
613         return; \
614     }
615
616
617 /**
618  * Implements unmarshalling process branch for typed child collection element
619  * 
620  * @param proper        the proper name of the child type
621  * @param namespaceURI  the XML namespace of the child element
622  * @param force         bypass use of hint and just cast down to check child
623  */
624 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
625     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
626         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
627         if (typesafe) { \
628             get##proper##s().push_back(typesafe); \
629             return; \
630         } \
631     }
632
633 /**
634  * Implements unmarshalling process branch for typed child singleton element
635  * 
636  * @param proper        the proper name of the child type
637  * @param namespaceURI  the XML namespace of the child element
638  * @param force         bypass use of hint and just cast down to check child
639  */
640 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
641     if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
642         proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
643         if (typesafe) { \
644             set##proper(typesafe); \
645             return; \
646         } \
647     }
648
649 /**
650  * Declares aliased get/set methods for named XML element content.
651  * 
652  * @param proper    the proper name to label the element's content
653  */
654 #define DECL_XMLOBJECT_CONTENT(proper) \
655     XMLTOOLING_DOXYGEN(Returns proper.) \
656     const XMLCh* get##proper() const { \
657         return getTextContent(); \
658     } \
659     XMLTOOLING_DOXYGEN(Sets or clears proper.) \
660     void set##proper(const XMLCh* proper) { \
661         setTextContent(proper); \
662     }
663
664 /**
665  * Implements marshalling/unmarshalling for element content.
666  */
667 #define IMPL_XMLOBJECT_CONTENT \
668     protected: \
669         void marshallElementContent(DOMElement* domElement) const { \
670             if(getTextContent()) { \
671                 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
672             } \
673         } \
674         void processElementContent(const XMLCh* elementContent) { \
675             setTextContent(elementContent); \
676         }
677
678
679 /**
680  * Implements cloning methods for an XMLObject specialization implementation class.
681  * 
682  * @param cname    the name of the XMLObject specialization
683  */
684 #define IMPL_XMLOBJECT_CLONE(cname) \
685     cname* clone##cname() const { \
686         return clone(); \
687     } \
688     cname* clone() const { \
689         std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
690         cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
691         if (ret) { \
692             domClone.release(); \
693             return ret; \
694         } \
695         return new cname##Impl(*this); \
696     }
697
698 /**
699  * Declares an XMLObject specialization with a simple content model and type,
700  * handling it as string data.
701  * 
702  * @param linkage   linkage specifier for the class
703  * @param cname     the name of the XMLObject specialization
704  * @param proper    the proper name to label the element's content
705  * @param desc      documentation for class
706  */
707 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
708     BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
709         DECL_XMLOBJECT_CONTENT(proper); \
710     END_XMLOBJECT
711
712 /**
713  * Declares and defines an implementation class for an XMLObject with
714  * a simple content model and type, handling it as string data.
715  * 
716  * @param linkage   linkage specifier for the class
717  * @param cname     the name of the XMLObject specialization
718  */
719 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
720     class linkage cname##Impl \
721         : public virtual cname, \
722             public xmltooling::AbstractSimpleElement, \
723             public xmltooling::AbstractChildlessElement, \
724             public xmltooling::AbstractDOMCachingXMLObject, \
725             public xmltooling::AbstractValidatingXMLObject, \
726             public xmltooling::AbstractXMLObjectMarshaller, \
727             public xmltooling::AbstractXMLObjectUnmarshaller \
728     { \
729     public: \
730         virtual ~cname##Impl() {} \
731         cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
732             : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
733         } \
734         cname##Impl(const cname##Impl& src) \
735             : xmltooling::AbstractXMLObject(src), \
736                 xmltooling::AbstractSimpleElement(src), \
737                 xmltooling::AbstractDOMCachingXMLObject(src), \
738                 xmltooling::AbstractValidatingXMLObject(src) {} \
739         IMPL_XMLOBJECT_CLONE(cname) \
740         IMPL_XMLOBJECT_CONTENT \
741     }
742     
743 /**
744  * Begins the declaration of an XMLObjectBuilder specialization.
745  * Basic boilerplate includes an empty virtual destructor, and
746  * a default builder that defaults the element name.
747  * 
748  * @param linkage           linkage specifier for the class
749  * @param cname             the name of the XMLObject specialization
750  * @param namespaceURI      the XML namespace of the default associated element
751  * @param namespacePrefix   the XML namespace prefix of the default associated element
752  */
753 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
754     XMLTOOLING_DOXYGEN(Builder for cname objects.) \
755     class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
756     public: \
757         virtual ~cname##Builder() {} \
758         XMLTOOLING_DOXYGEN(Default builder.) \
759         virtual cname* buildObject() const { \
760             return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
761         } \
762         XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
763         virtual cname* buildObject( \
764             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
765             ) const
766
767 /**
768  * Ends the declaration of an XMLObjectBuilder specialization.
769  */
770 #define END_XMLOBJECTBUILDER }
771
772 /**
773  * Declares a generic XMLObjectBuilder specialization.
774  * 
775  * @param linkage           linkage specifier for the class
776  * @param cname             the name of the XMLObject specialization
777  * @param namespaceURI      the XML namespace of the default associated element
778  * @param namespacePrefix   the XML namespace prefix of the default associated element
779  */
780  #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
781     BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
782     XMLTOOLING_DOXYGEN(Singleton builder.) \
783     static cname* build##cname() { \
784         const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
785             XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
786             ); \
787         if (b) \
788             return b->buildObject(); \
789         throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
790     } \
791     END_XMLOBJECTBUILDER
792
793 /**
794  * Implements the standard XMLObjectBuilder specialization function. 
795  * 
796  * @param cname the name of the XMLObject specialization
797  */
798 #define IMPL_XMLOBJECTBUILDER(cname) \
799     cname* cname##Builder::buildObject( \
800         const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
801         ) const \
802     { \
803         return new cname##Impl(nsURI,localName,prefix,schemaType); \
804     }
805
806 /**
807  * Begins the declaration of a Schema Validator specialization.
808  * 
809  * @param linkage           linkage specifier for the class
810  * @param cname the base name of the Validator specialization
811  */
812  #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
813     class linkage cname##SchemaValidator : public xmltooling::Validator \
814     { \
815     public: \
816         virtual ~cname##SchemaValidator() {} \
817         virtual cname##SchemaValidator* clone() const { \
818             return new cname##SchemaValidator(); \
819         } \
820         virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
821             const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
822             if (!ptr) \
823                 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
824
825 /**
826  * Ends the declaration of a Validator specialization.
827  */
828 #define END_XMLOBJECTVALIDATOR } }
829
830 /**
831  * Validator code that checks the object type.
832  * 
833  * @param cname     the name of the XMLObject specialization
834  */
835 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
836     const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
837     if (!ptr) \
838         throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
839
840 /**
841  * Validator code that checks for a required attribute, content, or singleton.
842  * 
843  * @param cname     the name of the XMLObject specialization
844  * @param proper    the proper name of the attribute, content, or singleton member 
845  */
846 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
847     if (!ptr->get##proper()) \
848         throw xmltooling::ValidationException(#cname" must have "#proper".")
849
850 /**
851  * Validator code that checks for one of a pair of
852  * required attributes, content, or singletons.
853  * 
854  * @param cname     the name of the XMLObject specialization
855  * @param proper1   the proper name of the first attribute, content, or singleton member 
856  * @param proper2   the proper name of the second attribute, content, or singleton member 
857  */
858 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
859     if (!ptr->get##proper1() && !ptr->get##proper2()) \
860         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
861
862 /**
863  * Validator code that checks for one of a pair of
864  * required attributes, content, or singletons, but disallows both.
865  * 
866  * @param cname     the name of the XMLObject specialization
867  * @param proper1   the proper name of the first attribute, content, or singleton member 
868  * @param proper2   the proper name of the second attribute, content, or singleton member 
869  */
870 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
871     if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
872         throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
873
874 /**
875  * Validator code that checks for one of a set of three
876  * required attributes, content, or singletons.
877  * 
878  * @param cname     the name of the XMLObject specialization
879  * @param proper1   the proper name of the first attribute, content, or singleton member
880  * @param proper2   the proper name of the second attribute, content, or singleton member
881  * @param proper3   the proper name of the third attribute, content, or singleton member
882  */
883 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
884     if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
885         throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
886
887 /**
888  * Validator code that checks for one of a set of three
889  * required attributes, content, or singletons but disallows more than one.
890  * 
891  * @param cname     the name of the XMLObject specialization
892  * @param proper1   the proper name of the first attribute, content, or singleton member
893  * @param proper2   the proper name of the second attribute, content, or singleton member
894  * @param proper3   the proper name of the third attribute, content, or singleton member
895  */
896 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
897     int c##proper1##proper2##proper3=0; \
898     if (ptr->get##proper1()!=NULL) \
899         c##proper1##proper2##proper3++; \
900     if (ptr->get##proper2()!=NULL) \
901         c##proper1##proper2##proper3++; \
902     if (ptr->get##proper3()!=NULL) \
903         c##proper1##proper2##proper3++; \
904     if (c##proper1##proper2##proper3 != 1) \
905         throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
906
907 /**
908  * Validator code that checks a co-constraint (if one present, the other must be)
909  * between a pair of attributes, content, or singletons.
910  * 
911  * @param cname     the name of the XMLObject specialization
912  * @param proper1   the proper name of the first attribute, content, or singleton member 
913  * @param proper2   the proper name of the second attribute, content, or singleton member 
914  */
915 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
916     if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
917         throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
918
919 /**
920  * Validator code that checks for a non-empty collection.
921  * 
922  * @param cname     the name of the XMLObject specialization
923  * @param proper    the proper name of the collection item 
924  */
925 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
926     if (ptr->get##proper##s().empty()) \
927         throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
928
929 /**
930  * Declares/defines a Validator specialization that checks object type and
931  * a non-empty simple content model.
932  * 
933  * @param linkage   linkage specifier for the class
934  * @param cname     the name of the XMLObject specialization
935  */
936 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
937     BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
938         XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
939     END_XMLOBJECTVALIDATOR
940
941 #include <utility>
942
943 /**
944  * @namespace xmltooling
945  * Public namespace of XML Tooling library
946  */
947 namespace xmltooling {
948
949     /**
950      * Template function for cloning a sequence of XMLObjects.
951      * Invokes the clone() member on each element of the input sequence and adds the copy to
952      * the output sequence. Order is preserved.
953      * 
954      * @param in    input sequence to clone
955      * @param out   output sequence to copy cloned pointers into
956      */
957     template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
958         for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
959             if (*i)
960                 out.push_back((*i)->clone());
961             else
962                 out.push_back(*i);
963         }
964     }
965
966     /**
967      * Functor for cleaning up heap objects in containers.
968      */
969     template<class T> struct cleanup
970     {
971         /**
972          * Function operator to delete an object.
973          * 
974          * @param ptr   object to delete
975          */
976         void operator()(T* ptr) {delete ptr;}
977         
978         /**
979          * Function operator to delete an object stored as const.
980          * 
981          * @param ptr   object to delete after casting away const
982          */
983         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
984     };
985
986     /**
987      * Functor for cleaning up heap objects in key/value containers.
988      */
989     template<class A,class B> struct cleanup_pair
990     {
991         /**
992          * Function operator to delete an object.
993          * 
994          * @param p   a pair in which the second component is the object to delete
995          */
996         void operator()(const std::pair<A,B*>& p) {delete p.second;}
997     };
998 };
999
1000 #endif /* __xmltooling_base_h__ */