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 after a NULL indicator.) \
319 virtual std::pair<bool,int> get##proper() const=0; \
320 XMLTOOLING_DOXYGEN(Sets the proper attribute using a string value.) \
321 virtual void set##proper(const XMLCh* proper)=0; \
322 XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
323 virtual void set##proper(int proper)=0
326 * Declares abstract get/set methods for a boolean XML attribute.
328 * @param proper the proper name of the attribute
329 * @param upcased the upcased name of the attribute
331 #define DECL_BOOLEAN_ATTRIB(proper,upcased) \
333 XMLTOOLING_DOXYGEN(proper attribute name) \
334 static const XMLCh upcased##_ATTRIB_NAME[]; \
335 XMLTOOLING_DOXYGEN(Returns the proper attribute after a NULL indicator.) \
336 virtual std::pair<bool,bool> proper() const=0; \
337 XMLTOOLING_DOXYGEN(Sets the proper attribute using an enumerated value.) \
338 virtual void proper(xmltooling::XMLConstants::xmltooling_bool_t value)=0; \
339 XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
340 void proper(bool value) { \
341 proper(value ? xmltooling::XMLConstants::XML_BOOL_ONE : xmltooling::XMLConstants::XML_BOOL_ZERO); \
343 XMLTOOLING_DOXYGEN(Sets the proper attribute using a string constant.) \
344 void set##proper(const XMLCh* value) { \
348 proper(xmltooling::XMLConstants::XML_BOOL_TRUE); \
351 proper(xmltooling::XMLConstants::XML_BOOL_FALSE); \
354 proper(xmltooling::XMLConstants::XML_BOOL_ONE); \
357 proper(xmltooling::XMLConstants::XML_BOOL_ZERO); \
360 proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
364 proper(xmltooling::XMLConstants::XML_BOOL_NULL); \
368 * Implements get/set methods and a private member for a typed XML attribute.
370 * @param proper the proper name of the attribute
371 * @param type the attribute's data type
373 #define IMPL_XMLOBJECT_ATTRIB(proper,type) \
377 const type* get##proper() const { \
380 void set##proper(const type* proper) { \
381 m_##proper = prepareForAssignment(m_##proper,proper); \
385 * Implements get/set methods and a private member for a string XML attribute.
387 * @param proper the proper name of the attribute
389 #define IMPL_STRING_ATTRIB(proper) \
390 IMPL_XMLOBJECT_ATTRIB(proper,XMLCh)
393 * Implements get/set methods and a private member for a DateTime XML attribute.
395 * @param proper the proper name of the attribute
397 #define IMPL_DATETIME_ATTRIB(proper) \
398 IMPL_XMLOBJECT_ATTRIB(proper,xmltooling::DateTime); \
399 void set##proper(time_t proper) { \
400 m_##proper = prepareForAssignment(m_##proper,proper); \
402 void set##proper(const XMLCh* proper) { \
403 m_##proper = prepareForAssignment(m_##proper,proper); \
407 * Implements get/set methods and a private member for an integer XML attribute.
409 * @param proper the proper name of the attribute
411 #define IMPL_INTEGER_ATTRIB(proper) \
415 pair<bool,int> get##proper() const { \
416 return make_pair((m_##proper!=NULL),(m_##proper!=NULL ? XMLString::parseInt(m_##proper): NULL)); \
418 void set##proper(const XMLCh* proper) { \
419 m_##proper = prepareForAssignment(m_##proper,proper); \
421 void set##proper(int proper) { \
422 char buf##proper[64]; \
423 sprintf(buf##proper,"%d",proper); \
424 auto_ptr_XMLCh wide##proper(buf##proper); \
425 set##proper(wide##proper.get()); \
429 * Implements get/set methods and a private member for a boolean XML attribute.
431 * @param proper the proper name of the attribute
433 #define IMPL_BOOLEAN_ATTRIB(proper) \
435 XMLConstants::xmltooling_bool_t m_##proper; \
437 pair<bool,bool> proper() const { \
439 (m_##proper!=XMLConstants::XML_BOOL_NULL), \
440 (m_##proper==XMLConstants::XML_BOOL_TRUE || m_##proper==XMLConstants::XML_BOOL_ONE) \
443 void proper(XMLConstants::xmltooling_bool_t value) { \
444 if (m_##proper != value) { \
445 releaseThisandParentDOM(); \
446 m_##proper = value; \
451 * Declares abstract get/set methods for a typed XML child object in a foreign namespace.
453 * @param proper the proper name of the child type
454 * @param ns the C++ namespace for the type
456 #define DECL_TYPED_FOREIGN_CHILD(proper,ns) \
458 XMLTOOLING_DOXYGEN(Returns the proper child.) \
459 virtual ns::proper* get##proper() const=0; \
460 XMLTOOLING_DOXYGEN(Sets the proper child.) \
461 virtual void set##proper(ns::proper* child)=0
464 * Declares abstract get/set methods for a typed XML child object.
466 * @param proper the proper name of the child type
468 #define DECL_TYPED_CHILD(proper) \
470 XMLTOOLING_DOXYGEN(Returns the proper child.) \
471 virtual proper* get##proper() const=0; \
472 XMLTOOLING_DOXYGEN(Sets the proper child.) \
473 virtual void set##proper(proper* child)=0
476 * Declares abstract get/set methods for a generic XML child object.
478 * @param proper the proper name of the child
480 #define DECL_XMLOBJECT_CHILD(proper) \
482 XMLTOOLING_DOXYGEN(Returns the proper child.) \
483 virtual xmltooling::XMLObject* get##proper() const=0; \
484 XMLTOOLING_DOXYGEN(Sets the proper child.) \
485 virtual void set##proper(xmltooling::XMLObject* child)=0
489 * Implements get/set methods and a private list iterator member for a typed XML child object.
491 * @param proper the proper name of the child type
493 #define IMPL_TYPED_CHILD(proper) \
495 proper* m_##proper; \
496 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
498 proper* get##proper() const { \
501 void set##proper(proper* child) { \
502 prepareForAssignment(m_##proper,child); \
503 *m_pos_##proper = m_##proper = child; \
507 * Implements get/set methods and a private list iterator member for
508 * a typed XML child object in a foreign namespace
510 * @param proper the proper name of the child type
511 * @param ns the C++ namespace for the type
513 #define IMPL_TYPED_FOREIGN_CHILD(proper,ns) \
515 ns::proper* m_##proper; \
516 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
518 ns::proper* get##proper() const { \
521 void set##proper(ns::proper* child) { \
522 prepareForAssignment(m_##proper,child); \
523 *m_pos_##proper = m_##proper = child; \
527 * Implements get/set methods and a private list iterator member for a generic XML child object.
529 * @param proper the proper name of the child
531 #define IMPL_XMLOBJECT_CHILD(proper) \
533 xmltooling::XMLObject* m_##proper; \
534 std::list<xmltooling::XMLObject*>::iterator m_pos_##proper; \
536 xmltooling::XMLObject* get##proper() const { \
539 void set##proper(xmltooling::XMLObject* child) { \
540 prepareForAssignment(m_##proper,child); \
541 *m_pos_##proper = m_##proper = child; \
545 * Declares abstract get/set methods for a typed XML child collection.
547 * @param proper the proper name of the child type
549 #define DECL_TYPED_CHILDREN(proper) \
551 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
552 virtual VectorOf(proper) get##proper##s()=0; \
553 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
554 virtual const std::vector<proper*>& get##proper##s() const=0
557 * Declares abstract get/set methods for a typed XML child collection in a foreign namespace.
559 * @param proper the proper name of the child type
560 * @param ns the C++ namespace for the type
562 #define DECL_TYPED_FOREIGN_CHILDREN(proper,ns) \
564 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
565 virtual VectorOf(ns::proper) get##proper##s()=0; \
566 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
567 virtual const std::vector<ns::proper*>& get##proper##s() const=0
570 * Declares abstract get/set methods for a generic XML child collection.
572 * @param proper the proper name of the child
574 #define DECL_XMLOBJECT_CHILDREN(proper) \
576 XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \
577 virtual VectorOf(xmltooling::XMLObject) get##proper##s()=0; \
578 XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \
579 virtual const std::vector<xmltooling::XMLObject*>& get##proper##s() const=0
582 * Implements get method and a private vector member for a typed XML child collection.
584 * @param proper the proper name of the child type
585 * @param fence insertion fence for new objects of the child collection in backing list
587 #define IMPL_TYPED_CHILDREN(proper,fence) \
589 std::vector<proper*> m_##proper##s; \
591 VectorOf(proper) get##proper##s() { \
592 return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \
594 const std::vector<proper*>& get##proper##s() const { \
595 return m_##proper##s; \
599 * Implements get method and a private vector member for a typed XML child collection
600 * in a foreign namespace.
602 * @param proper the proper name of the child type
603 * @param ns the C++ namespace for the type
604 * @param fence insertion fence for new objects of the child collection in backing list
606 #define IMPL_TYPED_FOREIGN_CHILDREN(proper,ns,fence) \
608 std::vector<ns::proper*> m_##proper##s; \
610 VectorOf(ns::proper) get##proper##s() { \
611 return VectorOf(ns::proper)(this, m_##proper##s, &m_children, fence); \
613 const std::vector<ns::proper*>& get##proper##s() const { \
614 return m_##proper##s; \
618 * Implements get method and a private vector member for a generic XML child collection.
620 * @param proper the proper name of the child
621 * @param fence insertion fence for new objects of the child collection in backing list
623 #define IMPL_XMLOBJECT_CHILDREN(proper,fence) \
625 std::vector<xmltooling::XMLObject*> m_##proper##s; \
627 VectorOf(xmltooling::XMLObject) get##proper##s() { \
628 return VectorOf(xmltooling::XMLObject)(this, m_##proper##s, &m_children, fence); \
630 const std::vector<xmltooling::XMLObject*>& get##proper##s() const { \
631 return m_##proper##s; \
635 * Implements marshalling for a string attribute
637 * @param proper the proper name of the attribute
638 * @param ucase the upcased name of the attribute
639 * @param namespaceURI the XML namespace of the attribute
641 #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \
643 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
647 * Implements marshalling for a DateTime attribute
649 * @param proper the proper name of the attribute
650 * @param ucase the upcased name of the attribute
651 * @param namespaceURI the XML namespace of the attribute
653 #define MARSHALL_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
655 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper->getRawData()); \
659 * Implements marshalling for an integer attribute
661 * @param proper the proper name of the attribute
662 * @param ucase the upcased name of the attribute
663 * @param namespaceURI the XML namespace of the attribute
665 #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
667 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
671 * Implements marshalling for a boolean attribute
673 * @param proper the proper name of the attribute
674 * @param ucase the upcased name of the attribute
675 * @param namespaceURI the XML namespace of the attribute
677 #define MARSHALL_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
678 switch (m_##proper) { \
679 case XMLConstants::XML_BOOL_TRUE: \
680 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_TRUE); \
682 case XMLConstants::XML_BOOL_ONE: \
683 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ONE); \
685 case XMLConstants::XML_BOOL_FALSE: \
686 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_FALSE); \
688 case XMLConstants::XML_BOOL_ZERO: \
689 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, XMLConstants::XML_ZERO); \
691 case XMLConstants::XML_BOOL_NULL: \
696 * Implements marshalling for a QName attribute
698 * @param proper the proper name of the attribute
699 * @param ucase the upcased name of the attribute
700 * @param namespaceURI the XML namespace of the attribute
702 #define MARSHALL_QNAME_ATTRIB(proper,ucase,namespaceURI) \
704 auto_ptr_XMLCh qstr(m_##proper->toString().c_str()); \
705 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, qstr.get()); \
709 * Implements marshalling for an ID attribute
711 * @param proper the proper name of the attribute
712 * @param ucase the upcased name of the attribute
713 * @param namespaceURI the XML namespace of the attribute
715 #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \
717 domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \
718 domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \
722 * Implements unmarshalling process branch for a string attribute
724 * @param proper the proper name of the attribute
725 * @param ucase the upcased name of the attribute
726 * @param namespaceURI the XML namespace of the attribute
728 #define PROC_STRING_ATTRIB(proper,ucase,namespaceURI) \
729 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
730 set##proper(attribute->getValue()); \
735 * Implements unmarshalling process branch for an ID attribute
737 * @param proper the proper name of the attribute
738 * @param ucase the upcased name of the attribute
739 * @param namespaceURI the XML namespace of the attribute
741 #define PROC_ID_ATTRIB(proper,ucase,namespaceURI) \
742 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
743 set##proper(attribute->getValue()); \
744 attribute->getOwnerElement()->setIdAttributeNode(attribute); \
749 * Implements unmarshalling process branch for a DateTime attribute
751 * @param proper the proper name of the attribute
752 * @param ucase the upcased name of the attribute
753 * @param namespaceURI the XML namespace of the attribute
755 #define PROC_DATETIME_ATTRIB(proper,ucase,namespaceURI) \
756 PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
759 * Implements unmarshalling process branch for a DateTime attribute
761 * @param proper the proper name of the attribute
762 * @param ucase the upcased name of the attribute
763 * @param namespaceURI the XML namespace of the attribute
765 #define PROC_QNAME_ATTRIB(proper,ucase,namespaceURI) \
766 if (xmltooling::XMLHelper::isNodeNamed(attribute, namespaceURI, ucase##_ATTRIB_NAME)) { \
767 set##proper(XMLHelper::getAttributeValueAsQName(attribute)); \
772 * Implements unmarshalling process branch for an integer attribute
774 * @param proper the proper name of the attribute
775 * @param ucase the upcased name of the attribute
776 * @param namespaceURI the XML namespace of the attribute
778 #define PROC_INTEGER_ATTRIB(proper,ucase,namespaceURI) \
779 PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
782 * Implements unmarshalling process branch for a boolean attribute
784 * @param proper the proper name of the attribute
785 * @param ucase the upcased name of the attribute
786 * @param namespaceURI the XML namespace of the attribute
788 #define PROC_BOOLEAN_ATTRIB(proper,ucase,namespaceURI) \
789 PROC_STRING_ATTRIB(proper,ucase,namespaceURI)
792 * Implements unmarshalling process branch for typed child collection 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_CHILDREN(proper,namespaceURI,force) \
799 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
800 proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
802 get##proper##s().push_back(typesafe); \
808 * Implements unmarshalling process branch for typed child collection 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_CHILDREN(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 get##proper##s().push_back(typesafe); \
826 * Implements unmarshalling process branch for typed child singleton element
828 * @param proper the proper name of the child type
829 * @param namespaceURI the XML namespace of the child element
830 * @param force bypass use of hint and just cast down to check child
832 #define PROC_TYPED_CHILD(proper,namespaceURI,force) \
833 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
834 proper* typesafe=dynamic_cast<proper*>(childXMLObject); \
836 set##proper(typesafe); \
842 * Implements unmarshalling process branch for typed child singleton element
843 * in a foreign namespace.
845 * @param proper the proper name of the child type
846 * @param ns the C++ namespace for the type
847 * @param namespaceURI the XML namespace of the child element
848 * @param force bypass use of hint and just cast down to check child
850 #define PROC_TYPED_FOREIGN_CHILD(proper,ns,namespaceURI,force) \
851 if (force || xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,ns::proper::LOCAL_NAME)) { \
852 ns::proper* typesafe=dynamic_cast<ns::proper*>(childXMLObject); \
854 set##proper(typesafe); \
860 * Implements unmarshalling process branch for a generic child singleton element
862 * @param proper the proper name of the child type
863 * @param namespaceURI the XML namespace of the child element
865 #define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \
866 if (xmltooling::XMLHelper::isNodeNamed(root,namespaceURI,proper::LOCAL_NAME)) { \
867 set##proper(childXMLObject); \
872 * Declares aliased get/set methods for named XML element content.
874 * @param proper the proper name to label the element's content
876 #define DECL_XMLOBJECT_CONTENT(proper) \
877 XMLTOOLING_DOXYGEN(Returns proper.) \
878 const XMLCh* get##proper() const { \
879 return getTextContent(); \
881 XMLTOOLING_DOXYGEN(Sets or clears proper.) \
882 void set##proper(const XMLCh* proper) { \
883 setTextContent(proper); \
887 * Declares aliased get/set methods for named integer XML element content.
889 * @param proper the proper name to label the element's content
891 #define DECL_INTEGER_CONTENT(proper) \
892 XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \
893 std::pair<bool,int> get##proper() const { \
894 return std::make_pair((getTextContent()!=NULL), (getTextContent()!=NULL ? XMLString::parseInt(getTextContent()) : NULL)); \
896 XMLTOOLING_DOXYGEN(Sets proper.) \
897 void set##proper(int proper) { \
899 sprintf(buf,"%d",proper); \
900 xmltooling::auto_ptr_XMLCh widebuf(buf); \
901 setTextContent(widebuf.get()); \
903 XMLTOOLING_DOXYGEN(Sets or clears proper.) \
904 void set##proper(const XMLCh* proper) { \
905 setTextContent(proper); \
909 * Implements marshalling/unmarshalling for element content.
911 #define IMPL_XMLOBJECT_CONTENT \
913 void marshallElementContent(DOMElement* domElement) const { \
914 if(getTextContent()) { \
915 domElement->appendChild(domElement->getOwnerDocument()->createTextNode(getTextContent())); \
918 void processElementContent(const XMLCh* elementContent) { \
919 setTextContent(elementContent); \
924 * Implements cloning methods for an XMLObject specialization implementation class.
926 * @param cname the name of the XMLObject specialization
928 #define IMPL_XMLOBJECT_CLONE(cname) \
929 cname* clone##cname() const { \
932 cname* clone() const { \
933 std::auto_ptr<xmltooling::XMLObject> domClone(xmltooling::AbstractDOMCachingXMLObject::clone()); \
934 cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
936 domClone.release(); \
939 return new cname##Impl(*this); \
943 * Declares an XMLObject specialization with a simple content model and type,
944 * handling it as string data.
946 * @param linkage linkage specifier for the class
947 * @param cname the name of the XMLObject specialization
948 * @param proper the proper name to label the element's content
949 * @param desc documentation for class
951 #define DECL_XMLOBJECT_SIMPLE(linkage,cname,proper,desc) \
952 BEGIN_XMLOBJECT(linkage,cname,xmltooling::SimpleElement,desc); \
953 DECL_XMLOBJECT_CONTENT(proper); \
957 * Declares and defines an implementation class for an XMLObject with
958 * a simple content model and type, handling it as string data.
960 * @param linkage linkage specifier for the class
961 * @param cname the name of the XMLObject specialization
963 #define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname) \
964 class linkage cname##Impl \
965 : public virtual cname, \
966 public xmltooling::AbstractSimpleElement, \
967 public xmltooling::AbstractChildlessElement, \
968 public xmltooling::AbstractDOMCachingXMLObject, \
969 public xmltooling::AbstractValidatingXMLObject, \
970 public xmltooling::AbstractXMLObjectMarshaller, \
971 public xmltooling::AbstractXMLObjectUnmarshaller \
974 virtual ~cname##Impl() {} \
975 cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \
976 : xmltooling::AbstractXMLObject(nsURI, localName, prefix, schemaType) { \
978 cname##Impl(const cname##Impl& src) \
979 : xmltooling::AbstractXMLObject(src), \
980 xmltooling::AbstractSimpleElement(src), \
981 xmltooling::AbstractDOMCachingXMLObject(src), \
982 xmltooling::AbstractValidatingXMLObject(src) {} \
983 IMPL_XMLOBJECT_CLONE(cname) \
984 IMPL_XMLOBJECT_CONTENT \
988 * Begins the declaration of an XMLObjectBuilder specialization.
989 * Basic boilerplate includes an empty virtual destructor, and
990 * a default builder that defaults the element name.
992 * @param linkage linkage specifier for the class
993 * @param cname the name of the XMLObject specialization
994 * @param namespaceURI the XML namespace of the default associated element
995 * @param namespacePrefix the XML namespace prefix of the default associated element
997 #define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
998 XMLTOOLING_DOXYGEN(Builder for cname objects.) \
999 class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \
1001 virtual ~cname##Builder() {} \
1002 XMLTOOLING_DOXYGEN(Default builder.) \
1003 virtual cname* buildObject() const { \
1004 return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
1006 XMLTOOLING_DOXYGEN(Builder that allows element/type override.) \
1007 virtual cname* buildObject( \
1008 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL \
1012 * Ends the declaration of an XMLObjectBuilder specialization.
1014 #define END_XMLOBJECTBUILDER }
1017 * Declares a generic XMLObjectBuilder specialization.
1019 * @param linkage linkage specifier for the class
1020 * @param cname the name of the XMLObject specialization
1021 * @param namespaceURI the XML namespace of the default associated element
1022 * @param namespacePrefix the XML namespace prefix of the default associated element
1024 #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \
1025 BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \
1026 XMLTOOLING_DOXYGEN(Singleton builder.) \
1027 static cname* build##cname() { \
1028 const cname##Builder* b = dynamic_cast<const cname##Builder*>( \
1029 XMLObjectBuilder::getBuilder(xmltooling::QName(namespaceURI,cname::LOCAL_NAME)) \
1032 return b->buildObject(); \
1033 throw xmltooling::XMLObjectException("Unable to obtain typed builder for "#cname"."); \
1035 END_XMLOBJECTBUILDER
1038 * Implements the standard XMLObjectBuilder specialization function.
1040 * @param cname the name of the XMLObject specialization
1042 #define IMPL_XMLOBJECTBUILDER(cname) \
1043 cname* cname##Builder::buildObject( \
1044 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
1047 return new cname##Impl(nsURI,localName,prefix,schemaType); \
1051 * Begins the declaration of a Schema Validator specialization.
1053 * @param linkage linkage specifier for the class
1054 * @param cname the base name of the Validator specialization
1056 #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \
1057 class linkage cname##SchemaValidator : public xmltooling::Validator \
1060 virtual ~cname##SchemaValidator() {} \
1061 virtual cname##SchemaValidator* clone() const { \
1062 return new cname##SchemaValidator(); \
1064 virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1065 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1067 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1070 * Begins the declaration of a Schema Validator specialization subclass.
1072 * @param linkage linkage specifier for the class
1073 * @param cname the base name of the Validator specialization
1074 * @param base base class for the validator
1076 #define BEGIN_XMLOBJECTVALIDATOR_SUB(linkage,cname,base) \
1077 class linkage cname##SchemaValidator : public base##SchemaValidator \
1080 virtual ~cname##SchemaValidator() {} \
1081 virtual cname##SchemaValidator* clone() const { \
1082 return new cname##SchemaValidator(); \
1084 virtual void validate(const xmltooling::XMLObject* xmlObject) const { \
1085 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1087 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1090 * Ends the declaration of a Validator specialization.
1092 #define END_XMLOBJECTVALIDATOR } }
1095 * Validator code that checks the object type.
1097 * @param cname the name of the XMLObject specialization
1099 #define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \
1100 const cname* ptr=dynamic_cast<const cname*>(xmlObject); \
1102 throw xmltooling::ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name()))
1105 * Validator code that checks for a required attribute, content, or singleton.
1107 * @param cname the name of the XMLObject specialization
1108 * @param proper the proper name of the attribute, content, or singleton member
1110 #define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \
1111 if (!ptr->get##proper()) \
1112 throw xmltooling::ValidationException(#cname" must have "#proper".")
1115 * Validator code that checks for a required integer attribute
1117 * @param cname the name of the XMLObject specialization
1118 * @param proper the proper name of the attribute, content, or singleton member
1120 #define XMLOBJECTVALIDATOR_REQUIRE_INTEGER(cname,proper) \
1121 if (!ptr->get##proper().first) \
1122 throw xmltooling::ValidationException(#cname" must have "#proper".")
1125 * Validator code that checks for one of a pair of
1126 * required attributes, content, or singletons.
1128 * @param cname the name of the XMLObject specialization
1129 * @param proper1 the proper name of the first attribute, content, or singleton member
1130 * @param proper2 the proper name of the second attribute, content, or singleton member
1132 #define XMLOBJECTVALIDATOR_ONEOF(cname,proper1,proper2) \
1133 if (!ptr->get##proper1() && !ptr->get##proper2()) \
1134 throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2".")
1137 * Validator code that checks for one of a pair of
1138 * required attributes, content, or singletons, but disallows both.
1140 * @param cname the name of the XMLObject specialization
1141 * @param proper1 the proper name of the first attribute, content, or singleton member
1142 * @param proper2 the proper name of the second attribute, content, or singleton member
1144 #define XMLOBJECTVALIDATOR_ONLYONEOF(cname,proper1,proper2) \
1145 if ((!ptr->get##proper1() && !ptr->get##proper2()) || (ptr->get##proper1() && ptr->get##proper2())) \
1146 throw xmltooling::ValidationException(#cname" must have "#proper1" or "#proper2" but not both.")
1149 * Validator code that checks for one of a set of three
1150 * required attributes, content, or singletons.
1152 * @param cname the name of the XMLObject specialization
1153 * @param proper1 the proper name of the first attribute, content, or singleton member
1154 * @param proper2 the proper name of the second attribute, content, or singleton member
1155 * @param proper3 the proper name of the third attribute, content, or singleton member
1157 #define XMLOBJECTVALIDATOR_ONEOF3(cname,proper1,proper2,proper3) \
1158 if (!ptr->get##proper1() && !ptr->get##proper2() && !ptr->get##proper3()) \
1159 throw xmltooling::ValidationException(#cname" must have "#proper1", "#proper2", or "#proper3".")
1162 * Validator code that checks for one of a set of three
1163 * required attributes, content, or singletons but disallows more than one.
1165 * @param cname the name of the XMLObject specialization
1166 * @param proper1 the proper name of the first attribute, content, or singleton member
1167 * @param proper2 the proper name of the second attribute, content, or singleton member
1168 * @param proper3 the proper name of the third attribute, content, or singleton member
1170 #define XMLOBJECTVALIDATOR_ONLYONEOF3(cname,proper1,proper2,proper3) \
1171 int c##proper1##proper2##proper3=0; \
1172 if (ptr->get##proper1()!=NULL) \
1173 c##proper1##proper2##proper3++; \
1174 if (ptr->get##proper2()!=NULL) \
1175 c##proper1##proper2##proper3++; \
1176 if (ptr->get##proper3()!=NULL) \
1177 c##proper1##proper2##proper3++; \
1178 if (c##proper1##proper2##proper3 != 1) \
1179 throw xmltooling::ValidationException(#cname" must have only one of "#proper1", "#proper2", or "#proper3".")
1182 * Validator code that checks a co-constraint (if one present, the other must be)
1183 * between a pair of attributes, content, or singletons.
1185 * @param cname the name of the XMLObject specialization
1186 * @param proper1 the proper name of the first attribute, content, or singleton member
1187 * @param proper2 the proper name of the second attribute, content, or singleton member
1189 #define XMLOBJECTVALIDATOR_NONEORBOTH(cname,proper1,proper2) \
1190 if ((ptr->get##proper1() && !ptr->get##proper2()) || (!ptr->get##proper1() && ptr->get##proper2())) \
1191 throw xmltooling::ValidationException(#cname" cannot have "#proper1" without "#proper2".")
1194 * Validator code that checks for a non-empty collection.
1196 * @param cname the name of the XMLObject specialization
1197 * @param proper the proper name of the collection item
1199 #define XMLOBJECTVALIDATOR_NONEMPTY(cname,proper) \
1200 if (ptr->get##proper##s().empty()) \
1201 throw xmltooling::ValidationException(#cname" must have at least one "#proper".")
1204 * Declares/defines a Validator specialization that checks object type and
1205 * a non-empty simple content model.
1207 * @param linkage linkage specifier for the class
1208 * @param cname the name of the XMLObject specialization
1210 #define XMLOBJECTVALIDATOR_SIMPLE(linkage,cname) \
1211 BEGIN_XMLOBJECTVALIDATOR(linkage,cname); \
1212 XMLOBJECTVALIDATOR_REQUIRE(cname,TextContent); \
1213 END_XMLOBJECTVALIDATOR
1218 * @namespace xmltooling
1219 * Public namespace of XML Tooling library
1221 namespace xmltooling {
1224 * Template function for cloning a sequence of XMLObjects.
1225 * Invokes the clone() member on each element of the input sequence and adds the copy to
1226 * the output sequence. Order is preserved.
1228 * @param in input sequence to clone
1229 * @param out output sequence to copy cloned pointers into
1231 template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
1232 for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
1234 out.push_back((*i)->clone());
1241 * Functor for cleaning up heap objects in containers.
1243 template<class T> struct cleanup
1246 * Function operator to delete an object.
1248 * @param ptr object to delete
1250 void operator()(T* ptr) {delete ptr;}
1253 * Function operator to delete an object stored as const.
1255 * @param ptr object to delete after casting away const
1257 void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
1261 * Functor for cleaning up heap objects in key/value containers.
1263 template<class A,class B> struct cleanup_pair
1266 * Function operator to delete an object.
1268 * @param p a pair in which the second component is the object to delete
1270 void operator()(const std::pair<A,B*>& p) {delete p.second;}
1274 #endif /* __xmltooling_base_h__ */