acts.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ACTS_H
  17. #define ACTS_H
  18. #include "map.h"
  19. #define ACT_FAIL() return act_failure
  20. typedef Map Acts;
  21. typedef void *(*Act_do)(int real, void *dat, void *args, void *extra);
  22. typedef void *(*Act_undo)(void *cng, void *dat, void *args, void *extra);
  23. typedef void *(*Act_dif)(void *cng, void *dat, void *args, void *extra);
  24. typedef struct Action {
  25. Act_do do_it;
  26. Act_undo undo;
  27. Act_dif dif;
  28. } Action;
  29. typedef enum Act_type {
  30. ACT_DO,
  31. ACT_UNDO,
  32. ACT_REDO,
  33. ACT_DIF,
  34. ACT_REDIF
  35. } Act_type;
  36. typedef struct Act {
  37. Act_type type;
  38. int real;
  39. uint32_t key_len;
  40. void *key;
  41. void *dat;
  42. void *args;
  43. void *cng;
  44. } Act;
  45. extern char act_failure[];
  46. Nit_error
  47. acts_init(Acts *acts);
  48. #define acts_dispose(...) map_dispose(__VA_ARGS__)
  49. Nit_error
  50. acts_add(Acts *acts, uint32_t key_len, const void *key,
  51. Act_do do_it, Act_undo undo, Act_dif dif);
  52. Nit_error
  53. acts_act(Acts *acts, Act *act, void *extra);
  54. #endif