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, TreeNode * > _children
 
std::multimap< std::string, InputParameters * > _action_params
 
std::multimap< std::string, 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 42 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.insert(std::make_pair(*action, new InputParameters(*params)));
77 }
TreeNode * _parent
Definition: SyntaxTree.h:69
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _name
Definition: SyntaxTree.h:68
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:70
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:66

◆ ~TreeNode()

SyntaxTree::TreeNode::~TreeNode ( )

Definition at line 79 of file SyntaxTree.C.

80 {
81  for (const auto & it : _action_params)
82  delete it.second;
83 
84  for (const auto & it : _moose_object_params)
85  delete it.second;
86 
87  for (const auto & it : _children)
88  delete it.second;
89 }
std::map< std::string, TreeNode * > _children
Definition: SyntaxTree.h:65
std::multimap< std::string, InputParameters * > _moose_object_params
Definition: SyntaxTree.h:67
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:66

Member Function Documentation

◆ getLongName()

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

Definition at line 227 of file SyntaxTree.C.

228 {
229  if (_parent)
230  return _parent->getLongName(delim) + delim + _name;
231  else
232  return _name;
233 }
TreeNode * _parent
Definition: SyntaxTree.h:69
std::string getLongName(const std::string &delim="/") const
Definition: SyntaxTree.C:227
std::string _name
Definition: SyntaxTree.h:68

◆ insertNode()

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

Definition at line 92 of file SyntaxTree.C.

Referenced by SyntaxTree::insertNode().

96 {
97  std::string::size_type pos = syntax.find_first_of("/");
98  std::string item;
99  bool is_leaf = true;
100 
101  item = syntax.substr(0, pos);
102  if (pos != std::string::npos)
103  {
104  syntax = syntax.substr(pos + 1);
105  is_leaf = false;
106  }
107 
108  bool node_created = false;
109  if (_children.find(item) == _children.end())
110  {
111  _children[item] = new TreeNode(
112  item, _syntax_tree, is_leaf && is_action_params ? &action : NULL, params, this);
113  if (is_leaf && !is_action_params)
114  _children[item]->insertParams(action, is_action_params, params);
115  node_created = true;
116  }
117 
118  if (!is_leaf)
119  _children[item]->insertNode(syntax, action, is_action_params, params);
120  else if (!node_created)
121  _children[item]->insertParams(action, is_action_params, params);
122 }
std::map< std::string, TreeNode * > _children
Definition: SyntaxTree.h:65
TreeNode(const std::string &name, SyntaxTree &syntax_tree, const std::string *action=NULL, InputParameters *params=NULL, TreeNode *parent=NULL)
Definition: SyntaxTree.C:68
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:70

◆ insertParams()

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

Definition at line 125 of file SyntaxTree.C.

128 {
129  if (is_action_params)
130  _action_params.insert(std::make_pair(action, new InputParameters(*params)));
131  else
132  _moose_object_params.insert(std::make_pair(action, new InputParameters(*params)));
133 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::multimap< std::string, InputParameters * > _moose_object_params
Definition: SyntaxTree.h:67
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:66

◆ print()

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

Definition at line 136 of file SyntaxTree.C.

Referenced by SyntaxTree::print().

137 {
138  std::string doc = "";
139  std::string long_name(getLongName());
140  std::string name(_syntax_tree.isLongNames() ? long_name : _name);
141  std::string out;
142 
143  if (depth < 0)
144  {
145  for (const auto & c_it : _children)
146  {
147  bool local_found = false;
148  std::string local_out(c_it.second->print(depth + 1, search_string, local_found));
149  found |= local_found; // Update the current frame's found variable
150  if (local_found)
151  out += local_out;
152  }
153  return out;
154  }
155 
156  // GlobalParamsAction is special - we need to just always print it out
157  // if (_name == "GlobalParamsAction")
158  // found = true;
159 
160  std::string indent((depth + 1) * 2, ' ');
161 
162  std::multimap<std::string, InputParameters *>::const_iterator it = _moose_object_params.begin();
163  do
164  {
165  bool local_found = false;
166  std::string local_out;
167 
168  // Compare the block name, if it's matched we are going to pass an empty search string
169  // which means match ALL parameters
170  std::string local_search_string;
171  if (MooseUtils::wildCardMatch(name, search_string))
172  found = true;
173  else
174  local_search_string = search_string;
175 
176  if (it != _moose_object_params.end())
177  doc = it->second->getClassDescription();
178  local_out += _syntax_tree.printBlockOpen(name, depth, doc);
179 
180  for (const auto & a_it : _action_params)
181  if (a_it.first != "EmptyAction")
182  {
183  local_out += _syntax_tree.printParams(
184  name, long_name, *(a_it.second), depth, local_search_string, local_found);
185  found |= local_found; // Update the current frame's found variable
186  // DEBUG
187  // Moose::out << "\n" << indent << "(" << ait->first << ")";
188  // DEBUG
189  }
190 
191  if (it != _moose_object_params.end())
192  {
193  local_out += _syntax_tree.printParams(
194  name, long_name, *it->second, depth, local_search_string, local_found);
195  found |= local_found;
196  // DEBUG
197  // Moose::out << "\n" << indent << "{" << it->first << "}";
198  // DEBUG
199  }
200 
201  local_out += _syntax_tree.preTraverse(depth);
202 
203  for (const auto & c_it : _children)
204  {
205  bool child_found = false;
206  std::string child_out(c_it.second->print(depth + 1, local_search_string, child_found));
207  found |= child_found; // Update the current frame's found variable
208 
209  if (child_found)
210  local_out += child_out;
211  }
212 
213  local_out += _syntax_tree.printBlockClose(name, depth);
214 
215  if (found)
216  out += local_out;
217 
218  // If there are no moose object params then we have to be careful about how we
219  // increment the iterator. We only want to increment if we aren't already
220  // at the end.
221  } while (it != _moose_object_params.end() && ++it != _moose_object_params.end());
222 
223  return out;
224 }
std::string indent(unsigned int spaces)
Create empty string for indenting.
Definition: ConsoleUtils.C:29
std::string getLongName(const std::string &delim="/") const
Definition: SyntaxTree.C:227
std::map< std::string, TreeNode * > _children
Definition: SyntaxTree.h:65
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:68
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:70
std::multimap< std::string, InputParameters * > _moose_object_params
Definition: SyntaxTree.h:67
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:66
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.
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:569
bool isLongNames() const
Definition: SyntaxTree.C:236

Member Data Documentation

◆ _action_params

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

Definition at line 66 of file SyntaxTree.h.

Referenced by TreeNode().

◆ _children

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

Definition at line 65 of file SyntaxTree.h.

◆ _moose_object_params

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

Definition at line 67 of file SyntaxTree.h.

◆ _name

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

Definition at line 68 of file SyntaxTree.h.

◆ _parent

TreeNode* SyntaxTree::TreeNode::_parent
protected

Definition at line 69 of file SyntaxTree.h.

◆ _syntax_tree

SyntaxTree& SyntaxTree::TreeNode::_syntax_tree
protected

Definition at line 70 of file SyntaxTree.h.


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