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
00042 #include <new>
00043 #include <memory>
00044
00045 #ifdef __XPLC_IOBJECT_H__
00046 #error "<xplc/delete.h> has to be included before <xplc/IObject.h>."
00047 #endif
00048
00049 #include <xplc/IObject.h>
00050
00055
00056 class CheckIObject {};
00057 class CheckIObjectOk {};
00059 class CheckIObjectOkVector {};
00060
00061 template<class T>
00062 class ConversionIObject
00063 {
00064 public:
00066 typedef char Yes;
00068 struct No { char dummy[2]; };
00069 static T* from;
00070 static Yes test(const IObject*);
00071 static No test(...);
00073 };
00074
00075 template<bool>
00076 struct XPLC_CTAssert;
00077 template<>
00079 struct XPLC_CTAssert<true> {};
00080
00081 template<class T>
00082 inline void operator&&(CheckIObject, const T* obj) {
00083 static_cast<void>(sizeof(XPLC_CTAssert<(sizeof(ConversionIObject<T>::test(ConversionIObject<T>::from)) != sizeof(typename ConversionIObject<T>::Yes))>));
00084 delete obj;
00085 }
00086
00087 template<class T>
00088 inline void operator&&(CheckIObjectOk, const T* obj) {
00089 delete obj;
00090 }
00091
00092 template<class T>
00093 inline void operator&&(CheckIObjectOkVector, const T* obj) {
00094 delete[] obj;
00095 }
00096
00097
00102 #undef xplcdelete
00103
00110 #define xplcdelete CheckIObjectOk() &&
00111
00118 #define delete CheckIObject() &&
00119
00125 #define deletev CheckIObjectOkVector() &&
00126
00127 #endif