Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/thirdparty/taocpp-pegtl/pegtl/analysis/insert_guard.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey
2
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3
4
#ifndef TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP
5
#define TAO_PEGTL_ANALYSIS_INSERT_GUARD_HPP
6
7
#include <utility>
8
9
#include "../config.hpp"
10
11
namespace tao
12
{
13
   namespace TAO_PEGTL_NAMESPACE
14
   {
15
      namespace analysis
16
      {
17
         template< typename C >
18
         class insert_guard
19
         {
20
         public:
21
            insert_guard( C& container, const typename C::value_type& value )
22
0
               : m_i( container.insert( value ) ),
23
0
                 m_c( &container )
24
0
            {
25
0
            }
26
27
            insert_guard( const insert_guard& ) = delete;
28
29
            insert_guard( insert_guard&& other ) noexcept
30
               : m_i( other.m_i ),
31
                 m_c( other.m_c )
32
            {
33
               other.m_c = nullptr;
34
            }
35
36
            ~insert_guard()
37
0
            {
38
0
               if( m_c && m_i.second ) {
39
0
                  m_c->erase( m_i.first );
40
0
               }
41
0
            }
42
43
            void operator=( const insert_guard& ) = delete;
44
            void operator=( insert_guard&& ) = delete;
45
46
            explicit operator bool() const noexcept
47
0
            {
48
0
               return m_i.second;
49
0
            }
50
51
         private:
52
            const std::pair< typename C::iterator, bool > m_i;
53
            C* m_c;
54
         };
55
56
         template< typename C >
57
         insert_guard< C > make_insert_guard( C& container, const typename C::value_type& value )
58
0
         {
59
0
            return insert_guard< C >( container, value );
60
0
         }
61
62
      }  // namespace analysis
63
64
   }  // namespace TAO_PEGTL_NAMESPACE
65
66
}  // namespace tao
67
68
#endif