<commit_before>#include <envire_core/graph/TreeView.hpp>

namespace envire { namespace core
{
    using vertex_descriptor = GraphTraits::vertex_descriptor;
    using edge_descriptor = GraphTraits::edge_descriptor;
    
    TreeView& TreeView::operator=(const TreeView& other)
    {
        //this operator has to be here because the default
        //operator= wants to copy treeUpdated, which is is not possible.
        
        //WARNING If you add members to this class, make sure
        //        to copy them!
        publisher = other.publisher;
        tree = other.tree;
        crossEdges = other.crossEdges;
        root = other.root;
        return *this;
    }
    
TreeView::TreeView(TreeView&& other) noexcept : crossEdges(std::move(other.crossEdges)),
                                                root(std::move(other.root)),
                                                tree(std::move(other.tree))
{
    //if the other TreeView was subscribed, unsubscribe it and 
    //subscribe this instead
    if(other.publisher != nullptr)
    {
      other.publisher->unsubscribeTreeView(&other);
      other.publisher->subscribeTreeView(this); //sets this.publisher
      other.publisher = nullptr;
    }
    crossEdgeAdded.swap(other.crossEdgeAdded);
    edgeAdded.swap(other.edgeAdded);
}


TreeView::~TreeView()
{
    if(nullptr != publisher)
    {
        //automatic unsubscribe
        publisher->unsubscribeTreeView(this);
        publisher = nullptr;
    }
}

void TreeView::setPublisher(TreeUpdatePublisher* pub)
{
    assert(publisher == nullptr);
    publisher = pub;
}

bool TreeView::isRoot(const vertex_descriptor vd) const
{
    return vd == root;
}

void TreeView::clear()
{
    tree.clear();
    crossEdges.clear();
}

void TreeView::unsubscribe()
{
    if(publisher != nullptr)
    {
        publisher->unsubscribeTreeView(this);
        publisher = nullptr;
    }
}

bool TreeView::edgeExists(const vertex_descriptor a, const vertex_descriptor b) const
{
    //an edge exists if either a is the parent of b and aChildren contains b
    //or the other way around.
    if(tree.find(a) == tree.end() || tree.find(b) == tree.end())
    {
        return false;
    }
    const VertexRelation& aRelation = tree.at(a);
    const VertexRelation& bRelation = tree.at(b);

    //If we assume that we made no mistake when populating the tree we could just <commit_msg>TreeView: clear(): clear root node aswell<commit_after>#include <envire_core/graph/TreeView.hpp>

namespace envire { namespace core
{
    using vertex_descriptor = GraphTraits::vertex_descriptor;
    using edge_descriptor = GraphTraits::edge_descriptor;
    
    TreeView& TreeView::operator=(const TreeView& other)
    {
        //this operator has to be here because the default
        //operator= wants to copy treeUpdated, which is is not possible.
        
        //WARNING If you add members to this class, make sure
        //        to copy them!
        publisher = other.publisher;
        tree = other.tree;
        crossEdges = other.crossEdges;
        root = other.root;
        return *this;
    }
    
TreeView::TreeView(TreeView&& other) noexcept : crossEdges(std::move(other.crossEdges)),
                                                root(std::move(other.root)),
                                                tree(std::move(other.tree))
{
    //if the other TreeView was subscribed, unsubscribe it and 
    //subscribe this instead
    if(other.publisher != nullptr)
    {
      other.publisher->unsubscribeTreeView(&other);
      other.publisher->subscribeTreeView(this); //sets this.publisher
      other.publisher = nullptr;
    }
    crossEdgeAdded.swap(other.crossEdgeAdded);
    edgeAdded.swap(other.edgeAdded);
}


TreeView::~TreeView()
{
    if(nullptr != publisher)
    {
        //automatic unsubscribe
        publisher->unsubscribeTreeView(this);
        publisher = nullptr;
    }
}

void TreeView::setPublisher(TreeUpdatePublisher* pub)
{
    assert(publisher == nullptr);
    publisher = pub;
}

bool TreeView::isRoot(const vertex_descriptor vd) const
{
    return vd == root;
}

void TreeView::clear()
{
    tree.clear();
    crossEdges.clear();
    root = GraphTraits::null_vertex();
}

void TreeView::unsubscribe()
{
    if(publisher != nullptr)
    {
        publisher->unsubscribeTreeView(this);
        publisher = nullptr;
    }
}

bool TreeView::edgeExists(const vertex_descriptor a, const vertex_descriptor b) const
{
    //an edge exists if either a is the parent of b and aChildren contains b
    //or the other way around.
    if(tree.find(a) == tree.end() || tree.find(b) == tree.end())
    {
        return false;
    }
    const VertexRelation& aRelation = tree.at(a);
    const VertexRelation& bRelation = tree.at(b);

    //If we assume that we made no mistake when populating the tree we could just 
{'fraction_non_alphanumeric': 0.10687022900763359, 'fraction_numerical': 0.0, 'mean_word_length': 2.567328918322296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4589150', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1388, 'n_words': 361}