This class produces produces a dump of the InputParameters that appears like the normal input file syntax.
More...
#include <JsonInputFileFormatter.h>
|
| void | addLine (const std::string &line, size_t max_line_len=0, const std::string &comment="") |
| | Adds a line to the output. More...
|
| |
| void | addBlock (const std::string &name, const nlohmann::json &block, bool top=false) |
| | Adds a new block to the output. More...
|
| |
| void | addParameters (const nlohmann::json ¶ms) |
| | Add a comment to the block. More...
|
| |
| void | addTypes (const std::string &key, const nlohmann::json &block) |
| | Add a dictionary of type blocks to the output. More...
|
| |
This class produces produces a dump of the InputParameters that appears like the normal input file syntax.
It is different from InputFileFormatter in that it takes its input from JsonSyntaxTree.
Definition at line 19 of file JsonInputFileFormatter.h.
◆ JsonInputFileFormatter()
| JsonInputFileFormatter::JsonInputFileFormatter |
( |
| ) |
|
◆ addBlock()
| void JsonInputFileFormatter::addBlock |
( |
const std::string & |
name, |
|
|
const nlohmann::json & |
block, |
|
|
bool |
top = false |
|
) |
| |
|
protected |
Adds a new block to the output.
- Parameters
-
| name | Name of the block. |
| block | Json holding data for the block. |
| top | Whether this is a top level block. |
Definition at line 72 of file JsonInputFileFormatter.C.
Referenced by addTypes(), and toString().
83 std::string desc = block.contains(
"description") ? nlohmann::to_string(block[
"description"]) :
"";
87 if (block.contains(
"parameters"))
90 if (block.contains(
"actions"))
93 nlohmann::json all_params;
94 auto & actions = block[
"actions"];
95 for (
auto && el : actions.items())
97 auto & params = el.value()[
"parameters"];
98 for (
auto && param_el : params.items())
99 all_params[param_el.key()] = param_el.value();
104 if (block.contains(
"star"))
110 if (block.contains(
"subblocks"))
112 auto & subblocks = block[
"subblocks"];
113 if (!subblocks.is_null())
114 for (
auto && el : subblocks.items())
◆ addLine()
| void JsonInputFileFormatter::addLine |
( |
const std::string & |
line, |
|
|
size_t |
max_line_len = 0, |
|
|
const std::string & |
comment = "" |
|
) |
| |
|
protected |
Adds a line to the output.
This will put in the proper indentation automatically.
- Parameters
-
| line | The line to add. |
| max_line_len | Used to determine where to start inline comments. comment Comment to add to the line. It will automatically be broken up over multiple lines if too long. |
Definition at line 28 of file JsonInputFileFormatter.C.
Referenced by addBlock(), addParameters(), and addTypes().
32 if (line.empty() && comment.empty())
49 std::vector<std::string> elements;
57 int len = 100 - max_line_len -
indent.size();
62 std::string first(max_line_len - line.size() + extra,
' ');
63 _stream << first <<
"# " << elements[0] <<
"\n";
64 std::string cindent(max_line_len +
indent.size() + extra,
' ');
65 for (
size_t i = 1; i < elements.size(); ++i)
66 _stream << cindent <<
"# " << elements[i] <<
"\n";
std::string indent(unsigned int spaces)
Create empty string for indenting.
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
◆ addParameters()
| void JsonInputFileFormatter::addParameters |
( |
const nlohmann::json & |
params | ) |
|
|
protected |
Add a comment to the block.
It will add the proper indentation and #.
- Parameters
-
| comment | The comment to add. |
Definition at line 144 of file JsonInputFileFormatter.C.
Referenced by addBlock().
147 for (
auto & el : params.items())
148 if (el.key().size() > max_name)
149 max_name = el.key().size();
152 std::map<std::string, std::string> lines;
153 for (
auto && el : params.items())
155 auto &
name = el.key();
156 auto & param = el.value();
158 param.contains(
"default") ?
MooseUtils::trim(nlohmann::to_string(param[
"default"])) :
"";
160 def = def.substr(1, def.size() - 2);
161 if (def.find(
' ') != std::string::npos)
162 def =
"'" + def +
"'";
163 std::string
indent(max_name -
name.size(),
' ');
164 std::string required;
165 if (param[
"required"])
166 required =
"(required)";
167 if (def.size() == 0 && required.size() == 0)
168 def =
"(no_default)";
169 std::string l =
name +
indent +
" = " + def + required;
170 if (l.size() > max_len)
174 for (
auto & el : params.items())
176 auto &
name = el.key();
177 auto & param = el.value();
178 auto & l = lines[
name];
179 auto desc = nlohmann::to_string(param[
"description"]);
182 const auto doc_unit = nlohmann::to_string(param[
"doc_unit"]);
183 if (!doc_unit.empty())
185 "Unit: " + doc_unit);
187 const auto group = nlohmann::to_string(param[
"group_name"]);
std::string name(const ElemQuality q)
std::string indent(unsigned int spaces)
Create empty string for indenting.
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
◆ addTypes()
| void JsonInputFileFormatter::addTypes |
( |
const std::string & |
key, |
|
|
const nlohmann::json & |
block |
|
) |
| |
|
protected |
Add a dictionary of type blocks to the output.
- Parameters
-
| key | This will be used to get the dictionary of types from block. |
| block | The Json data that is the parent of the types data. |
Definition at line 126 of file JsonInputFileFormatter.C.
Referenced by addBlock().
128 if (!block.contains(key))
130 auto & types = block[key];
137 for (
auto && el : types.items())
138 addBlock(
"<" + el.key() +
">", el.value());
◆ toString()
| std::string JsonInputFileFormatter::toString |
( |
const nlohmann::json & |
root | ) |
|
Returns a string representation of the tree in input file format.
- Parameters
-
| root | The root node of the tree to output. |
Definition at line 18 of file JsonInputFileFormatter.C.
Referenced by MooseApp::setupOptions().
22 for (
auto && el : root[
"blocks"].items())
23 addBlock(el.key(), el.value(),
true);
◆ _level
| int JsonInputFileFormatter::_level |
|
protected |
◆ _spaces
| const int JsonInputFileFormatter::_spaces |
|
protected |
◆ _stream
| std::ostringstream JsonInputFileFormatter::_stream |
|
protected |
The documentation for this class was generated from the following files: