1 /*
2  * This file is part of the Advance project.
3  *
4  * Copyright (C) 2002, 2004 Andrea Mazzoleni
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #ifndef __DATA_H
22 #define __DATA_H
23 
24 unsigned char* data_dup(const unsigned char* Adata, unsigned Asize);
25 unsigned char* data_alloc(unsigned size);
26 void data_free(unsigned char* data);
27 
28 class data_ptr {
29 	unsigned char* data;
30 	bool own;
31 public:
data_ptr()32 	data_ptr() : data(0), own(false) { }
33 
data_ptr(data_ptr & A)34 	data_ptr(data_ptr& A)
35 	{
36 		data = A.data;
37 		own = A.own;
38 		A.own = false;
39 	}
40 
data(Adata)41 	data_ptr(unsigned char* Adata, bool Aown = true) : data(Adata), own(Aown) { }
42 
~data_ptr()43 	~data_ptr() { if (own) data_free(data); }
44 
45 	void operator=(data_ptr& A)
46 	{
47 		if (own) data_free(data);
48 		data = A.data;
49 		own = A.own;
50 		A.own = false;
51 	}
52 
53 	void operator=(unsigned char* Adata)
54 	{
55 		if (own) data_free(data);
56 		data = Adata;
57 		own = true;
58 	}
59 
60 	operator unsigned char*() { return data; }
61 };
62 
63 #endif
64