FIMS  v0.8.0
Loading...
Searching...
No Matches
data_object.hpp
Go to the documentation of this file.
1
10#ifndef FIMS_COMMON_DATA_OBJECT_HPP
11#define FIMS_COMMON_DATA_OBJECT_HPP
12
13#include <exception>
14#include <vector>
15
16#include "model_object.hpp"
17#include "fims_vector.hpp"
18
19namespace fims_data_object {
20
24template <typename Type>
26 static uint32_t id_g;
29 size_t dimensions;
30 size_t imax;
31 size_t jmax;
32 size_t kmax;
33 size_t lmax;
34 Type na_value = static_cast<Type>(-999);
40 data.resize(imax);
41 uncertainty.resize(imax);
42 this->id = DataObject<Type>::id_g++;
43 }
44
48 DataObject(size_t imax, size_t jmax) : dimensions(2), imax(imax), jmax(jmax) {
49 data.resize(imax * jmax);
50 uncertainty.resize(imax * jmax);
51 this->id = DataObject<Type>::id_g++;
52 }
53
57 DataObject(size_t imax, size_t jmax, size_t kmax)
58 : dimensions(3), imax(imax), jmax(jmax), kmax(kmax) {
59 data.resize(imax * jmax * kmax);
60 uncertainty.resize(imax * jmax * kmax);
61 this->id = DataObject<Type>::id_g++;
62 }
63
67 DataObject(size_t imax, size_t jmax, size_t kmax, size_t lmax)
69 data.resize(imax * jmax * kmax * lmax);
70 uncertainty.resize(imax * jmax * kmax * lmax);
71 this->id = DataObject<Type>::id_g++;
72 }
73
79 inline Type operator()(size_t i) { return data[i]; }
80
87 inline Type& at(size_t i) {
88 if (i >= this->data.size()) {
89 throw std::overflow_error("DataObject error:i index out of bounds");
90 }
91 return data[i];
92 }
93
100 inline const Type operator()(size_t i, size_t j) {
101 return data[i * jmax + j];
102 }
103
111 inline Type& at(size_t i, size_t j) {
112 if ((i * jmax + j) >= this->data.size()) {
113 throw std::overflow_error("DataObject error: index out of bounds");
114 }
115 return data[i * jmax + j];
116 }
117
125 inline const Type operator()(size_t i, size_t j, size_t k) {
126 return data[i * jmax * kmax + j * kmax + k];
127 }
128
137 inline Type& at(size_t i, size_t j, size_t k) {
138 if ((i * jmax * kmax + j * kmax + k) >= this->data.size()) {
139 throw std::overflow_error("DataObject error: index out of bounds");
140 }
141 return data[i * jmax * kmax + j * kmax + k];
142 }
143
152 inline const Type operator()(size_t i, size_t j, size_t k, size_t l) {
153 return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
154 }
155
165 inline Type& at(size_t i, size_t j, size_t k, size_t l) {
166 if ((i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l) >=
167 this->data.size()) {
168 throw std::overflow_error("DataObject error: index out of bounds");
169 }
170 return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
171 }
172
178 size_t get_dimensions() const { return dimensions; }
179
185 size_t get_imax() const { return imax; }
186
192 size_t get_jmax() const { return jmax; }
193
199 size_t get_kmax() const { return kmax; }
200
206 size_t get_lmax() const { return lmax; }
207};
208
209template <typename Type>
210uint32_t DataObject<Type>::id_g = 0;
211
212} // namespace fims_data_object
213
214#endif
Definition fims_vector.hpp:27
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:273
Establishes the FIMS Vector class.
Definition of the FIMSObject structure.
Definition data_object.hpp:25
size_t get_dimensions() const
Get the dimensions object.
Definition data_object.hpp:178
Type & at(size_t i, size_t j, size_t k)
Definition data_object.hpp:137
size_t lmax
Definition data_object.hpp:33
Type operator()(size_t i)
Definition data_object.hpp:79
size_t get_imax() const
Get the imax object.
Definition data_object.hpp:185
size_t kmax
Definition data_object.hpp:32
const Type operator()(size_t i, size_t j)
Definition data_object.hpp:100
DataObject(size_t imax, size_t jmax, size_t kmax)
Definition data_object.hpp:57
fims::Vector< Type > uncertainty
Definition data_object.hpp:28
const Type operator()(size_t i, size_t j, size_t k)
Definition data_object.hpp:125
size_t get_jmax() const
Get the jmax object.
Definition data_object.hpp:192
fims::Vector< Type > data
Definition data_object.hpp:27
size_t get_lmax() const
Get the lmax object.
Definition data_object.hpp:206
Type na_value
Definition data_object.hpp:34
DataObject(size_t imax)
Definition data_object.hpp:39
size_t imax
Definition data_object.hpp:30
DataObject(size_t imax, size_t jmax, size_t kmax, size_t lmax)
Definition data_object.hpp:67
DataObject(size_t imax, size_t jmax)
Definition data_object.hpp:48
const Type operator()(size_t i, size_t j, size_t k, size_t l)
Definition data_object.hpp:152
Type & at(size_t i, size_t j, size_t k, size_t l)
Definition data_object.hpp:165
Type & at(size_t i)
Definition data_object.hpp:87
size_t get_kmax() const
Get the kmax object.
Definition data_object.hpp:199
size_t dimensions
Definition data_object.hpp:29
size_t jmax
Definition data_object.hpp:31
static uint32_t id_g
Definition data_object.hpp:26
Type & at(size_t i, size_t j)
Definition data_object.hpp:111
FIMSObject struct that defines member types and returns the unique id.
Definition model_object.hpp:25