LCOV - code coverage report
Current view: top level - process/include/mcrl2/process - balance_nesting_depth.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 14 18 77.8 %
Date: 2024-04-17 03:40:49 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): 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/process/balance_nesting_depth.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_PROCESS_BALANCE_NESTING_DEPTH_H
      13             : #define MCRL2_PROCESS_BALANCE_NESTING_DEPTH_H
      14             : 
      15             : #include "mcrl2/process/builder.h"
      16             : #include "mcrl2/process/join.h"
      17             : #include "mcrl2/utilities/detail/join.h"
      18             : 
      19             : namespace mcrl2 {
      20             : 
      21             : namespace process {
      22             : 
      23             : namespace detail
      24             : {
      25             : struct balance_summands_builder
      26             :     : public process_expression_builder<balance_summands_builder>
      27             : {
      28             :   typedef process_expression_builder<balance_summands_builder> super;
      29             :   using super::apply;
      30             : 
      31             :   template <class T>
      32           1 :   void apply(T& result, const process::choice& x)
      33             :   {
      34           1 :     std::vector<process_expression> summands = split_summands(x);
      35           1 :     process_expression new_summand;
      36         102 :     for (process_expression& summand: summands)
      37             :     {
      38         101 :       super::apply(new_summand, summand);
      39         101 :       summand = new_summand;
      40             :     }
      41             :     
      42           1 :     result = utilities::detail::join_balanced<process_expression>(
      43             :         summands.begin(), 
      44             :         summands.end(),
      45         100 :         [](const process::process_expression& x, const process_expression& y) {
      46         100 :           return choice(x, y);
      47             :         });
      48           1 :   }
      49             : };
      50             : 
      51             : } // namespace detail
      52             : 
      53             : /// \brief Reduces the nesting depth of the choice operator
      54             : template <typename T>
      55           0 : void balance_summands(T& x, typename std::enable_if<!std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr)
      56             : {
      57             :   detail::balance_summands_builder f;
      58           0 :   f.update(x);
      59           0 : }
      60             : 
      61             : /// \brief Reduces the nesting depth of the choice operator
      62             : template <typename T>
      63           1 : T balance_summands(const T& x, typename std::enable_if<std::is_base_of<atermpp::aterm, T>::value>::type* = nullptr)
      64             : {
      65           1 :   T result;
      66             :   detail::balance_summands_builder f;
      67           1 :   f.apply(result, x);
      68           2 :   return result;
      69           0 : }
      70             : 
      71             : } // namespace process
      72             : 
      73             : } // namespace mcrl2
      74             : 
      75             : #endif // MCRL2_PROCESS_BALANCE_NESTING_DEPTH_H

Generated by: LCOV version 1.14