3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
8 * See LICENSING which should be included
9 * along with this file for more details
12 #ifndef __FELIB_ALLOCATE_H__
13 #define __FELIB_ALLOCATE_H__
18 template <class type
> inline void Alloc2D (type
**&Map
, int XSize
, int YSize
) {
19 cint Size
= XSize
*(sizeof(type
*)+YSize
*sizeof(type
));
20 Map
= reinterpret_cast<type
**>(new char[Size
]);
21 type
*XPointer
= reinterpret_cast<type
*>(Map
+XSize
);
22 for (int x
= 0; x
< XSize
; ++x
, XPointer
+= YSize
) Map
[x
] = XPointer
;
26 template <class type
> inline void Alloc2D (type
**&Map
, int XSize
, int YSize
, const type
&Initializer
) {
27 cint Size
= XSize
*(sizeof(type
*)+YSize
*sizeof(type
));
28 Map
= reinterpret_cast<type
**>(new char[Size
]);
29 type
* XPointer
= reinterpret_cast<type
*>(Map
+XSize
);
30 for (int x
= 0; x
< XSize
; ++x
, XPointer
+= YSize
) {
32 for (int y
= 0; y
< YSize
; ++y
) Map
[x
][y
] = Initializer
;
37 template <class type
> inline void Alloc3D (type
***&Map
, int XSize
, int YSize
, int ZSize
) {
38 cint Size
= XSize
*(sizeof(type
**)+YSize
*(sizeof(type
*)+ZSize
*sizeof(type
)));
39 Map
= reinterpret_cast<type
***>(new char[Size
]);
40 type
**XPointer
= reinterpret_cast<type
**>(Map
+XSize
);
41 type
*YPointer
= reinterpret_cast<type
*>(XPointer
+XSize
*YSize
);
42 for (int x
= 0; x
< XSize
; ++x
, XPointer
+= YSize
) {
44 for (int y
= 0; y
< YSize
; ++y
, YPointer
+= ZSize
) Map
[x
][y
] = YPointer
;
49 template <class type
> inline void Alloc3D (type
***&Map
, int XSize
, int YSize
, int ZSize
, const type
&Initializer
) {
50 cint Size
= XSize
*(sizeof(type
**)+YSize
*(sizeof(type
*)+ZSize
*sizeof(type
)));
51 Map
= reinterpret_cast<type
***>(new char[Size
]);
52 type
**XPointer
= reinterpret_cast<type
**>(Map
+XSize
);
53 type
*YPointer
= reinterpret_cast<type
*>(XPointer
+XSize
*YSize
);
54 for (int x
= 0; x
< XSize
; ++x
, XPointer
+= YSize
) {
56 for (int y
= 0; y
< YSize
; ++y
, YPointer
+= ZSize
) {
58 for (int z
= 0; z
< ZSize
; ++z
) Map
[x
][y
][z
] = Initializer
;