123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef _LSUP_TRIPLE_H
- #define _LSUP_TRIPLE_H
- #include "term.h"
- typedef struct LSUP_Triple {
- LSUP_Term *s;
- LSUP_Term *p;
- LSUP_Term *o;
- } LSUP_Triple;
- typedef struct LSUP_SerTriple {
- LSUP_Buffer *s;
- LSUP_Buffer *p;
- LSUP_Buffer *o;
- } LSUP_SerTriple;
- typedef enum {
- TRP_POS_S = 0,
- TRP_POS_P = 1,
- TRP_POS_O = 2,
- } LSUP_TriplePos;
- /** @brief Serialize a RDF triple into a buffer triple.
- *
- * The internal structure must be freed with #LSUP_striple_done after use.
- *
- * @param spo[in] Triple to be serialized.
- * @param sspo[out] Buffer triple handle. It must point to an already allocated
- * structure.
- *
- * @return LSUP_OK or an error code resulting from #LSUP_term_serialize.
- */
- LSUP_rc
- LSUP_triple_serialize(const LSUP_Triple *spo, LSUP_SerTriple *sspo);
- /** @brief Deserialize a buffer triple into a RDF triple.
- *
- * The internal structure must be freed with #LSUP_triple_done after use.
- *
- * @param sspo[in] Buffer triple to be serialized.
- * @param spo[out] RDF triple handle. It must point to an already allocated
- * structure.
- *
- * @return LSUP_OK or an error code resulting from #LSUP_term_deserialize.
- */
- LSUP_rc
- LSUP_triple_deserialize(const LSUP_SerTriple *sspo, LSUP_Triple *spo);
- /** @brief Free the internal pointers of a triple.
- *
- * @param spo[in] Triple to be freed.
- */
- void
- LSUP_triple_done(LSUP_Triple *spo);
- /** @brief Free the internal pointers of a buffer triple.
- *
- * @param sspo[in] Buffer triple to be freed.
- */
- void
- LSUP_striple_done(LSUP_SerTriple *sspo);
- #define _FN_BODY \
- if (n == TRP_POS_S) return trp->s; \
- if (n == TRP_POS_P) return trp->p; \
- if (n == TRP_POS_O) return trp->o; \
- return NULL;
- /** @brief Get triple by term position.
- *
- * Useful for looping over all terms.
- *
- * @param trp[in] Triple pointer.
- *
- * @param n[in] A number between 0÷2.
- *
- * @return Corresponding triple term or NULL if n is out of range.
- */
- inline LSUP_Term *
- LSUP_triple_pos(const LSUP_Triple *trp, LSUP_TriplePos n)
- { _FN_BODY }
- /** @brief Get serialized triple by term position.
- *
- * Useful for looping over all terms.
- *
- * @param trp[in] Serialized triple pointer.
- *
- * @param n[in] A number between 0÷2.
- *
- * @return Corresponding serialized term or NULL if n is out of range.
- */
- inline LSUP_Buffer *
- LSUP_striple_pos(const LSUP_SerTriple *trp, LSUP_TriplePos n)
- { _FN_BODY }
- #undef _FN_BODY
- #endif
|