core/vil/file_formats/vil_nitf2_field_functor.cxx
Go to the documentation of this file.
00001 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for 
00003 // Air Force Research Laboratory, 2005.
00004 
00005 #include "vil_nitf2_field_functor.h"
00006 #include "vil_nitf2_tagged_record.h"
00007 #include "vil_nitf2_field.h"
00008 #include "vil_nitf2_index_vector.h"
00009 
00010 bool vil_nitf2_field_specified::
00011 operator() (vil_nitf2_field_sequence* record, 
00012             const vil_nitf2_index_vector& indexes, bool& result) 
00013 {
00014   if (!record->find_field_definition(tag)) {
00015     // Invalid tag
00016     return false;
00017   } 
00018   vil_nitf2_field* field = record->get_field(tag);
00019   if (field != 0) {
00020     vcl_string value;
00021     bool is_string_value = record->get_value(tag, indexes, value, true);
00022     if (is_string_value) {
00023       // a blank vcl_string field actually yields a valid field value (an empty 
00024       // vcl_string) so test the value
00025       result = !value.empty();
00026     } else {
00027       // other types of blank fields do not yield a field; since it
00028       // was found, it must not be blank
00029       result = false;
00030     }
00031   } else {
00032     // field not found; therefore the data was blank
00033     result = true;
00034   }
00035   return true;
00036 }
00037 
00038 bool vil_nitf2_max_field_value_plus_offset_and_threshold::
00039 operator() (vil_nitf2_field_sequence* record, 
00040             const vil_nitf2_index_vector& indexes, int& value) 
00041 {
00042   int value1 = 0;
00043   bool found = record->get_value(tag, indexes, value1, true);
00044   value1 *= tag_factor;
00045   value1 += offset;
00046   value = (value1 < min_threshold) ? min_threshold : value1;
00047   return found;
00048 }
00049 
00050 bool vil_nitf2_multiply_field_values::
00051 operator() (vil_nitf2_field_sequence* record, 
00052             const vil_nitf2_index_vector& indexes, int& value) {
00053   int value1, value2;
00054   bool found = record->get_value(tag_1, indexes, value1, true);
00055   found &= record->get_value(tag_2, indexes, value2, true);
00056   if (found) {
00057     value = value1 * value2;
00058     return true;
00059   } else {
00060     value = 0;
00061     return use_zero_if_tag_not_found;
00062   }
00063 }