// array.cc -- array template classes // $Id$ // // jtutil::array1d::array1d - 1D array template constructor // jtutil::array1d::~array1d - 1D array template destructor // // jtutil::array2d::array2d - 2D array template constructor // jtutil::array2d::~array2d - 2D array template destructor // // jtutil::array3d::array3d - 3D array template constructor // jtutil::array3d::~array3d - 3D array template destructor // // jtutil::array4d::array4d - 4D array template constructor // jtutil::array4d::~array4d - 4D array template destructor // // ***** template instantiations ***** // #include #include // for NULL #include "jt/stdc.h" #include "jt/util.hh" #include "jt/array.hh" //****************************************************************************** //****************************************************************************** //****************************************************************************** // // This function constructs an array1d object. // namespace jtutil { template array1d::array1d(int min_i_in, int max_i_in, fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), we_own_array_(array_in == NULL) { array_ = we_own_array_ ? new fp[N_i()] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { array_[i] = fp(0); } } } // namespace jtutil:: //****************************************************************************** // // This function destroys an array1d object. // namespace jtutil { template array1d::~array1d() { if (we_own_array_) then delete[] array_; } } // namespace jtutil:: //****************************************************************************** //****************************************************************************** //****************************************************************************** // // This function constructs an array2d object. // namespace jtutil { template array2d::array2d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, fp *array_in = NULL, int stride_i_in = 0, int stride_j_in = 0) : array_(array_in), min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), we_own_array_(array_in == NULL) { if (stride_j_ == 0) then stride_j_ = 1; if (stride_i_ == 0) then stride_i_ = N_j(); if (we_own_array_) then { // allocate it const int N_allocate = N_i() * N_j(); array_ = new fp[N_allocate]; } // must use unchecked subscripting here since setup isn't done yet offset_ = 0; // temp value, needed for following subscript_unchecked() offset_ = - subscript_unchecked(min_i_, min_j_); assert( subscript_unchecked(min_i(), min_j()) == 0 ); max_subscript_ = subscript_unchecked(max_i(), max_j()); // explicitly initialize array (new[] *doesn't* do this automagically) for (int i = min_i() ; i < max_i() ; ++i) { for (int j = min_j() ; j < max_j() ; ++j) { operator()(i,j) = fp(0); } } } } // namespace jtutil:: //****************************************************************************** // // This function destroys an array2d object. // namespace jtutil { template array2d::~array2d() { if (we_own_array_) then delete[] array_; } } // namespace jtutil:: //****************************************************************************** //****************************************************************************** //****************************************************************************** // // This function constructs an array3d object. // namespace jtutil { template array3d::array3d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), min_k_(min_k_in), max_k_(max_k_in), we_own_array_(array_in == NULL) { stride_j_ = N_k(); stride_i_ = N_j() * stride_j_; N_array_ = N_i() * stride_i_; array_ = we_own_array_ ? new fp[N_array_] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { array_[i] = fp(0); } offset_ = 0; // temp value, needed for following subscript() call offset_ = - subscript_unchecked(min_i_, min_j_, min_k_); // must use unchecked form here since setup isn't done yet } } // namespace jtutil:: //****************************************************************************** // // This function destroys an array3d object. // namespace jtutil { template array3d::~array3d() { if (we_own_array_) then delete[] array_; } } // namespace jtutil:: //****************************************************************************** //****************************************************************************** //****************************************************************************** // // This function constructs an array4d object. // namespace jtutil { template array4d::array4d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, int min_k_in, int max_k_in, int min_l_in, int max_l_in, fp *array_in = NULL) : min_i_(min_i_in), max_i_(max_i_in), min_j_(min_j_in), max_j_(max_j_in), min_k_(min_k_in), max_k_(max_k_in), min_l_(min_l_in), max_l_(max_l_in), we_own_array_(array_in == NULL) { stride_k_ = N_l(); stride_j_ = N_k() * stride_k_; stride_i_ = N_j() * stride_j_; N_array_ = N_i() * stride_i_; array_ = we_own_array_ ? new fp[N_array_] : array_in; // need to explicitly initialize -- new[] *doesn't* do this automagically for (int i = 0 ; i < N_array() ; ++i) { array_[i] = fp(0); } offset_ = 0; // temp value, needed for following subscript() call offset_ = - subscript_unchecked(min_i_, min_j_, min_k_, min_l_); // must use unchecked form here since setup isn't done yet } } // namespace jtutil:: //****************************************************************************** // // This function destroys an array4d object. // namespace jtutil { template array4d::~array4d() { if (we_own_array_) then delete[] array_; } } // namespace jtutil:: //****************************************************************************** //****************************************************************************** //****************************************************************************** // // ***** template instantiations ***** // #ifdef DISABLE_TEMPLATE_INSTANTATIONS // see comments in "../util/templates.cc" for why we need this ++ugly // kludge to conditionally disable the template instantations here #else template class jtutil::array1d; template class jtutil::array2d; template class jtutil::array1d; template class jtutil::array2d; template class jtutil::array3d; template class jtutil::array4d; template class jtutil::array1d; template class jtutil::array2d; template class jtutil::array3d; template class jtutil::array4d; #endif