ARTS 2.5.4 (git: 31ce4f0e)
make_default_gins.cc
Go to the documentation of this file.
1#include <iostream>
2#include <map>
3
4#include "global_data.h"
5#include "methods.h"
6#include "workspace.h"
7
8struct Types {
11};
12
13bool is_default(const String& x) { return x == NODEF; }
14
15int main() {
20
21 std::ofstream("default_gins.h") << R"--(#pragma once
22
23#include "workspace.h"
24
25Index create_workspace_gin_default_internal(Workspace& ws, const std::string_view method, const std::string_view gin);
26)--";
27
28 std::map<String, Types> has;
29
30 for (auto& method : global_data::md_data_raw) {
31 for (std::size_t i = 0; i < method.GIn().size(); i++) {
32 if (auto& def = method.GInDefault()[i]; not is_default(def)) {
33 auto group_ind = method.GInType()[i];
34 auto& group = global_data::wsv_groups[group_ind].name;
35 auto& vals =
36 has[var_string("::", method.Name(), "::", method.GIn()[i])];
37 vals.type = group_ind;
38 auto& val = vals.val;
39
40 if (group == "String") {
41 val = std::string("\"") + def + std::string("\"");
42 } else if (group == "Numeric") {
43 if ("NaN" == def or "nan" == def) {
44 val = "std::numeric_limits<Numeric>::quiet_NaN()";
45 } else if ("Inf" == def or "inf" == def) {
46 val = "std::numeric_limits<Numeric>::infinity()";
47 } else if ("-Inf" == def or "-inf" == def) {
48 val = "-std::numeric_limits<Numeric>::infinity()";
49 } else {
50 val = def;
51 }
52 } else if (def == "[]") {
53 val = var_string(group, "{}");
54 } else if (group == "ArrayOfIndex") {
55 if (def[0] == '[')
56 val = "std::initializer_list<Index>" + def;
57 else
58 val = def;
59 } else if (group == "Vector") {
60 if (def[0] == '[')
61 val = "std::initializer_list<Numeric>" + def;
62 else
63 val = def;
64 } else {
65 val = def;
66 }
67
68 if (val == "") val = var_string(group, "{}");
69
70 for (auto& x : val) {
71 if (x == '[')
72 x = '{';
73 else if (x == ']')
74 x = '}';
75 }
76 }
77 }
78 }
79
80 std::ofstream os("default_gins.cc");
81
82 os << R"--(#include "auto_md.h"
83
84template <typename T, Index group>
85Index get_and_set_wsv_gin_pos(Workspace& ws, Index pos, T&& data) {
86 static std::size_t anon=0;
87
88 if (pos < 0) {
89 pos = ws.add_wsv(WsvRecord(var_string("::defgin", anon++).c_str(), "do not modify", group));
90 }
91
92 *static_cast<T *>(ws[pos].get()) = std::forward<T>(data);
93
94 return pos;
95}
96
97Index create_workspace_gin_default_internal(Workspace& ws, const std::string_view method, const std::string_view gin) {
98 const String key{var_string("::", method, "::", gin)};
99 const static std::map<String, Index> gins {
100)--";
101
102 {
103 Index counter = 0;
104 for (auto& [key, items] : has) {
105 os << " {\"" << key << "\", " << counter++ << "},\n";
106 }
107 }
108
109 os << R"--( };
110
111 auto ptr = ws.WsvMap_ptr -> find(key);
112 Index pos = ptr == ws.WsvMap_ptr -> end() ? -1 : ptr -> second;
113
114 switch (gins.at(key)) {
115)--";
116 {
117 Index counter = 0;
118 for (auto& [key, items] : has) {
119 os << " case " << counter++ << ": return get_and_set_wsv_gin_pos<"
120 << global_data::wsv_groups[items.type] << ", " << items.type
121 << ">(ws, pos, " << items.val << ");\n";
122 }
123 }
124 os << R"--( }
125
126 return pos;
127}
128)--";
129}
void define_wsv_groups()
Define the array of workspace variable group names.
Definition: groups.cc:66
std::string var_string(Args &&... args)
Definition: debug.h:36
bool is_default(const String &x)
int main()
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void define_md_data_raw()
Definition: methods.cc:190
Declaration of the class MdRecord.
#define NODEF
Definition: methods.h:35
constexpr std::string_view items(std::string_view s, std::size_t i) noexcept
Get a view of a number of space-separated items from the list.
const ArrayOfGroupRecord wsv_groups
The names associated with Wsv groups as Strings.
Definition: global_data.h:91
const Array< MdRecord > md_data_raw
Lookup information for workspace methods.
Definition: methods.cc:42
Index type
String val
void define_wsv_data()
Definition: workspace.cc:48
void define_wsv_map()
Definition: workspace.cc:5877