LCOV - code coverage report
Current view: top level - core/include/mcrl2/core - traverser.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 12 12 100.0 %
Date: 2024-04-13 03:38:08 Functions: 2183 6798 32.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jeroen van der Wulp, 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/core/traverser.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_CORE_TRAVERSER_H
      13             : #define MCRL2_CORE_TRAVERSER_H
      14             : 
      15             : #include "mcrl2/core/identifier_string.h"
      16             : 
      17             : namespace mcrl2
      18             : {
      19             : 
      20             : namespace core
      21             : {
      22             : 
      23             : /**
      24             :  * \brief expression traverser that visits all sub expressions
      25             :  *
      26             :  * Types:
      27             :  *  \arg Derived the type of a derived class, as per CRTP
      28             :  *
      29             :  **/
      30             : template <typename Derived>
      31             : struct traverser
      32             : {
      33             :   template <typename Expression>
      34    53046240 :   void enter(Expression const&)
      35    53046240 :   {}
      36             : 
      37             :   template <typename Expression>
      38    53031417 :   void leave(Expression const&)
      39    53031417 :   {}
      40             : 
      41             :   template <typename T>
      42       12863 :   void apply(const T& x, typename atermpp::disable_if_container<T>::type* = nullptr)
      43             :   {
      44       12863 :     static_cast<Derived&>(*this).enter(x);
      45       12863 :     static_cast<Derived&>(*this).leave(x);
      46       12863 :   }
      47             : 
      48             :   // traverse containers
      49             :   template <typename Container>
      50     2383552 :   void apply(Container const& container, typename atermpp::enable_if_container<Container>::type* = nullptr)
      51             :   {
      52     7029662 :     for (typename Container::const_iterator i = container.begin(); i != container.end(); ++i)
      53             :     {
      54     4646110 :       static_cast<Derived*>(this)->apply(*i);
      55             :     }
      56     2383552 :   }
      57             : 
      58             :   // TODO: This dependency on identifier_string should be moved elsewhere...
      59             :   void apply(const core::identifier_string& x)
      60             :   {
      61             :     static_cast<Derived&>(*this).enter(x);
      62             :     static_cast<Derived&>(*this).leave(x);
      63             :   }
      64             : };
      65             : 
      66             : // apply a builder without additional template arguments
      67             : template <template <class> class Traverser>
      68             : struct apply_traverser: public Traverser<apply_traverser<Traverser> >
      69             : {
      70             :   typedef Traverser<apply_traverser<Traverser> > super;
      71             : 
      72             :   using super::enter;
      73             :   using super::leave;
      74             :   using super::apply;
      75             : };
      76             : 
      77             : template <template <class> class Traverser>
      78             : apply_traverser<Traverser>
      79             : make_apply_traverser()
      80             : {
      81             :   return apply_traverser<Traverser>();
      82             : }
      83             : 
      84             : } // namespace core
      85             : 
      86             : } // namespace mcrl2
      87             : 
      88             : #endif // MCRL2_CORE_TRAVERSER_H

Generated by: LCOV version 1.14