LRAUV  revA
I2D.h
Go to the documentation of this file.
1 /*
2  * I2D.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 I2D_H_
12 #define I2D_H_
13 
14 #include <stddef.h>
15 
16 template <typename T>
17 class I2D
18 {
19 public:
20 
21  virtual ~I2D() {};
22 
23  virtual T** getPtr2d() = 0;
24  virtual T* getPtr1d() = 0;
25  virtual int getM() const = 0;
26  virtual int getN() const = 0;
27 
28  // Allocates a 2D pointer array of size m*n
29  // If extra is true, and extra entry is allocated at array[m][0];
30  static T** New2D( int m, int n, bool extra = false )
31  {
32  T** array = NULL;
33  if( m * n > 0 )
34  {
35  array = new T*[m + ( extra ? 1 : 0 ) ];
36  array[0] = new T[m * n + ( extra ? 1 : 0 )];
37  for( int i = 1; i < m + ( extra ? 1 : 0 ); ++i )
38  {
39  array[i] = array[i - 1] + n;
40  }
41  }
42  return array;
43  }
44 
45  static void Delete2D( T** array )
46  {
47  if( NULL != array )
48  {
49  delete[] array[0];
50  delete[] array;
51  }
52  }
53 
54 protected:
55  // Protected constructors for abstract base class
56  I2D() {}
57  I2D( const I2D& ) {}
58 };
59 
60 ;
61 
62 #endif /* I2D_H_ */
virtual int getM() const =0
static T ** New2D(int m, int n, bool extra=false)
Definition: I2D.h:30
I2D(const I2D &)
Definition: I2D.h:57
I2D()
Definition: I2D.h:56
static void Delete2D(T **array)
Definition: I2D.h:45
virtual T * getPtr1d()=0
Definition: I2D.h:17
virtual T ** getPtr2d()=0
virtual ~I2D()
Definition: I2D.h:21
virtual int getN() const =0