xref: /haiku/src/apps/cortex/support/array_delete.h (revision 19ae20e67e91fc09cc9fc5c0e60e21e24e7a53eb)
1c284bb0fSMatt Madia /*
2*a820304dSMatt Madia  * Copyright 1998-1999, Be Incorporated.
3c284bb0fSMatt Madia  * Copyright (c) 1999-2000, Eric Moon.
4c284bb0fSMatt Madia  * All rights reserved.
5c284bb0fSMatt Madia  *
6c284bb0fSMatt Madia  * Redistribution and use in source and binary forms, with or without
7c284bb0fSMatt Madia  * modification, are permitted provided that the following conditions
8c284bb0fSMatt Madia  * are met:
9c284bb0fSMatt Madia  *
10c284bb0fSMatt Madia  * 1. Redistributions of source code must retain the above copyright
11c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer.
12c284bb0fSMatt Madia  *
13c284bb0fSMatt Madia  * 2. Redistributions in binary form must reproduce the above copyright
14c284bb0fSMatt Madia  *    notice, this list of conditions, and the following disclaimer in the
15c284bb0fSMatt Madia  *    documentation and/or other materials provided with the distribution.
16c284bb0fSMatt Madia  *
17c284bb0fSMatt Madia  * 3. The name of the author may not be used to endorse or promote products
18c284bb0fSMatt Madia  *    derived from this software without specific prior written permission.
19c284bb0fSMatt Madia  *
20c284bb0fSMatt Madia  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
21c284bb0fSMatt Madia  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22c284bb0fSMatt Madia  * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23c284bb0fSMatt Madia  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24c284bb0fSMatt Madia  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25c284bb0fSMatt Madia  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26c284bb0fSMatt Madia  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27c284bb0fSMatt Madia  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
28c284bb0fSMatt Madia  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29c284bb0fSMatt Madia  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30c284bb0fSMatt Madia  */
31c284bb0fSMatt Madia 
32c284bb0fSMatt Madia 
33a0795c6fSMarcus Overhagen /*******************************************************************************
34a0795c6fSMarcus Overhagen /
35a0795c6fSMarcus Overhagen /	File:			array_delete.h
36a0795c6fSMarcus Overhagen /
37a0795c6fSMarcus Overhagen /   Description:	Template for deleting a new[] array of something.
38a0795c6fSMarcus Overhagen /
39a0795c6fSMarcus Overhagen *******************************************************************************/
40a0795c6fSMarcus Overhagen 
41a0795c6fSMarcus Overhagen 
42a0795c6fSMarcus Overhagen #if !defined( _array_delete_h )
43a0795c6fSMarcus Overhagen #define _array_delete_h
44a0795c6fSMarcus Overhagen 
45a0795c6fSMarcus Overhagen //	Oooh! It's a template!
46a0795c6fSMarcus Overhagen template<class C> class array_delete {
47a0795c6fSMarcus Overhagen 	C * & m_ptr;
48a0795c6fSMarcus Overhagen public:
49a0795c6fSMarcus Overhagen 	//	auto_ptr<> uses delete, not delete[], so we have to write our own.
50a0795c6fSMarcus Overhagen 	//	I like hanging on to a reference, because if we manually delete the
51a0795c6fSMarcus Overhagen 	//	array and set the pointer to NULL (or otherwise change the pointer)
52a0795c6fSMarcus Overhagen 	//	it will still work. Others like the more elaborate implementation
53a0795c6fSMarcus Overhagen 	//	of auto_ptr<>. Your Mileage May Vary.
array_delete(C * & ptr)54a0795c6fSMarcus Overhagen 	array_delete(C * & ptr) : m_ptr(ptr) {}
~array_delete()55a0795c6fSMarcus Overhagen 	~array_delete() { delete[] m_ptr; }
56a0795c6fSMarcus Overhagen };
57a0795c6fSMarcus Overhagen 
58a0795c6fSMarcus Overhagen 
59a0795c6fSMarcus Overhagen #endif	/* array_delete_h */
60a0795c6fSMarcus Overhagen 
61