ARTS 2.5.4 (git: 31ce4f0e)
m_basic_types.h
Go to the documentation of this file.
1/* Copyright (C) 2004-2012 Oliver Lemke <olemke@core-dump.info>
2
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16 USA. */
17
27#ifndef M_BASIC_TYPES_H
28#define M_BASIC_TYPES_H
29
30#include <sstream>
31
32#include "agenda_class.h"
33#include "array.h"
34#include "arts.h"
35#include "exceptions.h"
36#include "gridded_fields.h"
37#include "matpackII.h"
38#include "matpackVII.h"
39#include "matpack_concepts.h"
40#include "messages.h"
41#include "mystring.h"
42#include "workspace_ng.h"
43
44/* To avoid redundant code preprocessor macros are used for code generation.
45 *
46 * Author: Oliver Lemke
47 * Date: 2004-09-20
48 */
49
51// The following template functions catch all calls to nelemGet,
52// ncolsGet,etc. for data types (groups) which do not provide the
53// requested attribute. A runtime error is thrown.
54
55#define TMPL_NGET_GENERIC(what) \
56 template <typename T> \
57 void what##Get(Index& n, const T& x, const Verbosity&) { \
58 if constexpr (matpack::has_##what<T>) \
59 n = x.what(); \
60 else \
61 ARTS_USER_ERROR("The variable has no " #what " attribute.\n") \
62 }
63
69TMPL_NGET_GENERIC(nshelves)
70TMPL_NGET_GENERIC(nvitrines)
71TMPL_NGET_GENERIC(nlibraries)
72
73// Undefine the macro to make sure that it is never used anywhere else
74#undef TMPL_NGET_GENERIC
75
76#define TMPL_NGET_AGENDA(what) \
77inline void what##Get(Workspace& ws _U_, Index&, const Agenda&, const Verbosity&) { \
78 ostringstream os; \
79 os << "The variable has no such attribute.\n"; \
80 throw runtime_error(os.str()); \
81 }
82
86TMPL_NGET_AGENDA(npages)
87TMPL_NGET_AGENDA(nbooks)
88TMPL_NGET_AGENDA(nshelves)
89TMPL_NGET_AGENDA(nvitrines)
90TMPL_NGET_AGENDA(nlibraries)
91
92// Undefine the macro to make sure that it is never used anywhere else
93#undef TMPL_NGET_AGENDA
94
95template <typename T>
96void IndexSetToLast(Index& n, const T& x, const Verbosity&) {
97 if constexpr (matpack::has_nelem<T>)
98 n = x.nelem() - 1;
99 else
100 ARTS_USER_ERROR("The variable has no last attribute.\n")
101}
102
104// The following functions are special implementations of the template
105// functions above. They set the corresponding workspace variable to the
106// value of the requested attribute.
107
108#define NGET_GENERIC(what, type) \
109inline void what##Get(Index& what, const type& x, const Verbosity&) { \
110 what = x.what(); \
111 }
112
113#define SET_TO_LAST_GENERIC(type) \
114inline void IndexSetToLast(Index& i, const type& x, const Verbosity&) { \
115 i = x.nelem() - 1; \
116 }
117
118// If you add a group here, add it is also to SET_TO_LAST
154
190
191NGET_GENERIC(ncols, Matrix)
192NGET_GENERIC(ncols, Sparse)
193NGET_GENERIC(ncols, Tensor3)
194NGET_GENERIC(ncols, Tensor4)
195NGET_GENERIC(ncols, Tensor5)
196NGET_GENERIC(ncols, Tensor6)
197NGET_GENERIC(ncols, Tensor7)
198
199NGET_GENERIC(nrows, Matrix)
200NGET_GENERIC(nrows, Sparse)
201NGET_GENERIC(nrows, Tensor3)
202NGET_GENERIC(nrows, Tensor4)
203NGET_GENERIC(nrows, Tensor5)
204NGET_GENERIC(nrows, Tensor6)
205NGET_GENERIC(nrows, Tensor7)
206
207NGET_GENERIC(npages, Tensor3)
208NGET_GENERIC(npages, Tensor4)
209NGET_GENERIC(npages, Tensor5)
210NGET_GENERIC(npages, Tensor6)
211NGET_GENERIC(npages, Tensor7)
212
213NGET_GENERIC(nbooks, Tensor4)
214NGET_GENERIC(nbooks, Tensor5)
215NGET_GENERIC(nbooks, Tensor6)
216NGET_GENERIC(nbooks, Tensor7)
217
218NGET_GENERIC(nshelves, Tensor5)
219NGET_GENERIC(nshelves, Tensor6)
220NGET_GENERIC(nshelves, Tensor7)
221
222NGET_GENERIC(nvitrines, Tensor6)
223NGET_GENERIC(nvitrines, Tensor7)
224
225NGET_GENERIC(nlibraries, Tensor7)
226
227// Undefine the macros to make sure that it is never used anywhere else
228#undef NGET_GENERIC
229#undef SET_TO_LAST_GENERIC
230
231inline void nelemGet(Workspace& /* ws */,
232 Index& nelem,
233 const ArrayOfAgenda& x,
234 const Verbosity&) {
235 nelem = x.nelem();
236}
237
238inline void IndexSetToLast(Workspace& /* ws */,
239 Index& nelem,
240 const ArrayOfAgenda& x,
241 const Verbosity&) {
242 nelem = x.nelem() - 1;
243}
244
245#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:92
The Matrix class.
Definition: matpackI.h:1261
The Tensor3 class.
Definition: matpackIII.h:346
The Tensor4 class.
Definition: matpackIV.h:429
The Tensor5 class.
Definition: matpackV.h:516
The Tensor6 class.
Definition: matpackVI.h:1099
The Tensor7 class.
Definition: matpackVII.h:2399
The Vector class.
Definition: matpackI.h:899
Workspace class.
Definition: workspace_ng.h:53
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
The declarations of all the exception classes.
Implementation of gridded fields.
void IndexSetToLast(Index &n, const T &x, const Verbosity &)
WORKSPACE METHOD: IndexSetToLast.
Definition: m_basic_types.h:96
#define NGET_GENERIC(what, type)
#define TMPL_NGET_GENERIC(what)
Definition: m_basic_types.h:55
#define TMPL_NGET_AGENDA(what)
Definition: m_basic_types.h:76
void nelemGet(Workspace &, Index &nelem, const ArrayOfAgenda &x, const Verbosity &)
#define SET_TO_LAST_GENERIC(type)
Header file for sparse matrices.
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Declarations having to do with the four output streams.
This file contains the definition of String, the ARTS string class.
Index nelem(const Lines &l)
Number of lines.
The Sparse class.
Definition: matpackII.h:75
This file contains the Workspace class.