Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __XPLC_DELETE_H__
00033 #define __XPLC_DELETE_H__
00034
00035 #if defined(__GNUC__) && __GNUC__ > 3
00036 # pragma GCC system_header
00037 #endif
00038
00046 #include <new>
00047 #include <memory>
00048
00049 #ifdef __XPLC_IOBJECT_H__
00050 #error "<xplc/delete.h> has to be included before <xplc/IObject.h>."
00051 #endif
00052
00053 #include <xplc/IObject.h>
00054
00059
00060 class CheckIObject {};
00061 class CheckIObjectOk {};
00063 class CheckIObjectOkVector {};
00064
00065 template<class T>
00066 class ConversionIObject
00067 {
00068 public:
00070 typedef char Yes;
00072 struct No { char dummy[2]; };
00073 static T* from;
00074 static Yes test(const IObject*);
00075 static No test(...);
00077 };
00078
00079 template<bool>
00080 struct XPLC_CTAssert;
00081 template<>
00083 struct XPLC_CTAssert<true> {};
00084
00085 template<class T>
00086 inline void operator&&(CheckIObject, const T* obj) {
00087 static_cast<void>(sizeof(XPLC_CTAssert<(sizeof(ConversionIObject<T>::test(ConversionIObject<T>::from)) != sizeof(typename ConversionIObject<T>::Yes))>));
00088 delete obj;
00089 }
00090
00091 template<class T>
00092 inline void operator&&(CheckIObjectOk, const T* obj) {
00093 delete obj;
00094 }
00095
00096 template<class T>
00097 inline void operator&&(CheckIObjectOkVector, const T* obj) {
00098 delete[] obj;
00099 }
00100
00101
00106 #undef xplcdelete
00107
00114 #define xplcdelete CheckIObjectOk() &&
00115
00122 #define delete CheckIObject() &&
00123
00129 #define deletev CheckIObjectOkVector() &&
00130
00131 #endif