Bridges-C++  3.2.0
Bridges(C++API)
BTElement.h
Go to the documentation of this file.
1 #ifndef BT_ELEMENT_H
2 #define BT_ELEMENT_H
3 
4 #include "TreeElement.h" //string, using std
5 
6 namespace bridges {
7  namespace datastructure {
18  template <typename E>
19  class BTElement : public TreeElement<E> {
20  private:
21  int leftPos = 0, rightPos = 1;
22  public:
34  BTElement(BTElement* l, BTElement* r, const E& e = E(),
35  const string& lab = string()) :
36  TreeElement<E>(e, lab) {
37  this->addChild(l);
38  this->addChild(r);
39  }
49  BTElement(const E& e = E(), const string& lab = string())
50  : BTElement(nullptr, nullptr, e, lab) {}
51 
56  virtual const string getDStype() const override {
57  return "BinaryTree";
58  }
59 
63  virtual BTElement* getLeft() {
64  return static_cast<BTElement*>(this->getChild(leftPos));
65  }
67  virtual const BTElement* getLeft() const {
68  return static_cast<const BTElement*>(this->getChild(leftPos));
69  }
71  void setLeft(BTElement* l) {
72  this->setChild(leftPos, l);
73  }
74 
76  virtual BTElement* getRight() {
77  return static_cast<BTElement*>(this->getChild(rightPos));
78  }
79 
81  virtual const BTElement* getRight() const {
82  return static_cast<const BTElement*>(this->getChild(rightPos));
83  }
85  void setRight(BTElement* r) {
86  this->setChild(rightPos, r);
87  }
88  }; //end of BTElement class
89  }
90 }//end of bridges namespace
91 #endif
virtual const string getDStype() const override
Definition: BTElement.h:56
virtual BTElement * getRight()
Definition: BTElement.h:76
virtual const BTElement * getLeft() const
Definition: BTElement.h:67
void setChild(const size_t &index, TreeElement *kid)
Sets child at index to "kid".
Definition: TreeElement.h:108
This class can be used to create tree elements, derived from Element.
Definition: TreeElement.h:24
void setRight(BTElement *r)
Definition: BTElement.h:85
TreeElement * getChild(const int &n)
Gets the nth child of this node.
Definition: TreeElement.h:73
virtual const BTElement * getRight() const
Definition: BTElement.h:81
virtual BTElement * getLeft()
Definition: BTElement.h:63
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
BTElement(BTElement *l, BTElement *r, const E &e=E(), const string &lab=string())
Constructs a BTElement with the provided value, label, left and right BTElements. ...
Definition: BTElement.h:34
void setLeft(BTElement *l)
Definition: BTElement.h:71
BTElement(const E &e=E(), const string &lab=string())
Constructs a BTElement with the provided value and label, setting the left and right BTElement to nul...
Definition: BTElement.h:49
This class can be used to create binary tree elements, derived from TreeElement.
Definition: BTElement.h:19
void addChild(TreeElement *child)
Adds a child to children.
Definition: TreeElement.h:94