LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp/standard_containers - deque.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 35 39 89.7 %
Date: 2024-05-01 03:37:31 Functions: 60 67 89.6 %
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_DEQUE_H
      19             : #define MCRL2_ATERMPP_STANDARD_CONTAINER_DEQUE_H
      20             : 
      21             : #include <deque>
      22             : #include "mcrl2/atermpp/detail/aterm_container.h"
      23             : #include "mcrl2/atermpp/detail/global_aterm_pool.h"
      24             : #include "mcrl2/atermpp/detail/thread_aterm_pool.h"
      25             : #include "mcrl2/utilities/shared_mutex.h"
      26             : 
      27             : /// \brief The main namespace for the aterm++ library.
      28             : namespace atermpp
      29             : {
      30             : 
      31             : /// \brief A deque class in which aterms can be stored. 
      32             : template < class T, class Alloc = std::allocator<detail::reference_aterm<T> > > 
      33             : class deque : public std::deque< detail::reference_aterm<T>, Alloc >              
      34             : {
      35             : protected:
      36             :   typedef std::deque< detail::reference_aterm<T>, Alloc > super;
      37             :   
      38             :   detail::generic_aterm_container<std::deque<detail::reference_aterm<T>, Alloc>> container_wrapper;
      39             : 
      40             : public:
      41             :   
      42             :   /// Standard typedefs.
      43             :   typedef typename super::allocator_type allocator_type;
      44             :   typedef typename super::value_type value_type;
      45             :   typedef typename super::size_type size_type;
      46             :   typedef typename super::reference reference;
      47             :   typedef typename super::iterator iterator;
      48             :   typedef typename super::const_iterator const_iterator;
      49             :   
      50             :   /// \brief Default constructor.
      51        6590 :   deque()
      52             :    : super(),
      53        6590 :      container_wrapper(*this)     
      54        6590 :   {}
      55             : 
      56             :   /// \brief Constructor.
      57             :   explicit deque (const allocator_type& alloc)
      58             :    : super::deque(alloc),
      59             :      container_wrapper(*this)     
      60             :   {}
      61             : 
      62             :   /// \brief Constructor.
      63             :   explicit deque (size_type n, const allocator_type& alloc = allocator_type())
      64             :    : super::deque(n, alloc),
      65             :      container_wrapper(*this)
      66             :   {}
      67             : 
      68             :   /// \brief Constructor.
      69             :   deque(size_type n, const value_type& val, const allocator_type& alloc = allocator_type())
      70             :    : super::deque(n, detail::reference_aterm(val), alloc),
      71             :      container_wrapper(*this)    
      72             :   {}
      73             : 
      74             :   /// \brief Constructor.
      75             :   template <class InputIterator>
      76         210 :   deque(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
      77             :    : super::deque(first, last, alloc),
      78         210 :      container_wrapper(*this)     
      79         210 :   {}
      80             :     
      81             :   /// \brief Constructor.
      82        4918 :   deque(const deque& x)
      83             :    : super::deque(x),
      84        4918 :      container_wrapper(*this)     
      85        4918 :   {}
      86             : 
      87             :   /// \brief Constructor.
      88             :   deque(const deque& x, const allocator_type& alloc)
      89             :    : super::deque(x, alloc),
      90             :      container_wrapper(*this)     
      91             :   {}
      92             :   
      93             :   /// \brief Constructor.
      94             :   deque(deque&& x)
      95             :    : super::deque(std::move(x)),
      96             :      container_wrapper(*this)     
      97             :   {}
      98             : 
      99             :   /// \brief Constructor.
     100             :   deque(deque&& x, const allocator_type& alloc)
     101             :    : super::deque(std::move(x), alloc),
     102             :      container_wrapper(*this)     
     103             :   {}
     104             : 
     105             :   /// \brief Constructor. 
     106        1947 :   deque(std::initializer_list<value_type> il, const allocator_type& alloc = allocator_type())
     107             :     : super::deque(il.begin(), il.end(), alloc),
     108        1947 :       container_wrapper(*this)      
     109        1947 :   {}
     110             : 
     111             :   /// \brief Copy assignment operator.
     112             :   deque& operator=(const deque& other) = default;
     113             : 
     114             :   /// \brief Move assignment operator.
     115             :   deque& operator=(deque&& other) = default;
     116             : 
     117             :   /// \brief Standard destructor.
     118       13665 :   ~deque() = default;
     119             : 
     120             :   void shrink_to_fit()
     121             :   {
     122             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     123             :     super::shrink_to_fit();
     124             :   }
     125             : 
     126         212 :   void clear() noexcept
     127             :   {
     128         212 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     129         212 :     super::clear();
     130         212 :   }
     131             : 
     132             :   iterator insert( const_iterator pos, const T& value )
     133             :   {
     134             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     135             :     return super::insert(pos, value);
     136             :   }
     137             : 
     138             :   iterator insert( const_iterator pos, T&& value )
     139             :   {
     140             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     141             :     return super::insert(pos, value);
     142             :   }
     143             :   
     144             :   iterator insert( const_iterator pos, size_type count, const T& value )
     145             :   {
     146             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     147             :     return super::insert(pos, count, value);
     148             :   }
     149             :     
     150             :   template< class InputIt >
     151             :   iterator insert( const_iterator pos,
     152             :                   InputIt first, InputIt last )
     153             :   {
     154             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     155             :     return super::insert(pos, first, last);  
     156             :   }
     157             :     
     158             :   iterator insert( const_iterator pos, std::initializer_list<T> ilist )
     159             :   {
     160             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     161             :     return super::insert(pos, ilist);
     162             :   }
     163             :   
     164             :   template< class... Args >
     165             :   iterator emplace( const_iterator pos, Args&&... args )
     166             :   {
     167             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     168             :     return super::emplace(pos, args...);
     169             :   }
     170             : 
     171             :   iterator erase( const_iterator pos )
     172             :   {
     173             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     174             :     return super::erase(pos);
     175             :   }
     176             : 
     177             :   iterator erase( const_iterator first, const_iterator last )
     178             :   {
     179             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     180             :     return super::erase(first, last);    
     181             :   }
     182             : 
     183       33383 :   void push_back( const T& value )
     184             :   {
     185       33383 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     186       66766 :     return super::push_back(value);  
     187       33383 :   }
     188             :   
     189             :   void push_back( T&& value )
     190             :   {
     191             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     192             :     return super::push_back(value);
     193             :   }
     194             : 
     195             :   template< class... Args >
     196       18805 :   reference emplace_back( Args&&... args )
     197             :   {
     198       18805 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     199       37610 :     return super::emplace_back(args...);
     200       18805 :   }
     201             : 
     202       11744 :   void pop_back()
     203             :   {
     204       11744 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     205       11744 :     super::pop_back();
     206       11744 :   }
     207             : 
     208             :   void push_front( const T& value )
     209             :   {
     210             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     211             :     super::push_front(value);
     212             :   }
     213             :                 
     214             :   void push_front( T&& value )
     215             :   {
     216             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     217             :     super::push_front(value);
     218             :   }
     219             : 
     220             :   template< class... Args >
     221             :   reference emplace_front( Args&&... args )
     222             :   {
     223             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     224             :     super::emplace_front(args...);
     225             :   }
     226             : 
     227        3893 :   void resize( size_type count )
     228             :   {
     229        3893 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     230        3893 :     super::resize(count);
     231        3893 :   }
     232             :   
     233             :   void resize( size_type count, const value_type& value )
     234             :   {
     235             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     236             :     super::resize(count, value);
     237             :   }
     238             : 
     239      224348 :   std::size_t size() const
     240             :   {
     241      224348 :     return super::size();
     242             :   }
     243             : 
     244           0 :   void swap( deque& other ) noexcept
     245             :   {
     246           0 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     247           0 :     super::swap(other); // Invalidates end() so must be protected.
     248           0 :   }
     249             : };
     250             : 
     251             : } // namespace atermpp
     252             : #endif // MCRL2_ATERMPP_STANDARD_CONTAINER_DEQUE_H

Generated by: LCOV version 1.14