Debian Codegraph @

dwsys/Command.h

raw
1 #ifndef _Command_h_
2 #define _Command_h_
3 /* Command.h
4 *
5 * Copyright (C) 1994-2018,2021 David Weenink, 2015 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Thing.h"
22 #include "Collection.h"
23
24
25 #pragma mark - class Command
26
27 Thing_declare (Command);
28
29 Thing_define (Command, Thing) {
30 Thing boss;
31 virtual void v_do ();
32 virtual void v_undo ();
33 };
34
35 void Command_init (Command me, conststring32 name, Thing boss);
36
37 void Command_do (Command me);
38
39 void Command_undo (Command me);
40
41
42 #pragma mark - class CommandHistory
43
44 Collection_define (CommandHistory, OrderedOf, Command) {
45 integer current;
46 };
47
48 /*
49 Active data structure. 'current' is position of the cursor in the command history list
50 Queries and insertions are at the current position
51 Invariants:
52 0 <= current <= size + 1;
53 */
54
55 void CommandHistory_forth (CommandHistory me);
56 /*
57 Precondition: ! offright
58 Postcondition: my current++;
59 */
60
61 void CommandHistory_back (CommandHistory me);
62 /*
63 Precondition: ! offleft
64 Postcondition: my current--;
65 */
66
67 Command CommandHistory_getItem (CommandHistory me);
68 /*
69 return command at my item [my current];
70 */
71
72 void CommandHistory_insertItem_move (CommandHistory me, autoCommand command);
73 /*
74 1. forget about item [ current+1..size ]
75 2. insert item after current.
76 3. new_size = current+1
77 */
78
79 bool CommandHistory_isEmpty (CommandHistory me);
80 /*
81 return my size == 0;
82 */
83
84 bool CommandHistory_isOffleft (CommandHistory me);
85 /*
86 return my current == 0;
87 */
88
89 bool CommandHistory_isOffright (CommandHistory me);
90 /*
91 return my size == 0 || my current == my size + 1;
92 */
93
94 conststring32 CommandHistory_commandName (CommandHistory me, integer offsetFromCurrent);
95 /*
96 offsetFromCurrent may be zero, positive or negative.
97 References outside the list will return nullptr.
98 */
99
100 #endif /* _Command_h_ */