ARTS  2.3.1285(git:92a29ea9-dirty)
interactive_workspace.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 Simon Pfreundschuh <simon.pfreundschuh@chalmers.se>
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 
29 #ifndef _ARTS_INTERACTIVE_WORKSPACE_H_
30 #define _ARTS_INTERACTIVE_WORKSPACE_H_
31 
32 #include "agenda_class.h"
33 #include "workspace_ng.h"
34 
35 extern void (*getaways[])(Workspace &, const MRecord &);
36 
38 
50 class Callback {
51  public:
58  : callback_(f){
59  // Nothing to do here.
60  };
61 
62  Callback(const Callback &) = default;
63  Callback(Callback &&) = default;
64  Callback &operator=(const Callback &) = default;
65  Callback &operator=(Callback &&) = default;
66  ~Callback() = default;
67 
73  virtual void execute(InteractiveWorkspace &ws) {(*callback_)(&ws);};
74 
75  private:
77 };
78 
85  public:
86  InteractiveWorkspace(const Index verbosity = 1,
87  const Index agenda_verbosity = 0);
88 
90  using Workspace::operator[];
91 
98  static void initialize();
99 
108  const char *execute_agenda(const Agenda *a);
109 
122  const char *execute_workspace_method(long id,
123  const ArrayOfIndex &output,
124  const ArrayOfIndex &input);
125 
137  void set_agenda_variable(Index id, const Agenda &src);
143  void set_index_variable(Index id, const Index &src);
149  void set_array_of_index_variable(Index id, size_t n, const Index *src);
155  void set_numeric_variable(Index id, const Numeric &src);
162  void set_string_variable(Index id, const char *src);
169  void set_array_of_string_variable(Index id, size_t n, const char *const *src);
176  void set_vector_variable(Index id, size_t n, const Numeric *src);
183  void set_matrix_variable(Index id, size_t m, size_t n, const Numeric *src);
190  void set_tensor3_variable(
191  Index id, size_t l, size_t m, size_t n, const Numeric *src);
198  void set_tensor4_variable(
199  Index id, size_t k, size_t l, size_t m, size_t n, const Numeric *src);
206  void set_tensor5_variable(Index id,
207  size_t k,
208  size_t l,
209  size_t m,
210  size_t n,
211  size_t o,
212  const Numeric *src);
219  void set_tensor6_variable(Index id,
220  size_t k,
221  size_t l,
222  size_t m,
223  size_t n,
224  size_t o,
225  size_t p,
226  const Numeric *src);
233  void set_tensor7_variable(Index id,
234  size_t k,
235  size_t l,
236  size_t m,
237  size_t n,
238  size_t o,
239  size_t p,
240  size_t q,
241  const Numeric *src);
257  void set_sparse_variable(Index id,
258  Index m,
259  Index n,
260  Index nnz,
261  const Numeric *src,
262  const int *row_indices,
263  const int *column_indices);
264 
265  void execute_callback(Index callback_id) {
266  callbacks_[callback_id]->execute(*this);
267  }
268 
281  Index id = callbacks_.size();
282  callbacks_.push_back(cb);
283  return id;
284  }
285 
287 
293  void initialize_variable(Index id);
294 
296 
304  Index add_variable(Index group_id, const char *name);
305 
307 
314  void erase_variable(Index i, Index group_id);
315 
317 
323  void swap(Index i, Index j);
324 
325  private:
326 
332  void resize();
333 
334  static size_t n_anonymous_variables_;
335  static std::vector<Callback *> callbacks_;
336 };
337 
338 #endif // _ARTS_INTERACTIVE_WORKSPACE_H_
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void execute_callback(Index callback_id)
External callbacks.
The Agenda class.
Definition: agenda_class.h:44
Callback(void(*f)(InteractiveWorkspace *))
Create callback.
void(* getaways[])(Workspace &, const MRecord &)
Definition: auto_md.cc:21480
bool is_initialized(Index i)
Checks existence of the given WSV.
Definition: workspace_ng.h:118
void initialize()
Initalize ARTS runtime.
Definition: arts_api.cc:60
const char * execute_workspace_method(InteractiveWorkspace *workspace, long id, unsigned long n_args_out, const long *args_out, unsigned long n_args_in, const long *args_in)
Execute workspace method.
Definition: arts_api.cc:262
This file contains the Workspace class.
static size_t n_anonymous_variables_
Callback & operator=(const Callback &)=default
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Definition: complex.cc:731
Declarations for agendas.
Method runtime data.
Definition: agenda_class.h:121
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Interactive ARTS workspace.
virtual void execute(InteractiveWorkspace &ws)
Execute callback.
~Callback()=default
long add_variable(InteractiveWorkspace *workspace, long group_id, const char *name)
Add variable of given type to workspace.
Definition: arts_api.cc:637
static Index add_callback(Callback *cb)
Add callback to workspace.
void(* callback_)(InteractiveWorkspace *)
const char * execute_agenda(InteractiveWorkspace *workspace, const Agenda *a)
Execute Agenda.
Definition: arts_api.cc:180
static std::vector< Callback * > callbacks_
Workspace class.
Definition: workspace_ng.h:40
#define q
DLL_PUBLIC void erase_variable(InteractiveWorkspace *workspace, long id, long group_id)
Erase variable from workspace.
Definition: arts_api.cc:644