LCOV - code coverage report
Current view: top level - core/include/mcrl2/core - add_binding.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 19 19 100.0 %
Date: 2020-09-22 00:46:14 Functions: 89 151 58.9 %
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/core/add_binding.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_CORE_ADD_BINDING_H
      13             : #define MCRL2_CORE_ADD_BINDING_H
      14             : 
      15             : #include "mcrl2/atermpp/type_traits.h"
      16             : 
      17             : namespace mcrl2
      18             : {
      19             : 
      20             : namespace core
      21             : {
      22             : 
      23             : /// \brief Traverser that defines functions for maintaining bound variables.
      24             : template <template <class> class TraverserOrBuilder, typename Derived, typename Variable>
      25     6048020 : class add_binding : public TraverserOrBuilder<Derived>
      26             : {
      27             :   public:
      28             :     typedef TraverserOrBuilder<Derived> super;
      29             :     typedef Variable variable_type;
      30             : 
      31             :   protected:
      32             :     std::multiset<variable_type> m_bound_variables;
      33             : 
      34             :     /// \brief Add a variable to the multiset of bound variables.
      35          51 :     void increase_bind_count(const variable_type& var)
      36             :     {
      37          51 :       m_bound_variables.insert(var);
      38          51 :     }
      39             : 
      40             :     /// \brief Add a sequence of variables to the multiset of bound variables.
      41             :     template <typename Container>
      42       14063 :     void increase_bind_count(const Container& variables, typename atermpp::enable_if_container<Container, variable_type>::type* = nullptr)
      43             :     {
      44       34177 :       for (typename Container::const_iterator i = variables.begin(); i != variables.end(); ++i)
      45             :       {
      46       20114 :         m_bound_variables.insert(*i);
      47             :       }
      48       14063 :     }
      49             : 
      50             :     /// \brief Remove a variable from the multiset of bound variables.
      51          51 :     void decrease_bind_count(const variable_type& var)
      52             :     {
      53          51 :       m_bound_variables.erase(m_bound_variables.find(var));
      54          51 :     }
      55             : 
      56             :     /// \brief Remove a sequence of variables from the multiset of bound variables.
      57             :     template <typename Container>
      58       13402 :     void decrease_bind_count(const Container& variables, typename atermpp::enable_if_container<Container, variable_type>::type* = nullptr)
      59             :     {
      60       33087 :       for (typename Container::const_iterator i = variables.begin(); i != variables.end(); ++i)
      61             :       {
      62       19685 :         m_bound_variables.erase(m_bound_variables.find(*i));
      63             :       }
      64       13402 :     }
      65             : 
      66             :   public:
      67             :     /// \brief Returns true if the variable v is bound.
      68     2275559 :     bool is_bound(variable_type const& v) const
      69             :     {
      70     2275559 :       return m_bound_variables.find(v) != m_bound_variables.end();
      71             :     }
      72             : 
      73             :     /// \brief Returns the bound variables.
      74        1257 :     const std::multiset<variable_type>& bound_variables() const
      75             :     {
      76        1257 :       return m_bound_variables;
      77             :     }
      78             : 
      79             :     /// \brief Returns the bind count of the variable v.
      80             :     typename std::multiset<variable_type>::size_type bind_count(const variable_type& v)
      81             :     {
      82             :       return m_bound_variables.count(v);
      83             :     }
      84             : };
      85             : 
      86             : } // namespace core
      87             : 
      88             : } // namespace mcrl2
      89             : 
      90             : #endif // MCRL2_CORE_ADD_BINDING_H

Generated by: LCOV version 1.13