-
Notifications
You must be signed in to change notification settings - Fork 37
IterTres15C
anna-dodd edited this page Jun 3, 2015
·
1 revision
nitf_HashTableIterator it = nitf_HashTable_begin(tre->hash);
nitf_HashTableIterator end = nitf_HashTable_end(tre->hash);
while (nitf_HashTableIterator_notEqualTo(&it, &end))
{
nitf_Pair* pair = nitf_HashTableIterator_get(&it);
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
nitf_HashTableIterator_increment(&it);
}
nitf_HashTableIterator end = nitf_HashTable_end(tre->hash);
while (nitf_HashTableIterator_notEqualTo(&it, &end))
{
nitf_Pair* pair = nitf_HashTableIterator_get(&it);
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
nitf_HashTableIterator_increment(&it);
}
The second method of TRE traversal is to use the foreach() function:
/*
int doSomething(nitf_HashTable* ht, nitf_Pair* pair, NITF_DATA* userData, nitf_Error* error)
{
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
}
*/
...
nitf_HashTable_foreach(tre->hash, (NITF_HASH_FUNCTOR)doSomething, NULL, &error);
int doSomething(nitf_HashTable* ht, nitf_Pair* pair, NITF_DATA* userData, nitf_Error* error)
{
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
}
*/
...
nitf_HashTable_foreach(tre->hash, (NITF_HASH_FUNCTOR)doSomething, NULL, &error);
The third, most intrusive method, does return the TRE fields in order. It is very different from the 2.0 API. You should never attempt to use this API when using version 2.0 of the library!
nitf_Pair* pair;
nitf_TRECursor cursor;
int status = NITF_SUCCESS;
cursor = nitf_TRE_begin(tre);
while (!nitf_TRE_isDone(&cursor, error) && (status == NITF_SUCCESS))
{
if ((status = nitf_TRE_iterate(&cursor, error)) == NITF_SUCCESS))
{
pair = nitf_HashTable_find(tre->hash, cursor.tag_str);
if (!pair)
{
/* Handle no field found */
}
else
{
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
}
}
}
nitf_TRECursor cursor;
int status = NITF_SUCCESS;
cursor = nitf_TRE_begin(tre);
while (!nitf_TRE_isDone(&cursor, error) && (status == NITF_SUCCESS))
{
if ((status = nitf_TRE_iterate(&cursor, error)) == NITF_SUCCESS))
{
pair = nitf_HashTable_find(tre->hash, cursor.tag_str);
if (!pair)
{
/* Handle no field found */
}
else
{
nitf_Field* f = (nitf_Field*)pair->data;
nitf_Field_print(f);
}
}
}
If you just want to dump the contents of the TRE, you can use the print() method:
if (!nitf_TRE_print(tre, &error))
{
/* Handle error */
}
{
/* Handle error */
}