PKIFdll.h
Go to the documentation of this file.00001
00009 #ifndef _PKIFDLL_H_
00010 #define _PKIFDLL_H_
00011
00012 #include "config.h"
00013
00014 #if defined(WIN32) || defined(_WIN32)
00015 #define WIN32_LEAN_AND_MEAN
00016 #if !defined(_WIN32_WINNT)
00017 #define _WIN32_WINNT 0x0500
00018 #endif
00019 #include "windows.h"
00020 #endif //defined(WIN32) || defined(_WIN32)
00021
00022 #include <string>
00023 #include <limits>
00024
00025 #include "PKIFString.h"
00026 #include "boost/shared_ptr.hpp"
00027 #include "pkif_shared_ptr.hpp"
00028
00029
00030
00031 #define NO_LOKI 1
00032
00033 #if defined(WIN32) || defined(_WIN32)
00034 #pragma warning(disable: 4251)
00035 #pragma warning( disable : 4786 )
00036 #endif //defined(WIN32) || defined(_WIN32)
00037
00038 #ifdef NO_NAMESPACE
00039 #define std
00040 #define CAC
00041 #define USING_NAMESPACE(x)
00042 #define BEGIN_NAMESPACE(x)
00043 #define END_NAMESPACE
00044 #define ANONYMOUS_NAMESPACE_BEGIN
00045 #else
00046 #define USING_NAMESPACE(x) using namespace x;
00047 #define BEGIN_NAMESPACE(x) namespace x {
00048 #define ANONYMOUS_NAMESPACE_BEGIN namespace {
00049 #define END_NAMESPACE }
00050 #endif
00051
00052 #if defined(WIN32) || defined(_WIN32)
00053 #define CAC_NO_VTABLE __declspec(novtable)
00054 #else
00055 #define CAC_NO_VTABLE
00056 #endif
00057
00058 #ifdef CAC_EXPORTS
00059 #if defined(WIN32) || defined(_WIN32)
00060 #define CAC_API __declspec(dllexport)
00061 #define EXPIMP_TEMPLATE
00062 #endif //defined(WIN32) || defined(_WIN32)
00063 #else
00064 #if defined(WIN32) || defined(_WIN32)
00065 #ifndef CAC_STATIC
00066 #define CAC_API __declspec(dllimport)
00067 #define EXPIMP_TEMPLATE extern
00068 #else
00069 #define CAC_API
00070 #define EXPIMP_TEMPLATE extern
00071 #endif //CAC_STATIC
00072 #else
00073 #define CAC_API
00074 #define EXPIMP_TEMPLATE extern
00075 #endif //defined(WIN32) || defined(_WIN32)
00076 #endif
00077
00078 #ifdef CAC_COVERAGE_TEST
00079 #if defined(WIN32) || defined(_WIN32)
00080 #define CAC_TEST_API __declspec(dllexport)
00081 #endif //defined(WIN32) || defined(_WIN32)
00082 #else
00083 #define CAC_TEST_API
00084 #endif
00085
00086
00087
00088
00089 #define DECLARE_SMART_POINTERS(c) \
00090 typedef boost::shared_ptr<c> c##Ptr;
00091
00092 #define FD_SMART_PTR(c) \
00093 class c; \
00094 typedef boost::shared_ptr<c> c##Ptr
00095
00096 #define FD_LIST_PTR(c) \
00097 class c; \
00098 FD_SMART_PTR(c); \
00099 typedef std::vector<c##Ptr, PKIFAlloc<c##Ptr> > c##List; \
00100 DECLARE_SMART_POINTERS(c##List)
00101
00102
00103 #define FD_NODE_LIST_PTR(c) \
00104 class c; \
00105 FD_SMART_PTR(c); \
00106 typedef std::vector<c##Ptr, PKIFAlloc<c##Ptr> > CPKIFCertificateNodeList; \
00107 DECLARE_SMART_POINTERS(CPKIFCertificateNodeList)
00108
00109
00110 #define FD_CRL_NODE_LIST_PTR(c) \
00111 class c; \
00112 FD_SMART_PTR(c); \
00113 typedef std::vector<c##Ptr, PKIFAlloc<c##Ptr> > CPKIFCRLNodeList; \
00114 DECLARE_SMART_POINTERS(CPKIFCRLNodeList)
00115
00116
00117
00118 #define FD_MC_PTR() \
00119 FD_SMART_PTR(IPKIFColleague); \
00120 typedef IPKIFColleague IPKIFMediator; \
00121 typedef boost::shared_ptr<IPKIFMediator> IPKIFMediatorPtr
00122
00123 #if defined(WIN32) || defined(_WIN32)
00124 CAC_API void* PKIFNew(size_t size);
00125 void CAC_API PKIFDelete(void* p);
00126 #else
00127 void * PKIFNew(size_t size);
00128 void PKIFDelete(void *p);
00129 #endif //defined(WIN32) || defined(_WIN32)
00130 template <class T>
00131 class PKIFAlloc {
00132 public:
00133
00134 typedef T value_type;
00135 typedef T* pointer;
00136 typedef const T* const_pointer;
00137 typedef T& reference;
00138 typedef const T& const_reference;
00139 typedef std::size_t size_type;
00140 typedef std::ptrdiff_t difference_type;
00141
00142
00143 template <class U>
00144 struct rebind {
00145 typedef PKIFAlloc<U> other;
00146 };
00147
00148
00156 pointer address (reference value) const {
00157 return &value;
00158 }
00166 const_pointer address (const_reference value) const {
00167 return &value;
00168 }
00169
00170
00171
00172
00180 PKIFAlloc() throw() {
00181 }
00189 PKIFAlloc(const PKIFAlloc&) throw() {
00190 }
00191 #if _MSC_VER > 1200
00192 template <class U>
00193 PKIFAlloc (const PKIFAlloc<U>&) throw() {
00194 }
00195 #endif
00196
00203 ~PKIFAlloc() throw() {
00204 }
00205
00206
00214 size_type max_size () const throw() {
00215 return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
00216 }
00217
00225 pointer allocate (size_type num, const void* = 0) {
00226
00227 pointer ret = (pointer)(PKIFNew(num*sizeof(T)));
00228 return ret;
00229 }
00230
00231
00239 void construct (
00241 pointer p,
00243 const T& value) {
00244
00245 new((void*)p)T(value);
00246 }
00247
00255 void destroy (
00257 pointer p) {
00258
00259 p->~T();
00260 }
00261
00262
00270 void deallocate (
00272 pointer p,
00274 size_type num) {
00275
00276 PKIFDelete((void*)p);
00277 }
00278 };
00279
00280
00281 template <class T1, class T2>
00282 bool operator== (const PKIFAlloc<T1>&,
00283 const PKIFAlloc<T2>&) throw() {
00284 return true;
00285 }
00286 template <class T1, class T2>
00287 bool operator!= (const PKIFAlloc<T1>&,
00288 const PKIFAlloc<T2>&) throw() {
00289 return false;
00290 }
00291
00292 #endif