triple.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _LSUP_TRIPLE_H
  2. #define _LSUP_TRIPLE_H
  3. #include "term.h"
  4. typedef struct LSUP_Triple {
  5. LSUP_Term *s;
  6. LSUP_Term *p;
  7. LSUP_Term *o;
  8. } LSUP_Triple;
  9. typedef struct LSUP_SerTriple {
  10. LSUP_SerTerm *s;
  11. LSUP_SerTerm *p;
  12. LSUP_SerTerm *o;
  13. } LSUP_SerTriple;
  14. typedef enum {
  15. TRP_POS_S = 0,
  16. TRP_POS_P = 1,
  17. TRP_POS_O = 2,
  18. } LSUP_TriplePos;
  19. #define _FN_BODY \
  20. if (n == 0) return trp->s; \
  21. if (n == 1) return trp->p; \
  22. if (n == 2) return trp->o; \
  23. return NULL;
  24. /** @brief Get triple by term position.
  25. *
  26. * Useful for looping over all terms.
  27. *
  28. * @param trp[in] Triple pointer.
  29. *
  30. * @param n[in] A number between 0÷2.
  31. *
  32. * @return Corresponding triple term or NULL if n is out of range.
  33. */
  34. inline LSUP_Term *
  35. LSUP_triple_term_by_pos(const LSUP_Triple *trp, LSUP_TriplePos n)
  36. { _FN_BODY }
  37. /** @brief Get serialized triple by term position.
  38. *
  39. * Useful for looping over all terms.
  40. *
  41. * @param trp[in] Serialized triple pointer.
  42. *
  43. * @param n[in] A number between 0÷2.
  44. *
  45. * @return Corresponding serialized term or NULL if n is out of range.
  46. */
  47. inline LSUP_SerTerm *
  48. LSUP_ser_triple_term_by_pos(const LSUP_SerTriple *trp, LSUP_TriplePos n)
  49. { _FN_BODY }
  50. // TODO Add constructors and destructors with term type checks.
  51. #endif