WvStreams
|
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * XPLC - Cross-Platform Lightweight Components 00004 * Copyright (C) 2004, Net Integration Technologies, Inc. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation; either version 2.1 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00019 * USA 00020 * 00021 * As a special exception, you may use this file as part of a free 00022 * software library without restriction. Specifically, if other files 00023 * instantiate templates or use macros or inline functions from this 00024 * file, or you compile this file and link it with other files to 00025 * produce an executable, this file does not by itself cause the 00026 * resulting executable to be covered by the GNU Lesser General Public 00027 * License. This exception does not however invalidate any other 00028 * reasons why the executable file might be covered by the GNU Lesser 00029 * General Public License. 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 /* __XPLC_DELETE_H__ */