ARTS  2.3.1285(git:92a29ea9-dirty)
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 "messages.h"
40 #include "mystring.h"
41 #include "workspace_ng.h"
42 
43 /* To avoid redundant code preprocessor macros are used for code generation.
44  *
45  * Author: Oliver Lemke
46  * Date: 2004-09-20
47  */
48 
50 // The following template functions catch all calls to nelemGet,
51 // ncolsGet,etc. for data types (groups) which do not provide the
52 // requested attribute. A runtime error is thrown.
53 
54 #define TMPL_NGET_GENERIC(what) \
55  template <typename T> \
56  void what##Get(Index&, const T&, const Verbosity&) { \
57  ostringstream os; \
58  os << "The variable has no such attribute.\n"; \
59  throw runtime_error(os.str()); \
60  }
61 
63 TMPL_NGET_GENERIC(ncols)
64 TMPL_NGET_GENERIC(nrows)
65 TMPL_NGET_GENERIC(npages)
66 TMPL_NGET_GENERIC(nbooks)
67 TMPL_NGET_GENERIC(nshelves)
68 TMPL_NGET_GENERIC(nvitrines)
69 TMPL_NGET_GENERIC(nlibraries)
70 
71 // Undefine the macro to make sure that it is never used anywhere else
72 #undef TMPL_NGET_GENERIC
73 
74 #define TMPL_NGET_AGENDA(what) \
75 inline void what##Get(Workspace& ws _U_, Index&, const Agenda&, const Verbosity&) { \
76  ostringstream os; \
77  os << "The variable has no such attribute.\n"; \
78  throw runtime_error(os.str()); \
79  }
80 
82 TMPL_NGET_AGENDA(ncols)
83 TMPL_NGET_AGENDA(nrows)
84 TMPL_NGET_AGENDA(npages)
85 TMPL_NGET_AGENDA(nbooks)
86 TMPL_NGET_AGENDA(nshelves)
87 TMPL_NGET_AGENDA(nvitrines)
88 TMPL_NGET_AGENDA(nlibraries)
89 
90 // Undefine the macro to make sure that it is never used anywhere else
91 #undef TMPL_NGET_AGENDA
92 
93 template <typename T>
94 void IndexSetToLast(Index&, const T&, const Verbosity&) {
95  ostringstream os;
96  os << "The variable has no such attribute.\n";
97  throw runtime_error(os.str());
98 }
99 
101 // The following functions are special implementations of the template
102 // functions above. They set the corresponding workspace variable to the
103 // value of the requested attribute.
104 
105 #define NGET_GENERIC(what, type) \
106 inline void what##Get(Index& what, const type& x, const Verbosity&) { \
107  what = x.what(); \
108  }
109 
110 #define SET_TO_LAST_GENERIC(type) \
111 inline void IndexSetToLast(Index& i, const type& x, const Verbosity&) { \
112  i = x.nelem() - 1; \
113  }
114 
115 // If you add a group here, add it is also to SET_TO_LAST
151 
187 
188 NGET_GENERIC(ncols, Matrix)
189 NGET_GENERIC(ncols, Sparse)
190 NGET_GENERIC(ncols, Tensor3)
191 NGET_GENERIC(ncols, Tensor4)
192 NGET_GENERIC(ncols, Tensor5)
193 NGET_GENERIC(ncols, Tensor6)
194 NGET_GENERIC(ncols, Tensor7)
195 
196 NGET_GENERIC(nrows, Matrix)
197 NGET_GENERIC(nrows, Sparse)
198 NGET_GENERIC(nrows, Tensor3)
199 NGET_GENERIC(nrows, Tensor4)
200 NGET_GENERIC(nrows, Tensor5)
201 NGET_GENERIC(nrows, Tensor6)
202 NGET_GENERIC(nrows, Tensor7)
203 
204 NGET_GENERIC(npages, Tensor3)
205 NGET_GENERIC(npages, Tensor4)
206 NGET_GENERIC(npages, Tensor5)
207 NGET_GENERIC(npages, Tensor6)
208 NGET_GENERIC(npages, Tensor7)
209 
210 NGET_GENERIC(nbooks, Tensor4)
211 NGET_GENERIC(nbooks, Tensor5)
212 NGET_GENERIC(nbooks, Tensor6)
213 NGET_GENERIC(nbooks, Tensor7)
214 
215 NGET_GENERIC(nshelves, Tensor5)
216 NGET_GENERIC(nshelves, Tensor6)
217 NGET_GENERIC(nshelves, Tensor7)
218 
219 NGET_GENERIC(nvitrines, Tensor6)
220 NGET_GENERIC(nvitrines, Tensor7)
221 
222 NGET_GENERIC(nlibraries, Tensor7)
223 
224 // Undefine the macros to make sure that it is never used anywhere else
225 #undef NGET_GENERIC
226 #undef SET_TO_LAST_GENERIC
227 
228 inline void nelemGet(Workspace& /* ws */,
229  Index& nelem,
230  const ArrayOfAgenda& x,
231  const Verbosity&) {
232  nelem = x.nelem();
233 }
234 
235 inline void IndexSetToLast(Workspace& /* ws */,
236  Index& nelem,
237  const ArrayOfAgenda& x,
238  const Verbosity&) {
239  nelem = x.nelem() - 1;
240 }
241 
242 #endif /* M_BASIC_TYPES_H */
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
#define NGET_GENERIC(what, type)
Index nelem() const
Number of elements.
Definition: array.h:195
Declarations having to do with the four output streams.
The Vector class.
Definition: matpackI.h:860
#define TMPL_NGET_GENERIC(what)
Definition: m_basic_types.h:54
The Sparse class.
Definition: matpackII.h:60
The Tensor4 class.
Definition: matpackIV.h:421
The Tensor7 class.
Definition: matpackVII.h:2382
This file contains the definition of Array.
This file contains the Workspace class.
The Tensor3 class.
Definition: matpackIII.h:339
The global header file for ARTS.
Header file for sparse matrices.
_CS_string_type str() const
Definition: sstream.h:491
#define TMPL_NGET_AGENDA(what)
Definition: m_basic_types.h:74
Declarations for agendas.
The declarations of all the exception classes.
void nelemGet(Workspace &, Index &nelem, const ArrayOfAgenda &x, const Verbosity &)
#define SET_TO_LAST_GENERIC(type)
The Matrix class.
Definition: matpackI.h:1193
void IndexSetToLast(Index &, const T &, const Verbosity &)
WORKSPACE METHOD: IndexSetToLast.
Definition: m_basic_types.h:94
This can be used to make arrays out of anything.
Definition: array.h:40
The Tensor6 class.
Definition: matpackVI.h:1088
Index nelem(const Lines &l)
Number of lines.
Workspace class.
Definition: workspace_ng.h:40
Implementation of gridded fields.
The Tensor5 class.
Definition: matpackV.h:506
This file contains the definition of String, the ARTS string class.