state.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* This file is part of nit.
  2. *
  3. * Nit is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * Nit is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with nit. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef STATE_H
  17. #define STATE_H
  18. #include "acts.h"
  19. #include "trie.h"
  20. typedef struct Branch_act {
  21. uint64_t branch;
  22. Act act;
  23. Trie_entry *real_next;
  24. } Branch_act;
  25. typedef void (*Act_dispose)(Act *act, void *extra);
  26. typedef struct State {
  27. Act_dispose act_dispose;
  28. Disposer disposer;
  29. Trie past;
  30. Trie_entry *end;
  31. Acts *acts;
  32. void *extra;
  33. uint64_t branch;
  34. unsigned undoing : 1;
  35. } State;
  36. Nit_error
  37. state_init(State *state, Acts *acts, uint64_t branch,
  38. Act_dispose dispose, void *extra);
  39. void
  40. state_dispose(State *state);
  41. Nit_error
  42. state_do(State *state, uint32_t key_len, const void *key,
  43. void *dat, void *args, int real);
  44. Nit_error
  45. state_undo(State *state);
  46. Nit_error
  47. state_redo(State *state, uint64_t branch, int real);
  48. /* Nit_error */
  49. /* state_realize(State *state) */
  50. /* { */
  51. /* List list; */
  52. /* Branch_act *b_act; */
  53. /* Nit_error err_str; */
  54. /* list_init(&list, NULL); */
  55. /* while (!(b_act = state->end->dat)->act.real) */
  56. /* if ((err_str = list_add(&list, NULL, &b_act->branch))) */
  57. /* return err_str; */
  58. /* } */
  59. #endif