Add cleanup templates.
[shibboleth/cpp-xmltooling.git] / xmltooling / internal.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /*\r
18  *  internal.h - internally visible classes\r
19  */\r
20 \r
21 #ifndef __xmltooling_internal_h__\r
22 #define __xmltooling_internal_h__\r
23 \r
24 #ifdef WIN32\r
25 # define _CRT_SECURE_NO_DEPRECATE 1\r
26 # define _CRT_NONSTDC_NO_DEPRECATE 1\r
27 #endif\r
28 \r
29 // eventually we might be able to support autoconf via cygwin...\r
30 #if defined (_MSC_VER) || defined(__BORLANDC__)\r
31 # include "config_win32.h"\r
32 #else\r
33 # include "config.h"\r
34 #endif\r
35 \r
36 #include "base.h"\r
37 #include "XMLToolingConfig.h"\r
38 \r
39 #include <vector>\r
40 \r
41 #define XMLTOOLING_LOGCAT "XMLTooling"\r
42 \r
43 namespace {\r
44     \r
45     class XMLToolingInternalConfig : public xmltooling::XMLToolingConfig\r
46     {\r
47     public:\r
48         XMLToolingInternalConfig() : m_lock(NULL) {}\r
49 \r
50         // global per-process setup and shutdown of runtime\r
51         bool init();\r
52         void term();\r
53 \r
54         // global mutex available to library applications\r
55         xmltooling::ILockable& lock();\r
56         void unlock();\r
57 \r
58         // configuration\r
59         bool load_library(const char* path, void* context=NULL);\r
60         bool log_config(const char* config=NULL);\r
61 \r
62     private:\r
63         std::vector<void*> m_libhandles;\r
64         void* m_lock;\r
65         //XSECProvider* m_xsec;\r
66         //PlugManager m_plugMgr;\r
67     };\r
68 \r
69     // Template cleanup functors for use with for_each algorithm\r
70     template<class T> struct cleanup\r
71     {\r
72         void operator()(T* ptr) {delete ptr;}\r
73         void operator()(const T* ptr) {delete const_cast<T*>(ptr);}\r
74     };\r
75 \r
76     template<class A,class B> struct cleanup_pair\r
77     {\r
78         void operator()(const std::pair<A,B*>& p) {delete p.second;}\r
79     };\r
80 };\r
81 \r
82 #endif /* __xmltooling_internal_h__ */\r