ARTS 2.5.0 (git: 9ee3ac6c)
workspace_ng.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
25#ifndef WORKSPACE_NG_INCLUDED
26#define WORKSPACE_NG_INCLUDED
27
28#include <map>
29#include <stack>
30
31class Workspace;
32
33#include "array.h"
34#include "wsv_aux.h"
35
40class Workspace {
41 protected:
42 struct WsvStruct {
43 void *wsv;
46 };
47
50
51 public:
52#ifndef NDEBUG
55#endif
56
59
61 static map<String, Index> WsvMap;
62
67 Workspace();
68
76 Workspace(const Workspace &workspace);
77
79 virtual ~Workspace();
80
82 static void define_wsv_data();
83
85 static void define_wsv_map();
86
88 static Index add_wsv(const WsvRecord &wsv);
89
96 void del(Index i);
97
105 void duplicate(Index i);
106
111 void initialize() { ws.resize(wsv_data.nelem()); }
112
119 return ((ws[i].size() != 0) && (ws[i].top()->initialized == true));
120 }
121
123 Index depth(Index i) { return (Index)ws[i].size(); }
124
133 void *pop(Index i);
134
141 void pop_free(Index i);
142
150 void push(Index i, void *wsv);
151
159 void push_uninitialized(Index i, void *wsv);
160
162 Index nelem() { return ws.nelem(); }
163
165 Index add_wsv_inplace(const WsvRecord &wsv);
166
168 void *operator[](Index i);
169};
170
179template <typename OutputStream>
180void PrintWsvName(OutputStream &outstream, Index i) {
181 outstream << Workspace::wsv_data[i].Name() << "(" << i << ") ";
182}
183
192template <typename OutputStream, typename Container>
193void PrintWsvNames(OutputStream &outstream, const Container &container) {
194 for (typename Container::const_iterator it = container.begin();
195 it != container.end();
196 it++) {
197 PrintWsvName(outstream, *it);
198 }
199}
200
201#endif /* WORKSPACE_NG_INCLUDED */
This file contains the definition of Array.
This can be used to make arrays out of anything.
Definition: array.h:107
Workspace class.
Definition: workspace_ng.h:40
void * operator[](Index i)
Retrieve a pointer to the given WSV.
static Index add_wsv(const WsvRecord &wsv)
Append a new WSV to the workspace.
Definition: workspace_ng.cc:54
virtual ~Workspace()
Destruct the workspace and free all WSVs.
Array< stack< WsvStruct * > > ws
Workspace variable container.
Definition: workspace_ng.h:49
void initialize()
Reset the size of the workspace.
Definition: workspace_ng.h:111
static void define_wsv_data()
Define workspace variables.
Definition: workspace.cc:39
static void define_wsv_map()
Map WSV names to indices.
Definition: workspace_ng.cc:48
Index depth(Index i)
Return scoping level of the given WSV.
Definition: workspace_ng.h:123
static Array< WsvRecord > wsv_data
Global WSV data.
Definition: workspace_ng.h:58
String context
Debugging context.
Definition: workspace_ng.h:54
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:77
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:118
Workspace()
Construct a new workspace.
Definition: workspace_ng.cc:39
void push_uninitialized(Index i, void *wsv)
Put a new WSV onto its stack.
static map< String, Index > WsvMap
Global map associated with wsv_data.
Definition: workspace_ng.h:61
Index nelem()
Get the number of workspace variables.
Definition: workspace_ng.h:162
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
void * pop(Index i)
Remove the topmost WSV from its stack.
Index add_wsv_inplace(const WsvRecord &wsv)
Add a new variable to existing workspace and to the static maps.
Definition: workspace_ng.cc:60
void push(Index i, void *wsv)
Push a new WSV onto its stack.
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:66
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:56
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void PrintWsvNames(OutputStream &outstream, const Container &container)
Print list of WSV names to output stream.
Definition: workspace_ng.h:193
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:180
Auxiliary header stuff related to workspace variable groups.