LCOV - code coverage report
Current view: top level - include/Tools/Algo/Digraph - Digraph_node.hxx (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 52 56 92.9 %
Date: 2024-06-12 12:04:18 Functions: 23 26 88.5 %

          Line data    Source code
       1             : #include <algorithm>
       2             : 
       3             : #include "Tools/Algo/Digraph/Digraph_node.hpp"
       4             : 
       5             : namespace spu
       6             : {
       7             : namespace tools
       8             : {
       9             : 
      10             : template<typename T>
      11       14332 : Digraph_node<T>::Digraph_node(std::vector<Digraph_node<T>*> parents,
      12             :                               std::vector<Digraph_node<T>*> children,
      13             :                               T* content,
      14             :                               const size_t depth)
      15       14332 :   : parents(parents)
      16       14332 :   , children(children)
      17       14332 :   , contents(content)
      18       14332 :   , depth(depth)
      19             : {
      20       14332 : }
      21             : 
      22             : template<typename T>
      23       28664 : Digraph_node<T>::~Digraph_node()
      24             : {
      25       28664 : }
      26             : 
      27             : template<typename T>
      28             : bool
      29             : Digraph_node<T>::is_no_parent() const
      30             : {
      31             :     return !this->parents.size();
      32             : }
      33             : 
      34             : template<typename T>
      35             : bool
      36             : Digraph_node<T>::is_no_child() const
      37             : {
      38             :     return !this->children.size();
      39             : }
      40             : 
      41             : template<typename T>
      42             : bool
      43             : Digraph_node<T>::is_empty() const
      44             : {
      45             :     return (this->contents == nullptr);
      46             : }
      47             : 
      48             : template<typename T>
      49             : const std::vector<Digraph_node<T>*>&
      50        2692 : Digraph_node<T>::get_parents() const
      51             : {
      52        2692 :     return this->parents;
      53             : }
      54             : 
      55             : template<typename T>
      56             : const std::vector<Digraph_node<T>*>&
      57      910687 : Digraph_node<T>::get_children() const
      58             : {
      59      910687 :     return this->children;
      60             : }
      61             : 
      62             : template<typename T>
      63             : T*
      64     1643424 : Digraph_node<T>::get_contents() const
      65             : {
      66     1643424 :     return this->contents;
      67             : }
      68             : 
      69             : template<typename T>
      70             : T*
      71     1507041 : Digraph_node<T>::get_c() const
      72             : {
      73     1507041 :     return this->get_contents();
      74             : }
      75             : 
      76             : template<typename T>
      77             : void
      78       14793 : Digraph_node<T>::set_contents(T* contents)
      79             : {
      80       14793 :     this->contents = contents;
      81       14793 : }
      82             : 
      83             : template<typename T>
      84             : void
      85         738 : Digraph_node<T>::set_depth(const size_t depth)
      86             : {
      87         738 :     this->depth = depth;
      88         738 : }
      89             : 
      90             : template<typename T>
      91             : size_t
      92       10294 : Digraph_node<T>::get_depth() const
      93             : {
      94       10294 :     return this->depth;
      95             : }
      96             : 
      97             : template<typename T>
      98             : int
      99          56 : Digraph_node<T>::get_child_pos(const Digraph_node<T>& parent) const
     100             : {
     101          56 :     const auto parent_it = std::find(this->parents.begin(), this->parents.end(), &parent);
     102          56 :     if (parent_it != this->parents.end())
     103          72 :         for (auto c = 0; c < (int)parent.get_children().size(); c++)
     104          72 :             if (parent.get_children()[c] == this) return c;
     105           0 :     return -1;
     106             : }
     107             : 
     108             : template<typename T>
     109             : int
     110          56 : Digraph_node<T>::get_parent_pos(const Digraph_node<T>& child) const
     111             : {
     112          56 :     const auto child_it = std::find(this->children.begin(), this->children.end(), &child);
     113          56 :     if (child_it != this->children.end())
     114          90 :         for (auto f = 0; f < (int)child.get_parents().size(); f++)
     115          90 :             if (child.get_parents()[f] == this) return f;
     116           0 :     return -1;
     117             : }
     118             : 
     119             : template<typename T>
     120             : bool
     121          56 : Digraph_node<T>::cut_child(const size_t pos)
     122             : {
     123          56 :     if (pos < this->children.size())
     124             :     {
     125          56 :         this->children.erase(this->children.begin() + pos);
     126          56 :         return true;
     127             :     }
     128             :     else
     129           0 :         return false;
     130             : }
     131             : 
     132             : template<typename T>
     133             : bool
     134          56 : Digraph_node<T>::cut_parent(const size_t pos)
     135             : {
     136          56 :     if (pos < this->parents.size())
     137             :     {
     138          56 :         this->parents.erase(this->parents.begin() + pos);
     139          56 :         return true;
     140             :     }
     141             :     else
     142           0 :         return false;
     143             : }
     144             : 
     145             : template<typename T>
     146             : bool
     147             : Digraph_node<T>::cut_children()
     148             : {
     149             :     if (this->children.size())
     150             :     {
     151             :         for (size_t c = 0; c < this->children.size(); c++)
     152             :             delete this->children[c];
     153             :         this->children.clear();
     154             :         return true;
     155             :     }
     156             :     else
     157             :         return false;
     158             : }
     159             : 
     160             : template<typename T>
     161             : void
     162       12144 : Digraph_node<T>::add_child(Digraph_node<T>* child, const int pos)
     163             : {
     164       12144 :     if ((size_t)pos > this->children.size() || pos == -1)
     165       12088 :         this->children.push_back(child);
     166             :     else
     167          56 :         this->children.insert(this->children.begin() + pos, child);
     168       12144 : }
     169             : 
     170             : template<typename T>
     171             : void
     172         140 : Digraph_node<T>::add_parent(Digraph_node<T>* parent, const int pos)
     173             : {
     174         140 :     if ((size_t)pos > this->parents.size() || pos == -1)
     175          84 :         this->parents.push_back(parent);
     176             :     else
     177          56 :         this->parents.insert(this->parents.begin() + pos, parent);
     178         140 : }
     179             : 
     180             : }
     181             : }

Generated by: LCOV version 1.14