Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/thirdparty/taocpp-pegtl/pegtl/memory_input.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_MEMORY_INPUT_HPP
5
#define TAO_PEGTL_MEMORY_INPUT_HPP
6
7
#include <cstddef>
8
#include <cstdint>
9
#include <cstring>
10
#include <string>
11
#include <type_traits>
12
#include <utility>
13
14
#include "config.hpp"
15
#include "eol.hpp"
16
#include "normal.hpp"
17
#include "nothing.hpp"
18
#include "position.hpp"
19
#include "tracking_mode.hpp"
20
21
#include "internal/action_input.hpp"
22
#include "internal/at.hpp"
23
#include "internal/bump.hpp"
24
#include "internal/eolf.hpp"
25
#include "internal/iterator.hpp"
26
#include "internal/marker.hpp"
27
#include "internal/until.hpp"
28
29
namespace tao
30
{
31
   namespace TAO_PEGTL_NAMESPACE
32
   {
33
      namespace internal
34
      {
35
         template< tracking_mode, typename Eol, typename Source >
36
         class memory_input_base;
37
38
         template< typename Eol, typename Source >
39
         class memory_input_base< tracking_mode::eager, Eol, Source >
40
         {
41
         public:
42
            using iterator_t = internal::iterator;
43
44
            template< typename T >
45
            memory_input_base( const iterator_t& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
46
               : m_begin( in_begin.data ),
47
                 m_current( in_begin ),
48
                 m_end( in_end ),
49
                 m_source( std::forward< T >( in_source ) )
50
            {
51
            }
52
53
            template< typename T >
54
            memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
55
0
               : m_begin( in_begin ),
56
0
                 m_current( in_begin ),
57
0
                 m_end( in_end ),
58
0
                 m_source( std::forward< T >( in_source ) )
59
0
            {
60
0
            }
Unexecuted instantiation: tao::pegtl::internal::memory_input_base<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::memory_input_base<char const (&) [10]>(char const*, char const*, char const (&) [10])
Unexecuted instantiation: tao::pegtl::internal::memory_input_base<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::memory_input_base<char const (&) [1]>(char const*, char const*, char const (&) [1])
61
62
            memory_input_base( const memory_input_base& ) = delete;
63
            memory_input_base( memory_input_base&& ) = delete;
64
65
0
            ~memory_input_base() = default;
66
67
            memory_input_base operator=( const memory_input_base& ) = delete;
68
            memory_input_base operator=( memory_input_base&& ) = delete;
69
70
            const char* current() const noexcept
71
0
            {
72
0
               return m_current.data;
73
0
            }
74
75
            const char* begin() const noexcept
76
0
            {
77
0
               return m_begin;
78
0
            }
79
80
            const char* end( const std::size_t /*unused*/ = 0 ) const noexcept
81
0
            {
82
0
               return m_end;
83
0
            }
84
85
            std::size_t byte() const noexcept
86
            {
87
               return m_current.byte;
88
            }
89
90
            std::size_t line() const noexcept
91
            {
92
               return m_current.line;
93
            }
94
95
            std::size_t byte_in_line() const noexcept
96
            {
97
               return m_current.byte_in_line;
98
            }
99
100
            void bump( const std::size_t in_count = 1 ) noexcept
101
0
            {
102
0
               internal::bump( m_current, in_count, Eol::ch );
103
0
            }
104
105
            void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
106
0
            {
107
0
               internal::bump_in_this_line( m_current, in_count );
108
0
            }
109
110
            void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
111
0
            {
112
0
               internal::bump_to_next_line( m_current, in_count );
113
0
            }
114
115
            TAO_PEGTL_NAMESPACE::position position( const iterator_t& it ) const
116
0
            {
117
0
               return TAO_PEGTL_NAMESPACE::position( it, m_source );
118
0
            }
119
120
            void restart( const std::size_t in_byte = 0, const std::size_t in_line = 1, const std::size_t in_byte_in_line = 0 )
121
            {
122
               m_current.data = m_begin;
123
               m_current.byte = in_byte;
124
               m_current.line = in_line;
125
               m_current.byte_in_line = in_byte_in_line;
126
            }
127
128
         protected:
129
            const char* const m_begin;
130
            iterator_t m_current;
131
            const char* const m_end;
132
            const Source m_source;
133
         };
134
135
         template< typename Eol, typename Source >
136
         class memory_input_base< tracking_mode::lazy, Eol, Source >
137
         {
138
         public:
139
            using iterator_t = const char*;
140
141
            template< typename T >
142
            memory_input_base( const internal::iterator& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
143
               : m_begin( in_begin ),
144
                 m_current( in_begin.data ),
145
                 m_end( in_end ),
146
                 m_source( std::forward< T >( in_source ) )
147
            {
148
            }
149
150
            template< typename T >
151
            memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
152
0
               : m_begin( in_begin ),
153
0
                 m_current( in_begin ),
154
0
                 m_end( in_end ),
155
0
                 m_source( std::forward< T >( in_source ) )
156
0
            {
157
0
            }
158
159
            memory_input_base( const memory_input_base& ) = delete;
160
            memory_input_base( memory_input_base&& ) = delete;
161
162
            ~memory_input_base() = default;
163
164
            memory_input_base operator=( const memory_input_base& ) = delete;
165
            memory_input_base operator=( memory_input_base&& ) = delete;
166
167
            const char* current() const noexcept
168
0
            {
169
0
               return m_current;
170
0
            }
171
172
            const char* begin() const noexcept
173
            {
174
               return m_begin.data;
175
            }
176
177
            const char* end( const std::size_t /*unused*/ = 0 ) const noexcept
178
0
            {
179
0
               return m_end;
180
0
            }
181
182
            std::size_t byte() const noexcept
183
            {
184
               return std::size_t( current() - m_begin.data );
185
            }
186
187
            void bump( const std::size_t in_count = 1 ) noexcept
188
0
            {
189
0
               m_current += in_count;
190
0
            }
191
192
            void bump_in_this_line( const std::size_t in_count = 1 ) noexcept
193
            {
194
               m_current += in_count;
195
            }
196
197
            void bump_to_next_line( const std::size_t in_count = 1 ) noexcept
198
0
            {
199
0
               m_current += in_count;
200
0
            }
201
202
            TAO_PEGTL_NAMESPACE::position position( const iterator_t it ) const
203
            {
204
               internal::iterator c( m_begin );
205
               internal::bump( c, std::size_t( it - m_begin.data ), Eol::ch );
206
               return TAO_PEGTL_NAMESPACE::position( c, m_source );
207
            }
208
209
            void restart()
210
            {
211
               m_current = m_begin.data;
212
            }
213
214
         protected:
215
            const internal::iterator m_begin;
216
            iterator_t m_current;
217
            const char* const m_end;
218
            const Source m_source;
219
         };
220
221
      }  // namespace internal
222
223
      template< tracking_mode P = tracking_mode::eager, typename Eol = eol::lf_crlf, typename Source = std::string >
224
      class memory_input
225
         : public internal::memory_input_base< P, Eol, Source >
226
      {
227
      public:
228
         static constexpr tracking_mode tracking_mode_v = P;
229
230
         using eol_t = Eol;
231
         using source_t = Source;
232
233
         using typename internal::memory_input_base< P, Eol, Source >::iterator_t;
234
235
         using action_t = internal::action_input< memory_input >;
236
237
         using internal::memory_input_base< P, Eol, Source >::memory_input_base;
238
239
         template< typename T >
240
         memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
241
0
            : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) )
242
0
         {
243
0
         }
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::memory_input<char const (&) [10]>(char const*, unsigned long, char const (&) [10])
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::memory_input<char const (&) [1]>(char const*, unsigned long, char const (&) [1])
244
245
         template< typename T >
246
         memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
247
0
            : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) )
248
0
         {
249
0
         }
250
251
         template< typename T >
252
         memory_input( std::string&&, T&& ) = delete;
253
254
         template< typename T >
255
         memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
256
0
            : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) )
257
0
         {
258
0
         }
259
260
         template< typename T >
261
         memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept( std::is_nothrow_constructible< Source, T&& >::value )
262
            : memory_input( { in_begin, in_byte, in_line, in_byte_in_line }, in_end, std::forward< T >( in_source ) )
263
         {
264
         }
265
266
         memory_input( const memory_input& ) = delete;
267
         memory_input( memory_input&& ) = delete;
268
269
         ~memory_input() = default;
270
271
         memory_input operator=( const memory_input& ) = delete;
272
         memory_input operator=( memory_input&& ) = delete;
273
274
         const Source& source() const noexcept
275
0
         {
276
0
            return this->m_source;
277
0
         }
278
279
         bool empty() const noexcept
280
0
         {
281
0
            return this->current() == this->end();
282
0
         }
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::empty() const
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::empty() const
283
284
         std::size_t size( const std::size_t /*unused*/ = 0 ) const noexcept
285
0
         {
286
0
            return std::size_t( this->end() - this->current() );
287
0
         }
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::size(unsigned long) const
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::size(unsigned long) const
288
289
         char peek_char( const std::size_t offset = 0 ) const noexcept
290
0
         {
291
0
            return this->current()[ offset ];
292
0
         }
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::peek_char(unsigned long) const
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::peek_char(unsigned long) const
293
294
         std::uint8_t peek_uint8( const std::size_t offset = 0 ) const noexcept
295
0
         {
296
0
            return static_cast< std::uint8_t >( peek_char( offset ) );
297
0
         }
298
299
         // Compatibility, remove with 3.0.0
300
         std::uint8_t peek_byte( const std::size_t offset = 0 ) const noexcept
301
         {
302
            return static_cast< std::uint8_t >( peek_char( offset ) );
303
         }
304
305
         iterator_t& iterator() noexcept
306
0
         {
307
0
            return this->m_current;
308
0
         }
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::iterator()
Unexecuted instantiation: tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::iterator()
309
310
         const iterator_t& iterator() const noexcept
311
0
         {
312
0
            return this->m_current;
313
0
         }
314
315
         using internal::memory_input_base< P, Eol, Source >::restart;
316
317
         template< rewind_mode M >
318
         void restart( const internal::marker< iterator_t, M >& m )
319
         {
320
            iterator() = m.iterator();
321
         }
322
323
         using internal::memory_input_base< P, Eol, Source >::position;
324
325
         TAO_PEGTL_NAMESPACE::position position() const
326
0
         {
327
0
            return position( iterator() );
328
0
         }
329
330
         void discard() const noexcept
331
         {
332
         }
333
334
         void require( const std::size_t /*unused*/ ) const noexcept
335
         {
336
         }
337
338
         template< rewind_mode M >
339
         internal::marker< iterator_t, M > mark() noexcept
340
0
         {
341
0
            return internal::marker< iterator_t, M >( iterator() );
342
0
         }
Unexecuted instantiation: tao::pegtl::internal::marker<tao::pegtl::internal::iterator, (tao::pegtl::rewind_mode)1> tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::mark<(tao::pegtl::rewind_mode)1>()
Unexecuted instantiation: tao::pegtl::internal::marker<tao::pegtl::internal::iterator, (tao::pegtl::rewind_mode)0> tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::mark<(tao::pegtl::rewind_mode)0>()
Unexecuted instantiation: tao::pegtl::internal::marker<tao::pegtl::internal::iterator, (tao::pegtl::rewind_mode)2> tao::pegtl::memory_input<(tao::pegtl::tracking_mode)0, tao::pegtl::ascii::eol::lf_crlf, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::mark<(tao::pegtl::rewind_mode)2>()
Unexecuted instantiation: tao::pegtl::internal::marker<char const*, (tao::pegtl::rewind_mode)2> tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::mark<(tao::pegtl::rewind_mode)2>()
Unexecuted instantiation: tao::pegtl::internal::marker<char const*, (tao::pegtl::rewind_mode)1> tao::pegtl::memory_input<(tao::pegtl::tracking_mode)1, tao::pegtl::ascii::eol::lf_crlf, char const*>::mark<(tao::pegtl::rewind_mode)1>()
343
344
         const char* at( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept
345
0
         {
346
0
            return this->begin() + p.byte;
347
0
         }
348
349
         const char* begin_of_line( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept
350
0
         {
351
0
            return at( p ) - p.byte_in_line;
352
0
         }
353
354
         const char* end_of_line( const TAO_PEGTL_NAMESPACE::position& p ) const noexcept
355
0
         {
356
0
            using input_t = memory_input< tracking_mode::lazy, Eol, const char* >;
357
0
            input_t in( at( p ), this->end(), "" );
358
0
            using grammar = internal::until< internal::at< internal::eolf > >;
359
0
            normal< grammar >::match< apply_mode::nothing, rewind_mode::dontcare, nothing, normal >( in );
360
0
            return in.current();
361
0
         }
362
363
         std::string line_at( const TAO_PEGTL_NAMESPACE::position& p ) const
364
0
         {
365
0
            return std::string( begin_of_line( p ), end_of_line( p ) );
366
0
         }
367
      };
368
369
#ifdef __cpp_deduction_guides
370
      template< typename... Ts >
371
      memory_input( Ts&&... )->memory_input<>;
372
#endif
373
374
   }  // namespace TAO_PEGTL_NAMESPACE
375
376
}  // namespace tao
377
378
#endif