taco-db  0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TreeNode.h
Go to the documentation of this file.
1 #ifndef UTILS_TREE_NODE_H
2 #define UTILS_TREE_NODE_H
3 
4 #include "tdb.h"
5 
6 #include "utils/misc.h"
7 #include "utils/tree/NodeTag.h"
8 
9 namespace taco {
10 
45 class TreeNode {
46 public:
47 
48  template<class ...UniquePtrs>
49  TreeNode(NodeTag tag, UniquePtrs&& ...input):
50  m_tag(tag),
51  m_input() {
52  m_input.reserve(sizeof...(UniquePtrs));
54  std::forward<UniquePtrs>(input)...);
55  }
56 
57  virtual ~TreeNode() {}
58 
59  TreeNode(TreeNode&&) = default;
60  TreeNode &operator=(TreeNode&&) = default;
61  TreeNode(const TreeNode&) = delete;
62  TreeNode &operator=(const TreeNode &) = delete;
63 
64  constexpr NodeTag
65  get_tag() const {
66  return m_tag;
67  }
68 
69  TreeNode *
70  get_input(size_t i) const {
71  if (i < m_input.size())
72  return m_input[i].get();
73  return nullptr;
74  }
75 
76  template<class Node>
77  Node *
78  get_input_as(size_t i) const {
79  if (i < m_input.size())
80  return static_cast<Node*>(m_input[i].get());
81  return nullptr;
82  }
83 
84  std::string
85  to_string() const {
86  std::string buf;
87  node_to_string(buf, 0);
88  return buf;
89  }
90 
96  void node_to_string(std::string &buf, int indent) const;
97 
98  const char *node_name() const {
99  return node_tag_name(get_tag());
100  }
101 
102  virtual void node_properties_to_string(std::string &buf,
103  int indent) const = 0;
104 
105  static void append_indent(std::string &buf, int indent);
106 private:
107  const NodeTag m_tag;
108 
109  std::vector<std::unique_ptr<TreeNode>> m_input;
110 
111 
112  static constexpr const int TO_STRING_INDENT_SIZE = 4;
113 };
114 
115 } // namespace taco
116 
117 #endif // UTILS_TREE_NODE_H
taco::TreeNode
TreeNode is the base class of all tree structures in TDB (e.g., parsing tree, logical plan,...
Definition: TreeNode.h:45
taco::TreeNode::~TreeNode
virtual ~TreeNode()
Definition: TreeNode.h:57
taco::TreeNode::TreeNode
TreeNode(NodeTag tag, UniquePtrs &&...input)
Definition: TreeNode.h:49
NodeTag.h
taco
Definition: datum.h:28
taco::node_tag_name
const char * node_tag_name(NodeTag tag)
Returns the class name of the tag's class.
Definition: NodeTag.cpp:78
taco::TreeNode::node_to_string
void node_to_string(std::string &buf, int indent) const
Prints the node contents to a string buffer.
Definition: TreeNode.cpp:10
misc.h
tdb.h
taco::TreeNode::node_name
const char * node_name() const
Definition: TreeNode.h:98
taco::TreeNode::get_input_as
Node * get_input_as(size_t i) const
Definition: TreeNode.h:78
taco::TreeNode::get_tag
constexpr NodeTag get_tag() const
Definition: TreeNode.h:65
taco::TreeNode::get_input
TreeNode * get_input(size_t i) const
Definition: TreeNode.h:70
taco::TreeNode::m_tag
const NodeTag m_tag
Definition: TreeNode.h:107
taco::TreeNode::to_string
std::string to_string() const
Definition: TreeNode.h:85
taco::TreeNode::node_properties_to_string
virtual void node_properties_to_string(std::string &buf, int indent) const =0
taco::TreeNode::operator=
TreeNode & operator=(TreeNode &&)=default
taco::TreeNode::m_input
std::vector< std::unique_ptr< TreeNode > > m_input
Definition: TreeNode.h:109
taco::TreeNode::append_indent
static void append_indent(std::string &buf, int indent)
Definition: TreeNode.cpp:25
taco::emplace_back_parameter_pack
void emplace_back_parameter_pack(Container &c, Arg0 &&arg0, Args &&...args)
Definition: misc.h:99
taco::NodeTag
NodeTag
Definition: NodeTag.h:12
taco::TreeNode::TO_STRING_INDENT_SIZE
static constexpr const int TO_STRING_INDENT_SIZE
Definition: TreeNode.h:112