ARTS  2.4.0(git:4fb77825)
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 */
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
array.h
This file contains the definition of Array.
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
This can be used to make arrays out of anything.
Definition: array.h:108
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
my_basic_string< char >
Workspace::WsvStruct::auto_allocated
bool auto_allocated
Definition: workspace_ng.h:45
Workspace::define_wsv_data
static void define_wsv_data()
Define workspace variables.
Definition: workspace.cc:39
Workspace::WsvStruct::wsv
void * wsv
Definition: workspace_ng.h:43
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::nelem
Index nelem()
Get the number of workspace variables.
Definition: workspace_ng.h:162
Workspace::depth
Index depth(Index i)
Return scoping level of the given WSV.
Definition: workspace_ng.h:123
Workspace::pop_free
void pop_free(Index i)
Remove the topmost WSV from its stack and free its memory.
Definition: workspace_ng.cc:141
PrintWsvName
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:180
Workspace::push
void push(Index i, void *wsv)
Push a new WSV onto its stack.
Definition: workspace_ng.cc:153
Workspace::initialize
void initialize()
Reset the size of the workspace.
Definition: workspace_ng.h:111
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::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
Workspace::is_initialized
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:118
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.
PrintWsvNames
void PrintWsvNames(OutputStream &outstream, const Container &container)
Print list of WSV names to output stream.
Definition: workspace_ng.h:193