moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / felib / allocate.h
blobe4ff00b4e071c7d998a999dc7ddeea2f839e46b2
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
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__
15 #include "typedef.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) {
31 Map[x] = XPointer;
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) {
43 Map[x] = XPointer;
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) {
55 Map[x] = XPointer;
56 for (int y = 0; y < YSize; ++y, YPointer += ZSize) {
57 Map[x][y] = YPointer;
58 for (int z = 0; z < ZSize; ++z) Map[x][y][z] = Initializer;
64 #endif