switch (ctxt->ctxt_type) {
case REC_INDI:
- individual_add_association(ctxt, assoc);
+ ADDFUNC2(individual,association)(ctxt, assoc);
default:
UNEXPECTED_CONTEXT(ctxt->ctxt_type);
}
return (Gedcom_ctxt)result;
}
-STRING_CB(association, sub_assoc_rela_start, relation)
+DEFINE_STRING_CB(association, sub_assoc_rela_start, relation)
+
+DEFINE_ADDFUNC2(association, note_sub, note)
+DEFINE_ADDFUNC2(association, source_citation, citation)
+DEFINE_ADDFUNC2(association, user_data, extra)
Gedcom_ctxt sub_assoc_type_start(_ELT_PARAMS_)
{
def_elt_end);
}
-void association_add_note(Gom_ctxt ctxt, struct note_sub* note)
+void CLEANFUNC(association)(struct association* assoc)
{
- struct association *assoc = SAFE_CTXT_CAST(association, ctxt);
- if (assoc)
- LINK_CHAIN_ELT(note_sub, assoc->note, note);
+ if (assoc) {
+ SAFE_FREE(assoc->type);
+ SAFE_FREE(assoc->relation);
+ DESTROY_CHAIN_ELTS(note_sub, assoc->note);
+ DESTROY_CHAIN_ELTS(source_citation, assoc->citation);
+ DESTROY_CHAIN_ELTS(user_data, assoc->extra);
+ }
}
-void association_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
+int write_associations(Gedcom_write_hndl hndl, int parent,
+ struct association *assoc)
{
- struct association *assoc = SAFE_CTXT_CAST(association, ctxt);
- if (assoc)
- LINK_CHAIN_ELT(source_citation, assoc->citation, cit);
-}
+ int result = 0;
+ struct association* obj;
-void association_add_user_data(Gom_ctxt ctxt, struct user_data* data)
-{
- struct association *obj = SAFE_CTXT_CAST(association, ctxt);
- if (obj)
- LINK_CHAIN_ELT(user_data, obj->extra, data);
-}
+ if (!assoc) return 1;
-void association_cleanup(struct association* assoc)
-{
- if (assoc) {
- SAFE_FREE(assoc->type);
- SAFE_FREE(assoc->relation);
- DESTROY_CHAIN_ELTS(note_sub, assoc->note, note_sub_cleanup);
- DESTROY_CHAIN_ELTS(source_citation, assoc->citation, citation_cleanup);
- DESTROY_CHAIN_ELTS(user_data, assoc->extra, user_data_cleanup);
+ for (obj = assoc; obj; obj = obj->next) {
+ result |= gedcom_write_element_xref(hndl, ELT_SUB_ASSO, 0, parent,
+ obj->to);
+ if (obj->type)
+ result |= gedcom_write_element_str(hndl, ELT_SUB_ASSO_TYPE, 0, parent,
+ obj->type);
+ if (obj->relation)
+ result |= gedcom_write_element_str(hndl, ELT_SUB_ASSO_RELA, 0, parent,
+ obj->relation);
+ if (obj->citation)
+ result |= write_citations(hndl, ELT_SUB_ASSO, obj->citation);
+ if (obj->note)
+ result |= write_note_subs(hndl, ELT_SUB_ASSO, obj->note);
+ if (obj->extra)
+ result |= write_user_data(hndl, obj->extra);
}
+
+ return result;
}