www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SyntaxTree::TreeNode Class Reference

This class represents a single node in our tree. More...

#include <SyntaxTree.h>

Public Member Functions

 TreeNode (const std::string &name, SyntaxTree &syntax_tree, const std::string *action=NULL, InputParameters *params=NULL, TreeNode *parent=NULL)
 
 ~TreeNode ()
 
void insertNode (std::string &syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
 
std::string print (short depth, const std::string &search_string, bool &found)
 
std::string getLongName (const std::string &delim="/") const
 

Protected Member Functions

void insertParams (const std::string &action, bool is_action_params, InputParameters *params=NULL)
 

Protected Attributes

std::map< std::string, std::unique_ptr< TreeNode > > _children
 
std::multimap< std::string, std::unique_ptr< InputParameters > > _action_params
 
std::multimap< std::string, std::unique_ptr< InputParameters > > _moose_object_params
 
std::string _name
 
TreeNode_parent
 
SyntaxTree_syntax_tree
 

Detailed Description

This class represents a single node in our tree.

Definition at line 43 of file SyntaxTree.h.

Constructor & Destructor Documentation

◆ TreeNode()

SyntaxTree::TreeNode::TreeNode ( const std::string &  name,
SyntaxTree syntax_tree,
const std::string *  action = NULL,
InputParameters params = NULL,
TreeNode parent = NULL 
)

Definition at line 68 of file SyntaxTree.C.

73  : _name(name), _parent(parent), _syntax_tree(syntax_tree)
74 {
75  if (action)
76  _action_params.emplace(*action, std::make_unique<InputParameters>(*params));
77 }
TreeNode * _parent
Definition: SyntaxTree.h:70
std::string _name
Definition: SyntaxTree.h:69
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:71
std::multimap< std::string, std::unique_ptr< InputParameters > > _action_params
Definition: SyntaxTree.h:67

◆ ~TreeNode()

SyntaxTree::TreeNode::~TreeNode ( )
default

Member Function Documentation

◆ getLongName()

std::string SyntaxTree::TreeNode::getLongName ( const std::string &  delim = "/") const

Definition at line 218 of file SyntaxTree.C.

219 {
220  if (_parent)
221  return _parent->getLongName(delim) + delim + _name;
222  else
223  return _name;
224 }
TreeNode * _parent
Definition: SyntaxTree.h:70
std::string getLongName(const std::string &delim="/") const
Definition: SyntaxTree.C:218
std::string _name
Definition: SyntaxTree.h:69

◆ insertNode()

void SyntaxTree::TreeNode::insertNode ( std::string &  syntax,
const std::string &  action,
bool  is_action_params = true,
InputParameters params = NULL 
)

Definition at line 82 of file SyntaxTree.C.

86 {
87  std::string::size_type pos = syntax.find_first_of("/");
88  std::string item;
89  bool is_leaf = true;
90 
91  item = syntax.substr(0, pos);
92  if (pos != std::string::npos)
93  {
94  syntax = syntax.substr(pos + 1);
95  is_leaf = false;
96  }
97 
98  bool node_created = false;
99  if (_children.find(item) == _children.end())
100  {
101  _children[item] = std::make_unique<TreeNode>(
102  item, _syntax_tree, is_leaf && is_action_params ? &action : NULL, params, this);
103  if (is_leaf && !is_action_params)
104  _children[item]->insertParams(action, is_action_params, params);
105  node_created = true;
106  }
107 
108  if (!is_leaf)
109  _children[item]->insertNode(syntax, action, is_action_params, params);
110  else if (!node_created)
111  _children[item]->insertParams(action, is_action_params, params);
112 }
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:71
std::map< std::string, std::unique_ptr< TreeNode > > _children
Definition: SyntaxTree.h:66

◆ insertParams()

void SyntaxTree::TreeNode::insertParams ( const std::string &  action,
bool  is_action_params,
InputParameters params = NULL 
)
protected

Definition at line 115 of file SyntaxTree.C.

118 {
119  if (is_action_params)
120  _action_params.emplace(action, std::make_unique<InputParameters>(*params));
121  else
122  _moose_object_params.emplace(action, std::make_unique<InputParameters>(*params));
123 }
std::multimap< std::string, std::unique_ptr< InputParameters > > _moose_object_params
Definition: SyntaxTree.h:68
std::multimap< std::string, std::unique_ptr< InputParameters > > _action_params
Definition: SyntaxTree.h:67

◆ print()

std::string SyntaxTree::TreeNode::print ( short  depth,
const std::string &  search_string,
bool &  found 
)

Definition at line 126 of file SyntaxTree.C.

127 {
128  std::string doc = "";
129  std::string long_name(getLongName());
130  std::string name(_syntax_tree.isLongNames() ? long_name : _name);
131  std::string out;
132 
133  if (depth < 0)
134  {
135  for (const auto & c_it : _children)
136  {
137  bool local_found = false;
138  std::string local_out(c_it.second->print(depth + 1, search_string, local_found));
139  found |= local_found; // Update the current frame's found variable
140  if (local_found)
141  out += local_out;
142  }
143  return out;
144  }
145 
146  // GlobalParamsAction is special - we need to just always print it out
147  // if (_name == "GlobalParamsAction")
148  // found = true;
149 
150  std::string indent((depth + 1) * 2, ' ');
151 
152  std::multimap<std::string, std::unique_ptr<InputParameters>>::const_iterator it =
153  _moose_object_params.begin();
154  do
155  {
156  bool local_found = false;
157  std::string local_out;
158 
159  // Compare the block name, if it's matched we are going to pass an empty search string
160  // which means match ALL parameters
161  std::string local_search_string;
162  if (MooseUtils::wildCardMatch(name, search_string))
163  found = true;
164  else
165  local_search_string = search_string;
166 
167  if (it != _moose_object_params.end())
168  doc = it->second->getClassDescription();
169  local_out += _syntax_tree.printBlockOpen(name, depth, doc);
170 
171  for (const auto & a_it : _action_params)
172  if (a_it.first != "EmptyAction")
173  {
174  local_out += _syntax_tree.printParams(
175  name, long_name, *(a_it.second), depth, local_search_string, local_found);
176  found |= local_found; // Update the current frame's found variable
177  // DEBUG
178  // Moose::out << "\n" << indent << "(" << ait->first << ")";
179  // DEBUG
180  }
181 
182  if (it != _moose_object_params.end())
183  {
184  local_out += _syntax_tree.printParams(
185  name, long_name, *it->second, depth, local_search_string, local_found);
186  found |= local_found;
187  // DEBUG
188  // Moose::out << "\n" << indent << "{" << it->first << "}";
189  // DEBUG
190  }
191 
192  local_out += _syntax_tree.preTraverse(depth);
193 
194  for (const auto & c_it : _children)
195  {
196  bool child_found = false;
197  std::string child_out(c_it.second->print(depth + 1, local_search_string, child_found));
198  found |= child_found; // Update the current frame's found variable
199 
200  if (child_found)
201  local_out += child_out;
202  }
203 
204  local_out += _syntax_tree.printBlockClose(name, depth);
205 
206  if (found)
207  out += local_out;
208 
209  // If there are no moose object params then we have to be careful about how we
210  // increment the iterator. We only want to increment if we aren't already
211  // at the end.
212  } while (it != _moose_object_params.end() && ++it != _moose_object_params.end());
213 
214  return out;
215 }
std::string name(const ElemQuality q)
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:31
std::string getLongName(const std::string &delim="/") const
Definition: SyntaxTree.C:218
virtual std::string printBlockOpen(const std::string &name, short depth, const std::string &doc)=0
This method is called at the beginning of each Node in the tree.
std::string _name
Definition: SyntaxTree.h:69
virtual std::string printParams(const std::string &prefix, const std::string &fully_qualified_name, InputParameters &params, short depth, const std::string &search_string, bool &found)=0
This function is called for each InputParameters object stored at a particular node.
virtual std::string preTraverse(short) const
This method is called once at each node in the syntax tree before traversing child nodes...
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:71
std::multimap< std::string, std::unique_ptr< InputParameters > > _moose_object_params
Definition: SyntaxTree.h:68
virtual std::string printBlockClose(const std::string &name, short depth) const =0
This method is called at the end of of each Node in the tree.
std::map< std::string, std::unique_ptr< TreeNode > > _children
Definition: SyntaxTree.h:66
std::multimap< std::string, std::unique_ptr< InputParameters > > _action_params
Definition: SyntaxTree.h:67
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:874
OStreamProxy out
bool isLongNames() const
Definition: SyntaxTree.C:227

Member Data Documentation

◆ _action_params

std::multimap<std::string, std::unique_ptr<InputParameters> > SyntaxTree::TreeNode::_action_params
protected

Definition at line 67 of file SyntaxTree.h.

Referenced by TreeNode().

◆ _children

std::map<std::string, std::unique_ptr<TreeNode> > SyntaxTree::TreeNode::_children
protected

Definition at line 66 of file SyntaxTree.h.

◆ _moose_object_params

std::multimap<std::string, std::unique_ptr<InputParameters> > SyntaxTree::TreeNode::_moose_object_params
protected

Definition at line 68 of file SyntaxTree.h.

◆ _name

std::string SyntaxTree::TreeNode::_name
protected

Definition at line 69 of file SyntaxTree.h.

◆ _parent

TreeNode* SyntaxTree::TreeNode::_parent
protected

Definition at line 70 of file SyntaxTree.h.

◆ _syntax_tree

SyntaxTree& SyntaxTree::TreeNode::_syntax_tree
protected

Definition at line 71 of file SyntaxTree.h.


The documentation for this class was generated from the following files: