ARTS  2.0.49
workspace_ng.cc
Go to the documentation of this file.
1 /* Copyright (C) 2004-2008 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 
19 // File description
21 
31 #include "workspace_ng.h"
32 #include "wsv_aux.h"
33 #include "auto_workspace.h"
34 
36 
38 
39 map<String, Index> Workspace::WsvMap;
40 
42 
46 {
47 }
48 
49 
51 {
52  for ( Index i=0 ; i<wsv_data.nelem() ; ++i )
53  {
54  WsvMap[wsv_data[i].Name()] = i;
55  }
56 }
57 
58 
60 {
61  Workspace::wsv_data.push_back(wsv);
63  return wsv_data.nelem()-1;
64 }
65 
66 
68 
74 {
75  WsvStruct *wsvs = ws[i].top ();
76 
77  if (wsvs &&& wsvs->wsv)
78  {
79  wsmh.deallocate (wsv_data[i].Group(), wsvs->wsv);
80  wsvs->wsv = NULL;
81  wsvs->auto_allocated = false;
82  wsvs->initialized = false;
83  }
84 }
85 
86 
88 
94 {
95  WsvStruct *wsvs = new WsvStruct;
96 
97  wsvs->auto_allocated = true;
98  if (ws[i].size() && ws[i].top()->wsv)
99  {
100  wsvs->wsv = wsmh.duplicate (wsv_data[i].Group(), ws[i].top()->wsv);
101  wsvs->initialized = true;
102  }
103  else
104  {
105  wsvs->wsv = NULL;
106  wsvs->initialized = false;
107  }
108  ws[i].push (wsvs);
109 }
110 
111 
113 {
114  ws.resize (wsv_data.nelem());
115 }
116 
117 
119 
128 Workspace::Workspace (const Workspace& workspace) : ws(workspace.ws.nelem())
129 {
130  for (Index i=0; i < workspace.ws.nelem(); i++)
131  {
132  WsvStruct *wsvs = new WsvStruct;
133  wsvs->auto_allocated = false;
134  if (workspace.ws[i].size() && workspace.ws[i].top()->wsv)
135  {
136  wsvs->wsv = workspace.ws[i].top()->wsv;
137  wsvs->initialized = workspace.ws[i].top()->initialized;
138  }
139  else
140  {
141  wsvs->wsv = NULL;
142  wsvs->initialized = false;
143  }
144  ws[i].push (wsvs);
145  }
146 }
147 
148 
150 
154 {
155  for (int i = 0; i < ws.nelem (); i++)
156  {
157  WsvStruct *wsvs;
158 
159  while (ws[i].size ())
160  {
161  wsvs = ws[i].top ();
162  if (wsvs->auto_allocated && wsvs->wsv)
163  {
164  wsmh.deallocate (wsv_data[i].Group(), wsvs->wsv);
165  }
166  delete (wsvs);
167  ws[i].pop ();
168  }
169  }
170  ws.empty ();
171 }
172 
173 
175 
182 {
183  WsvStruct *wsvs = ws[i].top ();
184  void *vp = NULL;
185  if (wsvs)
186  {
187  vp = wsvs->wsv;
188  delete wsvs;
189  ws[i].pop ();
190  }
191  return vp;
192 }
193 
194 
196 
202 {
203  WsvStruct *wsvs = ws[i].top ();
204 
205  if (wsvs)
206  {
207  if (wsvs->wsv)
208  wsmh.deallocate (wsv_data[i].Group(), wsvs->wsv);
209 
210  delete wsvs;
211  ws[i].pop ();
212  }
213 }
214 
215 
217 
223 void Workspace::push (Index i, void *wsv)
224 {
225  WsvStruct *wsvs = new WsvStruct;
226  wsvs->auto_allocated = false;
227  wsvs->initialized = true;
228  wsvs->wsv = wsv;
229  ws[i].push (wsvs);
230 }
231 
232 
234 
243 {
244  WsvStruct *wsvs = new WsvStruct;
245  wsvs->auto_allocated = false;
246  wsvs->initialized = false;
247  wsvs->wsv = wsv;
248  ws[i].push (wsvs);
249 }
250 
251 
253 
260 {
261  if (!ws[i].size ())
262  push (i, NULL);
263 
264  if (!ws[i].top ()->wsv)
265  {
266  ws[i].top ()->auto_allocated = true;
267  ws[i].top ()->wsv = wsmh.allocate (wsv_data[i].Group());
268  }
269 
270  ws[i].top ()->initialized = true;
271 
272  return (ws[i].top()->wsv);
273 }
274 
WorkspaceMemoryHandler
Definition: auto_workspace.h:35
Workspace::wsv_data
static Array< WsvRecord > wsv_data
Definition: workspace_ng.h:59
Workspace::pop
void * pop(Index i)
Pop the topmost wsv from its stack.
Definition: workspace_ng.cc:181
Workspace::WsvStruct
Definition: workspace_ng.h:49
WorkspaceMemoryHandler::allocate
void * allocate(Index wsvg)
Getaway function to call the allocation function for the WSV group with the given Index.
Definition: auto_workspace.h:669
Array< WsvRecord >
wsmh
WorkspaceMemoryHandler wsmh
Definition: workspace_ng.cc:35
Workspace::ws
Array< stack< WsvStruct * > > ws
Workspace variable container.
Definition: workspace_ng.h:56
Workspace::WsvStruct::auto_allocated
bool auto_allocated
Definition: workspace_ng.h:52
Workspace::WsvStruct::wsv
void * wsv
Definition: workspace_ng.h:50
Workspace::operator[]
void * operator[](Index i)
Retrieve pointer to the given WSV.
Definition: workspace_ng.cc:259
Workspace::del
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:73
WorkspaceMemoryHandler::deallocate
void deallocate(Index wsvg, void *vp)
Getaway function to call the deallocation function for the WSV group with the given Index.
Definition: auto_workspace.h:677
WorkspaceMemoryHandler::duplicate
void * duplicate(Index wsvg, void *vp)
Getaway function to call the duplication function for the WSV group with the given Index.
Definition: auto_workspace.h:685
Workspace::pop_free
void pop_free(Index i)
Pop the topmost wsv from its stack and free its memory.
Definition: workspace_ng.cc:201
Workspace::push
void push(Index i, void *wsv)
Push a new wsv onto its stack.
Definition: workspace_ng.cc:223
Workspace::initialize
void initialize()
Definition: workspace_ng.cc:112
Workspace::duplicate
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:93
Workspace::push_uninitialized
void push_uninitialized(Index i, void *wsv)
Push a new wsv onto its stack but mark it as uninitialized.
Definition: workspace_ng.cc:242
Workspace::Workspace
Workspace()
Construct a new workspace.
Definition: workspace_ng.cc:45
Workspace::WsvStruct::initialized
bool initialized
Definition: workspace_ng.h:51
auto_workspace.h
Defines the enum type that acts as a handle for workspace variables groups.
WsvRecord
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:49
workspace_ng.h
This file contains the declaration and partly the implementation of the workspace class.
Workspace::WsvMap
static map< String, Index > WsvMap
Definition: workspace_ng.h:62
Workspace
Workspace class.
Definition: workspace_ng.h:47
Workspace::add_wsv
static Index add_wsv(const WsvRecord &wsv)
Definition: workspace_ng.cc:59
Workspace::~Workspace
virtual ~Workspace()
Destruct the workspace.
Definition: workspace_ng.cc:153
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()
Definition: workspace_ng.cc:50
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:172
wsv_aux.h
Auxiliary header stuff related to workspace variable groups.