ARTS  2.0.49
workspace_ng.h
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 
32 #ifndef WORKSPACE_NG_INCLUDED
33 #define WORKSPACE_NG_INCLUDED
34 
35 #include <stack>
36 #include <map>
37 
38 class Workspace;
39 
40 #include "array.h"
41 #include "wsv_aux.h"
42 
44 
47 class Workspace {
48 private:
49  struct WsvStruct {
50  void *wsv;
53  };
54 
57 
58 public:
60 
62  static map<String, Index> WsvMap;
63 
64  Workspace ();
65  Workspace (const Workspace& workspace);
66  virtual ~Workspace ();
67 
68  static void define_wsv_data();
69  static void define_wsv_map();
70  static Index add_wsv (const WsvRecord& wsv);
71 
72  void del (Index i);
73 
74  void duplicate (Index i);
75 
76  void initialize ();
77 
79  bool is_initialized (Index i) {
80  return ((ws[i].size () != 0)
81  && (ws[i].top()->initialized == true)); }
82 
83  void *pop (Index i);
84 
85  void pop_free (Index i);
86 
87  void push (Index i, void *wsv);
88 
89  void push_uninitialized (Index i, void *wsv);
90 
91  Index nelem () {return ws.nelem ();}
92 
93  void *operator[](Index i);
94 };
95 
96 
98 
104 template <typename OutputStream> void
105 PrintWsvName (OutputStream& outstream, Index i)
106 {
107  outstream << Workspace::wsv_data[i].Name () << "(" << i << ") ";
108 }
109 
110 
112 
119 template <typename OutputStream, typename Container> void
120 PrintWsvNames (OutputStream& outstream, const Container& container)
121 {
122  for (typename Container::const_iterator it = container.begin ();
123  it != container.end (); it++ )
124  {
125  PrintWsvName (outstream, *it);
126  }
127 
128 }
129 
130 
131 #endif /* WORKSPACE_NG_INCLUDED */
132 
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
array.h
This file contains the definition of Array.
Array
This can be used to make arrays out of anything.
Definition: array.h:103
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::define_wsv_data
static void define_wsv_data()
Definition: workspace.cc:50
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
Workspace::nelem
Index nelem()
Definition: workspace_ng.h:91
Workspace::pop_free
void pop_free(Index i)
Pop the topmost wsv from its stack and free its memory.
Definition: workspace_ng.cc:201
PrintWsvName
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:105
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
WsvRecord
This class contains all static information for one workspace variable.
Definition: wsv_aux.h:49
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
Workspace::is_initialized
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:79
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
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:120