示例#1
0
NITFAPI(nitf_TREPrivateData *) nitf_TREPrivateData_construct(
        nitf_Error * error)
{
    nitf_TREPrivateData *priv = (nitf_TREPrivateData*) NITF_MALLOC(
            sizeof(nitf_TREPrivateData));
    if (!priv)
    {
        nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO),
                        NITF_CTXT, NITF_ERR_MEMORY);
        return NULL;
    }

    priv->length = 0;
    priv->descriptionName = NULL;
    priv->description = NULL;
    priv->userData = NULL;

    /* create the hashtable for the fields */
    priv->hash = nitf_HashTable_construct(NITF_TRE_HASH_SIZE, error);

    if (!priv->hash)
    {
        nitf_TREPrivateData_destruct(&priv);
        return NULL;
    }

    /* ??? change policy? */
    nitf_HashTable_setPolicy(priv->hash, NITF_DATA_ADOPT);

    return priv;
}
示例#2
0
NITFPROT(NITF_BOOL) nitf_TREPrivateData_flush(nitf_TREPrivateData *priv,
                                         nitf_Error * error)
{
    if (priv && priv->hash)
    {
        /* destruct each field in the hash */
        nitf_HashTable_foreach(priv->hash,
                               (NITF_HASH_FUNCTOR) destructHashValue,
                               NULL, error);
        /* destruct the hash */
        nitf_HashTable_destruct(&(priv->hash));

    }

    /* create the hashtable for the fields */
    priv->hash = nitf_HashTable_construct(NITF_TRE_HASH_SIZE, error);

    if (!priv->hash)
    {
        nitf_TREPrivateData_destruct(&priv);
        return NITF_FAILURE;
    }

    nitf_HashTable_setPolicy(priv->hash, NITF_DATA_ADOPT);

    return NITF_SUCCESS;
}
示例#3
0
NITFPRIV(nitf_PluginRegistry *) implicitConstruct(nitf_Error * error)
{
    size_t pathLen;
    const char *pluginEnvVar;

    /*  Create the registry object  */
    nitf_PluginRegistry *reg =
        (nitf_PluginRegistry *) NITF_MALLOC(sizeof(nitf_PluginRegistry));

    /*  If we have a memory problem, init our error struct and return  */
    if (!reg)
    {
        nitf_Error_init(error,
                        NITF_STRERROR(NITF_ERRNO),
                        NITF_CTXT, NITF_ERR_MEMORY);
        return NULL;
    }

    /* set these to NULL to possibly protect us later */
    reg->compressionHandlers = NULL;
    reg->treHandlers = NULL;
    reg->decompressionHandlers = NULL;
    reg->dsos = NULL;

    reg->dsos = nitf_List_construct(error);
    if (!reg->dsos)
    {
        implicitDestruct(&reg);
        return NULL;
    }


    /*  Construct our hash object  */
    reg->treHandlers = nitf_HashTable_construct(NITF_TRE_HASH_SIZE, error);

    /*  If we have a problem, get rid of this object and return  */
    if (!reg->treHandlers)
    {
        implicitDestruct(&reg);
        return NULL;
    }

    /* do not adopt the data - we will clean it up ourselves */
    nitf_HashTable_setPolicy(reg->treHandlers, NITF_DATA_RETAIN_OWNER);

    reg->compressionHandlers =
        nitf_HashTable_construct(NITF_COMPRESSION_HASH_SIZE, error);


    /*  If we have a problem, get rid of this object and return  */
    if (!reg->compressionHandlers)
    {
        implicitDestruct(&reg);
        return NULL;
    }

    /* do not adopt the data - we will clean it up ourselves */
    nitf_HashTable_setPolicy(reg->compressionHandlers, NITF_DATA_RETAIN_OWNER);

    reg->decompressionHandlers =
        nitf_HashTable_construct(NITF_DECOMPRESSION_HASH_SIZE, error);

    /*  If we have a problem, get rid of this object and return  */
    if (!reg->decompressionHandlers)
    {
        implicitDestruct(&reg);
        return NULL;
    }

    /* do not adopt the data - we will clean it up ourselves */
    nitf_HashTable_setPolicy(reg->decompressionHandlers,
                             NITF_DATA_RETAIN_OWNER);

    /*  Start with a clean slate  */
    memset(reg->path, 0, NITF_MAX_PATH);

    /*  Take the environment variable, or...  */
    pluginEnvVar = getenv(NITF_PLUGIN_PATH);
    if (!pluginEnvVar)
    {
        /*  Take the default path  */
        /*strcpy(reg->path, NITF_DEFAULT_PLUGIN_PATH);*/
        return reg;
    }
    else
    {
        strcpy(reg->path, pluginEnvVar);
    }
    /*
     * If the we have a user-defined path, they might not
     * have terminated their environment variable with a
     * trailing delimiter.  No problem, we can do it for them.
     */
    pathLen = strlen(reg->path);
    if (pathLen > 0 && !isDelimiter(reg->path[pathLen - 1]))
    {
        /*  Need to append delimiter to end  */
        reg->path[pathLen++] = DIR_DELIMITER;
        reg->path[pathLen++] = '\0';
    }

    /*  Return the object, its okay!  */
    return reg;
}
示例#4
0
void nitf::HashTable::setPolicy(int policy)
{
    nitf_HashTable_setPolicy(getNative(), policy);
}