www.mooseframework.org
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SyntaxTree Class Referenceabstract

#include <SyntaxTree.h>

Inheritance diagram for SyntaxTree:
[legend]

Classes

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

Public Member Functions

 SyntaxTree (bool use_long_names=false)
 
virtual ~SyntaxTree ()
 
void insertNode (std::string syntax, const std::string &action, bool is_action_params=true, InputParameters *params=NULL)
 
std::string print (const std::string &search_string)
 
void seenIt (const std::string &prefix, const std::string &item)
 
bool haveSeenIt (const std::string &prefix, const std::string &item) const
 
virtual std::string preamble () const
 This method is called once at the beginning of the tree traversal and can be used to build up header information. More...
 
virtual std::string postscript () const
 This method is called once at the end of the tree traversal and can be used to add any necessary trailing information to the final formatted string. More...
 
virtual std::string preTraverse (short) const
 This method is called once at each node in the syntax tree before traversing child nodes. More...
 
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. More...
 
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. More...
 
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. More...
 

Protected Member Functions

bool isLongNames () const
 

Protected Attributes

std::unique_ptr< TreeNode_root
 
bool _use_long_names
 

Private Attributes

std::set< std::string > _params_printed
 

Detailed Description

Definition at line 23 of file SyntaxTree.h.

Constructor & Destructor Documentation

◆ SyntaxTree()

SyntaxTree::SyntaxTree ( bool  use_long_names = false)

Definition at line 19 of file SyntaxTree.C.

20  : SyntaxFormatterInterface(), _use_long_names(use_long_names)
21 {
22 }
bool _use_long_names
Definition: SyntaxTree.h:77

◆ ~SyntaxTree()

SyntaxTree::~SyntaxTree ( )
virtualdefault

Member Function Documentation

◆ haveSeenIt()

bool SyntaxTree::haveSeenIt ( const std::string &  prefix,
const std::string &  item 
) const

Definition at line 63 of file SyntaxTree.C.

Referenced by InputFileFormatter::printParams(), and YAMLFormatter::printParams().

64 {
65  return _params_printed.find(prefix + item) != _params_printed.end();
66 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:80

◆ insertNode()

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

Definition at line 27 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

31 {
32  if (!_root)
33  _root = std::make_unique<TreeNode>("", *this);
34 
35  _root->insertNode(syntax, action, is_action_params, params);
36 }
std::unique_ptr< TreeNode > _root
Definition: SyntaxTree.h:76

◆ isLongNames()

bool SyntaxTree::isLongNames ( ) const
protected

Definition at line 227 of file SyntaxTree.C.

228 {
229  return _use_long_names;
230 }
bool _use_long_names
Definition: SyntaxTree.h:77

◆ postscript()

virtual std::string SyntaxFormatterInterface::postscript ( ) const
inlinevirtualinherited

This method is called once at the end of the tree traversal and can be used to add any necessary trailing information to the final formatted string.

Returns
- The formatted postscript string

Reimplemented in YAMLFormatter.

Definition at line 41 of file SyntaxFormatterInterface.h.

Referenced by print().

41 { return std::string(); }

◆ preamble()

virtual std::string SyntaxFormatterInterface::preamble ( ) const
inlinevirtualinherited

This method is called once at the beginning of the tree traversal and can be used to build up header information.

Returns
- The formatted preamble string

Reimplemented in YAMLFormatter.

Definition at line 33 of file SyntaxFormatterInterface.h.

Referenced by print().

33 { return std::string(); }

◆ preTraverse()

virtual std::string SyntaxFormatterInterface::preTraverse ( short  ) const
inlinevirtualinherited

This method is called once at each node in the syntax tree before traversing child nodes.

Returns
- The formatted pre-node traversal string

Reimplemented in YAMLFormatter.

Definition at line 47 of file SyntaxFormatterInterface.h.

47 { return std::string(); }

◆ print()

std::string SyntaxTree::print ( const std::string &  search_string)

Definition at line 39 of file SyntaxTree.C.

Referenced by ActionWarehouse::printInputFile().

40 {
41  bool found = false;
42  std::string output;
43 
44  // Clear the list of "seen" parameters before printing the tree
45  _params_printed.clear();
46 
47  if (_root)
48  output = _root->print(-1, search_string, found);
49 
50  if (found)
51  return preamble() + output + postscript();
52  else
53  return "";
54 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:80
virtual std::string preamble() const
This method is called once at the beginning of the tree traversal and can be used to build up header ...
std::unique_ptr< TreeNode > _root
Definition: SyntaxTree.h:76
virtual std::string postscript() const
This method is called once at the end of the tree traversal and can be used to add any necessary trai...

◆ printBlockClose()

virtual std::string SyntaxFormatterInterface::printBlockClose ( const std::string &  name,
short  depth 
) const
pure virtualinherited

This method is called at the end of of each Node in the tree.

It is typically used to provide formatting necessary when closing blocks.

Returns
- The formatted block close string

Implemented in YAMLFormatter, and InputFileFormatter.

◆ printBlockOpen()

virtual std::string SyntaxFormatterInterface::printBlockOpen ( const std::string &  name,
short  depth,
const std::string &  doc 
)
pure virtualinherited

This method is called at the beginning of each Node in the tree.

It is typically used to provide formatting necessary when opening new blocks.

Returns
- The formatted block open string

Implemented in YAMLFormatter, and InputFileFormatter.

◆ printParams()

virtual std::string SyntaxFormatterInterface::printParams ( const std::string &  prefix,
const std::string &  fully_qualified_name,
InputParameters params,
short  depth,
const std::string &  search_string,
bool &  found 
)
pure virtualinherited

This function is called for each InputParameters object stored at a particular node.

It is responsible for formatting the parameters for the current node.

Returns
- The formatted parameters string for a Node.

Implemented in YAMLFormatter, and InputFileFormatter.

◆ seenIt()

void SyntaxTree::seenIt ( const std::string &  prefix,
const std::string &  item 
)

Definition at line 57 of file SyntaxTree.C.

Referenced by InputFileFormatter::printParams(), and YAMLFormatter::printParams().

58 {
59  _params_printed.insert(prefix + item);
60 }
std::set< std::string > _params_printed
Definition: SyntaxTree.h:80

Member Data Documentation

◆ _params_printed

std::set<std::string> SyntaxTree::_params_printed
private

Definition at line 80 of file SyntaxTree.h.

Referenced by haveSeenIt(), print(), and seenIt().

◆ _root

std::unique_ptr<TreeNode> SyntaxTree::_root
protected

Definition at line 76 of file SyntaxTree.h.

Referenced by insertNode(), and print().

◆ _use_long_names

bool SyntaxTree::_use_long_names
protected

Definition at line 77 of file SyntaxTree.h.

Referenced by isLongNames().


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