summaryrefslogtreecommitdiff
path: root/src/include/tome/squelch/automatizer.hpp
blob: fae52a2bc6f63211bf9019147a8b983c22eb98cf (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef H_53108fce_b059_4a82_99db_e1d4970ebd77
#define H_53108fce_b059_4a82_99db_e1d4970ebd77

#include <boost/noncopyable.hpp>
#include <memory>
#include <vector>
#include <jansson.h>

#include "tome/squelch/rule_fwd.hpp"
#include "tome/squelch/cursor_fwd.hpp"
#include "tome/squelch/tree_printer_fwd.hpp"
#include "tome/squelch/condition_fwd.hpp"
#include "types_fwd.h"

namespace squelch {

/**
 * Automatizer
 */
class Automatizer : public boost::noncopyable
{
public:
	Automatizer(std::shared_ptr<TreePrinter> tree_printer,
		    std::shared_ptr<Cursor> cursor)
		: m_selected_rule(0)
		, m_begin(0)
		, m_tree_printer(tree_printer)
		, m_cursor(cursor)
		, m_rules() {
	}

	/**
	 * Append a rule
	 */
	int append_rule(std::shared_ptr<Rule> rule);

	/**
	 * Swap two rules
	 */
	void swap_rules(int i, int j);

	/**
	 * Apply all rules to the given object
	 */
	bool apply_rules(object_type *o_ptr, int item_idx) const;

	/**
	 * Build a JSON data structure to represent
	 * all the rules.
	 */
        std::shared_ptr<json_t> to_json() const;

	/**
	 * Load rules from a JSON data structure.
	 */
	void load_json(json_t *json);

	/**
	 * Remove currently selected condition or rule.
	 */
	int remove_current_selection();

	/**
	 * Reset view.
	 */
	void reset_view();

	/**
	 * Show current rule
	 */
	void show_current() const;

	/**
	 * Scroll view up
	 */
	void scroll_up();

	/**
	 * Scroll view down
	 */
	void scroll_down();

	/**
	 * Scroll view left
	 */
	void scroll_left();

	/**
	 * Scroll view right
	 */
	void scroll_right();

	/**
	 * Move selection up
	 */
	void move_up();

	/**
	 * Move selection down
	 */
	void move_down();

	/**
	 * Move selection left
	 */
	void move_left();

	/**
	 * Move selection right
	 */
	void move_right();

	/**
	 * Add new condition to selected rule
	 */
	void add_new_condition(std::function<std::shared_ptr<Condition> ()> factory);

	/**
	 * Get rule names. The names are not stable across multiple
	 * calls to methods on this class.
	 */
	void get_rule_names(std::vector<const char *> *names) const;

	/**
	 * Get current number of rules.
	 */
	int rules_count() const;

	/**
	 * Get the "beginning" rule.
	 */
	int rules_begin() const;

	/**
	 * Select a new rule.
	 */
	void select_rule(int selected_rule);

	/**
	 * Return selected rule index
	 */
	int selected_rule() const;

	/**
	 * Return selected rule
	 */
	std::shared_ptr<Rule> current_rule();

private:
	int m_selected_rule;
	int m_begin;
	std::shared_ptr<TreePrinter> m_tree_printer;
	std::shared_ptr<Cursor> m_cursor;
	std::vector < std::shared_ptr < Rule > > m_rules;
};

} // namespace

#endif