Alamo
InputScraper.H
Go to the documentation of this file.
1#ifndef IO_INPUTSCRAPER_H
2#define IO_INPUTSCRAPER_H
3
4#include <optional>
5#include <ostream>
6#include <source_location>
7#include <sstream>
8#include <string>
9#include <vector>
10
11#include "Set/Base.H"
12
13namespace IO
14{
15class ParmParse;
16
18{
19public:
20 struct FlowNode;
21
23 {
24 std::string value;
25 std::vector<FlowNode> children;
26 };
27
28 struct FlowNode
29 {
30 std::string kind = "input";
31 std::string input;
32 std::source_location location;
33 bool has_unnamed_default = false;
34 std::vector<FlowBranch> branches;
35 std::vector<FlowNode> children;
36 };
37
38 struct InputNode
39 {
40 struct Condition
41 {
42 std::string path;
43 std::string value;
44 };
45
47 {
48 std::string kind;
49 int count = 0;
50 std::vector<std::string> members;
51 std::vector<std::string> units;
52 std::source_location location;
53 std::vector<Condition> conditions;
54 };
55
56 std::string kind = "scope";
57 std::string name;
58 std::string full_name;
59 std::string directive;
60 std::source_location location;
61 std::vector<std::string> options;
62 bool required = false;
63 bool has_default = false;
64 bool has_default_value = false;
65 bool has_unnamed_default = false;
66 std::string default_value;
67 std::vector<std::vector<Condition>> contexts;
68 std::vector<Constraint> constraints;
69 std::vector<InputNode> children;
70 };
71
73 {
74 std::string note;
75 std::source_location location;
76 };
77
79 {
80 public:
81 TraversalBranchScope(ParmParse &pp, std::string name, std::string value);
83
84 private:
85 bool active = false;
86 };
87
88 static void SetTraversalMode(bool enabled);
89 static bool InTraversalMode();
90 static bool ShouldExecute();
91 static const InputNode &InputTree();
92 static void ClearInputTree();
93 static void SetTraversalOutputFile(std::string path);
94 static const std::string &TraversalOutputFile();
95 static void WriteInputTreeJson(std::ostream &os);
96 static void WriteInputTreeJsonFile(const std::string &path);
97
98 static std::string DirectiveName(const std::source_location &location);
99
100 static void RecordInput(ParmParse &pp,
101 std::string name,
102 std::string directive,
103 const std::source_location &location,
104 std::vector<std::string> options = {},
105 std::optional<std::string> default_value = std::nullopt,
106 bool has_unnamed_default = false);
107 static void RecordConstraint( ParmParse &pp,
108 std::string kind,
109 int count,
110 std::vector<std::string> members,
111 std::vector<std::string> units,
112 const std::source_location &location);
113 static void RecordTraversalIgnore( const std::source_location &location,
114 std::string note);
115 static void CaptureSequenceTemplate(ParmParse &pp,
116 const std::string &sequence_name,
117 const std::string &template_name);
118 static void PrintTraversalBranch(ParmParse &pp, std::string name, const std::string &value);
119
120 template<typename T>
121 static std::string InputValueString(const T &value)
122 {
123 std::ostringstream os;
124 os << value;
125 return os.str();
126 }
127
128 static std::string InputValueString(const std::string &value) { return value; }
129 static std::string InputValueString(const char *value) { return std::string(value); }
130
131 template<typename T>
132 static std::string InputArrayString(const std::vector<T> &values)
133 {
134 std::ostringstream os;
135 for (std::size_t i = 0; i < values.size(); i++)
136 {
137 if (i) os << " ";
138 os << InputValueString(values[i]);
139 }
140 return os.str();
141 }
142
143 static std::string InputArrayString(const Set::Vector &value)
144 {
145 std::ostringstream os;
146 for (int i = 0; i < AMREX_SPACEDIM; i++)
147 {
148 if (i) os << " ";
149 os << value(i);
150 }
151 return os.str();
152 }
153
154 static std::string InputArrayString(const Set::Matrix &value)
155 {
156 std::ostringstream os;
157 for (int i = 0; i < AMREX_SPACEDIM; i++)
158 {
159 for (int j = 0; j < AMREX_SPACEDIM; j++)
160 {
161 if (i || j) os << " ";
162 os << value(i, j);
163 }
164 }
165 return os.str();
166 }
167
168private:
171 static bool traversal_mode;
172 static std::string traversal_output_file;
173 static std::vector<InputNode::Condition> traversal_conditions;
174 static std::vector<FlowNode> input_flow;
175 static std::vector<FlowNode> *traversal_flow;
176 static std::vector<std::vector<FlowNode> *> traversal_flow_stack;
177 static std::vector<TraversalIgnore> traversal_ignores;
178
179 static InputNode &GetPath(InputNode &root, const std::string &path);
180 static std::string KindForDirective(const std::string &directive,
181 const std::vector<std::string> &options = {});
182 static std::string MergeKind(const std::string &old_kind, const std::string &new_kind);
183 static void AddContext(InputNode &node, const std::vector<InputNode::Condition> &conditions);
184 static void RecordFlowInput(const std::string &path,
185 const std::string &directive,
186 const std::vector<std::string> &options,
187 const std::source_location &location,
188 bool has_unnamed_default);
189 static void PushTraversalCondition(ParmParse &pp, std::string name, std::string value);
190 static void PopTraversalCondition();
191 static void PushTraversalBranch(ParmParse &pp, const std::string &name,
192 const std::string &value);
193 static void PopTraversalBranch();
194};
195}
196
197#endif
static std::vector< FlowNode > input_flow
static void RecordInput(ParmParse &pp, std::string name, std::string directive, const std::source_location &location, std::vector< std::string > options={}, std::optional< std::string > default_value=std::nullopt, bool has_unnamed_default=false)
static void WriteInputTreeJsonFile(const std::string &path)
static void ClearInputTree()
static std::string InputValueString(const char *value)
static std::string InputValueString(const std::string &value)
static void SetTraversalMode(bool enabled)
static void CaptureSequenceTemplate(ParmParse &pp, const std::string &sequence_name, const std::string &template_name)
static void PrintTraversalBranch(ParmParse &pp, std::string name, const std::string &value)
static void RecordConstraint(ParmParse &pp, std::string kind, int count, std::vector< std::string > members, std::vector< std::string > units, const std::source_location &location)
static std::string DirectiveName(const std::source_location &location)
static std::string MergeKind(const std::string &old_kind, const std::string &new_kind)
static const InputNode & InputTree()
static void PopTraversalCondition()
static InputNode & GetPath(InputNode &root, const std::string &path)
static void AddContext(InputNode &node, const std::vector< InputNode::Condition > &conditions)
static std::vector< std::vector< FlowNode > * > traversal_flow_stack
static std::string InputArrayString(const Set::Vector &value)
static bool ShouldExecute()
static bool InTraversalMode()
static std::string InputValueString(const T &value)
static void WriteInputTreeJson(std::ostream &os)
static InputNode input_tree
static bool traversal_mode
static std::string InputArrayString(const std::vector< T > &values)
static std::string traversal_output_file
static std::vector< TraversalIgnore > traversal_ignores
static std::string KindForDirective(const std::string &directive, const std::vector< std::string > &options={})
static void PushTraversalBranch(ParmParse &pp, const std::string &name, const std::string &value)
static std::vector< FlowNode > * traversal_flow
static void PopTraversalBranch()
static void SetTraversalOutputFile(std::string path)
static void RecordFlowInput(const std::string &path, const std::string &directive, const std::vector< std::string > &options, const std::source_location &location, bool has_unnamed_default)
static void PushTraversalCondition(ParmParse &pp, std::string name, std::string value)
static std::vector< InputNode::Condition > traversal_conditions
static void RecordTraversalIgnore(const std::source_location &location, std::string note)
static std::string InputArrayString(const Set::Matrix &value)
static int traversal_print_depth
static const std::string & TraversalOutputFile()
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:21
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
Definition Base.H:24
std::vector< FlowNode > children
std::vector< FlowBranch > branches
std::source_location location
std::vector< FlowNode > children
std::vector< std::string > members
std::vector< std::string > units
std::vector< Condition > conditions
std::source_location location
std::vector< std::string > options
std::vector< InputNode > children
std::vector< std::vector< Condition > > contexts
std::vector< Constraint > constraints
std::source_location location