LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp/detail - aterm_appl_iterator.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 29 34 85.3 %
Date: 2024-04-26 03:18:02 Functions: 18 22 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jan Friso Groote, Wieger Wesselink
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file mcrl2/atermpp/aterm_appl_iterator.h
      10             : /// \brief Iterator for term_appl.
      11             : 
      12             : #ifndef MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H
      13             : #define MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H
      14             : 
      15             : #include "mcrl2/atermpp/detail/aterm_appl.h"
      16             : 
      17             : namespace atermpp
      18             : {
      19             : 
      20             : /// \brief Iterator for term_appl.
      21             : template <typename Term>
      22             : class term_appl_iterator
      23             : {
      24             :     template <class T>
      25             :     friend class term_appl;
      26             : 
      27             :     template < class Derived, class Base >
      28             :     friend term_appl_iterator<Derived> detail::aterm_appl_iterator_cast(term_appl_iterator<Base> a,
      29             :                                                                 typename std::enable_if<
      30             :                                                                      std::is_base_of<aterm, Base>::value &&
      31             :                                                                      std::is_base_of<aterm, Derived>::value
      32             :                                                                 >::type*);
      33             : 
      34             : 
      35             :   protected:
      36             :     const Term* m_term;
      37             :     
      38             :     /// \brief Constructor.
      39             :     /// \param t A pointer of an array of terms over which the iterator will range.
      40   627647778 :     term_appl_iterator(const Term* t)
      41   627647778 :       : m_term(t)
      42   627647778 :     {}
      43             : 
      44             :   public:
      45             :     typedef Term value_type;
      46             :     typedef const Term& reference;
      47             :     typedef const Term* pointer;
      48             :     typedef ptrdiff_t difference_type;
      49             :     typedef std::random_access_iterator_tag iterator_category;
      50             : 
      51             :     /// \brief The copy constructor.
      52             :     /// \param other The iterator that is copy constructed.
      53   190604003 :     term_appl_iterator(const term_appl_iterator& other)
      54   190604003 :       : m_term(other.m_term)
      55   190604003 :     {}
      56             : 
      57             :     /// \brief The assignment operator.
      58             :     /// \param other The term to be assigned.
      59             :     /// \return A reference to the assigned iterator.
      60             :     term_appl_iterator& operator=(const term_appl_iterator& other)
      61             :     {
      62             :       m_term=other.m_term;
      63             :       return *this;
      64             :     }
      65             :     
      66             :     /// \brief The dereference operator.
      67             :     /// \return The dereferenced term.
      68   771831323 :     const Term& operator*() const
      69             :     {
      70   771831323 :       return *m_term;
      71             :     }
      72             : 
      73             :     /// \brief Dereference the current iterator.
      74             :     /// \return The dereference term.
      75           0 :     const Term* operator->() const
      76             :     {
      77           0 :       return m_term;
      78             :     }
      79             : 
      80             :     /// \brief The dereference operator.
      81             :     /// \param n The index of the element to be dereferenced.
      82             :     /// \return The dereferenced term.
      83             :     const Term& operator[](difference_type n) const
      84             :     {
      85             :       return *(m_term+n);
      86             :     }
      87             : 
      88             :     /// \brief Prefix increment.
      89             :     /// \return The iterator after it is incremented.
      90   763888458 :     term_appl_iterator& operator++()
      91             :     {
      92   763888458 :       ++m_term;
      93   763888458 :       return *this;
      94             :     }
      95             : 
      96             :     /// \brief Postfix increment.
      97             :     /// \return The iterator before incrementing it.
      98     4929226 :     term_appl_iterator operator++(int)
      99             :     {
     100     4929226 :       term_appl_iterator temp=*this;
     101     4929226 :       ++m_term;
     102     4929226 :       return temp;
     103             :     }
     104             : 
     105             :     /// \brief Prefix decrement.
     106             :     /// \return The iterator after decrementing it.
     107     3002714 :     term_appl_iterator& operator--()
     108             :     {
     109     3002714 :       --m_term;
     110     3002714 :       return *this;
     111             :     }
     112             : 
     113             :     /// \brief Post decrement an iterator.
     114             :     /// \return The iterator before decrementing it.
     115             :     term_appl_iterator operator--(int)
     116             :     {
     117             :       term_appl_iterator temp=*this;
     118             :       --m_term;
     119             :       return *this;
     120             :     }
     121             : 
     122             :     /// \brief Increase the iterator with n steps.
     123             :     /// \param n The difference with which the iterator is increased.
     124             :     /// \return The increased iterator.
     125           0 :     term_appl_iterator& operator+=(difference_type n)
     126             :     {
     127           0 :       m_term+=n;
     128           0 :       return *this;
     129             :     }
     130             : 
     131             :     /// \brief Decrease the iterator with n steps.
     132             :     /// \param n a difference with which the iterator is decreased.
     133             :     /// \return The decreased iterator.
     134             :     term_appl_iterator& operator-=(difference_type n)
     135             :     {
     136             :       m_term-=n;
     137             :       return *this;
     138             :     }
     139             : 
     140             :     /// \brief Increase by a constant value.
     141             :     /// \return The iterator incremented by n.
     142    18860606 :     term_appl_iterator operator+(ptrdiff_t n) const
     143             :     {
     144    18860606 :       term_appl_iterator temp=*this;
     145    18860606 :       return temp.m_term+n;
     146             :     }
     147             : 
     148             :     /// \brief Decrease by a constant value.
     149             :     /// \return The iterator decremented by n.
     150             :     term_appl_iterator operator-(ptrdiff_t n) const
     151             :     {
     152             :       term_appl_iterator temp=*this;
     153             :       return temp.m_term-n;
     154             :     }
     155             : 
     156             :     /// \brief The negative distance from this to the other iterator.
     157             :     /// \param other the other iterator.
     158             :     /// \return The negative distance: this-other.
     159     9836512 :     ptrdiff_t operator-(const term_appl_iterator& other) const
     160             :     {
     161     9836512 :       return m_term-other.m_term;
     162             :     }
     163             : 
     164             :     /// \brief Provide the distance to the other iterator.
     165             :     /// \param other the other iterator.
     166             :     /// \return the distance from other to this iterator.
     167             :     ptrdiff_t distance_to(const term_appl_iterator& other) const
     168             :     {
     169             :       return other.m_term-m_term;
     170             :     }
     171             : 
     172             : 
     173             :     /// \brief Equality of iterators.
     174             :     /// \param other The iterator with which this iterator is compared.
     175             :     /// \return true if the iterators point to the same term_list.
     176    27732681 :     bool operator ==(const term_appl_iterator& other) const
     177             :     {
     178    27732681 :       return m_term == other.m_term;
     179             :     }
     180             : 
     181             :     /// \brief Inequality of iterators.
     182             :     /// \param other The iterator with which this iterator is compared.
     183             :     /// \return true if the iterators do not point to the same term_appl.
     184  1030213048 :     bool operator !=(const term_appl_iterator& other) const
     185             :     {
     186  1030213048 :       return m_term != other.m_term;
     187             :     }
     188             : 
     189             :     /// \brief Comparison of iterators.
     190             :     /// \param other The iterator with which this iterator is compared.
     191             :     /// \return true if the pointer to this termterm is smaller than the other pointer.
     192             :     bool operator <(const term_appl_iterator& other) const
     193             :     {
     194             :       return m_term < other.m_term;
     195             :     }
     196             : 
     197             :     /// \brief Comparison of iterators.
     198             :     /// \param other The iterator with which this iterator is compared.
     199             :     /// \return true if the iterators point to the same term_appl.
     200             :     bool operator <=(const term_appl_iterator& other) const
     201             :     {
     202             :       return m_term <= other.m_term;
     203             :     }
     204             : 
     205             :     /// \brief Comparison of iterators.
     206             :     /// \param other The iterator with which this iterator is compared.
     207             :     /// \return true if the iterators point to the same term_appl.
     208             :     bool operator >(const term_appl_iterator& other) const
     209             :     {
     210             :       return m_term > other.m_term;
     211             :     }
     212             : 
     213             :     /// \brief Comparison of iterators.
     214             :     /// \param other The iterator with which this iterator is compared.
     215             :     /// \return true if the iterators point to the same term_appl.
     216             :     bool operator >=(const term_appl_iterator& other) const
     217             :     {
     218             :       return m_term >= other.m_term;
     219             :     }
     220             : };
     221             : 
     222             : namespace detail
     223             : {
     224             :   /// This function can be used to translate an term_appl_iterator of one sort into another. 
     225             :   template < class Derived, class Base >
     226    37748010 :   term_appl_iterator<Derived> aterm_appl_iterator_cast(term_appl_iterator<Base> a,
     227             :                                                        typename std::enable_if<
     228             :                                                                      std::is_base_of<aterm, Base>::value &&
     229             :                                                                      std::is_base_of<aterm, Derived>::value
     230             :                                                                 >::type* /* = nullptr */)
     231             :   {
     232             :     static_assert(sizeof(Derived) == sizeof(aterm),
     233             :                 "term_appl_iterator only works on aterm classes to which no extra fields are added");
     234             :     static_assert(sizeof(Base) == sizeof(aterm),
     235             :                 "term_appl_iterator only works on aterm classes to which no extra fields are added");
     236    37748010 :     return term_appl_iterator<Derived>(reinterpret_cast<const Derived*>(a.m_term));
     237             :   }
     238             : 
     239             : } // namespace detail
     240             : 
     241             : } // namespace atermpp
     242             : 
     243             : #endif // MCRL2_ATERMPP_DETAIL_ATERM_APPL_ITERATOR_H

Generated by: LCOV version 1.14