blob: 52beb3b0bca102a1104f150e73b4a6851f4705cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_COUNTER_HPP
#define TAOCPP_PEGTL_INCLUDE_CONTRIB_COUNTER_HPP
#include <cassert>
#include <utility>
#include "../config.hpp"
#include "../normal.hpp"
#include "../internal/demangle.hpp"
namespace tao
{
namespace TAOCPP_PEGTL_NAMESPACE
{
struct counter_data
{
unsigned start = 0;
unsigned success = 0;
unsigned failure = 0;
};
struct counter_state
{
std::map< std::string, counter_data > counts;
};
template< typename Rule >
struct counter
: normal< Rule >
{
template< typename Input >
static void start( const Input&, counter_state& ts )
{
++ts.counts[ internal::demangle< Rule >() ].start;
}
template< typename Input >
static void success( const Input&, counter_state& ts )
{
++ts.counts[ internal::demangle< Rule >() ].success;
}
template< typename Input >
static void failure( const Input&, counter_state& ts )
{
++ts.counts[ internal::demangle< Rule >() ].failure;
}
};
} // namespace TAOCPP_PEGTL_NAMESPACE
} // namespace tao
#endif
|