ARTS  2.2.66
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 
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:
59 #ifndef NDEBUG
62 #endif
63 
65 
67  static map<String, Index> WsvMap;
68 
69  Workspace ();
70  Workspace (const Workspace& workspace);
71  virtual ~Workspace ();
72 
73  static void define_wsv_data();
74  static void define_wsv_map();
75  static Index add_wsv (const WsvRecord& wsv);
76 
77  void del (Index i);
78 
79  void duplicate (Index i);
80 
81  void initialize ();
82 
84  bool is_initialized (Index i) {
85  return ((ws[i].size () != 0)
86  && (ws[i].top()->initialized == true)); }
87 
88  void *pop (Index i);
89 
90  void pop_free (Index i);
91 
92  void push (Index i, void *wsv);
93 
94  void push_uninitialized (Index i, void *wsv);
95 
96  Index nelem () {return ws.nelem ();}
97 
98  void *operator[](Index i);
99 };
100 
101 
103 
109 template <typename OutputStream> void
110 PrintWsvName (OutputStream& outstream, Index i)
111 {
112  outstream << Workspace::wsv_data[i].Name () << "(" << i << ") ";
113 }
114 
115 
117 
124 template <typename OutputStream, typename Container> void
125 PrintWsvNames (OutputStream& outstream, const Container& container)
126 {
127  for (typename Container::const_iterator it = container.begin ();
128  it != container.end (); it++ )
129  {
130  PrintWsvName (outstream, *it);
131  }
132 
133 }
134 
135 
136 #endif /* WORKSPACE_NG_INCLUDED */
137 
Workspace::wsv_data
static Array< WsvRecord > wsv_data
Definition: workspace_ng.h:64
Workspace::pop
void * pop(Index i)
Pop the topmost wsv from its stack.
Definition: workspace_ng.cc:191
Workspace::WsvStruct
Definition: workspace_ng.h:49
array.h
This file contains the definition of Array.
Workspace::context
String context
Only for debugging.
Definition: workspace_ng.h:61
Array
This can be used to make arrays out of anything.
Definition: array.h:107
Workspace::ws
Array< stack< WsvStruct * > > ws
Workspace variable container.
Definition: workspace_ng.h:56
my_basic_string< char >
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:269
Workspace::del
void del(Index i)
Delete WSV.
Definition: workspace_ng.cc:76
Workspace::nelem
Index nelem()
Definition: workspace_ng.h:96
Workspace::pop_free
void pop_free(Index i)
Pop the topmost wsv from its stack and free its memory.
Definition: workspace_ng.cc:211
PrintWsvName
void PrintWsvName(OutputStream &outstream, Index i)
Print WSV name to output stream.
Definition: workspace_ng.h:110
Workspace::push
void push(Index i, void *wsv)
Push a new wsv onto its stack.
Definition: workspace_ng.cc:233
Workspace::initialize
void initialize()
Definition: workspace_ng.cc:115
Workspace::duplicate
void duplicate(Index i)
Duplicate WSV.
Definition: workspace_ng.cc:96
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:252
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:54
Workspace::WsvMap
static map< String, Index > WsvMap
Definition: workspace_ng.h:67
Workspace
Workspace class.
Definition: workspace_ng.h:47
Workspace::add_wsv
static Index add_wsv(const WsvRecord &wsv)
Definition: workspace_ng.cc:62
Workspace::~Workspace
virtual ~Workspace()
Destruct the workspace.
Definition: workspace_ng.cc:159
Workspace::is_initialized
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:84
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Workspace::define_wsv_map
static void define_wsv_map()
Definition: workspace_ng.cc:53
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:125