Fixes associated with wildcard test classes.
[shibboleth/cpp-xmltooling.git] / xmltooling / base.h
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file base.h
19  * 
20  * Base header file definitions
21  * Must be included prior to including any other header
22  */
23
24 #if !defined(__xmltooling_base_h__)
25 #define __xmltooling_base_h__
26
27 #if defined (_MSC_VER) || defined(__BORLANDC__)
28   #include <xmltooling/config_pub_win32.h>
29 #else
30   #include <xmltooling/config_pub.h>
31 #endif
32
33 /**
34  * @namespace xmltooling
35  * Public namespace of XML Tooling library
36  */
37
38 // Windows and GCC4 Symbol Visibility Macros
39
40 #ifdef WIN32
41   #define XMLTOOL_IMPORT __declspec(dllimport)
42   #define XMLTOOL_EXPORT __declspec(dllexport)
43   #define XMLTOOL_DLLLOCAL
44   #define XMLTOOL_DLLPUBLIC
45 #else
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")))
51   #else
52     #define XMLTOOL_EXPORT
53     #define XMLTOOL_DLLLOCAL
54     #define XMLTOOL_DLLPUBLIC
55   #endif
56 #endif
57
58 // Define XMLTOOL_API for DLL builds
59 #ifdef XMLTOOLING_EXPORTS
60   #define XMLTOOL_API XMLTOOL_EXPORT
61 #else
62   #define XMLTOOL_API XMLTOOL_IMPORT
63 #endif
64
65 // Throwable classes must always be visible on GCC in all binaries
66 #ifdef WIN32
67   #define XMLTOOL_EXCEPTIONAPI(api) api
68 #elif defined(GCC_HASCLASSVISIBILITY)
69   #define XMLTOOL_EXCEPTIONAPI(api) XMLTOOL_EXPORT
70 #else
71   #define XMLTOOL_EXCEPTIONAPI(api)
72 #endif
73
74 // Macro to block copy c'tor and assignment operator for a class
75 #define MAKE_NONCOPYABLE(type) \
76     private: \
77         type(const type&); \
78         type& operator=(const type&);
79
80 #ifndef NULL
81 #define NULL    0
82 #endif
83
84 #include <utility>
85
86 namespace xmltooling {
87
88     /**
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.
92      * 
93      * @param in    input sequence to clone
94      * @param out   output sequence to copy cloned pointers into
95      */
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++) {
98             if (*i)
99                 out.push_back((*i)->clone());
100             else
101                 out.push_back(*i);
102         }
103     }
104
105     /*
106      * Functor for cleaning up heap objects in containers.
107      */
108     template<class T> struct cleanup
109     {
110         /**
111          * Function operator to delete an object.
112          * 
113          * @param ptr   object to delete
114          */
115         void operator()(T* ptr) {delete ptr;}
116         
117         /**
118          * Function operator to delete an object stored as const.
119          * 
120          * @param ptr   object to delete after casting away const
121          */
122         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}
123     };
124
125     /*
126      * Functor for cleaning up heap objects in key/value containers.
127      */
128     template<class A,class B> struct cleanup_pair
129     {
130         /**
131          * Function operator to delete an object.
132          * 
133          * @param p   a pair in which the second component is the object to delete
134          */
135         void operator()(const std::pair<A,B*>& p) {delete p.second;}
136     };
137 };
138
139 #endif /* __xmltooling_base_h__ */