#pragma once #include #include #include #include #include "../../core/Defines.h" #include "Node.h" class BaseTree { public: BaseTree(); virtual ~BaseTree(); virtual const Node* GetNode(const unsigned32 index) const = 0; virtual Node* GetNode(const unsigned32 index) = 0; virtual unsigned32 GetNodeCount() const = 0; virtual unsigned8 GetMaxLevel() const = 0; virtual bool IsEmpty() const = 0; virtual void Clear() = 0; virtual Node* Create(unsigned8 level) = 0; // Destroy the node at the given index. Note that this is not required to fix references to this node, so it is quite unsafe to call! // This is only to save memory when, for example, moving nodes from one tree to the other virtual void Destroy(unsigned32 index) = 0; // Algorithms that can be done on any tree: virtual void Shave(unsigned8 depth) = 0; virtual std::vector SortOnLevel() = 0; // General information about the tree virtual std::vector GetParentCounts() const = 0; virtual std::vector GetNodesPerLevel() const = 0; virtual std::vector GetOctreeNodesPerLevel() const = 0; virtual unsigned64 GetPointerCount() const = 0; virtual void PrintDebugInfo() const = 0; // Reading and writing to/from files virtual bool ReadTree(const char* fileName) = 0; virtual bool WriteTree(const char* fileName) = 0; virtual bool VerifyTree(const char* fileName) = 0; virtual bool ReadAdditionalPool(const char* fileName) = 0; virtual bool WriteAdditionalPool(const char* fileName) = 0; // Pool building information virtual unsigned8 GetAdditionalTreeInfoSize() const = 0; virtual std::vector GetAdditionalTreeInfo(const std::vector& nodePointers) const = 0; virtual unsigned8 GetAdditionalBytesPerNode(unsigned8 level) const = 0; virtual std::vector GetAdditionalNodeBytes(const Node* node) const = 0; virtual bool LastChildHasAdditionalBytes() const = 0; virtual unsigned8 GetAdditionalBytesPerPointer(unsigned8 level) const = 0; virtual std::vector GetAdditionalPointerBytes(const Node* node, ChildIndex child) const = 0; // Returns the number of bytes per pointer for each level as a vector std::vector GetAdditionalBytesPerPointer() const; // Returns the number of bytes per node for each level as a vector. std::vector GetAdditionalBytesPerNode() const; inline unsigned16 GetTreeIndex() const { return mTreeIndex; } inline static BaseTree* Get(unsigned16 rootIndex) { return mTreePool[rootIndex]; } private: unsigned16 AssignRootIndex(); static std::vector mTreePool; unsigned16 mTreeIndex; };