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>
34 * @namespace xmltooling
35 * Public namespace of XML Tooling library
38 // Windows and GCC4 Symbol Visibility Macros
40 #define XMLTOOL_IMPORT __declspec(dllimport)
41 #define XMLTOOL_EXPORT __declspec(dllexport)
42 #define XMLTOOL_DLLLOCAL
43 #define XMLTOOL_DLLPUBLIC
45 #define XMLTOOL_IMPORT
46 #ifdef GCC_HASCLASSVISIBILITY
47 #define XMLTOOL_EXPORT __attribute__ ((visibility("default")))
48 #define XMLTOOL_DLLLOCAL __attribute__ ((visibility("hidden")))
49 #define XMLTOOL_DLLPUBLIC __attribute__ ((visibility("default")))
51 #define XMLTOOL_EXPORT
52 #define XMLTOOL_DLLLOCAL
53 #define XMLTOOL_DLLPUBLIC
57 // Define XMLTOOL_API for DLL builds
58 #ifdef XMLTOOLING_EXPORTS
59 #define XMLTOOL_API XMLTOOL_EXPORT
61 #define XMLTOOL_API XMLTOOL_IMPORT
64 // Throwable classes must always be visible on GCC in all binaries
66 #define XMLTOOL_EXCEPTIONAPI(api) api
67 #elif defined(GCC_HASCLASSVISIBILITY)
68 #define XMLTOOL_EXCEPTIONAPI(api) XMLTOOL_EXPORT
70 #define XMLTOOL_EXCEPTIONAPI(api)
78 #define XMLTOOLING_DOXYGEN(desc) /##** desc */
80 #define XMLTOOLING_DOXYGEN(desc)
84 * Blocks copy c'tor and assignment operator for a class.
86 #define MAKE_NONCOPYABLE(type) \
89 type& operator=(const type&);
92 * Begins the declaration of an XMLObject specialization.
93 * Basic boilerplate includes a protected constructor, empty virtual destructor,
94 * and Unicode constants for the default associated element's name and prefix.
96 * @param cname the name of the class to declare
97 * @param base the base class to derive from using public virtual inheritance
99 #define BEGIN_XMLOBJECT(cname,base) \
100 class XMLTOOL_API cname : public virtual base, public virtual ValidatingXMLObject { \
104 virtual ~cname() {} \
105 XMLTOOLING_DOXYGEN(Type-specific clone method.) \
106 virtual cname* clone##cname() const=0; \
107 XMLTOOLING_DOXYGEN(Element prefix) \
108 static const XMLCh PREFIX[]; \
109 XMLTOOLING_DOXYGEN(Element local name) \
110 static const XMLCh LOCAL_NAME[]
113 * Ends the declaration of an XMLObject specialization.
115 #define END_XMLOBJECT }
118 * Declares abstract get/set methods for a named XML attribute.
120 * @param proper the proper name of the attribute
121 * @param upcased the upcased name of the attribute
123 #define DECL_XMLOBJECT_ATTRIB(proper,upcased) \
124 XMLTOOLING_DOXYGEN(proper attribute name) \
125 static const XMLCh upcased##_ATTRIB_NAME[]; \
126 XMLTOOLING_DOXYGEN(Returns the proper attribute.) \
127 virtual const XMLCh* get##proper() const=0; \
128 XMLTOOLING_DOXYGEN(Sets the proper attribute.) \
129 virtual void set##proper(const XMLCh* proper)=0
132 * Implements get/set methods and a private member for a named XML attribute.
134 * @param proper the proper name of the attribute
136 #define IMPL_XMLOBJECT_ATTRIB(proper) \
140 const XMLCh* get##proper() const { \
143 void set##proper(const XMLCh* proper) { \
144 m_##proper = prepareForAssignment(m_##proper,proper); \
148 * Implements cloning methods for an XMLObject specialization implementation class.
150 * @param cname the name of the XMLObject specialization
152 #define IMPL_XMLOBJECT_CLONE(cname) \
153 cname* clone##cname() const { \
156 cname* clone() const { \
157 auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone()); \
158 cname##Impl* ret=dynamic_cast<cname##Impl*>(domClone.get()); \
160 domClone.release(); \
163 return new cname##Impl(*this); \
167 * Begins the declaration of an XMLObjectBuilder specialization.
168 * Basic boilerplate includes an empty virtual destructor, and
171 * @param cname the name of the XMLObject specialization
173 #define BEGIN_XMLOBJECTBUILDER(cname) \
174 XMLTOOLING_DOXYGEN(Builder for cname objects.) \
175 class XMLTOOL_API cname##Builder : public xmltooling::XMLObjectBuilder { \
177 virtual ~cname##Builder() {} \
178 XMLTOOLING_DOXYGEN(Default builder.) \
179 virtual cname* buildObject() const=0
182 * Ends the declaration of an XMLObjectBuilder specialization.
184 #define END_XMLOBJECTBUILDER }
187 * Begins the declaration of an XMLObjectBuilder specialization implementation class.
189 * @param cname the name of the XMLObject specialization
190 * @param namespaceURI the XML namespace of the default associated element
192 #define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI) \
193 class XMLTOOL_DLLLOCAL cname##BuilderImpl : public cname##Builder { \
195 cname* buildObject( \
196 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\
198 cname* buildObject() const { \
199 return buildObject(namespaceURI,cname::LOCAL_NAME,cname::PREFIX); \
203 * Ends the declaration of an XMLObjectBuilder specialization implementation class.
205 #define END_XMLOBJECTBUILDERIMPL }
209 namespace xmltooling {
212 * Template function for cloning a sequence of XMLObjects.
213 * Invokes the clone() member on each element of the input sequence and adds the copy to
214 * the output sequence. Order is preserved.
216 * @param in input sequence to clone
217 * @param out output sequence to copy cloned pointers into
219 template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
220 for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
222 out.push_back((*i)->clone());
229 * Functor for cleaning up heap objects in containers.
231 template<class T> struct cleanup
234 * Function operator to delete an object.
236 * @param ptr object to delete
238 void operator()(T* ptr) {delete ptr;}
241 * Function operator to delete an object stored as const.
243 * @param ptr object to delete after casting away const
245 void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
249 * Functor for cleaning up heap objects in key/value containers.
251 template<class A,class B> struct cleanup_pair
254 * Function operator to delete an object.
256 * @param p a pair in which the second component is the object to delete
258 void operator()(const std::pair<A,B*>& p) {delete p.second;}
262 #endif /* __xmltooling_base_h__ */