ARTS 2.5.0 (git: 9ee3ac6c)
workspace_ng.cc
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#include "workspace_ng.h"
26
28#include "wsv_aux.h"
29
30namespace global_data {
32}
34
36
37map<String, Index> Workspace::WsvMap;
38
40 : ws(0)
41#ifndef NDEBUG
42 ,
43 context("")
44#endif
45{
46}
47
49 for (Index i = 0; i < wsv_data.nelem(); ++i) {
50 WsvMap[wsv_data[i].Name()] = i;
51 }
52}
53
55 Workspace::wsv_data.push_back(wsv);
57 return wsv_data.nelem() - 1;
58}
59
61 const Index pos = add_wsv(wsv);
62 ws.push_back(stack<WsvStruct *>());
63 return pos;
64}
65
67 WsvStruct *wsvs = ws[i].top();
68
69 if (wsvs && wsvs->wsv) {
71 wsvs->wsv = NULL;
72 wsvs->auto_allocated = false;
73 wsvs->initialized = false;
74 }
75}
76
78 WsvStruct *wsvs = new WsvStruct;
79
80 wsvs->auto_allocated = true;
81 if (ws[i].size() && ws[i].top()->wsv) {
83 ws[i].top()->wsv);
84 wsvs->initialized = true;
85 } else {
86 wsvs->wsv = NULL;
87 wsvs->initialized = false;
88 }
89 ws[i].push(wsvs);
90}
91
92Workspace::Workspace(const Workspace &workspace) : ws(workspace.ws.nelem()) {
93#ifndef NDEBUG
94 context = workspace.context;
95#endif
96 for (Index i = 0; i < workspace.ws.nelem(); i++) {
97 WsvStruct *wsvs = new WsvStruct;
98 wsvs->auto_allocated = false;
99 if (workspace.ws[i].size() && workspace.ws[i].top()->wsv) {
100 wsvs->wsv = workspace.ws[i].top()->wsv;
101 wsvs->initialized = workspace.ws[i].top()->initialized;
102 } else {
103 wsvs->wsv = NULL;
104 wsvs->initialized = false;
105 }
106 ws[i].push(wsvs);
107 }
108}
109
111#ifndef NDEBUG
112#pragma omp critical(ws_destruct)
113 if (context != "") cout << "WS destruct: " << context << endl;
114#endif
115 for (int i = 0; i < ws.nelem(); i++) {
116 WsvStruct *wsvs;
117
118 while (ws[i].size()) {
119 wsvs = ws[i].top();
120 if (wsvs->auto_allocated && wsvs->wsv) {
122 }
123 delete (wsvs);
124 ws[i].pop();
125 }
126 }
127}
128
130 WsvStruct *wsvs = ws[i].top();
131 void *vp = NULL;
132 if (wsvs) {
133 vp = wsvs->wsv;
134 delete wsvs;
135 ws[i].pop();
136 }
137 return vp;
138}
139
141 WsvStruct *wsvs = ws[i].top();
142
143 if (wsvs) {
144 if (wsvs->wsv)
146
147 delete wsvs;
148 ws[i].pop();
149 }
150}
151
152void Workspace::push(Index i, void *wsv) {
153 WsvStruct *wsvs = new WsvStruct;
154 wsvs->auto_allocated = false;
155 wsvs->initialized = true;
156 wsvs->wsv = wsv;
157 ws[i].push(wsvs);
158}
159
161 WsvStruct *wsvs = new WsvStruct;
162 wsvs->auto_allocated = false;
163 wsvs->initialized = false;
164 wsvs->wsv = wsv;
165 ws[i].push(wsvs);
166}
167
169 if (!ws[i].size()) push(i, NULL);
170
171 if (!ws[i].top()->wsv) {
172 ws[i].top()->auto_allocated = true;
173 ws[i].top()->wsv = workspace_memory_handler.allocate(wsv_data[i].Group());
174 }
175
176 ws[i].top()->initialized = true;
177
178 return (ws[i].top()->wsv);
179}
This can be used to make arrays out of anything.
Definition: array.h:107
Handling of workspace memory.
void * duplicate(Index group_index, void *ptr)
Duplicate workspace variable of given group.
void deallocate(Index group_index, void *ptr)
Getaway function to call the deallocation function for the WSV group with the given Index.
void * allocate(Index group_index)
Allocate workspace WSV of given group.
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
static void define_wsv_map()
Map WSV names to indices.
Definition: workspace_ng.cc:48
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
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
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
Index nelem(const Lines &l)
Number of lines.
WorkspaceMemoryHandler workspace_memory_handler
The workspace memory handler Defined in workspace_ng.cc.
The WorkspaceMemoryHandler.
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.