#include "2DArray.h"

来源:互联网 发布:sql注入举例 编辑:程序博客网 时间:2024/05/16 07:45

#include <stddef.h>
#include <iostream>
//OR #define NULL ((void *)0)

template < typename T >
T **Allocate2DArray( int nRows, int nCols)
{
    //(step 1) allocate memory for array of elements of column
    T **ppi = new T *[nRows];

    //(step 2) allocate memory for array of elements of each row
    T *curPtr = new T [nRows * nCols];
 
 for (int j = 0; j < nRows * nCols; j++)
  curPtr[j] = 0;

    // Now point the pointers in the right place
    for( int i = 0; i < nRows; ++i)
    {
        *(ppi + i) = curPtr;
         curPtr += nCols;
    }
    return ppi;
}

template < typename T >
void Free2DArray(T** Array)
{
    delete [] *Array;
    delete [] Array;
}

template < typename T >
struct neon {
 int mf, nf, pf;
 int ml, nl, pl;
 T **C;
 T **A, **B;
 T **M1, **M2, **M3, **M4, **M5, **M6, **M7;
/*
 T **tAM1, **tBM1;
 T **tAM2;
 T **tBM3;
 T **tBM4;
 T **tAM5;
 T **tAM6, **tBM6;
 T **tAM7, **tBM7;
 
 T **A11, **A12, **A21, **A22;
 T **B11, **B12, **B21, **B22;*/
 neon () {
  mf = nf = pf = 0;
  ml = nl = pl = 0;
  C = NULL;
  A = B = NULL;
  M1 = M2 = M3 = M4 = M5 = M6 = M7 = NULL;
/*
  tAM1 = tBM1 = NULL;
  tAM2 = NULL;
  tBM3 = NULL;
  tBM4 = NULL;
  tAM5 = NULL;
  tAM6 = tBM6 = NULL;
  tAM7 = tBM7 = NULL;

  A11 = A12 = A21 = A22 = NULL;
  B11 = B12 = B21 = B22 = NULL;*/
 }
 neon (
  int _mf, int _nf, int _pf,
  int _ml, int _nl, int _pl,
  T **_C,
  T **_A, T **_B,
  T **_M1,T **_M2,T **_M3,T **_M4,T **_M5,T **_M6,T **_M7
/*,
  T **_tAM1, T **_tBM1,
  T **_tAM2,
  T **_tBM3,
  T **_tBM4,
  T **_tAM5,
  T **_tAM6, T **_tBM6,
  T **_tAM7, T **_tBM7,

  T **_A11, T **_A12, T **_A21, T **_A22,
  T **_B11, T **_B12, T **_B21, T **_B22*/
 ) {
  mf = _mf, nf = _nf, pf = _pf,
  ml = _ml, nl = _nl, pl = _pl,
  C = _C,
  A = _A, B = _B,
  M1=_M1, M2=_M2, M3=_M3, M4=_M4, M5=_M5, M6=_M6, M7=_M7;
/*
  tAM1 = _tAM1, tBM1 = _tBM1,
  tAM2 = _tAM2,
  tBM3 = _tBM3,
  tBM4 = _tBM4,
  tAM5 = _tAM5,
  tAM6 = _tAM6, tBM6 = _tBM6,
  tAM7 = _tAM7, tBM7 = _tBM7,

  A11 = _A11, A12 = _A12, A21 = _A21, A22 = _A22,
  B11 = _B11, B12 = _B12, B21 = _B21, B22 = _B22;*/
 }
 void unpack (
  int (&_mf), int (&_nf), int (&_pf),
  int (&_ml), int (&_nl), int (&_pl),
  T **(&_C),
  T **(&_A), T **(&_B),
  T **(&_M1),T **(&_M2),T **(&_M3),T **(&_M4),T **(&_M5),T **(&_M6),T **(&_M7)
/*,
  T **(&_tAM1), T **(&_tBM1),
  T **(&_tAM2),
  T **(&_tBM3),
  T **(&_tBM4),
  T **(&_tAM5),
  T **(&_tAM6), T **(&_tBM6),
  T **(&_tAM7), T **(&_tBM7),

  T **(&_A11), T **(&_A12), T **(&_A21), T **(&_A22),
  T **(&_B11), T **(&_B12), T **(&_B21), T **(&_B22)*/
  ) {
  _mf = mf, _nf = nf, _pf = pf,
  _ml = ml, _nl = nl, _pl = pl,
  _C = C,
  _A = A, _B = B,
  _M1=M1, _M2=M2, _M3=M3, _M4=M4, _M5=M5, _M6=M6, _M7=M7;
/*
  _tAM1 = tAM1, _tBM1 = tBM1,
  _tAM2 = tAM2,
  _tBM3 = tBM3,
  _tBM4 = tBM4,
  _tAM5 = tAM5,
  _tAM6 = tAM6, _tBM6 = tBM6,
  _tAM7 = tAM7, _tBM7 = tBM7,

  _A11 = A11, _A12 = A12, _A21 = A21, _A22 = A22,
  _B11 = B11, _B12 = B12, _B21 = B21, _B22 = B22;*/
 }
};