PSCF v1.4.0
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
40 template <typename Data>
41 class RArray : public Array<Data>
42 {
43
44 public:
45
49 RArray() :
50 Array<Data>()
51 {}
52
60 RArray(RArray<Data> const & other) :
61 Array<Data>()
62 {
63 UTIL_CHECK(other.data_);
64 UTIL_CHECK(other.capacity > 0);
65 data_ = other.data_;
66 capacity_ = other.capacity_;
67 }
68
77 void associate(Array<Data> &array)
78 {
79 if (data_) {
80 UTIL_THROW("Attempt to re-associate an RArray");
81 }
82 if (array.capacity() <= 0) {
83 UTIL_THROW("Unallocated target array: Capacity_ <= 0");
84 }
85 data_ = &array[0];
86 capacity_ = array.capacity();
87 }
88
95 void associate(Data* array, int capacity)
96 {
97 if (data_) {
98 UTIL_THROW("Attempt to re-associate an RArray");
99 }
100 data_ = array;
102 }
103
104 private:
105
106 using Array<Data>::data_;
107 using Array<Data>::capacity_;
108
112 RArray<Data>& operator=(RArray<Data> const & other);
113
114 }; // end class RArray
115
116}
117#endif
Array container class template.
Definition Array.h:40
Data * data_
Pointer to an array of Data elements.
Definition Array.h:107
int capacity() const
Return allocated size.
Definition Array.h:144
int capacity_
Allocated size of the data_ array.
Definition Array.h:110
An Array that acts as a reference to another Array or C array.
Definition RArray.h:42
RArray(RArray< Data > const &other)
Copy constructor.
Definition RArray.h:60
void associate(Data *array, int capacity)
Associate this RArray with an existing C array.
Definition RArray.h:95
void associate(Array< Data > &array)
Associate this RArray with an existing Array object.
Definition RArray.h:77
RArray()
Constructor.
Definition RArray.h:49
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
Utility classes for scientific computation.