8#ifndef WORKSPACE_NG_INCLUDED
9#define WORKSPACE_NG_INCLUDED
11#include <unordered_map>
21 std::shared_ptr<void>
wsv;
25using WorkspaceVariable = stack<WorkspaceVariableStruct, std::vector<WorkspaceVariableStruct>>;
36class Workspace final :
public std::enable_shared_from_this<Workspace> {
67 [[nodiscard]]
static std::shared_ptr<Workspace>
create();
70 [[nodiscard]] std::shared_ptr<Workspace>
shallowcopy()
const;
100 [[nodiscard]] Index
depth(Index i) const;
119 template <typename T>
121 using U = std::remove_cv_t<T>;
122 std::shared_ptr<U> wsv_ptr(
const_cast<U *
>(&wsv), [](U *) {});
124 wsvs.initialized =
true;
137 template <
typename T>
139 using U = std::remove_cv_t<T>;
140 std::shared_ptr<U> wsv_ptr(
const_cast<U *
>(&wsv), [](U *) {});
142 wsvs.initialized =
false;
155 template <
typename T>
158 wsvs.initialized =
true;
159 wsvs.wsv = std::forward<std::shared_ptr<T>>(wsv_ptr);
160 ws[i].push(std::move(
wsvs));
174 T*
get(
const char *name) {
176 return static_cast<T*
>(
ws[pos].top().wsv.get());
192 template <
typename OutputStream>
194 outstream << (*wsv_data_ptr)[i].Name() <<
"(" << i <<
") ";
198 std::shared_ptr<Workspace>
deepcopy();
217 else { T mout{x};
return std::make_shared<T>(std::move(mout)); }
This file contains the definition of Array.
int arts_omp_get_max_threads()
Wrapper for omp_get_max_threads.
bool arts_omp_in_parallel()
Wrapper for omp_in_parallel.
Header file for helper functions for OpenMP.
This can be used to make arrays out of anything.
Index nelem() const ARTS_NOEXCEPT
OmpParallelCopyGuard(T &ws, bool do_copy_manually)
std::shared_ptr< T > copy
OmpParallelCopyGuard(T &ws)
OmpParallelCopyGuard(const OmpParallelCopyGuard &cp)
std::shared_ptr< wsv_data_type > wsv_data_ptr
void swap(Workspace &other) noexcept
Swap with another workspace.
Index add_wsv(const WsvRecord &wsv)
Add a new variable to this workspace.
static std::shared_ptr< Workspace > create()
Creates a new Workspace, it has to be created as a shared pointer.
WorkspaceBorrowGuard borrow_uninitialized(Index i, T &wsv)
Put a new WSV onto its stack.
void PrintWsvName(OutputStream &outstream, Index i) const
Print WSV name to output stream.
std::shared_ptr< Workspace > shallowcopy() const
Shallow copy of a Workspace, it has to be created as a shared pointer.
void pop(Index i)
Remove the topmost WSV from its stack.
void claim_agenda_ownership()
T * get(const char *name)
Retrieve a value ptr if it exist (FIXME: C++20 allows const char* as template argument)
unordered_map< String, Index > WsvMap_type
bool is_initialized(Index i) const
Checks existence of the given WSV.
Workspace(Workspace &&) noexcept=default
Allow move construction of this object in public.
wsv_data_type wsvs(const ArrayOfIndex &) const
Workspace * original_workspace
void duplicate(Index i)
Duplicate WSV.
Index nelem() const
Get the number of workspace variables.
Array< WorkspaceVariable > ws
Workspace variable container.
Workspace()
Construct a new workspace.
std::shared_ptr< Workspace > deepcopy()
Gets a full copy that owns all the data (only gets the top of the stack)
std::shared_ptr< WsvMap_type > WsvMap_ptr
Array< WsvRecord > wsv_data_type
Index depth(Index i) const
Return scoping level of the given WSV.
void set_empty(Index i)
Delete WSV.
std::shared_ptr< void > operator[](Index i)
Retrieve a pointer to the given WSV.
WorkspaceBorrowGuard borrow(Index i, T &wsv)
Push a new WSV onto its stack.
void push_move(Index i, std::shared_ptr< T > &&wsv_ptr)
Move a WSV onto its stack.
This class contains all static information for one workspace variable.
~WorkspaceBorrowGuard() noexcept
std::shared_ptr< void > wsv
std::shared_ptr< T > get_shallow_copy(const T &x)
stack< WorkspaceVariableStruct, std::vector< WorkspaceVariableStruct > > WorkspaceVariable
Auxiliary header stuff related to workspace variable groups.