Simpatico  v1.10
RArray.h
1 #ifndef UTIL_R_ARRAY_H
2 #define UTIL_R_ARRAY_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/containers/Array.h>
12 #include <util/containers/FSArray.h>
13 #include <util/global.h>
14 
15 namespace Util
16 {
17 
45  template <typename Data>
46  class RArray : public Array<Data>
47  {
48 
49  using Array<Data>::data_;
51 
52  public:
53 
57  RArray() :
58  Array<Data>()
59  {}
60 
68  RArray(const RArray<Data>& other) :
69  Array<Data>()
70  {
71  data_ = other.data_;
72  capacity_ = other.capacity_;
73  }
74 
83  void associate(Array<Data> &array)
84  {
85  if (data_ != 0) {
86  UTIL_THROW("Attempt to re-associate an RArray");
87  }
88  if (array.capacity() <= 0) {
89  UTIL_THROW("Unallocated target array: Capacity_ <= 0");
90  }
91  data_ = &array[0];
92  capacity_ = array.capacity();
93  }
94 
101  void associate(Data* array, int capacity)
102  {
103  if (data_ != 0) {
104  UTIL_THROW("Attempt to re-associate an RArray");
105  }
106  data_ = array;
108  }
109 
110  private:
111 
115  RArray<Data>& operator=(const RArray<Data>& other);
116 
117  }; // end class RArray
118 
119 }
120 #endif
Data * data_
Pointer to an array of Data elements.
Definition: Array.h:103
void associate(Array< Data > &array)
Associate this RArray with an existing Array object.
Definition: RArray.h:83
RArray(const RArray< Data > &other)
Copy constructor.
Definition: RArray.h:68
void associate(Data *array, int capacity)
Associate this RArray with an existing C array.
Definition: RArray.h:101
int capacity_
Allocated size of the data_ array.
Definition: Array.h:106
Array container class template.
Definition: AutoCorrArray.h:28
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1
RArray()
Constructor.
Definition: RArray.h:57
An Array that acts as a reference to another Array or C array.
Definition: RArray.h:46
int capacity() const
Return allocated size.
Definition: Array.h:153