-
Notifications
You must be signed in to change notification settings - Fork 3
/
function_state_reset.hpp
48 lines (38 loc) · 1.28 KB
/
function_state_reset.hpp
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
/*=============================================================================
Copyright (c) 2001-2009 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef FUNCTION_STATE_RESET_HPP_
#define FUNCTION_STATE_RESET_HPP_
// boost
#include <boost/spirit/include/qi.hpp>
// STL
#include <vector>
///////////////////////////////////////////////////////////////////////////////
// A functor that resets the function-related state variables
///////////////////////////////////////////////////////////////////////////////
struct function_state_reset
{
template <typename>
struct result { typedef void type; };
function_state_reset(
std::vector<int>& code
, boost::spirit::qi::symbols<char, int>& vars
, int& nvars)
: code(code)
, vars(vars)
, nvars(nvars)
{
}
void operator()(int address) const
{
code[address+1] = nvars;
nvars = 0; // reset
vars.clear(); // reset
};
std::vector<int>& code;
boost::spirit::qi::symbols<char, int>& vars;
int& nvars;
};
#endif /* FUNCTION_STATE_RESET_HPP_ */