LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp/standard_containers - stack.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 16 16 100.0 %
Date: 2024-05-01 03:37:31 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jan Friso Groote, Maurice Laveaux
       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             : //
      10             : /// \file mcrl2/data/standard_containers/deque.h
      11             : /// \brief This file contains a deque class that behaves 
      12             : ///        exactly as a standard deque. It can only be used
      13             : ///        to store class instances that derive from aterms.
      14             : ///        The stored aterms are protected as a whole, i.e.,
      15             : ///        time and memory is saved as individual protection
      16             : ///        per element is unnecessary. 
      17             : 
      18             : #ifndef MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H
      19             : #define MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H
      20             : 
      21             : #include "mcrl2/atermpp/detail/aterm_container.h"
      22             : #include "mcrl2/atermpp/detail/thread_aterm_pool.h"
      23             : #include "mcrl2/atermpp/standard_containers/deque.h"
      24             : #include "mcrl2/utilities/shared_mutex.h"
      25             : 
      26             : /// \brief The main namespace for the aterm++ library.
      27             : namespace atermpp
      28             : {
      29             : 
      30             : /// \brief A deque class in which aterms can be stored. 
      31             : template < class T, 
      32             :            class Container = atermpp::deque< T > > 
      33             : class stack
      34             : {
      35             : private:
      36             :   Container m_container;
      37             : 
      38             : public:
      39             :   
      40             :   /// Standard typedefs.
      41             :   typedef typename Container::allocator_type allocator_type;
      42             :   typedef typename Container::value_type value_type;
      43             :   typedef typename Container::size_type size_type;
      44             :   typedef typename Container::reference reference;
      45             :   typedef typename Container::const_reference const_reference;
      46             :   typedef typename Container::iterator iterator;
      47             :   typedef typename Container::const_iterator const_iterator;
      48             :   
      49             :   /// \brief Constructor.
      50        4918 :   explicit stack(const Container& cont = Container())
      51        4918 :    : m_container(cont)     
      52        4918 :   {}
      53             : 
      54             :   /// \brief Constructor.
      55             :   explicit stack( Container&& cont )
      56             :    : m_container(cont)
      57             :   {}
      58             : 
      59             :   stack(const stack& other) = default;
      60             :   stack(stack&& other) = default;
      61             : 
      62             :   /// \brief Constructor.
      63             :   template< class InputIt >
      64             :   stack( InputIt first, InputIt last )
      65             :     : m_container(first, last)
      66             :   {}
      67             : 
      68             :   /// \brief Constructor.
      69             :   template <class InputIterator>
      70             :   stack(InputIterator first, InputIterator last,
      71             :         const allocator_type& alloc = allocator_type())
      72             :    : m_container(first, last, alloc)  
      73             :   {}
      74             : 
      75             :   template< class Alloc >
      76             :   explicit stack( const Alloc& alloc )
      77             :     : m_container(alloc)
      78             :   {}
      79             : 
      80             :   template< class Alloc >
      81             :   stack( const Container& cont, const Alloc& alloc )
      82             :     : m_container(cont, alloc)
      83             :   {}
      84             : 
      85             :   template< class Alloc >
      86             :   stack( Container&& cont, const Alloc& alloc )
      87             :     : m_container(cont, alloc)
      88             :   {}
      89             : 
      90             :   template< class Alloc >
      91             :   stack( const stack& other, const Alloc& alloc)
      92             :     : m_container(other.m_container, alloc)
      93             :   {}
      94             : 
      95             :   template< class Alloc >
      96             :   stack( stack&& other, const Alloc& alloc)
      97             :     : m_container(std::move(other.m_container), alloc)
      98             :   {}
      99             : 
     100             :   template< class InputIt, class Alloc >
     101             :   stack( InputIt first, InputIt last, const Alloc& alloc )
     102             :     : m_container(first, last, alloc)
     103             :   {}
     104             :     
     105             :   /// \brief Copy assignment operator.
     106             :   stack& operator=(const stack& other) = default;
     107             : 
     108             :   /// \brief Move assignment operator.
     109             :   stack& operator=(stack&& other) = default;
     110             : 
     111             :   /// \brief Standard destructor.
     112        4918 :   ~stack()=default;
     113             : 
     114       21945 :   reference top()
     115             :   {
     116       21945 :     return m_container.back();
     117             :   }
     118             : 
     119             :   const_reference top() const
     120             :   {
     121             :     return m_container.back();
     122             :   }
     123             : 
     124       21945 :   bool empty() const
     125             :   {
     126       21945 :     return m_container.empty();
     127             :   }
     128             : 
     129       21945 :   size_type size() const
     130             :   {
     131       21945 :     return m_container.size();
     132             :   }
     133             : 
     134             :   void push( const value_type& value )
     135             :   {
     136             :     m_container.push_back(value);
     137             :   }
     138             : 
     139             :   void push( value_type&& value )
     140             :   {
     141             :     m_container.push_back(std::move(value));
     142             :   }
     143             : 
     144             :   template< class... Args >
     145       11003 :   void emplace( Args&&... args )
     146             :   {
     147       11003 :     m_container.emplace_back(std::forward<Args>(args)...);
     148       11003 :   }
     149             : 
     150       11003 :   void pop()
     151             :   {
     152       11003 :     m_container.pop_back();
     153       11003 :   }
     154             : 
     155             :   void swap( stack& other ) noexcept
     156             :   {
     157             :     using std::swap; swap(m_container, other.m_container);
     158             :   }
     159             : 
     160             :   void mark(std::stack<std::reference_wrapper<detail::_aterm>>& todo) const
     161             :   {
     162             :     m_container.mark(todo);
     163             :   }
     164             : };
     165             : 
     166             : } // namespace atermpp
     167             : #endif // MCRL2_ATERMPP_STANDARD_CONTAINER_STACK_H

Generated by: LCOV version 1.14