summaryrefslogtreecommitdiff
path: root/test/rlparse.d/actparams.cc
blob: d9e9d6ff8908c0a405f2b0912444750b0aaf5c88 (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
59
60
61
62
63

#include <colm/tree.h> 
#include <colm/bytecode.h>

#include <iostream>
#include <map>
#include <set>

using std::map;
using std::set;
using std::string;
using std::pair;
using std::cout;
using std::endl;

extern "C" {
	colm_value_t cc_action_params_find( struct colm_program *prg, tree_t **sp, str_t *_machine, str_t *_action );
	colm_value_t cc_action_params_insert( struct colm_program *prg, tree_t **sp, str_t *_machine, str_t *_action );
}

typedef set<string> Set;
typedef map< string, Set > Map;
static Map machineMap;

value_t cc_action_params_find( struct colm_program *prg, tree_t **sp, str_t *_machine, str_t *_action )
{
	string machine( _machine->value->data, _machine->value->length );
	string action( _action->value->data, _action->value->length );

	// cout << "cc_action_params_find " << machine << " " << action << " ";

	long res = 0;
	Map::iterator M = machineMap.find( machine );
	if ( M != machineMap.end() )
		res = M->second.find( action ) != M->second.end();

	// cout << ( res ? "FOUND" : "NOT FOUND" ) << endl;

	colm_tree_downref( prg, sp, (tree_t*)_machine );
	colm_tree_downref( prg, sp, (tree_t*)_action );

	return (value_t) res;
}

value_t cc_action_params_insert( struct colm_program *prg, tree_t **sp, str_t *_machine, str_t *_action )
{
	string machine( _machine->value->data, _machine->value->length );
	string action( _action->value->data, _action->value->length );

	// cout << "cc_action_params_insert " << machine << " " << action << endl;

	Map::iterator M = machineMap.find( machine );
	if ( M == machineMap.end() )
		machineMap.insert( pair<string, Set>( machine, Set() )  );

	M = machineMap.find( machine );
	M->second.insert( action );

	colm_tree_downref( prg, sp, (tree_t*)_machine );
	colm_tree_downref( prg, sp, (tree_t*)_action );

	return 0;
}