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 #if !defined(__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
41 #define XMLTOOL_IMPORT __declspec(dllimport)
42 #define XMLTOOL_EXPORT __declspec(dllexport)
43 #define XMLTOOL_DLLLOCAL
44 #define XMLTOOL_DLLPUBLIC
46 #define XMLTOOL_IMPORT
47 #ifdef GCC_HASCLASSVISIBILITY
48 #define XMLTOOL_EXPORT __attribute__ ((visibility("default")))
49 #define XMLTOOL_DLLLOCAL __attribute__ ((visibility("hidden")))
50 #define XMLTOOL_DLLPUBLIC __attribute__ ((visibility("default")))
52 #define XMLTOOL_EXPORT
53 #define XMLTOOL_DLLLOCAL
54 #define XMLTOOL_DLLPUBLIC
58 // Define XMLTOOL_API for DLL builds
59 #ifdef XMLTOOLING_EXPORTS
60 #define XMLTOOL_API XMLTOOL_EXPORT
62 #define XMLTOOL_API XMLTOOL_IMPORT
65 // Throwable classes must always be visible on GCC in all binaries
67 #define XMLTOOL_EXCEPTIONAPI(api) api
68 #elif defined(GCC_HASCLASSVISIBILITY)
69 #define XMLTOOL_EXCEPTIONAPI(api) XMLTOOL_EXPORT
71 #define XMLTOOL_EXCEPTIONAPI(api)
74 // Macro to block copy c'tor and assignment operator for a class
75 #define MAKE_NONCOPYABLE(type) \
78 type& operator=(const type&);
86 namespace xmltooling {
89 * Template function for cloning a sequence of XMLObjects.
90 * Invokes the clone() member on each element of the input sequence and adds the copy to
91 * the output sequence. Order is preserved.
93 * @param in input sequence to clone
94 * @param out output sequence to copy cloned pointers into
96 template<class InputSequence,class OutputSequence> void clone(const InputSequence& in, OutputSequence& out) {
97 for (typename InputSequence::const_iterator i=in.begin(); i!=in.end(); i++) {
99 out.push_back((*i)->clone());
106 * Functor for cleaning up heap objects in containers.
108 template<class T> struct cleanup
111 * Function operator to delete an object.
113 * @param ptr object to delete
115 void operator()(T* ptr) {delete ptr;}
118 * Function operator to delete an object stored as const.
120 * @param ptr object to delete after casting away const
122 void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
126 * Functor for cleaning up heap objects in key/value containers.
128 template<class A,class B> struct cleanup_pair
131 * Function operator to delete an object.
133 * @param p a pair in which the second component is the object to delete
135 void operator()(const std::pair<A,B*>& p) {delete p.second;}
139 #endif /* __xmltooling_base_h__ */