ARTS  2.4.0(git:4fb77825)
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 }
WorkspaceMemoryHandler
Handling of workspace memory.
Definition: workspace_memory_handler.h:36
Workspace::wsv_data
static Array< WsvRecord > wsv_data
Global WSV data.
Definition: workspace_ng.h:58
Workspace::pop
void * pop(Index i)
Remove the topmost WSV from its stack.
Definition: workspace_ng.cc:130
Workspace::WsvStruct
Definition: workspace_ng.h:42
workspace_memory_handler.h
The WorkspaceMemoryHandler.
Group
Definition: make_autoarts_h.cc:10
Workspace::ws
Array< stack< WsvStruct * > > ws
Workspace variable container.
Definition: workspace_ng.h:49
Workspace::context
String context
Debugging context.
Definition: workspace_ng.h:54
Array< WsvRecord >
WorkspaceMemoryHandler::duplicate
void * duplicate(Index group_index, void *ptr)
Duplicate workspace variable of given group.
Definition: workspace_memory_handler.h:62
Workspace::add_wsv_inplace
Index add_wsv_inplace(const WsvRecord &wsv)
Add a new variable to existing workspace and to the static maps.
Definition: workspace_ng.cc:60
Absorption::nelem
Index nelem(const Lines &l)
Number of lines.
Definition: absorptionlines.h:1820
WorkspaceMemoryHandler::deallocate
void deallocate(Index group_index, void *ptr)
Getaway function to call the deallocation function for the WSV group with the given Index.
Definition: workspace_memory_handler.h:53
global_data::workspace_memory_handler
WorkspaceMemoryHandler workspace_memory_handler
The workspace memory handler Defined in workspace_ng.cc.
Definition: interactive_workspace.cc:21
Workspace::WsvStruct::auto_allocated
bool auto_allocated
Definition: workspace_ng.h:45
Workspace::WsvStruct::wsv
void * wsv
Definition: workspace_ng.h:43
WorkspaceMemoryHandler::allocate
void * allocate(Index group_index)
Allocate workspace WSV of given group.
Definition: workspace_memory_handler.h:44
Workspace::operator[]
void * operator[](Index i)
Retrieve a pointer to the given WSV.
Definition: workspace_ng.cc:169
Workspace::del
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:66
Workspace::pop_free
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
Definition: workspace_ng.cc:141
Workspace::push
void push(Index i, void *wsv)
Push a new WSV onto its stack.
Definition: workspace_ng.cc:153
Workspace::duplicate
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:77
Workspace::push_uninitialized
void push_uninitialized(Index i, void *wsv)
Put a new WSV onto its stack.
Definition: workspace_ng.cc:161
Workspace::Workspace
Workspace()
Construct a new workspace.
Definition: workspace_ng.cc:39
Workspace::WsvStruct::initialized
bool initialized
Definition: workspace_ng.h:44
WsvRecord
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:56
workspace_ng.h
This file contains the Workspace class.
global_data
Definition: agenda_record.cc:33
Workspace::WsvMap
static map< String, Index > WsvMap
Global map associated with wsv_data.
Definition: workspace_ng.h:61
Workspace
Workspace class.
Definition: workspace_ng.h:40
Workspace::add_wsv
static Index add_wsv(const WsvRecord &wsv)
Append a new WSV to the workspace.
Definition: workspace_ng.cc:54
Workspace::~Workspace
virtual ~Workspace()
Destruct the workspace and free all WSVs.
Definition: workspace_ng.cc:110
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Workspace::define_wsv_map
static void define_wsv_map()
Map WSV names to indices.
Definition: workspace_ng.cc:48
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:195
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.