FIMS  v0.9.3
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 this->register_self(this->id);
44 }
45
49 DataObject(size_t imax, size_t jmax) : dimensions(2), imax(imax), jmax(jmax) {
50 data.resize(imax * jmax);
51 uncertainty.resize(imax * jmax);
52 this->id = DataObject<Type>::id_g++;
53 this->register_self(this->id);
54 }
55
59 DataObject(size_t imax, size_t jmax, size_t kmax)
60 : dimensions(3), imax(imax), jmax(jmax), kmax(kmax) {
61 data.resize(imax * jmax * kmax);
62 uncertainty.resize(imax * jmax * kmax);
63 this->id = DataObject<Type>::id_g++;
64 this->register_self(this->id);
65 }
66
70 DataObject(size_t imax, size_t jmax, size_t kmax, size_t lmax)
72 data.resize(imax * jmax * kmax * lmax);
73 uncertainty.resize(imax * jmax * kmax * lmax);
74 this->id = DataObject<Type>::id_g++;
75 this->register_self(this->id);
76 }
77
83 inline Type operator()(size_t i) { return data[i]; }
84
91 inline Type& at(size_t i) {
92 if (i >= this->data.size()) {
93 throw std::overflow_error("DataObject error:i index out of bounds");
94 }
95 return data[i];
96 }
97
104 inline const Type operator()(size_t i, size_t j) {
105 return data[i * jmax + j];
106 }
107
115 inline Type& at(size_t i, size_t j) {
116 if ((i * jmax + j) >= this->data.size()) {
117 throw std::overflow_error("DataObject error: index out of bounds");
118 }
119 return data[i * jmax + j];
120 }
121
129 inline const Type operator()(size_t i, size_t j, size_t k) {
130 return data[i * jmax * kmax + j * kmax + k];
131 }
132
141 inline Type& at(size_t i, size_t j, size_t k) {
142 if ((i * jmax * kmax + j * kmax + k) >= this->data.size()) {
143 throw std::overflow_error("DataObject error: index out of bounds");
144 }
145 return data[i * jmax * kmax + j * kmax + k];
146 }
147
156 inline const Type operator()(size_t i, size_t j, size_t k, size_t l) {
157 return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
158 }
159
169 inline Type& at(size_t i, size_t j, size_t k, size_t l) {
170 if ((i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l) >=
171 this->data.size()) {
172 throw std::overflow_error("DataObject error: index out of bounds");
173 }
174 return data[i * jmax * kmax * lmax + j * kmax * lmax + k * lmax + l];
175 }
176
182 size_t get_dimensions() const { return dimensions; }
183
189 size_t get_imax() const { return imax; }
190
196 size_t get_jmax() const { return jmax; }
197
203 size_t get_kmax() const { return kmax; }
204
210 size_t get_lmax() const { return lmax; }
211};
212
213template <typename Type>
214uint32_t DataObject<Type>::id_g = 0;
215
216} // namespace fims_data_object
217
218#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:182
Type & at(size_t i, size_t j, size_t k)
Definition data_object.hpp:141
size_t lmax
Definition data_object.hpp:33
Type operator()(size_t i)
Definition data_object.hpp:83
size_t get_imax() const
Get the imax object.
Definition data_object.hpp:189
size_t kmax
Definition data_object.hpp:32
const Type operator()(size_t i, size_t j)
Definition data_object.hpp:104
DataObject(size_t imax, size_t jmax, size_t kmax)
Definition data_object.hpp:59
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:129
size_t get_jmax() const
Get the jmax object.
Definition data_object.hpp:196
fims::Vector< Type > data
Definition data_object.hpp:27
size_t get_lmax() const
Get the lmax object.
Definition data_object.hpp:210
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:70
DataObject(size_t imax, size_t jmax)
Definition data_object.hpp:49
const Type operator()(size_t i, size_t j, size_t k, size_t l)
Definition data_object.hpp:156
Type & at(size_t i, size_t j, size_t k, size_t l)
Definition data_object.hpp:169
Type & at(size_t i)
Definition data_object.hpp:91
size_t get_kmax() const
Get the kmax object.
Definition data_object.hpp:203
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:115
void register_self(const uint32_t id)
Registers a FIMSObject instance with the memory tracker.
Definition model_object.hpp:35
FIMSObject struct that defines member types and returns the unique id.
Definition model_object.hpp:55