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 * Ends the declaration of an XMLObject specialization.
245 #define END_XMLOBJECT }
248 * Declares abstract get/set methods for a typed XML attribute.
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
254 #define DECL_XMLOBJECT_ATTRIB(proper,upcased,type) \
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
264 * Declares abstract get/set methods for a string XML attribute.
266 * @param proper the proper name of the attribute
267 * @param upcased the upcased name of the attribute
269 #define DECL_STRING_ATTRIB(proper,upcased) \
270 DECL_XMLOBJECT_ATTRIB(proper,upcased,XMLCh)
273 * Declares abstract get/set methods for a string XML attribute.
275 * @param proper the proper name of the attribute
276 * @param upcased the upcased name of the attribute
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
286 * Declares abstract get/set methods for an integer XML attribute.
288 * @param proper the proper name of the attribute
289 * @param upcased the upcased name of the attribute
291 #define DECL_INTEGER_ATTRIB(proper,upcased) \
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
301 * Implements get/set methods and a private member for a typed XML attribute.
303 * @param proper the proper name of the attribute
304 * @param type the attribute's data type
306 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
310 const type* get##proper() const { \
313 void set##proper(const type* proper) { \
314 m_##proper = prepareForAssignment(m_##proper,proper); \
318 * Implements get/set methods and a private member for a string XML attribute.
320 * @param proper the proper name of the attribute
322 #define IMPL_STRING_ATTRIB(proper) \
323 IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
326 * Implements get/set methods and a private member for a DateTime XML attribute.
328 * @param proper the proper name of the attribute
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); \
335 void set##proper(const XMLCh* proper) { \
336 m_##proper = prepareForAssignment(m_##proper,proper); \
340 * Implements get/set methods and a private member for an integer XML attribute.
342 * @param proper the proper name of the attribute
344 #define IMPL_INTEGER_ATTRIB(proper) \
348 int get##proper() const { \
351 void set##proper(int proper) { \
352 if (m_##proper != proper) { \
353 releaseThisandParentDOM(); \
354 m_##proper = proper; \
359 * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
361 * @param proper the proper name of the child type
362 * @param ns the C++ namespace for the type
364 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
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
372 * Declares abstract get/set methods for a typed XML child object.
374 * @param proper the proper name of the child type
376 #define DECL_TYPED_CHILD(proper) \
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
384 * Declares abstract get/set methods for a generic XML child object.
386 * @param proper the proper name of the child
388 #define DECL_XMLOBJECT_CHILD(proper) \
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
397 * Implements get/set methods and a private list iterator member for a typed XML child object.
399 * @param proper the proper name of the child type
401 #define IMPL_TYPED_CHILD(proper) \
403 proper* m_##proper; \
404 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
406 proper* get##proper() const { \
409 void set##proper(proper* child) { \
410 prepareForAssignment(m_##proper,child); \
411 *m_pos_##proper = m_##proper = child; \
415 * Implements get/set methods and a private list iterator member for a generic XML child object.
417 * @param proper the proper name of the child
419 #define IMPL_XMLOBJECT_CHILD(proper) \
421 xmltooling::XMLObject* m_##proper; \
422 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
424 xmltooling::XMLObject* get##proper() const { \
427 void set##proper(xmltooling::XMLObject* child) { \
428 prepareForAssignment(m_##proper,child); \
429 *m_pos_##proper = m_##proper = child; \
433 * Declares abstract get/set methods for a typed XML child collection.
435 * @param proper the proper name of the child type
437 #define DECL_TYPED_CHILDREN(proper) \
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
445 * Declares abstract get/set methods for a generic XML child collection.
447 * @param proper the proper name of the child
449 #define DECL_XMLOBJECT_CHILDREN(proper) \
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
457 * Implements get method and a private vector member for a typed XML child collection.
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
462 #define IMPL_TYPED_CHILDREN(proper,fence) \
464 std::vector<proper*> m_##proper##s; \
466 VectorOf(proper) get##proper##s() { \
467 return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
469 const std::vector<proper*>& get##proper##s() const { \
470 return m_##proper##s; \
474 * Implements get method and a private vector member for a generic XML child collection.
476 * @param proper the proper name of the child
477 * @param fence insertion fence for new objects of the child collection in backing list
479 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
481 std::vector<xmltooling::XMLObject*> m_##proper##s; \
483 VectorOf(xmltooling::XMLObject) get##proper##s() { \
484 return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
486 const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
487 return m_##proper##s; \
491 * Implements marshalling for a string attribute
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
497 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
498 if(get##proper()) { \
499 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()); \
503 * Implements marshalling for a DateTime attribute
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
509 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
510 if(get##proper()) { \
511 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, get##proper()->getRawData()); \
515 * Implements marshalling for an integer attribute
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
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())
528 * Implements marshalling for a QName attribute
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
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()); \
541 * Implements marshalling for an ID attribute
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
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); \
554 * Implements unmarshalling process branch for a string attribute
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
560 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
561 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
562 set##proper(attribute->getValue()); \
567 * Implements unmarshalling process branch for an ID attribute
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
573 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
574 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
575 set##proper(attribute->getValue()); \
576 attribute->getOwnerElement()->setIdAttributeNode(attribute); \
581 * Implements unmarshalling process branch for a DateTime attribute
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
587 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
588 PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
591 * Implements unmarshalling process branch for a DateTime attribute
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
597 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
598 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
599 set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
604 * Implements unmarshalling process branch for an integer attribute
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
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())); \
618 * Implements unmarshalling process branch for typed child collection element
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
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); \
628 get##proper##s().push_back(typesafe); \
634 * Implements unmarshalling process branch for typed child singleton element
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
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); \
644 set##proper(typesafe); \
650 * Declares aliased get/set methods for named XML element content.
652 * @param proper the proper name to label the element's content
654 #define DECL_XMLOBJECT_CONTENT(proper) \
655 XMLTOOLING_DOXYGEN(Returns proper.) \
656 const XMLCh* get##proper() const { \
657 return getTextContent(); \
659 XMLTOOLING_DOXYGEN(Sets or clears proper.) \
660 void set##proper(const XMLCh* proper) { \
661 setTextContent(proper); \
665 * Implements marshalling/unmarshalling for element content.
667 #define IMPL_XMLOBJECT_CONTENT \
669 void marshallElementContent(DOMElement* domElement) const { \
670 if(getTextContent()) { \
671 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
674 void processElementContent(const XMLCh* elementContent) { \
675 setTextContent(elementContent); \
680 * Implements cloning methods for an XMLObject specialization implementation class.
682 * @param cname the name of the XMLObject specialization
684 #define IMPL_XMLOBJECT_CLONE(cname) \
685 cname* clone##cname() const { \
688 cname* clone() const { \
689 std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
690 cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
692 domClone.release(); \
695 return new cname##Impl(*this); \
699 * Declares an XMLObject specialization with a simple content model and type,
700 * handling it as string data.
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
707 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
708 BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
709 DECL_XMLOBJECT_CONTENT(proper); \
713 * Declares and defines an implementation class for an XMLObject with
714 * a simple content model and type, handling it as string data.
716 * @param linkage linkage specifier for the class
717 * @param cname the name of the XMLObject specialization
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 \
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) { \
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 \
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.
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
753 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
754 XMLTOOLING_DOXYGEN(Builder for cname objects.) \
755 class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
757 virtual ~cname##Builder() {} \
758 XMLTOOLING_DOXYGEN(Default builder.) \
759 virtual cname* buildObject() const { \
760 return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
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 \
768 * Ends the declaration of an XMLObjectBuilder specialization.
770 #define END_XMLOBJECTBUILDER }
773 * Declares a generic XMLObjectBuilder specialization.
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
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)) \
788 return b->buildObject(); \
789 throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
794 * Implements the standard XMLObjectBuilder specialization function.
796 * @param cname the name of the XMLObject specialization
798 #define IMPL_XMLOBJECTBUILDER(cname) \
799 cname* cname##Builder::buildObject( \
800 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
803 return new cname##Impl(nsURI,localName,prefix,schemaType); \
807 * Begins the declaration of a Schema Validator specialization.
809 * @param linkage linkage specifier for the class
810 * @param cname the base name of the Validator specialization
812 #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
813 class linkage cname##SchemaValidator : public xmltooling::Validator \
816 virtual ~cname##SchemaValidator() {} \
817 virtual cname##SchemaValidator* clone() const { \
818 return new cname##SchemaValidator(); \
820 virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
821 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
823 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
826 * Ends the declaration of a Validator specialization.
828 #define END_XMLOBJECTVALIDATOR } }
831 * Validator code that checks the object type.
833 * @param cname the name of the XMLObject specialization
835 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
836 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
838 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
841 * Validator code that checks for a required attribute, content, or singleton.
843 * @param cname the name of the XMLObject specialization
844 * @param proper the proper name of the attribute, content, or singleton member
846 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
847 if (!ptr->get##proper()) \
848 throw xmltooling::ValidationException(#cname" must have "#proper".")
851 * Validator code that checks for one of a pair of
852 * required attributes, content, or singletons.
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
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".")
863 * Validator code that checks for one of a pair of
864 * required attributes, content, or singletons, but disallows both.
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
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.")
875 * Validator code that checks for one of a set of three
876 * required attributes, content, or singletons.
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
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".")
888 * Validator code that checks for one of a set of three
889 * required attributes, content, or singletons but disallows more than one.
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
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".")
908 * Validator code that checks a co-constraint (if one present, the other must be)
909 * between a pair of attributes, content, or singletons.
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
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".")
920 * Validator code that checks for a non-empty collection.
922 * @param cname the name of the XMLObject specialization
923 * @param proper the proper name of the collection item
925 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
926 if (ptr->get##proper##s().empty()) \
927 throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
930 * Declares/defines a Validator specialization that checks object type and
931 * a non-empty simple content model.
933 * @param linkage linkage specifier for the class
934 * @param cname the name of the XMLObject specialization
936 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
937 BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
938 XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
939 END_XMLOBJECTVALIDATOR
944 * @namespace xmltooling
945 * Public namespace of XML Tooling library
947 namespace xmltooling {
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.
954 * @param in input sequence to clone
955 * @param out output sequence to copy cloned pointers into
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++) {
960 out.push_back((*i)->clone());
967 * Functor for cleaning up heap objects in containers.
969 template<class T> struct cleanup
972 * Function operator to delete an object.
974 * @param ptr object to delete
976 void operator()(T* ptr) {delete ptr;}
979 * Function operator to delete an object stored as const.
981 * @param ptr object to delete after casting away const
983 void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
987 * Functor for cleaning up heap objects in key/value containers.
989 template<class A,class B> struct cleanup_pair
992 * Function operator to delete an object.
994 * @param p a pair in which the second component is the object to delete
996 void operator()(const std::pair<A,B*>& p) {delete p.second;}
1000 #endif /* __xmltooling_base_h__ */