ARTS  2.3.1285(git:92a29ea9-dirty)
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 
30 namespace global_data {
32 }
34 
36 
37 map<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 
92 Workspace::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  ws.empty();
128 }
129 
131  WsvStruct *wsvs = ws[i].top();
132  void *vp = NULL;
133  if (wsvs) {
134  vp = wsvs->wsv;
135  delete wsvs;
136  ws[i].pop();
137  }
138  return vp;
139 }
140 
142  WsvStruct *wsvs = ws[i].top();
143 
144  if (wsvs) {
145  if (wsvs->wsv)
147 
148  delete wsvs;
149  ws[i].pop();
150  }
151 }
152 
153 void Workspace::push(Index i, void *wsv) {
154  WsvStruct *wsvs = new WsvStruct;
155  wsvs->auto_allocated = false;
156  wsvs->initialized = true;
157  wsvs->wsv = wsv;
158  ws[i].push(wsvs);
159 }
160 
162  WsvStruct *wsvs = new WsvStruct;
163  wsvs->auto_allocated = false;
164  wsvs->initialized = false;
165  wsvs->wsv = wsv;
166  ws[i].push(wsvs);
167 }
168 
170  if (!ws[i].size()) push(i, NULL);
171 
172  if (!ws[i].top()->wsv) {
173  ws[i].top()->auto_allocated = true;
174  ws[i].top()->wsv = workspace_memory_handler.allocate(wsv_data[i].Group());
175  }
176 
177  ws[i].top()->initialized = true;
178 
179  return (ws[i].top()->wsv);
180 }
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
static Array< WsvRecord > wsv_data
Global WSV data.
Definition: workspace_ng.h:58
Index nelem() const
Number of elements.
Definition: array.h:195
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:77
void * duplicate(Index group_index, void *ptr)
Duplicate workspace variable of given group.
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
This file contains the Workspace class.
String context
Debugging context.
Definition: workspace_ng.h:54
WorkspaceMemoryHandler workspace_memory_handler
The workspace memory handler Defined in workspace_ng.cc.
virtual ~Workspace()
Destruct the workspace and free all WSVs.
void * operator[](Index i)
Retrieve a pointer to the given WSV.
Index nelem()
Get the number of workspace variables.
Definition: workspace_ng.h:162
void * allocate(Index group_index)
Allocate workspace WSV of given group.
void * pop(Index i)
Remove the topmost WSV from its stack.
Workspace()
Construct a new workspace.
Definition: workspace_ng.cc:39
void deallocate(Index group_index, void *ptr)
Getaway function to call the deallocation function for the WSV group with the given Index...
void push(Index i, void *wsv)
Push a new WSV onto its stack.
static map< String, Index > WsvMap
Global map associated with wsv_data.
Definition: workspace_ng.h:61
static Index add_wsv(const WsvRecord &wsv)
Append a new WSV to the workspace.
Definition: workspace_ng.cc:54
void push_uninitialized(Index i, void *wsv)
Put a new WSV onto its stack.
Array< stack< WsvStruct * > > ws
Workspace variable container.
Definition: workspace_ng.h:49
Workspace class.
Definition: workspace_ng.h:40
static void define_wsv_map()
Map WSV names to indices.
Definition: workspace_ng.cc:48
Index add_wsv_inplace(const WsvRecord &wsv)
Add a new variable to existing workspace and to the static maps.
Definition: workspace_ng.cc:60
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:56
The WorkspaceMemoryHandler.
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:66
Handling of workspace memory.
Auxiliary header stuff related to workspace variable groups.