NAMD
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
msm::Array< T > Class Template Reference

#include <MsmMap.h>

Public Member Functions

 Array ()
 
 Array (int n)
 
 Array (const Array &a)
 
 ~Array ()
 
Arrayoperator= (const Array &a)
 
int len () const
 
int max () const
 
const T & operator[] (int i) const
 
const T & elem (int i) const
 
T & operator[] (int i)
 
T & elem (int i)
 
void append (const T &t)
 
void resize (int n)
 
void setmax (int m)
 
const T * buffer () const
 
T * buffer ()
 
const T * buffer (int &n) const
 
T * buffer (int &n)
 
void reset (const T &t)
 

Protected Member Functions

void copy (const Array &a)
 

Protected Attributes

T * abuffer
 
int alen
 
int amax
 

Friends

void swap (Array &, Array &)
 

Detailed Description

template<class T>
class msm::Array< T >

Definition at line 202 of file MsmMap.h.

Constructor & Destructor Documentation

template<class T>
msm::Array< T >::Array ( )
inline

Definition at line 210 of file MsmMap.h.

210 : abuffer(0), alen(0), amax(0) { }
int amax
Definition: MsmMap.h:276
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
template<class T>
msm::Array< T >::Array ( int  n)
inline

Definition at line 211 of file MsmMap.h.

211 : abuffer(0), alen(0), amax(0) { resize(n); }
int amax
Definition: MsmMap.h:276
void resize(int n)
Definition: MsmMap.h:254
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
template<class T>
msm::Array< T >::Array ( const Array< T > &  a)
inline

Definition at line 212 of file MsmMap.h.

212 : abuffer(0), alen(0), amax(0) { copy(a); }
int amax
Definition: MsmMap.h:276
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
void copy(const Array &a)
Definition: MsmMap.h:309
template<class T>
msm::Array< T >::~Array ( )
inline

Definition at line 213 of file MsmMap.h.

213 { setmax(0); }
void setmax(int m)
Definition: MsmMap.h:281

Member Function Documentation

template<class T>
void msm::Array< T >::append ( const T &  t)
inline

Definition at line 250 of file MsmMap.h.

Referenced by ComputeMsm::doWork().

250  {
251  if (alen==amax) setmax(2*amax+1);
252  abuffer[alen++] = t;
253  }
int amax
Definition: MsmMap.h:276
T * abuffer
Definition: MsmMap.h:275
void setmax(int m)
Definition: MsmMap.h:281
int alen
Definition: MsmMap.h:276
template<class T>
const T* msm::Array< T >::buffer ( ) const
inline
template<class T>
T* msm::Array< T >::buffer ( )
inline

Definition at line 260 of file MsmMap.h.

260 { return abuffer; }
T * abuffer
Definition: MsmMap.h:275
template<class T>
const T* msm::Array< T >::buffer ( int &  n) const
inline

Definition at line 261 of file MsmMap.h.

261 { n = alen; return abuffer; }
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
template<class T>
T* msm::Array< T >::buffer ( int &  n)
inline

Definition at line 262 of file MsmMap.h.

262 { n = alen; return abuffer; }
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
template<class T >
void Array< T >::copy ( const Array< T > &  a)
protected

Definition at line 309 of file MsmMap.h.

References msm::Array< T >::abuffer, msm::Array< T >::alen, and msm::Array< T >::amax.

Referenced by msm::Array< msm::PatchDiagram >::Array(), and msm::Array< msm::PatchDiagram >::operator=().

309  {
310  setmax(a.amax);
311  alen = a.alen;
312  for (int i = 0; i < alen; i++) {
313  abuffer[i] = a.abuffer[i];
314  }
315  }
T * abuffer
Definition: MsmMap.h:275
void setmax(int m)
Definition: MsmMap.h:281
int alen
Definition: MsmMap.h:276
template<class T>
const T& msm::Array< T >::elem ( int  i) const
inline

Definition at line 227 of file MsmMap.h.

Referenced by msm::Array< msm::PatchDiagram >::operator[]().

227  {
228  if (i < 0 || i >= alen) {
229  char msg[100];
230  snprintf(msg, sizeof(msg), "Array index: alen=%d, i=%d\n", alen, i);
231  NAMD_die(msg);
232  }
233  return abuffer[i];
234  }
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
void NAMD_die(const char *err_msg)
Definition: common.C:83
template<class T>
T& msm::Array< T >::elem ( int  i)
inline

Definition at line 242 of file MsmMap.h.

242  {
243  if (i < 0 || i >= alen) {
244  char msg[100];
245  snprintf(msg, sizeof(msg), "Array index: alen=%d, i=%d\n", alen, i);
246  NAMD_die(msg);
247  }
248  return abuffer[i];
249  }
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
void NAMD_die(const char *err_msg)
Definition: common.C:83
template<class T>
int msm::Array< T >::len ( ) const
inline
template<class T>
int msm::Array< T >::max ( ) const
inline

Definition at line 219 of file MsmMap.h.

219 { return amax; }
int amax
Definition: MsmMap.h:276
template<class T>
Array& msm::Array< T >::operator= ( const Array< T > &  a)
inline

Definition at line 214 of file MsmMap.h.

214  {
215  if (this != &a) copy(a); // don't allow self-assignment
216  return(*this);
217  }
void copy(const Array &a)
Definition: MsmMap.h:309
template<class T>
const T& msm::Array< T >::operator[] ( int  i) const
inline

Definition at line 220 of file MsmMap.h.

220  {
221 #ifdef DEBUG_MSM
222  return elem(i);
223 #else
224  return abuffer[i];
225 #endif
226  }
T * abuffer
Definition: MsmMap.h:275
const T & elem(int i) const
Definition: MsmMap.h:227
template<class T>
T& msm::Array< T >::operator[] ( int  i)
inline

Definition at line 235 of file MsmMap.h.

235  {
236 #ifdef DEBUG_MSM
237  return elem(i);
238 #else
239  return abuffer[i];
240 #endif
241  }
T * abuffer
Definition: MsmMap.h:275
const T & elem(int i) const
Definition: MsmMap.h:227
template<class T>
void msm::Array< T >::reset ( const T &  t)
inline

Definition at line 263 of file MsmMap.h.

263  {
264  for (int n = 0; n < alen; n++) abuffer[n] = t;
265  }
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
template<class T>
void msm::Array< T >::resize ( int  n)
inline

Definition at line 254 of file MsmMap.h.

Referenced by msm::Array< msm::PatchDiagram >::Array(), ComputeMsm::doWork(), msm::PatchData::init(), ComputeMsmMgr::initialize(), and ComputeMsmMgr::initialize_create().

254  {
255  if (n > amax) setmax(n);
256  alen = n;
257  }
int amax
Definition: MsmMap.h:276
void setmax(int m)
Definition: MsmMap.h:281
int alen
Definition: MsmMap.h:276
template<class T >
void Array< T >::setmax ( int  m)

Definition at line 281 of file MsmMap.h.

References NAMD_die().

Referenced by msm::Array< msm::PatchDiagram >::append(), msm::Array< msm::PatchDiagram >::resize(), and msm::Array< msm::PatchDiagram >::~Array().

281  {
282  if (m == amax) return;
283  else if (m > 0) {
284  T *newbuffer = new T[m];
285  if ( ! newbuffer) {
286  char msg[100];
287  snprintf(msg, sizeof(msg),
288  "Can't allocate %lu KB for msm::Array\n",
289  (unsigned long)(m * sizeof(T) / 1024));
290  NAMD_die(msg);
291  }
292  if (alen > m) alen = m; // new buffer is shorter than old buffer
293  for (int i = 0; i < alen; i++) {
294  newbuffer[i] = abuffer[i];
295  }
296  delete[] abuffer;
297  abuffer = newbuffer;
298  amax = m;
299  }
300  else { // consider m == 0
301  delete[] abuffer;
302  abuffer = 0;
303  alen = 0;
304  amax = 0;
305  }
306  }
int amax
Definition: MsmMap.h:276
T * abuffer
Definition: MsmMap.h:275
int alen
Definition: MsmMap.h:276
void NAMD_die(const char *err_msg)
Definition: common.C:83

Friends And Related Function Documentation

template<class T>
void swap ( Array< T > &  s,
Array< T > &  t 
)
friend

Member Data Documentation

template<class T>
T* msm::Array< T >::abuffer
protected
template<class T>
int msm::Array< T >::alen
protected
template<class T>
int msm::Array< T >::amax
protected

The documentation for this class was generated from the following file: