Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

delete.h

Go to the documentation of this file.
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 
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 /* __XPLC_DELETE_H__ */

Generated on Sun Sep 26 04:01:25 2004 for XPLC by doxygen1.2.18