https://mooseframework.inl.gov
JsonSyntaxTree.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "InputParameters.h"
13 #include "FileLineInfo.h"
14 #include "nlohmann/json.h"
15 #include <string>
16 #include <vector>
17 #include <utility>
18 
23 {
24 public:
25  JsonSyntaxTree(const std::string & search_string);
26  virtual ~JsonSyntaxTree() {}
27 
40  bool addParameters(const std::string & parent_path,
41  const std::string & path,
42  bool is_type,
43  const std::string & action,
44  bool is_action,
45  InputParameters * params,
46  const FileLineInfo & lineinfo,
47  const std::string & classname);
48 
56  void addActionTask(const std::string & path,
57  const std::string & action,
58  const std::string & task,
59  const FileLineInfo & lineinfo);
64  const nlohmann::json & getRoot() const { return _root; }
65 
71  void addSyntaxType(const std::string & path, const std::string type);
72 
76  void addGlobal();
77 
81  static std::string basicCppType(const std::string & cpp_type);
82 
83 protected:
84  std::string buildOptions(const std::iterator_traits<InputParameters::iterator>::value_type & p,
85  bool & out_of_range_allowed,
86  std::map<MooseEnumItem, std::string> & docs);
87 
88  size_t setParams(InputParameters * params, bool search_match, nlohmann::json & all_params);
89 
90  static std::string
91  buildOutputString(const std::iterator_traits<InputParameters::iterator>::value_type & p);
92  static std::vector<std::string> splitPath(const std::string & path);
93  nlohmann::json & getJson(const std::string & parent, const std::string & path, bool is_type);
94  nlohmann::json & getJson(const std::string & path);
95  std::pair<std::string, std::string> getObjectLabel(const std::string & obj) const;
96  std::pair<std::string, std::string> getActionLabel(const std::string & action) const;
97 
98  nlohmann::json _root;
99  std::string _search;
100 
103  std::map<std::string, std::pair<std::string, std::string>> _action_label_map;
104  std::map<std::string, std::pair<std::string, std::string>> _object_label_map;
106 
107  // Allow the MooseServer class to use protected static convenience methods
108  friend class MooseServer;
109 };
void addSyntaxType(const std::string &path, const std::string type)
Add an associated type to a block.
std::string buildOptions(const std::iterator_traits< InputParameters::iterator >::value_type &p, bool &out_of_range_allowed, std::map< MooseEnumItem, std::string > &docs)
void addActionTask(const std::string &path, const std::string &action, const std::string &task, const FileLineInfo &lineinfo)
Add a task to the tree.
nlohmann::json & getJson(const std::string &parent, const std::string &path, bool is_type)
size_t setParams(InputParameters *params, bool search_match, nlohmann::json &all_params)
static std::vector< std::string > splitPath(const std::string &path)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Holds the syntax in a Json::Value tree.
static std::string buildOutputString(const std::iterator_traits< InputParameters::iterator >::value_type &p)
JsonSyntaxTree(const std::string &search_string)
bool addParameters(const std::string &parent_path, const std::string &path, bool is_type, const std::string &action, bool is_action, InputParameters *params, const FileLineInfo &lineinfo, const std::string &classname)
Add parameters to the tree.
std::map< std::string, std::pair< std::string, std::string > > _action_label_map
const nlohmann::json & getRoot() const
Get the root of the tree.
static std::string basicCppType(const std::string &cpp_type)
Utilities for making sense of c++ types.
Holds file and line information.
Definition: FileLineInfo.h:18
nlohmann::json _root
virtual ~JsonSyntaxTree()
std::pair< std::string, std::string > getActionLabel(const std::string &action) const
std::pair< std::string, std::string > getObjectLabel(const std::string &obj) const
std::string _search
void addGlobal()
Add the global section to the output.
std::map< std::string, std::pair< std::string, std::string > > _object_label_map