safeDelete.h
Engine/source/core/util/safeDelete.h
Public Defines
SAFE_DELETE(a) {delete (); () = ; }
Safely delete an object and set the pointer to NULL.
SAFE_DELETE_ARRAY(a) { delete [] (); () = ; }
Safely delete an array and set the pointer to NULL.
Synonym for SAFE_FREE_REFERENCE()
SAFE_DELETE_OBJECT(a) { ( () != ) ()->deleteObject(); () = ; }
Safely delete a SimObject and set the pointer to NULL.
SAFE_FREE(a) { ( () != ) (( *)); () = ; }
Safely free memory and set the pointer to NULL.
SAFE_FREE_REFERENCE(a) { (() != ) ()->freeReference(); () = ; }
Safely free a reference to a Message and set the pointer to NULL.
Detailed Description
Public Defines
SAFE_DELETE(a) {delete (); () = ; }
Safely delete an object and set the pointer to NULL.
Parameters:
a | Object to delete |
SAFE_DELETE_ARRAY(a) { delete [] (); () = ; }
Safely delete an array and set the pointer to NULL.
Parameters:
a | Array to delete |
SAFE_DELETE_MESSAGE()
Synonym for SAFE_FREE_REFERENCE()
Parameters:
a | Object to delete |
SAFE_DELETE_OBJECT(a) { ( () != ) ()->deleteObject(); () = ; }
Safely delete a SimObject and set the pointer to NULL.
Parameters:
a | Object to delete |
SAFE_FREE(a) { ( () != ) (( *)); () = ; }
Safely free memory and set the pointer to NULL.
Parameters:
a | Pointer to memory to free |
SAFE_FREE_REFERENCE(a) { (() != ) ()->freeReference(); () = ; }
Safely free a reference to a Message and set the pointer to NULL.
Parameters:
a | Pointer to message to free |
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _TORQUE_SAFEDELETE_H_ 25#define _TORQUE_SAFEDELETE_H_ 26 27/// @addtogroup utility_macros Utility Macros 28// @{ 29 30#undef SAFE_DELETE 31 32//----------------------------------------------------------------------------- 33/// @brief Safely delete an object and set the pointer to NULL 34/// 35/// @param a Object to delete 36/// @see #SAFE_DELETE_ARRAY(), #SAFE_DELETE_OBJECT(), #SAFE_FREE(), #SAFE_FREE_REFERENCE() 37//----------------------------------------------------------------------------- 38#define SAFE_DELETE(a) {delete (a); (a) = NULL; } 39 40#undef SAFE_DELETE_ARRAY 41 42//----------------------------------------------------------------------------- 43/// @brief Safely delete an array and set the pointer to NULL 44/// 45/// @param a Array to delete 46/// @see #SAFE_DELETE(), #SAFE_DELETE_OBJECT(), #SAFE_FREE(), #SAFE_FREE_REFERENCE() 47//----------------------------------------------------------------------------- 48#define SAFE_DELETE_ARRAY(a) { delete [] (a); (a) = NULL; } 49 50#undef SAFE_DELETE_OBJECT 51 52//----------------------------------------------------------------------------- 53/// @brief Safely delete a SimObject and set the pointer to NULL 54/// 55/// @param a Object to delete 56/// @see #SAFE_DELETE_ARRAY(), #SAFE_DELETE(), #SAFE_FREE(), #SAFE_FREE_REFERENCE() 57//----------------------------------------------------------------------------- 58#define SAFE_DELETE_OBJECT(a) { if( (a) != NULL ) (a)->deleteObject(); (a) = NULL; } 59 60#undef SAFE_FREE 61 62//----------------------------------------------------------------------------- 63/// @brief Safely free memory and set the pointer to NULL 64/// 65/// @param a Pointer to memory to free 66/// @see #SAFE_DELETE_ARRAY(), #SAFE_DELETE_OBJECT(), #SAFE_DELETE(), #SAFE_FREE_REFERENCE() 67//----------------------------------------------------------------------------- 68#define SAFE_FREE(a) { if( (a) != NULL ) dFree ((void *)a); (a) = NULL; } 69 70// CodeReview: Is the NULL conditional needed? [5/14/2007 Pat] 71 72#undef SAFE_FREE_REFERENCE 73 74//----------------------------------------------------------------------------- 75/// @brief Safely free a reference to a Message and set the pointer to NULL 76/// 77/// @param a Pointer to message to free 78/// @see #SAFE_DELETE_ARRAY(), #SAFE_DELETE_OBJECT(), #SAFE_FREE(), #SAFE_DELETE() 79//----------------------------------------------------------------------------- 80#define SAFE_FREE_REFERENCE(a) { if((a) != NULL) (a)->freeReference(); (a) = NULL; } 81 82#undef SAFE_DELETE_MESSAGE 83 84//----------------------------------------------------------------------------- 85/// @brief Synonym for SAFE_FREE_REFERENCE() 86/// 87/// @param a Object to delete 88/// @see #SAFE_DELETE(), #SAFE_DELETE_ARRAY(), #SAFE_DELETE_OBJECT(), #SAFE_FREE(), #SAFE_FREE_REFERENCE() 89//----------------------------------------------------------------------------- 90#define SAFE_DELETE_MESSAGE SAFE_FREE_REFERENCE 91 92// @} 93 94#endif // _TORQUE_SAFEDELETE_H_ 95 96