Debian Codegraph @

dwsys/Command.cpp

raw symbols SCIP
1 /* Command.cpp
2 *
3 * Copyright (C) 1994-2019 David Weenink
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "Command.h"
20
21 #pragma mark - class Command
22
23 void structCommand :: v_do () { };
24 void structCommand :: v_undo () { };
25
26 Thing_implement (Command, Thing, 0);
27
28 void Command_init (Command me, conststring32 name, Thing boss) {
29 Thing_setName (me, name);
30 my boss = boss;
31 }
32
33 void Command_do (Command me) {
34 my v_do ();
35 }
36
37 void Command_undo (Command me) {
38 my v_undo ();
39 }
40
41 #pragma mark - class CommandHistory
42
43 Thing_implement (CommandHistory, Ordered, 0);
44
45 void CommandHistory_forth (CommandHistory me) {
46 my current ++;
47 }
48
49 void CommandHistory_back (CommandHistory me) {
50 my current --;
51 }
52
53 Command CommandHistory_getItem (CommandHistory me) {
54 Melder_assert (my current > 0 && my current <= my size);
55 return my at [my current];
56 }
57
58 void CommandHistory_insertItem_move (CommandHistory me, autoCommand command) {
59 for (integer i = my size; i >= my current + 1; i --)
60 my removeItem (i);
61 my addItem_move (command.move());
62 while (my size > 20)
63 my removeItem (1);
64 my current = my size;
65 }
66
67 bool CommandHistory_isEmpty (CommandHistory me) {
68 return my size == 0;
69 }
70
71 bool CommandHistory_isOffleft (CommandHistory me) {
72 return my current == 0;
73 }
74
75 bool CommandHistory_isOffright (CommandHistory me) {
76 return my size == 0 || my current == my size + 1;
77 }
78
79 conststring32 CommandHistory_commandName (CommandHistory me, integer offsetFromCurrent) {
80 const integer pos = my current + offsetFromCurrent;
81 return pos >= 1 && pos <= my size ? Thing_getName (my at [pos]) : nullptr;
82 }
83
84 /* End of file Command.cpp */