ARTS  2.3.1285(git:92a29ea9-dirty)
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 
31 class Workspace;
32 
33 #include "array.h"
34 #include "wsv_aux.h"
35 
40 class Workspace {
41  protected:
42  struct WsvStruct {
43  void *wsv;
46  };
47 
50 
51  public:
52 #ifndef NDEBUG
53 
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 
179 template <typename OutputStream>
180 void PrintWsvName(OutputStream &outstream, Index i) {
181  outstream << Workspace::wsv_data[i].Name() << "(" << i << ") ";
182 }
183 
192 template <typename OutputStream, typename Container>
193 void 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 */
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 depth(Index i)
Return scoping level of the given WSV.
Definition: workspace_ng.h:123
Index nelem() const
Number of elements.
Definition: array.h:195
void initialize()
Reset the size of the workspace.
Definition: workspace_ng.h:111
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:77
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:118
void PrintWsvNames(OutputStream &outstream, const Container &container)
Print list of WSV names to output stream.
Definition: workspace_ng.h:193
This file contains the definition of Array.
String context
Debugging context.
Definition: workspace_ng.h:54
virtual ~Workspace()
Destruct the workspace and free all WSVs.
static void define_wsv_data()
Define workspace variables.
Definition: workspace.cc:39
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 PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:180
void * pop(Index i)
Remove the topmost WSV from its stack.
Workspace()
Construct a new workspace.
Definition: workspace_ng.cc:39
This can be used to make arrays out of anything.
Definition: array.h:40
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
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:66
Auxiliary header stuff related to workspace variable groups.