#ifndef BINARYTREEVEC_HPP #define BINARYTREEVEC_HPP /* ************************************************************************** */ #include "../binarytree.hpp" #include "../../vector/vector.hpp" /* ************************************************************************** */ namespace lasd { /* ************************************************************************** */ template class BinaryTreeVec : virtual public BinaryTree{ // Must extend BinaryTree private: protected: using BinaryTree::size; // using BinaryTree::Node; struct NodeVec : virtual protected BinaryTree::Node { // Must extend Node private: protected: using BinaryTree::Node::data; ulong index; BinaryTreeVec* ReferenceToTree = nullptr; public: NodeVec(Data&, ulong, BinaryTreeVec*); struct NodeVec& operator=(const NodeVec&); // Copy assignment of abstract types should not be possible. struct NodeVec& operator=(NodeVec&&) noexcept; // Move assignment of abstract types should not be possible. bool IsLeaf() const noexcept override; // (concrete function should not throw exceptions) bool HasLeftChild() const noexcept override; // (concrete function should not throw exceptions) bool HasRightChild() const noexcept override; // (concrete function should not throw exceptions) struct BinaryTree::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) struct BinaryTree::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) friend class BinaryTreeVec; }; protected: Vector::NodeVec*> tree; public: // Default constructor BinaryTreeVec() = default; /* ************************************************************************ */ // Specific constructors BinaryTreeVec(const LinearContainer&); // A binary tree obtained from a LinearContainer /* ************************************************************************ */ // Copy constructor BinaryTreeVec(const BinaryTreeVec&); // Move constructor BinaryTreeVec(BinaryTreeVec&&) noexcept; /* ************************************************************************ */ // Destructor virtual ~BinaryTreeVec(); /* ************************************************************************ */ // Copy assignment BinaryTreeVec& operator=(const BinaryTreeVec&); // Move assignment BinaryTreeVec& operator=(BinaryTreeVec&&) noexcept; /* ************************************************************************ */ // Comparison operators bool operator==(const BinaryTreeVec&) const noexcept; bool operator!=(const BinaryTreeVec&) const noexcept; /* ************************************************************************ */ // Specific member functions (inherited from BinaryTree) struct BinaryTree::Node& Root() const override; // Override BinaryTree member (throw std::length_error when empty) /* ************************************************************************ */ // Specific member functions (inherited from Container) void Clear() override; // Override Container member /* ----- override of map and fold in breadth ----- */ using typename BinaryTree::MapFunctor; using typename BinaryTree::FoldFunctor; void MapBreadth(const MapFunctor, void*) override; void FoldBreadth(const FoldFunctor, const void*, void*) const override; }; /* ************************************************************************** */ } #include "binarytreevec.cpp" #endif