Esempio n. 1
0
NITFPRIV(void) polyDestroy(NITF_DATA* data)
{
    /* TODO!! */
    cgm_PolyLineElement* poly = (cgm_PolyLineElement*)data;
    nitf_ListIterator it, end;

    nitf_List* list = (nitf_List*)poly->vertices;

    if (poly->attributes)
        cgm_LineAttributes_destruct( &(poly->attributes) );

    it = nitf_List_begin(list);
    end = nitf_List_end(list);

    while (nitf_ListIterator_notEqualTo(&it, &end))
    {
        cgm_Vertex* v = (cgm_Vertex*)nitf_ListIterator_get(&it);
        cgm_Vertex_destruct(&v);
        nitf_ListIterator_increment(&it);
    }

    nitf_List_destruct(&list);

    NITF_FREE(data);
}
Esempio n. 2
0
NITFAPI(void) cgm_PictureBody_destruct(cgm_PictureBody** body)
{
    if (*body)
    {
        if ( (*body)->elements )
        {
            nitf_List_destruct( & (*body)->elements );
        }
        if ( (*body)->auxColor )
        {
            cgm_Color_destruct(&((*body)->auxColor));
        }
        NITF_FREE( *body );
        *body = NULL;
    }
}
Esempio n. 3
0
NITFPRIV(void) implicitDestruct(nitf_PluginRegistry ** reg)
{

    /*  If it is not NULL set  */
    if (*reg)
    {
        if ((*reg)->dsos)
            nitf_List_destruct(&(*reg)->dsos);

        if ((*reg)->treHandlers)
            nitf_HashTable_destruct(&(*reg)->treHandlers);
        if ((*reg)->compressionHandlers)
            nitf_HashTable_destruct(&(*reg)->compressionHandlers);
        if ((*reg)->decompressionHandlers)
            nitf_HashTable_destruct(&(*reg)->decompressionHandlers);
        NITF_FREE(*reg);
        *reg = NULL;
    }
}
Esempio n. 4
0
NITFPRIV(int) nitf_TRECursor_evaluatePostfix(nitf_TRE *tre,
                                             char idx[10][10],
                                             int looping,
                                             char *expression,
                                             nitf_Error *error)
{
    nitf_List *parts = NULL;
    nitf_IntStack *stack = NULL;
    int expressionValue;

    /* create the postfix stack */
    stack = nitf_IntStack_construct(error);
    if (!stack)
        goto CATCH_ERROR;

    /* split the expression by spaces */
    parts = nitf_Utils_splitString(expression, 0, error);
    if (!parts)
        goto CATCH_ERROR;

    while(!nitf_List_isEmpty(parts))
    {
        char* expr = (char*) nitf_List_popFront(parts);
        if (strlen(expr) == 1 &&
                (expr[0] == '+' || expr[0] == '-' || expr[0] == '*' ||
                        expr[0] == '/' || expr[0] == '%'))
        {
            int op1, op2, stackSize;
            stackSize = nitf_IntStack_depth(stack, error) + 1;

            if (stackSize == 0)
            {
                /* error for postfix... */
                nitf_Error_init(error,
                        "nitf_TRECursor_evaluatePostfix: invalid expression",
                        NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                goto CATCH_ERROR;
            }

            op2 = nitf_IntStack_pop(stack, error);
            if (stackSize == 1)
                op1 = 0; /* assume 0 for the first operand of a unary op */
            else
                op1 = nitf_IntStack_pop(stack, error);

            switch(expr[0])
            {
            case '+':
                nitf_IntStack_push(stack, (op1 + op2), error);
                break;
            case '-':
                nitf_IntStack_push(stack, (op1 - op2), error);
                break;
            case '*':
                nitf_IntStack_push(stack, (op1 * op2), error);
                break;
            case '/':
                /* check for divide by zero */
                if (op2 == 0)
                {
                    nitf_Error_init(error,
                            "nitf_TRECursor_evaluatePostfix: attempt to divide by zero",
                            NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                    goto CATCH_ERROR;
                }
                nitf_IntStack_push(stack, (op1 / op2), error);
                break;
            case '%':
                nitf_IntStack_push(stack, (op1 % op2), error);
                break;
            }
        }
        else
        {
            /* evaluate as an integer and push onto the stack */
            if (nitf_Utils_isNumeric(expr))
            {
                nitf_IntStack_push(stack, NITF_ATO32(expr), error);
            }
            else
            {
                /* must be a dependent field */
                int intVal;
                nitf_Field *field = NULL;
                nitf_Pair *pair = nitf_TRECursor_getTREPair(tre, expr, idx,
                        looping, error);

                if (!pair)
                {
                    nitf_Error_init(error,
                            "nitf_TRECursor_evaluatePostfix: invalid TRE field reference",
                            NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
                    goto CATCH_ERROR;
                }
                field = (nitf_Field *) pair->data;

                /* get the int value */
                if (!nitf_Field_get(field, (char*) &intVal, NITF_CONV_INT,
                         sizeof(intVal), error))
                {
                    goto CATCH_ERROR;
                }
                nitf_IntStack_push(stack, intVal, error);
            }
        }

        /* must cleanup after ourselves */
        if (expr)
            NITF_FREE(expr);
    }

    /* if all is well, the postfix stack should have one value */
    if (nitf_IntStack_depth(stack, error) != 0)
    {
        nitf_Error_init(error, "Invalid postfix expression",
                NITF_CTXT, NITF_ERR_INVALID_PARAMETER);
        goto CATCH_ERROR;
    }

    expressionValue = nitf_IntStack_pop(stack, error);

    nitf_IntStack_destruct(&stack);
    nitf_List_destruct(&parts);

    return expressionValue;

  CATCH_ERROR:
    if (stack) nitf_IntStack_destruct(&stack);
    if (parts) nitf_List_destruct(&parts);
    return -1;
}