nitf_TextSubheader_clone(nitf_TextSubheader * source, nitf_Error * error) { nitf_TextSubheader *subhdr = NULL; if (source) { subhdr = (nitf_TextSubheader *) NITF_MALLOC(sizeof(nitf_TextSubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); if (!subhdr->securityGroup) goto CATCH_ERROR; /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_TE); _NITF_CLONE_FIELD(subhdr, source, NITF_TEXTID); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTALVL); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTDT); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTITL); _NITF_CLONE_FIELD(subhdr, source, NITF_TSCLAS); _NITF_CLONE_FIELD(subhdr, source, NITF_ENCRYP); _NITF_CLONE_FIELD(subhdr, source, NITF_TXTFMT); _NITF_CLONE_FIELD(subhdr, source, NITF_TXSHDL); _NITF_CLONE_FIELD(subhdr, source, NITF_TXSOFL); /* init to NULL in case */ subhdr->extendedSection = NULL; if (source->extendedSection) { subhdr->extendedSection = nitf_Extensions_clone(source->extendedSection, error); if (!subhdr->extendedSection) goto CATCH_ERROR; } return subhdr; } CATCH_ERROR: nitf_TextSubheader_destruct(&subhdr); return NULL; }
nitf_RESubheader_clone(nitf_RESubheader * source, nitf_Error * error) { nitf_Uint32 subLen; nitf_RESubheader *subhdr = NULL; if (source) { subhdr = (nitf_RESubheader *) NITF_MALLOC(sizeof(nitf_RESubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); if (!subhdr->securityGroup) goto CATCH_ERROR; /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_RE); _NITF_CLONE_FIELD(subhdr, source, NITF_RESTAG); _NITF_CLONE_FIELD(subhdr, source, NITF_RESVER); _NITF_CLONE_FIELD(subhdr, source, NITF_RESCLAS); /* And some ints */ _NITF_CLONE_FIELD(subhdr, source, NITF_RESSHL); subhdr->dataLength = source->dataLength; subhdr->subheaderFields = NULL; NITF_TRY_GET_UINT32(source->subheaderFieldsLength, &subLen, error); if (source->subheaderFields) { subhdr->subheaderFields = (char* )NITF_MALLOC(subLen); if (!subhdr->subheaderFields) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } memcpy(subhdr->subheaderFields, source->subheaderFields, subLen); } return subhdr; } CATCH_ERROR: return NULL; }
NITFPROT(nitf_BandInfo *) nitf_BandInfo_clone(nitf_BandInfo * source, nitf_Error * error) { /* Start with a NULL pointer */ nitf_BandInfo *info = NULL; if (source) { info = (nitf_BandInfo *) NITF_MALLOC(sizeof(nitf_BandInfo)); if (!info) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } /* This must occur before cloning, in case an error */ /* occurs and the object must be destructed */ info->lut = NULL; _NITF_CLONE_FIELD(info, source, NITF_IREPBAND); _NITF_CLONE_FIELD(info, source, NITF_ISUBCAT); _NITF_CLONE_FIELD(info, source, NITF_IFC); _NITF_CLONE_FIELD(info, source, NITF_IMFLT); _NITF_CLONE_FIELD(info, source, NITF_NLUTS); _NITF_CLONE_FIELD(info, source, NITF_NELUT); if (source->lut) { info->lut = nitf_LookupTable_clone(source->lut, error); } return info; } CATCH_ERROR: return NULL; }
nitf_GraphicSubheader_clone(nitf_GraphicSubheader * source, nitf_Error * error) { nitf_GraphicSubheader *subhdr = NULL; if (source) { subhdr = (nitf_GraphicSubheader *) NITF_MALLOC(sizeof(nitf_GraphicSubheader)); if (!subhdr) { nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); return NULL; } subhdr->securityGroup = nitf_FileSecurity_clone(source->securityGroup, error); /* Copy some fields */ _NITF_CLONE_FIELD(subhdr, source, NITF_SY); _NITF_CLONE_FIELD(subhdr, source, NITF_SID); _NITF_CLONE_FIELD(subhdr, source, NITF_SNAME); _NITF_CLONE_FIELD(subhdr, source, NITF_SSCLAS); _NITF_CLONE_FIELD(subhdr, source, NITF_ENCRYP); _NITF_CLONE_FIELD(subhdr, source, NITF_SFMT); _NITF_CLONE_FIELD(subhdr, source, NITF_SSTRUCT); _NITF_CLONE_FIELD(subhdr, source, NITF_SDLVL); _NITF_CLONE_FIELD(subhdr, source, NITF_SALVL); _NITF_CLONE_FIELD(subhdr, source, NITF_SLOC); _NITF_CLONE_FIELD(subhdr, source, NITF_SBND1); _NITF_CLONE_FIELD(subhdr, source, NITF_SCOLOR); _NITF_CLONE_FIELD(subhdr, source, NITF_SBND2); _NITF_CLONE_FIELD(subhdr, source, NITF_SRES2); _NITF_CLONE_FIELD(subhdr, source, NITF_SXSHDL); _NITF_CLONE_FIELD(subhdr, source, NITF_SXSOFL); /* init to NULL for safety */ subhdr->extendedSection = NULL; if (source->extendedSection) { subhdr->extendedSection = nitf_Extensions_clone(source->extendedSection, error); if (!subhdr->extendedSection) goto CATCH_ERROR; } return subhdr; } CATCH_ERROR: nitf_GraphicSubheader_destruct(&subhdr); return NULL; }