2 * Copyright 2001-2006 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Base header file definitions
21 * Must be included prior to including any other header
24 #ifndef __xmltooling_base_h__
25 #define __xmltooling_base_h__
27 #if defined (_MSC_VER) || defined(__BORLANDC__)
28 #include <xmltooling/config_pub_win32.h>
30 #include <xmltooling/config_pub.h>
33 // Windows and GCC4 Symbol Visibility Macros
35 #define XMLTOOL_IMPORT __declspec(dllimport)
36 #define XMLTOOL_EXPORT __declspec(dllexport)
37 #define XMLTOOL_DLLLOCAL
38 #define XMLTOOL_DLLPUBLIC
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")))
46 #define XMLTOOL_EXPORT
47 #define XMLTOOL_DLLLOCAL
48 #define XMLTOOL_DLLPUBLIC
52 // Define XMLTOOL_API for DLL builds
53 #ifdef XMLTOOLING_EXPORTS
54 #define XMLTOOL_API XMLTOOL_EXPORT
56 #define XMLTOOL_API XMLTOOL_IMPORT
59 // Throwable classes must always be visible on GCC in all binaries
61 #define XMLTOOL_EXCEPTIONAPI(api) api
62 #elif defined(GCC_HASCLASSVISIBILITY)
63 #define XMLTOOL_EXCEPTIONAPI(api) XMLTOOL_EXPORT
65 #define XMLTOOL_EXCEPTIONAPI(api)
69 #define XMLTOOLING_DOXYGEN(desc) /##** desc */
71 #define XMLTOOLING_DOXYGEN(desc)
75 * Blocks copy c'tor and assignment operator for a class.
77 #define MAKE_NONCOPYABLE(type) \
80 type& operator=(const type&);
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, \
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, \
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 */
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.
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
209 #define DECL_XMLOBJECT_ABSTRACT(linkage,cname,base,desc) \
210 XMLTOOLING_DOXYGEN(desc) \
211 class linkage cname : public virtual base { \
215 virtual ~cname() {} \
216 XMLTOOLING_DOXYGEN(Element local name) \
217 static const XMLCh LOCAL_NAME[]; \
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.
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
230 #define BEGIN_XMLOBJECT(linkage,cname,base,desc) \
231 XMLTOOLING_DOXYGEN(desc) \
232 class linkage cname : public virtual base, public virtual xmltooling::ValidatingXMLObject { \
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[]
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.
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
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 { \
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[]
266 * Ends the declaration of an XMLObject specialization.
268 #define END_XMLOBJECT }
271 * Declares abstract get/set methods for a typed XML attribute.
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
277 #define DECL_XMLOBJECT_ATTRIB(proper,upcased,type) \
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
287 * Declares abstract get/set methods for a string XML attribute.
289 * @param proper the proper name of the attribute
290 * @param upcased the upcased name of the attribute
292 #define DECL_STRING_ATTRIB(proper,upcased) \
293 DECL_XMLOBJECT_ATTRIB(proper,upcased,XMLCh)
296 * Declares abstract get/set methods for a string XML attribute.
298 * @param proper the proper name of the attribute
299 * @param upcased the upcased name of the attribute
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
309 * Declares abstract get/set methods for an integer XML attribute.
311 * @param proper the proper name of the attribute
312 * @param upcased the upcased name of the attribute
314 #define DECL_INTEGER_ATTRIB(proper,upcased) \
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
324 * Declares abstract get/set methods for a boolean XML attribute.
326 * @param proper the proper name of the attribute
327 * @param upcased the upcased name of the attribute
329 #define DECL_BOOLEAN_ATTRIB(proper,upcased) \
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
339 * Implements get/set methods and a private member for a typed XML attribute.
341 * @param proper the proper name of the attribute
342 * @param type the attribute's data type
344 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
348 const type* get##proper() const { \
351 void set##proper(const type* proper) { \
352 m_##proper = prepareForAssignment(m_##proper,proper); \
356 * Implements get/set methods and a private member for a string XML attribute.
358 * @param proper the proper name of the attribute
360 #define IMPL_STRING_ATTRIB(proper) \
361 IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
364 * Implements get/set methods and a private member for a DateTime XML attribute.
366 * @param proper the proper name of the attribute
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); \
373 void set##proper(const XMLCh* proper) { \
374 m_##proper = prepareForAssignment(m_##proper,proper); \
378 * Implements get/set methods and a private member for an integer XML attribute.
380 * @param proper the proper name of the attribute
382 #define IMPL_INTEGER_ATTRIB(proper) \
386 int get##proper() const { \
389 void set##proper(int proper) { \
390 if (m_##proper != proper) { \
391 releaseThisandParentDOM(); \
392 m_##proper = proper; \
397 * Implements get/set methods and a private member for a boolean XML attribute.
399 * @param proper the proper name of the attribute
401 #define IMPL_BOOLEAN_ATTRIB(proper) \
405 bool proper() const { \
408 void proper(bool value) { \
409 if (m_##proper != value) { \
410 releaseThisandParentDOM(); \
411 m_##proper = value; \
416 * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
418 * @param proper the proper name of the child type
419 * @param ns the C++ namespace for the type
421 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
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
429 * Declares abstract get/set methods for a typed XML child object.
431 * @param proper the proper name of the child type
433 #define DECL_TYPED_CHILD(proper) \
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
441 * Declares abstract get/set methods for a generic XML child object.
443 * @param proper the proper name of the child
445 #define DECL_XMLOBJECT_CHILD(proper) \
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
454 * Implements get/set methods and a private list iterator member for a typed XML child object.
456 * @param proper the proper name of the child type
458 #define IMPL_TYPED_CHILD(proper) \
460 proper* m_##proper; \
461 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
463 proper* get##proper() const { \
466 void set##proper(proper* child) { \
467 prepareForAssignment(m_##proper,child); \
468 *m_pos_##proper = m_##proper = child; \
472 * Implements get/set methods and a private list iterator member for
473 * a typed XML child object in a foreign namespace
475 * @param proper the proper name of the child type
476 * @param ns the C++ namespace for the type
478 #define IMPL_TYPED_FOREIGN_CHILD(proper,ns) \
480 ns::proper* m_##proper; \
481 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
483 ns::proper* get##proper() const { \
486 void set##proper(ns::proper* child) { \
487 prepareForAssignment(m_##proper,child); \
488 *m_pos_##proper = m_##proper = child; \
492 * Implements get/set methods and a private list iterator member for a generic XML child object.
494 * @param proper the proper name of the child
496 #define IMPL_XMLOBJECT_CHILD(proper) \
498 xmltooling::XMLObject* m_##proper; \
499 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
501 xmltooling::XMLObject* get##proper() const { \
504 void set##proper(xmltooling::XMLObject* child) { \
505 prepareForAssignment(m_##proper,child); \
506 *m_pos_##proper = m_##proper = child; \
510 * Declares abstract get/set methods for a typed XML child collection.
512 * @param proper the proper name of the child type
514 #define DECL_TYPED_CHILDREN(proper) \
516 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
517 virtual VectorOf(proper) get##proper##s()=0; \
518 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
519 virtual const std::vector<proper*>& get##proper##s() const=0
522 * Declares abstract get/set methods for a typed XML child collection in a foreign namespace.
524 * @param proper the proper name of the child type
525 * @param ns the C++ namespace for the type
527 #define DECL_TYPED_FOREIGN_CHILDREN(proper,ns) \
529 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
530 virtual VectorOf(ns::proper) get##proper##s()=0; \
531 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
532 virtual const std::vector<ns::proper*>& get##proper##s() const=0
535 * Declares abstract get/set methods for a generic XML child collection.
537 * @param proper the proper name of the child
539 #define DECL_XMLOBJECT_CHILDREN(proper) \
541 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
542 virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
543 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
544 virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
547 * Implements get method and a private vector member for a typed XML child collection.
549 * @param proper the proper name of the child type
550 * @param fence insertion fence for new objects of the child collection in backing list
552 #define IMPL_TYPED_CHILDREN(proper,fence) \
554 std::vector<proper*> m_##proper##s; \
556 VectorOf(proper) get##proper##s() { \
557 return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
559 const std::vector<proper*>& get##proper##s() const { \
560 return m_##proper##s; \
564 * Implements get method and a private vector member for a typed XML child collection
565 * in a foreign namespace.
567 * @param proper the proper name of the child type
568 * @param ns the C++ namespace for the type
569 * @param fence insertion fence for new objects of the child collection in backing list
571 #define IMPL_TYPED_FOREIGN_CHILDREN(proper,ns,fence) \
573 std::vector<ns::proper*> m_##proper##s; \
575 VectorOf(ns::proper) get##proper##s() { \
576 return VectorOf(ns::proper)(this, m_##proper##s, &m_children, fence); \
578 const std::vector<ns::proper*>& get##proper##s() const { \
579 return m_##proper##s; \
583 * Implements get method and a private vector member for a generic XML child collection.
585 * @param proper the proper name of the child
586 * @param fence insertion fence for new objects of the child collection in backing list
588 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
590 std::vector<xmltooling::XMLObject*> m_##proper##s; \
592 VectorOf(xmltooling::XMLObject) get##proper##s() { \
593 return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
595 const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
596 return m_##proper##s; \
600 * Implements marshalling for a string attribute
602 * @param proper the proper name of the attribute
603 * @param ucase the upcased name of the attribute
604 * @param namespaceURI the XML namespace of the attribute
606 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
607 if(get##proper()) { \
608 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
612 * Implements marshalling for a DateTime attribute
614 * @param proper the proper name of the attribute
615 * @param ucase the upcased name of the attribute
616 * @param namespaceURI the XML namespace of the attribute
618 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
619 if(get##proper()) { \
620 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()->getRawData()); \
624 * Implements marshalling for an integer attribute
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
630 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
631 char buf##proper[64]; \
632 sprintf(buf##proper,"%d",get##proper()); \
633 auto_ptr_XMLCh wide##proper(buf##proper); \
634 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, wide##proper.get())
637 * Implements marshalling for a boolean attribute
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
643 #define MARSHALL_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
644 XMLCh flag##proper[2]; \
645 flag##proper[0]=m_##proper ? chDigit_1 : chDigit_0; \
646 flag##proper[1]=chNull; \
647 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, flag##proper)
650 * Implements marshalling for a QName attribute
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
656 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
657 if(get##proper()) { \
658 auto_ptr_XMLCh qstr(get##proper()->toString().c_str()); \
659 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
663 * Implements marshalling for an ID attribute
665 * @param proper the proper name of the attribute
666 * @param ucase the upcased name of the attribute
667 * @param namespaceURI the XML namespace of the attribute
669 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
670 if(get##proper()) { \
671 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
672 domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
676 * Implements unmarshalling process branch for a string attribute
678 * @param proper the proper name of the attribute
679 * @param ucase the upcased name of the attribute
680 * @param namespaceURI the XML namespace of the attribute
682 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
683 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
684 set##proper(attribute->getValue()); \
689 * Implements unmarshalling process branch for an ID attribute
691 * @param proper the proper name of the attribute
692 * @param ucase the upcased name of the attribute
693 * @param namespaceURI the XML namespace of the attribute
695 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
696 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
697 set##proper(attribute->getValue()); \
698 attribute->getOwnerElement()->setIdAttributeNode(attribute); \
703 * Implements unmarshalling process branch for a DateTime attribute
705 * @param proper the proper name of the attribute
706 * @param ucase the upcased name of the attribute
707 * @param namespaceURI the XML namespace of the attribute
709 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
710 PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
713 * Implements unmarshalling process branch for a DateTime attribute
715 * @param proper the proper name of the attribute
716 * @param ucase the upcased name of the attribute
717 * @param namespaceURI the XML namespace of the attribute
719 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
720 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
721 set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
726 * Implements unmarshalling process branch for an integer attribute
728 * @param proper the proper name of the attribute
729 * @param ucase the upcased name of the attribute
730 * @param namespaceURI the XML namespace of the attribute
732 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
733 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
734 set##proper(XMLString::parseInt(attribute->getValue())); \
739 * Implements unmarshalling process branch for a boolean attribute
741 * @param proper the proper name of the attribute
742 * @param ucase the upcased name of the attribute
743 * @param namespaceURI the XML namespace of the attribute
745 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
746 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
747 const XMLCh* value=attribute->getValue(); \
749 if (*value==chLatin_t || *value==chDigit_1) \
751 else if (*value==chLatin_f || *value==chDigit_0) \
758 * Implements unmarshalling process branch for typed child collection element
760 * @param proper the proper name of the child type
761 * @param namespaceURI the XML namespace of the child element
762 * @param force bypass use of hint and just cast down to check child
764 #define PROC_TYPED_CHILDREN(proper,namespaceURI,force) \
765 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
766 proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
768 get##proper##s().push_back(typesafe); \
774 * Implements unmarshalling process branch for typed child collection element
775 * in a foreign namespace.
777 * @param proper the proper name of the child type
778 * @param ns the C++ namespace for the type
779 * @param namespaceURI the XML namespace of the child element
780 * @param force bypass use of hint and just cast down to check child
782 #define PROC_TYPED_FOREIGN_CHILDREN(proper,ns,namespaceURI,force) \
783 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
784 ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
786 get##proper##s().push_back(typesafe); \
792 * Implements unmarshalling process branch for typed child singleton element
794 * @param proper the proper name of the child type
795 * @param namespaceURI the XML namespace of the child element
796 * @param force bypass use of hint and just cast down to check child
798 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
799 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
800 proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
802 set##proper(typesafe); \
808 * Implements unmarshalling process branch for typed child singleton element
809 * in a foreign namespace.
811 * @param proper the proper name of the child type
812 * @param ns the C++ namespace for the type
813 * @param namespaceURI the XML namespace of the child element
814 * @param force bypass use of hint and just cast down to check child
816 #define PROC_TYPED_FOREIGN_CHILD(proper,ns,namespaceURI,force) \
817 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
818 ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
820 set##proper(typesafe); \
826 * Implements unmarshalling process branch for a generic child singleton element
828 * @param proper the proper name of the child type
829 * @param namespaceURI the XML namespace of the child element
831 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
832 if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
833 set##proper(childXMLObject); \
838 * Declares aliased get/set methods for named XML element content.
840 * @param proper the proper name to label the element's content
842 #define DECL_XMLOBJECT_CONTENT(proper) \
843 XMLTOOLING_DOXYGEN(Returns proper.) \
844 const XMLCh* get##proper() const { \
845 return getTextContent(); \
847 XMLTOOLING_DOXYGEN(Sets or clears proper.) \
848 void set##proper(const XMLCh* proper) { \
849 setTextContent(proper); \
853 * Declares aliased get/set methods for named integer XML element content.
855 * @param proper the proper name to label the element's content
857 #define DECL_INTEGER_CONTENT(proper) \
858 XMLTOOLING_DOXYGEN(Returns proper.) \
859 int get##proper() const { \
860 return XMLString::parseInt(getTextContent()); \
862 XMLTOOLING_DOXYGEN(Sets or clears proper.) \
863 void set##proper(int proper) { \
865 sprintf(buf,"%d",proper); \
866 xmltooling::auto_ptr_XMLCh widebuf(buf); \
867 setTextContent(widebuf.get()); \
871 * Implements marshalling/unmarshalling for element content.
873 #define IMPL_XMLOBJECT_CONTENT \
875 void marshallElementContent(DOMElement* domElement) const { \
876 if(getTextContent()) { \
877 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
880 void processElementContent(const XMLCh* elementContent) { \
881 setTextContent(elementContent); \
886 * Implements cloning methods for an XMLObject specialization implementation class.
888 * @param cname the name of the XMLObject specialization
890 #define IMPL_XMLOBJECT_CLONE(cname) \
891 cname* clone##cname() const { \
894 cname* clone() const { \
895 std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
896 cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
898 domClone.release(); \
901 return new cname##Impl(*this); \
905 * Declares an XMLObject specialization with a simple content model and type,
906 * handling it as string data.
908 * @param linkage linkage specifier for the class
909 * @param cname the name of the XMLObject specialization
910 * @param proper the proper name to label the element's content
911 * @param desc documentation for class
913 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
914 BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
915 DECL_XMLOBJECT_CONTENT(proper); \
919 * Declares and defines an implementation class for an XMLObject with
920 * a simple content model and type, handling it as string data.
922 * @param linkage linkage specifier for the class
923 * @param cname the name of the XMLObject specialization
925 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
926 class linkage cname##Impl \
927 : public virtual cname, \
928 public xmltooling::AbstractSimpleElement, \
929 public xmltooling::AbstractChildlessElement, \
930 public xmltooling::AbstractDOMCachingXMLObject, \
931 public xmltooling::AbstractValidatingXMLObject, \
932 public xmltooling::AbstractXMLObjectMarshaller, \
933 public xmltooling::AbstractXMLObjectUnmarshaller \
936 virtual ~cname##Impl() {} \
937 cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
938 : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
940 cname##Impl(const cname##Impl& src) \
941 : xmltooling::AbstractXMLObject(src), \
942 xmltooling::AbstractSimpleElement(src), \
943 xmltooling::AbstractDOMCachingXMLObject(src), \
944 xmltooling::AbstractValidatingXMLObject(src) {} \
945 IMPL_XMLOBJECT_CLONE(cname) \
946 IMPL_XMLOBJECT_CONTENT \
950 * Begins the declaration of an XMLObjectBuilder specialization.
951 * Basic boilerplate includes an empty virtual destructor, and
952 * a default builder that defaults the element name.
954 * @param linkage linkage specifier for the class
955 * @param cname the name of the XMLObject specialization
956 * @param namespaceURI the XML namespace of the default associated element
957 * @param namespacePrefix the XML namespace prefix of the default associated element
959 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
960 XMLTOOLING_DOXYGEN(Builder for cname objects.) \
961 class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
963 virtual ~cname##Builder() {} \
964 XMLTOOLING_DOXYGEN(Default builder.) \
965 virtual cname* buildObject() const { \
966 return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
968 XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
969 virtual cname* buildObject( \
970 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
974 * Ends the declaration of an XMLObjectBuilder specialization.
976 #define END_XMLOBJECTBUILDER }
979 * Declares a generic XMLObjectBuilder specialization.
981 * @param linkage linkage specifier for the class
982 * @param cname the name of the XMLObject specialization
983 * @param namespaceURI the XML namespace of the default associated element
984 * @param namespacePrefix the XML namespace prefix of the default associated element
986 #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
987 BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
988 XMLTOOLING_DOXYGEN(Singleton builder.) \
989 static cname* build##cname() { \
990 const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
991 XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
994 return b->buildObject(); \
995 throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
1000 * Implements the standard XMLObjectBuilder specialization function.
1002 * @param cname the name of the XMLObject specialization
1004 #define IMPL_XMLOBJECTBUILDER(cname) \
1005 cname* cname##Builder::buildObject( \
1006 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
1009 return new cname##Impl(nsURI,localName,prefix,schemaType); \
1013 * Begins the declaration of a Schema Validator specialization.
1015 * @param linkage linkage specifier for the class
1016 * @param cname the base name of the Validator specialization
1018 #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
1019 class linkage cname##SchemaValidator : public xmltooling::Validator \
1022 virtual ~cname##SchemaValidator() {} \
1023 virtual cname##SchemaValidator* clone() const { \
1024 return new cname##SchemaValidator(); \
1026 virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1027 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1029 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1032 * Begins the declaration of a Schema Validator specialization subclass.
1034 * @param linkage linkage specifier for the class
1035 * @param cname the base name of the Validator specialization
1036 * @param base base class for the validator
1038 #define BEGIN_XMLOBJECTVALIDATOR_SUB(linkage,cname,base) \
1039 class linkage cname##SchemaValidator : public base##SchemaValidator \
1042 virtual ~cname##SchemaValidator() {} \
1043 virtual cname##SchemaValidator* clone() const { \
1044 return new cname##SchemaValidator(); \
1046 virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1047 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1049 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1052 * Ends the declaration of a Validator specialization.
1054 #define END_XMLOBJECTVALIDATOR } }
1057 * Validator code that checks the object type.
1059 * @param cname the name of the XMLObject specialization
1061 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
1062 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1064 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1067 * Validator code that checks for a required attribute, content, or singleton.
1069 * @param cname the name of the XMLObject specialization
1070 * @param proper the proper name of the attribute, content, or singleton member
1072 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
1073 if (!ptr->get##proper()) \
1074 throw xmltooling::ValidationException(#cname" must have "#proper".")
1077 * Validator code that checks for one of a pair of
1078 * required attributes, content, or singletons.
1080 * @param cname the name of the XMLObject specialization
1081 * @param proper1 the proper name of the first attribute, content, or singleton member
1082 * @param proper2 the proper name of the second attribute, content, or singleton member
1084 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
1085 if (!ptr->get##proper1() && !ptr->get##proper2()) \
1086 throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
1089 * Validator code that checks for one of a pair of
1090 * required attributes, content, or singletons, but disallows both.
1092 * @param cname the name of the XMLObject specialization
1093 * @param proper1 the proper name of the first attribute, content, or singleton member
1094 * @param proper2 the proper name of the second attribute, content, or singleton member
1096 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1097 if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1098 throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1101 * Validator code that checks for one of a set of three
1102 * required attributes, content, or singletons.
1104 * @param cname the name of the XMLObject specialization
1105 * @param proper1 the proper name of the first attribute, content, or singleton member
1106 * @param proper2 the proper name of the second attribute, content, or singleton member
1107 * @param proper3 the proper name of the third attribute, content, or singleton member
1109 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1110 if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1111 throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1114 * Validator code that checks for one of a set of three
1115 * required attributes, content, or singletons but disallows more than one.
1117 * @param cname the name of the XMLObject specialization
1118 * @param proper1 the proper name of the first attribute, content, or singleton member
1119 * @param proper2 the proper name of the second attribute, content, or singleton member
1120 * @param proper3 the proper name of the third attribute, content, or singleton member
1122 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1123 int c##proper1##proper2##proper3=0; \
1124 if (ptr->get##proper1()!=NULL) \
1125 c##proper1##proper2##proper3++; \
1126 if (ptr->get##proper2()!=NULL) \
1127 c##proper1##proper2##proper3++; \
1128 if (ptr->get##proper3()!=NULL) \
1129 c##proper1##proper2##proper3++; \
1130 if (c##proper1##proper2##proper3 != 1) \
1131 throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1134 * Validator code that checks a co-constraint (if one present, the other must be)
1135 * between a pair of attributes, content, or singletons.
1137 * @param cname the name of the XMLObject specialization
1138 * @param proper1 the proper name of the first attribute, content, or singleton member
1139 * @param proper2 the proper name of the second attribute, content, or singleton member
1141 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1142 if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1143 throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1146 * Validator code that checks for a non-empty collection.
1148 * @param cname the name of the XMLObject specialization
1149 * @param proper the proper name of the collection item
1151 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1152 if (ptr->get##proper##s().empty()) \
1153 throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1156 * Declares/defines a Validator specialization that checks object type and
1157 * a non-empty simple content model.
1159 * @param linkage linkage specifier for the class
1160 * @param cname the name of the XMLObject specialization
1162 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1163 BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1164 XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1165 END_XMLOBJECTVALIDATOR
1170 * @namespace xmltooling
1171 * Public namespace of XML Tooling library
1173 namespace xmltooling {
1176 * Template function for cloning a sequence of XMLObjects.
1177 * Invokes the clone() member on each element of the input sequence and adds the copy to
1178 * the output sequence. Order is preserved.
1180 * @param in input sequence to clone
1181 * @param out output sequence to copy cloned pointers into
1183 template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1184 for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1186 out.push_back((*i)->clone());
1193 * Functor for cleaning up heap objects in containers.
1195 template<class T> struct cleanup
1198 * Function operator to delete an object.
1200 * @param ptr object to delete
1202 void operator()(T* ptr) {delete ptr;}
1205 * Function operator to delete an object stored as const.
1207 * @param ptr object to delete after casting away const
1209 void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1213 * Functor for cleaning up heap objects in key/value containers.
1215 template<class A,class B> struct cleanup_pair
1218 * Function operator to delete an object.
1220 * @param p a pair in which the second component is the object to delete
1222 void operator()(const std::pair<A,B*>& p) {delete p.second;}
1226 #endif /* __xmltooling_base_h__ */