/vol/vipdata/irtk/common++/include/irtkDeallocate.h

00001 /*=========================================================================
00002 
00003   Library   : Image Registration Toolkit (IRTK)
00004   Module    : $Id: irtkDeallocate.h 2 2008-12-23 12:40:14Z dr $
00005   Copyright : Imperial College, Department of Computing
00006               Visual Information Processing (VIP), 2008 onwards
00007   Date      : $Date: 2008-12-23 12:40:14 +0000 (Tue, 23 Dec 2008) $
00008   Version   : $Revision: 2 $
00009   Changes   : $Author: dr $
00010 
00011 =========================================================================*/
00012 
00013 #ifndef _IRTKDEALLOCATE_H
00014 
00015 #define _IRTKDEALLOCATE_H
00016 
00017 #include <irtkCommon.h>
00018 
00019 template <class Type> inline Type **Deallocate(Type **matrix)
00020 {
00021   delete []matrix[0];
00022   delete []matrix;
00023   matrix = NULL;
00024 
00025 #ifdef DEBUG
00026   memory_allocated -= x*y*sizeof(Type);
00027   cout << "Deallocate: Memory allocated is " << memory_allocated << " bytes.\n";
00028 #endif
00029 
00030   return NULL;
00031 }
00032 
00033 template <class Type> inline Type ***Deallocate(Type ***matrix)
00034 {
00035   delete []matrix[0][0];
00036   delete []matrix[0];
00037   delete []matrix;
00038 
00039 #ifdef DEBUG
00040   memory_allocated -= x*y*z*sizeof(Type);
00041   cout << "Deallocate: Memory allocated is " << memory_allocated << " bytes.\n";
00042 #endif
00043 
00044   matrix = NULL;
00045   return NULL;
00046 }
00047 
00048 template <class Type> inline Type ****Deallocate(Type ****matrix)
00049 {
00050   delete []matrix[0][0][0];
00051   delete []matrix[0][0];
00052   delete []matrix[0];
00053   delete []matrix;
00054 
00055   matrix = NULL;
00056   return NULL;
00057 }
00058 
00059 #endif