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 47 of file SyntaxTree.h.

Constructor & Destructor Documentation

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

Definition at line 73 of file SyntaxTree.C.

Referenced by insertNode().

78  : _name(name), _parent(parent), _syntax_tree(syntax_tree)
79 {
80  if (action)
81  _action_params.insert(std::make_pair(*action, new InputParameters(*params)));
82 }
TreeNode * _parent
Definition: SyntaxTree.h:74
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::string _name
Definition: SyntaxTree.h:73
SyntaxTree & _syntax_tree
Definition: SyntaxTree.h:75
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:71
SyntaxTree::TreeNode::~TreeNode ( )

Definition at line 84 of file SyntaxTree.C.

85 {
86  for (const auto & it : _action_params)
87  delete it.second;
88 
89  for (const auto & it : _moose_object_params)
90  delete it.second;
91 
92  for (const auto & it : _children)
93  delete it.second;
94 }
std::map< std::string, TreeNode * > _children
Definition: SyntaxTree.h:70
std::multimap< std::string, InputParameters * > _moose_object_params
Definition: SyntaxTree.h:72
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:71

Member Function Documentation

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

Definition at line 232 of file SyntaxTree.C.

Referenced by getLongName(), and print().

233 {
234  if (_parent)
235  return _parent->getLongName(delim) + delim + _name;
236  else
237  return _name;
238 }
TreeNode * _parent
Definition: SyntaxTree.h:74
std::string _name
Definition: SyntaxTree.h:73
std::string getLongName(const std::string &delim="/") const
Definition: SyntaxTree.C:232
void SyntaxTree::TreeNode::insertNode ( std::string &  syntax,
const std::string &  action,
bool  is_action_params = true,
InputParameters params = NULL 
)

Definition at line 97 of file SyntaxTree.C.

Referenced by SyntaxTree::insertNode().

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

Definition at line 130 of file SyntaxTree.C.

133 {
134  if (is_action_params)
135  _action_params.insert(std::make_pair(action, new InputParameters(*params)));
136  else
137  _moose_object_params.insert(std::make_pair(action, new InputParameters(*params)));
138 }
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:72
std::multimap< std::string, InputParameters * > _action_params
Definition: SyntaxTree.h:71
std::string SyntaxTree::TreeNode::print ( short  depth,
const std::string &  search_string,
bool &  found 
)

Definition at line 141 of file SyntaxTree.C.

Referenced by SyntaxTree::print().

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

Member Data Documentation

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

Definition at line 71 of file SyntaxTree.h.

Referenced by insertParams(), print(), TreeNode(), and ~TreeNode().

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

Definition at line 70 of file SyntaxTree.h.

Referenced by insertNode(), print(), and ~TreeNode().

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

Definition at line 72 of file SyntaxTree.h.

Referenced by insertParams(), print(), and ~TreeNode().

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

Definition at line 73 of file SyntaxTree.h.

Referenced by getLongName(), and print().

TreeNode* SyntaxTree::TreeNode::_parent
protected

Definition at line 74 of file SyntaxTree.h.

Referenced by getLongName().

SyntaxTree& SyntaxTree::TreeNode::_syntax_tree
protected

Definition at line 75 of file SyntaxTree.h.

Referenced by insertNode(), and print().


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