LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp - aterm_int.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 9 9 100.0 %
Date: 2020-09-16 00:45:56 Functions: 5 6 83.3 %
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/atermpp/aterm_int.h
      10             : /// \brief Term containing an integer.
      11             : 
      12             : #ifndef MCRL2_ATERMPP_ATERM_INT_H
      13             : #define MCRL2_ATERMPP_ATERM_INT_H
      14             : 
      15             : #include "mcrl2/atermpp/detail/global_aterm_pool.h"
      16             : 
      17             : namespace atermpp
      18             : {
      19             : 
      20             : /// \brief An integer term stores a single std::size_t value. It carries
      21             : ///            no arguments.
      22             : /// \details A special function symbol is used to identify integer terms
      23             : ///                      internally.
      24    23370663 : class aterm_int : public aterm
      25             : {
      26             : public:
      27             :   /// \brief Default constructor.
      28        4377 :   aterm_int() noexcept
      29        4377 :   {}
      30             : 
      31             :   /// \brief Constructs an integer term from a value.
      32    23365505 :   explicit aterm_int(std::size_t value)
      33    23365505 :    : aterm(detail::g_term_pool().create_int(value))
      34    23365505 :   {}
      35             : 
      36             :   /// This class has user-declared copy constructor so declare default copy and move operators.
      37         905 :   aterm_int(const aterm_int& other) noexcept = default;
      38             :   aterm_int& operator=(const aterm_int& other) noexcept = default;
      39             :   aterm_int(aterm_int&& other) noexcept = default;
      40             :   aterm_int& operator=(aterm_int&& other) noexcept = default;
      41             : 
      42             :   /// \brief Provide the value stored in an aterm. 
      43             :   /// \returns The value of the integer term.
      44     7980147 :   std::size_t value() const noexcept
      45             :   {
      46     7980147 :     return reinterpret_cast<const detail::_aterm_int*>(m_term)->value();
      47             :   }
      48             : 
      49             :   /// \brief Swaps two integer terms without changing the protection.
      50             :   /// \param t The term that is swapped with the current term. 
      51             :   void swap(aterm_int& t) noexcept
      52             :   {
      53             :     aterm::swap(t);
      54             :   }
      55             : };
      56             : 
      57             : } // namespace atermpp
      58             : 
      59             : namespace std
      60             : {
      61             : 
      62             : /// \brief Swaps two aterm_ints.
      63             : /// \details This operation is more efficient than exchanging terms by an assignment,
      64             : ///          as swapping does not require to change the protection of terms.
      65             : ///          In order to be used in the standard containers, the declaration must
      66             : ///          be preceded by an empty template declaration.
      67             : /// \param t1 The first term
      68             : /// \param t2 The second term
      69             : template <>  
      70             : inline void swap(atermpp::aterm_int& t1, atermpp::aterm_int& t2) noexcept
      71             : {
      72             :   t1.swap(t2);
      73             : } 
      74             : } // namespace std 
      75             : 
      76             : #endif // MCRL2_ATERMPP_ATERM_INT_H

Generated by: LCOV version 1.13