| 1 | #cxx . . $ `<file>/dwsys/Command.h`/ifndef _Command_h_ |
| 2 | #define _Command_h_cxx . . $ `dwsys/Command.h:2:9`! |
| 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"cxx . . $ `<file>/sys/Thing.h`/ |
| 22 | #include "Collection.h"cxx . . $ `<file>/sys/Collection.h`/ |
| 23 | |
| 24 | |
| 25 | #pragma mark - class Command |
| 26 | |
| 27 | Thing_declarecxx . . $ constCommand# (Command); |
| 28 | |
| 29 | Thing_definecxx . . $ mutableCommand# (Command, Thing) { |
| 30 | Thingcxx . . $ Thing# bosscxx . . $ structCommand#boss.; |
| 31 | virtual void v_docxx . . $ structCommand#v_do(49f6e7a06ebc5aa8). (); |
| 32 | virtual void v_undocxx . . $ structCommand#v_undo(49f6e7a06ebc5aa8). (); |
| 33 | }; |
| 34 | |
| 35 | void Command_initcxx . . $ Command_init(47ae7cbabe6d8df8). (Commandcxx . . $ Command# me, conststring32cxx . . $ conststring32# name, Thingcxx . . $ Thing# boss); |
| 36 | |
| 37 | void Command_docxx . . $ Command_do(822ebc8b9e234a4). (Commandcxx . . $ Command# me); |
| 38 | |
| 39 | void Command_undocxx . . $ Command_undo(822ebc8b9e234a4). (Commandcxx . . $ Command# me); |
| 40 | |
| 41 | |
| 42 | #pragma mark - class CommandHistory |
| 43 | |
| 44 | Collection_definecxx . . $ CommandHistory_create(8cfba7284879d337). (CommandHistory, OrderedOf, Command) { |
| 45 | integercxx . . $ integer# currentcxx . . $ structCommandHistory#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_forthcxx . . $ CommandHistory_forth(7258301033e2d904). (CommandHistorycxx . . $ CommandHistory# me); |
| 56 | /* |
| 57 | Precondition: ! offright |
| 58 | Postcondition: my current++; |
| 59 | */ |
| 60 | |
| 61 | void CommandHistory_backcxx . . $ CommandHistory_back(7258301033e2d904). (CommandHistorycxx . . $ CommandHistory# me); |
| 62 | /* |
| 63 | Precondition: ! offleft |
| 64 | Postcondition: my current--; |
| 65 | */ |
| 66 | |
| 67 | Commandcxx . . $ Command# CommandHistory_getItemcxx . . $ CommandHistory_getItem(af102feab7dfa2d0). (CommandHistorycxx . . $ CommandHistory# me); |
| 68 | /* |
| 69 | return command at my item [my current]; |
| 70 | */ |
| 71 | |
| 72 | void CommandHistory_insertItem_movecxx . . $ CommandHistory_insertItem_move(e8345a325df32818). (CommandHistorycxx . . $ CommandHistory# me, autoCommandcxx . . $ 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_isEmptycxx . . $ CommandHistory_isEmpty(1e1e8785c23ca14b). (CommandHistorycxx . . $ CommandHistory# me); |
| 80 | /* |
| 81 | return my size == 0; |
| 82 | */ |
| 83 | |
| 84 | bool CommandHistory_isOffleftcxx . . $ CommandHistory_isOffleft(1e1e8785c23ca14b). (CommandHistorycxx . . $ CommandHistory# me); |
| 85 | /* |
| 86 | return my current == 0; |
| 87 | */ |
| 88 | |
| 89 | bool CommandHistory_isOffrightcxx . . $ CommandHistory_isOffright(1e1e8785c23ca14b). (CommandHistorycxx . . $ CommandHistory# me); |
| 90 | /* |
| 91 | return my size == 0 || my current == my size + 1; |
| 92 | */ |
| 93 | |
| 94 | conststring32cxx . . $ conststring32# CommandHistory_commandNamecxx . . $ CommandHistory_commandName(cfbef1f0ff993ce0). (CommandHistorycxx . . $ CommandHistory# me, integercxx . . $ 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_ */ |