ARTS 2.5.11 (git: 725533f0)
m_basic_types.h
Go to the documentation of this file.
1
10#ifndef M_BASIC_TYPES_H
11#define M_BASIC_TYPES_H
12
13#include <sstream>
14
15#include "agenda_class.h"
16#include "array.h"
17#include "arts.h"
18#include "exceptions.h"
19#include "gridded_fields.h"
20#include "matpack_data.h"
21#include "matpack_concepts.h"
22#include "messages.h"
23#include "mystring.h"
24#include "workspace_ng.h"
25
26/* To avoid redundant code preprocessor macros are used for code generation.
27 *
28 * Author: Oliver Lemke
29 * Date: 2004-09-20
30 */
31
33// The following template functions catch all calls to nelemGet,
34// ncolsGet,etc. for data types (groups) which do not provide the
35// requested attribute. A runtime error is thrown.
36
37#define TMPL_NGET_GENERIC(what) \
38 template <typename T> \
39 void what##Get(Index& n, const T& x, const Verbosity&) { \
40 if constexpr (matpack::has_##what<T>) \
41 n = x.what(); \
42 else \
43 ARTS_USER_ERROR("The variable has no " #what " attribute.\n") \
44 }
45
51TMPL_NGET_GENERIC(nshelves)
52TMPL_NGET_GENERIC(nvitrines)
53TMPL_NGET_GENERIC(nlibraries)
54
55// Undefine the macro to make sure that it is never used anywhere else
56#undef TMPL_NGET_GENERIC
57
58#define TMPL_NGET_AGENDA(what) \
59inline void what##Get(Workspace& ws _U_, Index&, const Agenda&, const Verbosity&) { \
60 ostringstream os; \
61 os << "The variable has no such attribute.\n"; \
62 throw runtime_error(os.str()); \
63 }
64
68TMPL_NGET_AGENDA(npages)
69TMPL_NGET_AGENDA(nbooks)
70TMPL_NGET_AGENDA(nshelves)
71TMPL_NGET_AGENDA(nvitrines)
72TMPL_NGET_AGENDA(nlibraries)
73
74// Undefine the macro to make sure that it is never used anywhere else
75#undef TMPL_NGET_AGENDA
76
77template <typename T>
78void IndexSetToLast(Index& n, const T& x, const Verbosity&) {
79 if constexpr (matpack::has_nelem<T>)
80 n = x.nelem() - 1;
81 else
82 ARTS_USER_ERROR("The variable has no last attribute.\n")
83}
84
86// The following functions are special implementations of the template
87// functions above. They set the corresponding workspace variable to the
88// value of the requested attribute.
89
90#define NGET_GENERIC(what, type) \
91inline void what##Get(Index& what, const type& x, const Verbosity&) { \
92 what = x.what(); \
93 }
94
95#define SET_TO_LAST_GENERIC(type) \
96inline void IndexSetToLast(Index& i, const type& x, const Verbosity&) { \
97 i = x.nelem() - 1; \
98 }
99
100// If you add a group here, add it is also to SET_TO_LAST
101NGET_GENERIC(nelem, Vector)
105NGET_GENERIC(nelem, ArrayOfVector)
106NGET_GENERIC(nelem, ArrayOfArrayOfVector)
107NGET_GENERIC(nelem, ArrayOfMatrix)
108NGET_GENERIC(nelem, ArrayOfArrayOfMatrix)
109NGET_GENERIC(nelem, ArrayOfSparse)
110NGET_GENERIC(nelem, ArrayOfTensor3)
111NGET_GENERIC(nelem, ArrayOfArrayOfTensor3)
112NGET_GENERIC(nelem, ArrayOfTensor4)
113NGET_GENERIC(nelem, ArrayOfTensor5)
114NGET_GENERIC(nelem, ArrayOfTensor6)
115NGET_GENERIC(nelem, ArrayOfArrayOfTensor6)
116NGET_GENERIC(nelem, ArrayOfTensor7)
132NGET_GENERIC(nelem, ArrayOfPropagationMatrix)
133NGET_GENERIC(nelem, ArrayOfArrayOfPropagationMatrix)
136
141SET_TO_LAST_GENERIC(ArrayOfVector)
142SET_TO_LAST_GENERIC(ArrayOfArrayOfVector)
143SET_TO_LAST_GENERIC(ArrayOfMatrix)
144SET_TO_LAST_GENERIC(ArrayOfArrayOfMatrix)
145SET_TO_LAST_GENERIC(ArrayOfSparse)
146SET_TO_LAST_GENERIC(ArrayOfTensor3)
147SET_TO_LAST_GENERIC(ArrayOfArrayOfTensor3)
148SET_TO_LAST_GENERIC(ArrayOfTensor4)
149SET_TO_LAST_GENERIC(ArrayOfTensor5)
150SET_TO_LAST_GENERIC(ArrayOfTensor6)
151SET_TO_LAST_GENERIC(ArrayOfArrayOfTensor6)
152SET_TO_LAST_GENERIC(ArrayOfTensor7)
168SET_TO_LAST_GENERIC(ArrayOfPropagationMatrix)
169SET_TO_LAST_GENERIC(ArrayOfArrayOfPropagationMatrix)
172
173NGET_GENERIC(ncols, Matrix)
174NGET_GENERIC(ncols, Sparse)
175NGET_GENERIC(ncols, Tensor3)
176NGET_GENERIC(ncols, Tensor4)
177NGET_GENERIC(ncols, Tensor5)
178NGET_GENERIC(ncols, Tensor6)
179NGET_GENERIC(ncols, Tensor7)
180
181NGET_GENERIC(nrows, Matrix)
182NGET_GENERIC(nrows, Sparse)
183NGET_GENERIC(nrows, Tensor3)
184NGET_GENERIC(nrows, Tensor4)
185NGET_GENERIC(nrows, Tensor5)
186NGET_GENERIC(nrows, Tensor6)
187NGET_GENERIC(nrows, Tensor7)
188
189NGET_GENERIC(npages, Tensor3)
190NGET_GENERIC(npages, Tensor4)
191NGET_GENERIC(npages, Tensor5)
192NGET_GENERIC(npages, Tensor6)
193NGET_GENERIC(npages, Tensor7)
194
195NGET_GENERIC(nbooks, Tensor4)
196NGET_GENERIC(nbooks, Tensor5)
197NGET_GENERIC(nbooks, Tensor6)
198NGET_GENERIC(nbooks, Tensor7)
199
200NGET_GENERIC(nshelves, Tensor5)
201NGET_GENERIC(nshelves, Tensor6)
202NGET_GENERIC(nshelves, Tensor7)
203
204NGET_GENERIC(nvitrines, Tensor6)
205NGET_GENERIC(nvitrines, Tensor7)
206
207NGET_GENERIC(nlibraries, Tensor7)
208
209// Undefine the macros to make sure that it is never used anywhere else
210#undef NGET_GENERIC
211#undef SET_TO_LAST_GENERIC
212
213inline void nelemGet(Workspace& /* ws */,
214 Index& nelem,
215 const ArrayOfAgenda& x,
216 const Verbosity&) {
217 nelem = x.nelem();
218}
219
220inline void IndexSetToLast(Workspace& /* ws */,
221 Index& nelem,
222 const ArrayOfAgenda& x,
223 const Verbosity&) {
224 nelem = x.nelem() - 1;
225}
226
227#endif /* M_BASIC_TYPES_H */
Declarations for agendas.
This file contains the definition of Array.
The global header file for ARTS.
Index nelem() const ARTS_NOEXCEPT
Definition array.h:75
Workspace class.
#define ARTS_USER_ERROR(...)
Definition debug.h:153
The declarations of all the exception classes.
Implementation of gridded fields.
void IndexSetToLast(Index &n, const T &x, const Verbosity &)
WORKSPACE METHOD: IndexSetToLast.
#define NGET_GENERIC(what, type)
#define TMPL_NGET_GENERIC(what)
#define TMPL_NGET_AGENDA(what)
void nelemGet(Workspace &, Index &nelem, const ArrayOfAgenda &x, const Verbosity &)
#define SET_TO_LAST_GENERIC(type)
Declarations having to do with the four output streams.
This file contains the definition of String, the ARTS string class.
This file contains the Workspace class.