47 wsvs.initialized =
true;
50 wsvs.wsv = std::make_shared<Agenda>(*
this);
54 wsvs.initialized =
false;
56 ws[i].push(std::move(
wsvs));
61 ws(workspace.ws.nelem()),
62 wsv_data_ptr(workspace.wsv_data_ptr),
63 WsvMap_ptr(workspace.WsvMap_ptr),
64 original_workspace(workspace.original_workspace) {
65 for (Index i = 0; i < workspace.
ws.
nelem(); i++) {
66 if (workspace.
ws[i].size() && workspace.
ws[i].top().wsv) {
68 wsvs.wsv = workspace.
ws[i].top().wsv;
69 wsvs.initialized = workspace.
ws[i].top().initialized;
70 ws[i].push(std::move(
wsvs));
76 for (Index i=0; i<
nelem(); i++) {
80 if (group == WorkspaceGroupIndexValue<Agenda>) {
83 }
else if (group == WorkspaceGroupIndexValue<ArrayOfAgenda>) {
84 for (
auto& ag: *
static_cast<ArrayOfAgenda*
>((*this)[i].get())) {
85 ag.set_workspace(*
this);
97 wsv_data_ptr.swap(other.wsv_data_ptr);
98 WsvMap_ptr.swap(other.WsvMap_ptr);
99 std::swap(original_workspace, other.original_workspace);
102 claim_agenda_ownership();
103 other.claim_agenda_ownership();
107 return ws[i].size() and
ws[i].top().initialized;
126 ws[i].top().initialized =
true;
127 return ws[i].top().wsv;
133 WsvMap_ptr(
std::make_shared<unordered_map<
String, Index>>()),
134 original_workspace(this) {
138 for (Index i = 0; i < (*wsv_data_ptr).nelem(); i++) {
147 auto out = std::make_shared<Workspace>(std::move(mout));
148 out->wsv_data_ptr = std::make_shared<Workspace::wsv_data_type>(
150 out->WsvMap_ptr = std::make_shared<Workspace::WsvMap_type>(
152 out->ws.resize(
nelem());
154 for (Index i = 0; i < out->nelem(); i++) {
155 auto &wsv_data = out->wsv_data_ptr->operator[](i);
165 if (wsv_data.Group() == WorkspaceGroupIndexValue<Agenda>) {
168 }
else if (wsv_data.Group() == WorkspaceGroupIndexValue<ArrayOfAgenda>) {
171 a =
a.deepcopy_if(*out);
177 if (wsv_data.has_defaults()) {
178 if (wsv_data.Group() == WorkspaceGroupIndexValue<Agenda>) {
179 wsv_data.update_default_value(
182 if (wsv_data.Group() == WorkspaceGroupIndexValue<ArrayOfAgenda>) {
183 wsv_data.update_default_value(
194 out.reserve(inds.
nelem());
195 for (
auto ind : inds) out.push_back(
wsv_data_ptr->at(ind));
201 out.reserve(wsv_data.nelem());
202 for (
auto &wsv : wsv_data) {
203 Index &pos = out.emplace_back();
214 "Mismatching groups")
221 return std::make_shared<Workspace>(std::move(mout));
226 return std::make_shared<Workspace>(std::move(mout));
ArrayOfAgenda deepcopy_if(Workspace &ws, const ArrayOfAgenda &agendas)
Same as Agenda member method but for an entire array.
Declarations for agendas.
void set_workspace(Workspace &x)
Agenda deepcopy_if(Workspace &) const
Creates a deep copy of the agenda if necessary (i.e., different workspace)!
This can be used to make arrays out of anything.
Index nelem() const ARTS_NOEXCEPT
Handling of workspace memory.
std::shared_ptr< void > allocate(Index group_index)
Allocate workspace WSV of given group.
std::shared_ptr< void > duplicate(Index group_index, const std::shared_ptr< void > &ptr)
Duplicate workspace variable of given group.
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.
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)
bool is_initialized(Index i) const
Checks existence of the given WSV.
wsv_data_type wsvs(const ArrayOfIndex &) const
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
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.
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.
const String & Name() const
Name of this workspace variable.
Helper macros for debugging.
#define ARTS_ASSERT(condition,...)
#define ARTS_USER_ERROR_IF(condition,...)
WorkspaceMemoryHandler workspace_memory_handler
The workspace memory handler Defined in workspace_ng.cc.
std::map< String, Index > WsvMap
const map< String, Index > WsvGroupMap
The map associated with wsv_groups.
The WorkspaceMemoryHandler.
This file contains the Workspace class.
Auxiliary header stuff related to workspace variable groups.