9 #ifndef __DIADES__UTILS__NARYTREE__HH__ 10 #define __DIADES__UTILS__NARYTREE__HH__ 34 template<
typename Node,
typename Leaf,
template<
typename,
typename>
class _Map>
50 virtual bool isLeaf()
const = 0;
59 template<
typename NodeIterator>
71 result =
static_cast<const TreeLeaf *
> (
this)->leaf();
88 auto branches =
static_cast<const TreeBranches *
> (
this);
89 auto branchIt = branches->
find(*begin);
90 if(branchIt == branches->end())
96 return branchIt->second->getLeaf(++begin, end, result);
167 using Map = _Map<Node, std::unique_ptr<TreeElement> >;
193 return _branches.begin();
203 return _branches.end();
214 return _branches.find(node);
228 template<
typename NodeIterator>
237 auto result = _branches.emplace(*begin, std::make_unique<TreeLeaf>(info));
239 return static_cast<TreeLeaf *
> (result.first->second.get())->leaf();
241 auto branchIt = _branches.find(*begin);
242 if(branchIt == _branches.end())
245 auto result = _branches.emplace(*begin, std::make_unique<TreeBranches>());
302 template<
typename NodeIterator>
309 _firstBranches = std::make_unique<TreeBranches>();
312 return _firstBranches->insertSuccessiveBranches(begin, end, info);
322 template<
typename NodeIterator>
330 return _firstBranches->getLeaf(begin, end, result);
341 _firstBranches.reset(
nullptr);
typename Map::const_iterator ConstIterator
TreeLeaf(const Leaf &leaf)
Leaf & insertSuccessiveBranches(NodeIterator begin, NodeIterator end, const Leaf &info)
std::unique_ptr< TreeBranches > _firstBranches
_Map< Node, std::unique_ptr< TreeElement > > Map
virtual bool isLeaf() const
virtual bool isLeaf() const =0
ConstIterator find(const Node &node) const
bool getLeaf(NodeIterator begin, NodeIterator end, Leaf &result) const
NAryTree & operator=(NAryTree const &other)=default
NAryTree()=default
Default constructor.
const Leaf & leaf() const
GraphIterator< Node > NodeIterator
bool getLeaf(NodeIterator begin, NodeIterator end, Leaf &result)
Namespace of the Diades project.
ConstIterator end() const
virtual bool isLeaf() const
~NAryTree()=default
Destructor.
Leaf & insertSuccessiveBranches(NodeIterator begin, NodeIterator end, const Leaf &info)
ConstIterator begin() const