8#ifndef MODELARRAYREF2_HPP
9#define MODELARRAYREF2_HPP
11#include "ModelArray.hpp"
18typedef ModelArray* ModelArrayReference;
19typedef const ModelArray* ModelArrayConstReference;
20typedef std::vector<ModelArrayReference> MARBackingStore;
21typedef std::vector<ModelArrayConstReference> MARConstBackingStore;
36template <auto arrayName,
typename S,
bool access = RO>
class ModelArrayRef {
39 : backingStore(backingStoreIn)
53 const double&
operator[](
const ModelArray::MultiDim& dims)
56 return backingStore[
static_cast<size_t>(arrayName)]->
operator[](dims);
70 return backingStore[
static_cast<size_t>(arrayName)]->
operator[](index);
78 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i);
86 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j);
91 const double&
operator()(
size_t i,
size_t j,
size_t k)
const
94 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k);
99 const double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l)
const
102 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l);
107 const double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l,
size_t m)
const
110 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m);
115 const double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n)
const
118 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n);
124 size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n,
size_t p)
const
127 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n, p);
133 size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n,
size_t p,
size_t q)
const
136 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n, p, q);
151 return backingStore[
static_cast<size_t>(arrayName)]->
zIndexAndLayer(hIndex, layer);
158 return *backingStore[
static_cast<size_t>(arrayName)];
190 const S& backingStore;
192 void checkMaybeThrow()
const
194#ifdef DEBUG_MODELARRAYREF
198 if (!backingStore[
static_cast<size_t>(arrayName)])
199 throw std::invalid_argument(
200 "No registered ModelArray at " + std::to_string(
static_cast<size_t>(arrayName)));
217template <auto arrayName>
class ModelArrayRef<arrayName, MARBackingStore, RW> {
220 : backingStore(backingStoreIn)
237 return backingStore[
static_cast<size_t>(arrayName)]->
operator[](dims);
251 return backingStore[
static_cast<size_t>(arrayName)]->
operator[](index);
259 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i);
267 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j);
275 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k);
280 double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l)
const
283 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l);
288 double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l,
size_t m)
const
291 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m);
296 double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n)
const
299 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n);
304 double&
operator()(
size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n,
size_t p)
const
307 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n, p);
313 size_t i,
size_t j,
size_t k,
size_t l,
size_t m,
size_t n,
size_t p,
size_t q)
const
316 return backingStore[
static_cast<size_t>(arrayName)]->
operator()(i, j, k, l, m, n, p, q);
331 return backingStore[
static_cast<size_t>(arrayName)]->
zIndexAndLayer(hIndex, layer);
338 return *backingStore[
static_cast<size_t>(arrayName)];
344 const MARBackingStore& backingStore;
346 void checkMaybeThrow()
const
348#ifdef DEBUG_MODELARRAYREF
349 if (!backingStore[
static_cast<size_t>(arrayName)])
350 throw std::invalid_argument(
351 "No registered ModelArray at " + std::to_string(
static_cast<size_t>(arrayName)));
A class that holds the array data for the model.
double & zIndexAndLayer(size_t hIndex, size_t layer)
Special access function for ZFields.
double & operator[](const ModelArray::MultiDim &dims)
Returns the data at the indices.
double & operator()(size_t i) const
Returns the specified point from a 1 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k) const
Returns the specified point from a 3 dimensional ModelArray.
double & operator()(size_t i, size_t j) const
Returns the specified point from a 2 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t p) const
Returns the specified point from a 7 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const
Returns the specified point from a 5 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t p, size_t q) const
Returns the specified point from a 8 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k, size_t l) const
Returns the specified point from a 4 dimensional ModelArray.
double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const
Returns the specified point from a 6 dimensional ModelArray.
double & operator[](size_t index) const
Returns the data at the specified one dimensional index.
ModelArray & data() const
Direct access top the underlying data array.
A class which provides indirect access to ModelArray.
const double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n) const
Returns the specified point from a 6 dimensional ModelArray.
const double & zIndexAndLayer(size_t hIndex, size_t layer)
Special access function for ZFields.
const double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t p, size_t q) const
Returns the specified point from a 8 dimensional ModelArray.
const double & operator[](size_t index) const
Returns the data at the specified one dimensional index.
const double & operator()(size_t i, size_t j) const
Returns the specified point from a 2 dimensional ModelArray.
const double & operator()(size_t i, size_t j, size_t k, size_t l) const
Returns the specified point from a 4 dimensional ModelArray.
const double & operator()(size_t i, size_t j, size_t k) const
Returns the specified point from a 3 dimensional ModelArray.
const double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m, size_t n, size_t p) const
Returns the specified point from a 7 dimensional ModelArray.
const double & operator()(size_t i) const
Returns the specified point from a 1 dimensional ModelArray.
const double & operator()(size_t i, size_t j, size_t k, size_t l, size_t m) const
Returns the specified point from a 5 dimensional ModelArray.
ModelArray operator-(double subtrahend) const
Returns a ModelArray containing the per-element difference between the object and the provided ModelA...
ModelArray operator/(const ModelArray &divisor) const
Returns a ModelArray containing the per-element ratio between the object and the provided ModelArray.
const double & operator[](const ModelArray::MultiDim &dims)
Returns the data at the indices.
ModelArray operator+(double addend) const
Returns a ModelArray containing the per-element sum of the object and the provided ModelArray.
const ModelArray & data() const
Direct access top the underlying data array.
ModelArray operator*(const ModelArray &multiplier) const
Returns a ModelArray containing the per-element product of the object and the provided ModelArray.
ModelArray operator/(double divisor) const
Returns a ModelArray containing the per-element ratio between the object and the provided ModelArray.
ModelArray operator*(double multiplier) const
Returns a ModelArray containing the per-element product of the object and the provided ModelArray.
ModelArray operator+(const ModelArray &addend) const
Returns a ModelArray containing the per-element sum of the object and the provided ModelArray.
ModelArray operator-(const ModelArray &subtrahend) const
Returns a ModelArray containing the per-element difference between the object and the provided ModelA...