PSCF v1.1
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
15namespace Util
16{
17
45 template <typename Data>
46 class RArray : public Array<Data>
47 {
48
49 using Array<Data>::data_;
50 using Array<Data>::capacity_;
51
52 public:
53
57 RArray() :
58 Array<Data>()
59 {}
60
68 RArray(RArray<Data> const & 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=(RArray<Data> const & other);
116
117 }; // end class RArray
118
119}
120#endif
Array container class template.
Definition: Array.h:34
Data * data_
Pointer to an array of Data elements.
Definition: Array.h:109
int capacity() const
Return allocated size.
Definition: Array.h:159
int capacity_
Allocated size of the data_ array.
Definition: Array.h:112
An Array that acts as a reference to another Array or C array.
Definition: RArray.h:47
RArray(RArray< Data > const &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
void associate(Array< Data > &array)
Associate this RArray with an existing Array object.
Definition: RArray.h:83
RArray()
Constructor.
Definition: RArray.h:57
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