#include #pragma once #include "misc/advanced_mutex.h" #include #include #include #include "misc/memtracker.h" #ifndef __attribute_deprecated__ #define __attribute_deprecated__ [[deprecated]] #endif namespace ts { class TreeEntry; class TreeView { public: struct LinkedTreeEntry { std::shared_ptr previous; std::shared_ptr next; std::shared_ptr child_head; std::weak_ptr parent; const std::shared_ptr entry; explicit LinkedTreeEntry(std::shared_ptr entry) : entry(std::move(entry)) { memtrack::allocated(this); } virtual ~LinkedTreeEntry() { memtrack::freed(this); } }; public: TreeView(); virtual ~TreeView(); size_t entry_count() const; std::deque> entries(const std::shared_ptr& /* head */ = nullptr, int /* deep */ = -1) const; std::deque> entries_sub(const std::shared_ptr& /* parent */ = nullptr, int /* deep */ = -1) const; std::shared_ptr find_entry(ChannelId /* channel id */) const; std::shared_ptr find_linked_entry(ChannelId /* channel id */, const std::shared_ptr& /* head */ = nullptr, int deep = -1) const; bool has_entry(const std::shared_ptr& /* entry */, const std::shared_ptr& /* head */ = nullptr, int deep = -1) const; bool insert_entry(const std::shared_ptr& entry, const std::shared_ptr& /* parent */ = nullptr, const std::shared_ptr& /* previous */ = nullptr); bool move_entry(const std::shared_ptr& /* entry */, const std::shared_ptr& /* parent */ = nullptr, const std::shared_ptr& /* previous */ = nullptr); std::deque> delete_entry(std::shared_ptr /* entry */); //Copy that here because of reference could be changed (linked->entry) void print_tree(const std::function& /* entry */, int /* deep */)>&) const; protected: std::shared_ptr head; private: inline std::shared_ptr linked(const std::shared_ptr& /* entry */) const; inline std::deque> query_deep(const std::shared_ptr& /* layer */ = nullptr,int /* max deep */ = -1) const; inline void query_deep_(std::deque>& /* result */, const std::shared_ptr& /* layer */ = nullptr,int /* max deep */ = -1) const; inline std::deque> query_deep_entry(const std::shared_ptr& /* layer */ = nullptr,int /* max deep */ = -1) const; inline bool has_entry_(const std::shared_ptr& /* entry */, const std::shared_ptr& /* head */ = nullptr, int deep = -1) const; void print_tree_(const std::function& /* entry */, int /* deep */)>&, std::shared_ptr /* head */, int /* deep */) const; inline void cut_entry(const std::shared_ptr&); }; class TreeEntry { public: virtual ChannelId channelId() const = 0; virtual ChannelId previousChannelId() const = 0; virtual void setPreviousChannelId(ChannelId) = 0; virtual void setParentChannelId(ChannelId) = 0; virtual void setLinkedHandle(const std::weak_ptr& /* self */) {} }; }