LRAUV  revA
I3D.h
Go to the documentation of this file.
1 /*
2  * I3D.h
3  *
4  * Interface for classes that contain 2D pointer-based matrices.
5  * Contains static methods for creating and deleting 2D pointer-based matrices.
6  *
7  * Created on: Feb 7, 2014
8  * Author: godin
9  */
10 
11 #ifndef I3D_H_
12 #define I3D_H_
13 
14 #include <math.h>
15 #include <sys/types.h>
16 
17 template <typename T>
18 class I3D
19 {
20 public:
21 
22  virtual ~I3D() {};
23 
24  virtual T*** getPtr3d() = 0;
25  virtual T** getPtr2d() = 0;
26  virtual T* getPtr1d() = 0;
27  virtual int getM() const = 0;
28  virtual int getN() const = 0;
29  virtual int getO() const = 0;
30 
31  // Allocates a 3D pointer array of size m*n
32  // If extra is true, and extra entry is allocated at array[m][n][0];
33  static T*** New3D( int m, int n, int o, bool extra = false )
34  {
35  T*** array = NULL;
36  if( m * n * o > 0 )
37  {
38  array = new T**[m + ( extra ? 1 : 0 ) ];
39  array[0] = new T*[m * n + ( extra ? 1 : 0 )];
40  array[0][0] = new T[m * n * o + ( extra ? 1 : 0 )];
41  for( int i = 0; i < m + ( extra ? 1 : 0 ); ++i )
42  {
43  if( i > 0 )
44  {
45  array[i] = array[i - 1] + n;
46  array[i][0] = array[ i - 1 ][0] + n * o;
47  }
48  for( int j = 1; j < n + ( extra ? 1 : 0 ); ++j )
49  {
50  array[i][j] = array[i][j - 1] + o;
51  }
52  }
53 
54  }
55  return array;
56  }
57 
58  static void Delete3D( T*** array )
59  {
60  if( NULL != array )
61  {
62  delete[] array[0][0];
63  delete[] array[0];
64  delete[] array;
65  }
66  }
67 
68 protected:
69  // Protected constructors for abstract base class
70  I3D() {}
71  I3D( const I3D& ) {}
72 };
73 
74 #endif /* I3D_H_ */
Definition: I3D.h:18
I3D(const I3D &)
Definition: I3D.h:71
virtual int getM() const =0
virtual int getN() const =0
virtual ~I3D()
Definition: I3D.h:22
static T *** New3D(int m, int n, int o, bool extra=false)
Definition: I3D.h:33
I3D()
Definition: I3D.h:70
virtual int getO() const =0
virtual T *** getPtr3d()=0
static void Delete3D(T ***array)
Definition: I3D.h:58
virtual T * getPtr1d()=0
virtual T ** getPtr2d()=0