triple.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_Buffer *s;
  11. LSUP_Buffer *p;
  12. LSUP_Buffer *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. /** @brief Serialize a RDF triple into a buffer triple.
  20. *
  21. * The internal structure must be freed with #LSUP_striple_done after use.
  22. *
  23. * @param spo[in] Triple to be serialized.
  24. * @param sspo[out] Buffer triple handle. It must point to an already allocated
  25. * structure.
  26. *
  27. * @return LSUP_OK or an error code resulting from #LSUP_term_serialize.
  28. */
  29. LSUP_rc
  30. LSUP_triple_serialize(const LSUP_Triple *spo, LSUP_SerTriple *sspo);
  31. /** @brief Deserialize a buffer triple into a RDF triple.
  32. *
  33. * The internal structure must be freed with #LSUP_triple_done after use.
  34. *
  35. * @param sspo[in] Buffer triple to be serialized.
  36. * @param spo[out] RDF triple handle. It must point to an already allocated
  37. * structure.
  38. *
  39. * @return LSUP_OK or an error code resulting from #LSUP_term_deserialize.
  40. */
  41. LSUP_rc
  42. LSUP_triple_deserialize(const LSUP_SerTriple *sspo, LSUP_Triple *spo);
  43. /** @brief Free the internal pointers of a triple.
  44. *
  45. * @param spo[in] Triple to be freed.
  46. */
  47. void
  48. LSUP_triple_done(LSUP_Triple *spo);
  49. /** @brief Free the internal pointers of a buffer triple.
  50. *
  51. * @param sspo[in] Buffer triple to be freed.
  52. */
  53. void
  54. LSUP_striple_done(LSUP_SerTriple *sspo);
  55. #define _FN_BODY \
  56. if (n == TRP_POS_S) return trp->s; \
  57. if (n == TRP_POS_P) return trp->p; \
  58. if (n == TRP_POS_O) return trp->o; \
  59. return NULL;
  60. /** @brief Get triple by term position.
  61. *
  62. * Useful for looping over all terms.
  63. *
  64. * @param trp[in] Triple pointer.
  65. *
  66. * @param n[in] A number between 0÷2.
  67. *
  68. * @return Corresponding triple term or NULL if n is out of range.
  69. */
  70. inline LSUP_Term *
  71. LSUP_triple_pos(const LSUP_Triple *trp, LSUP_TriplePos n)
  72. { _FN_BODY }
  73. /** @brief Get serialized triple by term position.
  74. *
  75. * Useful for looping over all terms.
  76. *
  77. * @param trp[in] Serialized triple pointer.
  78. *
  79. * @param n[in] A number between 0÷2.
  80. *
  81. * @return Corresponding serialized term or NULL if n is out of range.
  82. */
  83. inline LSUP_Buffer *
  84. LSUP_striple_pos(const LSUP_SerTriple *trp, LSUP_TriplePos n)
  85. { _FN_BODY }
  86. #undef _FN_BODY
  87. #endif