15 # include <vcl_msvc_warnings.h> 23 t->
children.push_back( i->get_tree() );
30 fields.insert(std::make_pair(str, field));
38 for (
auto node : *field_defs)
40 if (node && node->is_field_definition()) {
46 std::cerr <<
"vil_nitf2_field_sequence:create_array_fields(): Error created required std::vector field " 47 << field_def->
tag <<
"; bailing out.\n";
50 }
else if (node && node->is_repeat_node()) {
57 std::cerr <<
"vil_nitf2_field_sequence::create_array_fields(): unsupported node type!\n";
68 for (
auto node : *field_defs)
70 if (node && node->is_field_definition()) {
74 VIL_NITF2_LOG(log_debug) <<
" (Setting tag " << field_def->
tag <<
" dimension " 75 << index <<
" to " << repeat_count <<
".)" << std::endl;
78 std::cerr <<
"vil_nitf2_field_sequence:set_array_field_dimension(): array field " 79 << field_def->
tag <<
" not found!\n";
81 }
else if (node && node->is_repeat_node()) {
86 std::cerr <<
"vil_nitf2_field_sequence::set_array_fields_dimension(): unsupported node type!\n";
98 std::cerr <<
"vil_nitf2_field_sequence::read() missing field definitions!\n";
100 for (
auto node : *field_defs)
102 if (node && node->is_field_definition())
112 bool conditionValid = (*(field_def->
condition_functor))(
this, indexes, condition);
113 if (conditionValid) {
114 field_exists = condition;
118 std::cerr <<
"vil_nitf2_field_sequence::read(): Cannot evaluate condition for tag " << field_def->
tag <<
'\n';
126 int variable_width = -1;
128 bool computed_width = (*(field_def->
width_functor))(
this, indexes, variable_width);
129 if (!computed_width) {
132 std::cerr <<
"vil_nitf2_field_sequence::read(): Cannot evaluate width functor for tag " << field_def->
tag <<
'\n';
137 if (variable_width == 0) {
138 VIL_NITF2_LOG(log_debug) <<
"Skipping field " << field_def->
tag <<
", whose length = 0." << std::endl;
144 if (indexes.size()==0) {
151 if ( fieldReadError ){
158 bool read_error =
true;
169 std::cerr <<
"vil_nitf2_field_sequence::read(): Couldn't find std::vector field!\n";
178 else if (node && node->is_repeat_node())
183 int repeat_count = 0;
184 bool computed_repeat =
false;
186 computed_repeat = (*(repeat_node->
repeat_functor))(
this, indexes, repeat_count);
188 if (!computed_repeat) {
191 std::cerr <<
"Cannot evaluate repeat count for repeat node\n";
208 if (indexes.size() == 0) {
214 std::string nesting_level_indicator((indexes.size()+1)*2,
'-');
216 <<
"Repeating fields " << repeat_count <<
" times:" << std::endl;
217 for (
int i=0; i<repeat_count; ++i)
237 nested_indexes.push_back(i);
242 VIL_NITF2_LOG(log_debug) << nesting_level_indicator <<
"End repeating fields." << std::endl;
245 std::cerr <<
"vil_nitf2_tagged_record::read(): unsupported node.\n";
258 std::cerr <<
"vil_nitf2_field_sequence::write(): Missing field definitions!\n";
259 for (
auto node : *field_defs)
261 if (node && node->is_field_definition())
265 std::cerr <<
"vil_nitf2_field_sequence::write(): Missing field definition!\n";
276 expected |= condition;
278 std::cerr <<
"vil_nitf2_field_sequence::write(): Cound not evaluate condition for field " 279 << field_def->
tag << std::endl;
285 if (field && !expected) {
286 std::cerr <<
"vil_nitf2_field_sequence::write(): Field " << field_def->
tag 287 <<
" is being ignored because its condition is not satisfied.\n";
292 int variable_width = -1;
294 bool computed_width = (*(field_def->
width_functor))(
this, indexes, variable_width);
295 if (!computed_width) {
298 std::cerr <<
"vil_nitf2_field_sequence::write(): Cannot evaluate width functor for tag " << field_def->
tag << std::endl;
302 if (variable_width == 0) {
303 VIL_NITF2_LOG(log_debug) <<
"Skipping field " << field_def->
tag <<
", whose length = 0." << std::endl;
307 if (!field && expected) {
309 std::cerr <<
"vil_nitf2_field_sequence::write(): Field " << field_def->
tag 310 <<
" is unspecified; writing blanks.\n";
312 if (variable_width > 0)
325 else if (node && node->is_repeat_node())
329 int repeat_count = 0;
330 bool computed_repeat =
false;
332 computed_repeat = (*(repeat_node->
repeat_functor))(
this, indexes, repeat_count);
334 if (!computed_repeat) {
337 std::cerr <<
"vil_nitf2_field_sequence::write(): Cannot evaluate repeat count for repeat node\n";
341 for (
int i=0; i < repeat_count; ++i) {
343 nested_indexes.push_back(i);
348 std::cerr <<
"vil_nitf2_field_sequence::write(): Ignoring unsupported node.\n";
357 for (
auto & field_map_entry :
fields)
366 auto field_map_entry =
fields.find(tag);
367 if (field_map_entry ==
fields.end())
369 return field_map_entry->second;
373 #define NITF_FIELD_SEQ_GET_VALUE(T) \ 374 bool vil_nitf2_field_sequence::get_value(std::string tag, T& out_value) const { \ 375 vil_nitf2_field* field = get_field(tag); \ 376 vil_nitf2_scalar_field* scalar_field = field ? field->scalar_field() : 0; \ 377 if (!scalar_field) { \ 381 if (!scalar_field->value(out_value)) { \ 382 std::cerr << "vil_nitf2_field_sequence::get_value(" << tag << ") called with wrong type.\n"; \ 397 #define NITF_FIELD_SEQ_GET_ARRAY_VALUE(T) \ 398 bool vil_nitf2_field_sequence::get_value(std::string tag, \ 399 const vil_nitf2_index_vector& indexes, \ 401 bool ignore_extra_indexes) const { \ 402 vil_nitf2_field* field = get_field(tag); \ 407 vil_nitf2_index_vector trimmed_indexes(indexes); \ 408 if (ignore_extra_indexes && (int)indexes.size() > field->num_dimensions()) { \ 409 trimmed_indexes.resize(field->num_dimensions()); \ 411 if (trimmed_indexes.size()==0) { \ 412 return field->scalar_field() && field->scalar_field()->value(out_value); \ 414 return field->array_field()->value(trimmed_indexes, out_value); \ 429 #define NITF_FIELD_SEQ_GET_VALUES(T) \ 430 bool vil_nitf2_field_sequence::get_values(std::string tag, \ 431 const vil_nitf2_index_vector& indexes, \ 432 std::vector<T>& out_values, \ 433 bool clear_out_values) const \ 435 vil_nitf2_field* field = get_field(tag); \ 440 if (clear_out_values) { \ 441 out_values.clear(); \ 443 int num_dims = field->num_dimensions(); \ 444 if (num_dims == (int)indexes.size()) { \ 447 if (get_value(tag, indexes, value, false)) { \ 448 out_values.push_back(value); \ 454 vil_nitf2_array_field* array_field = field->array_field(); \ 455 if (!array_field) { \ 460 int dimension = array_field->next_dimension(indexes); \ 461 for (int index=0; index < dimension; ++index) { \ 462 vil_nitf2_index_vector next_indexes = indexes; \ 463 next_indexes.push_back(index); \ 464 if (!get_values(tag, next_indexes, out_values, false)) { \ 472 bool vil_nitf2_field_sequence::get_values(std::string tag, std::vector<T>& out_values) const \ 474 return get_values(tag, vil_nitf2_index_vector(), out_values, true); \ virtual ~vil_nitf2_field_sequence()
vxl_int_32 vil_nitf2_long
vil_nitf2_field_functor< int > * width_functor
bool read(vil_nitf2_istream &input, const vil_nitf2_field_definitions *field_defs=nullptr, const vil_nitf2_index_vector &indexes=vil_nitf2_index_vector())
bool create_array_fields(const vil_nitf2_field_definitions *field_defs, int num_dimensions)
vil_nitf2_scalar_field * scalar_field()
void set_array_fields_dimension(const vil_nitf2_field_definitions *field_defs, const vil_nitf2_index_vector &index, int repeat_count)
vil_nitf2_array_field * array_field()
vil_nitf2_field_definitions * field_definitions
#define VIL_NITF2_LOG(LEVEL)
#define NITF_FIELD_SEQ_GET_VALUES(T)
#define NITF_FIELD_SEQ_GET_VALUE(T)
bool write(vil_nitf2_ostream &output, int variable_width=-1) const
virtual bool write(vil_nitf2_ostream &, const vil_nitf2_field_definitions *field_defs=nullptr, vil_nitf2_index_vector indexes=vil_nitf2_index_vector())
vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of Stellar Science Ltd.
Stream interface for VIL image loaders.
std::vector< vil_nitf2_field * > fields_vector
#define NITF_FIELD_SEQ_GET_ARRAY_VALUE(T)
vil_nitf2_field * get_field(const std::string &tag) const
virtual bool read_vector_element(vil_nitf2_istream &input, const vil_nitf2_index_vector &indexes, int variable_width)=0
Reads from input stream the scalar value at specified index.
vil_nitf2_field_definition_repeat_node * repeat_node()
virtual bool write_vector_element(vil_nitf2_ostream &output, const vil_nitf2_index_vector &indexes, int variable_width) const =0
Writes to output stream the scalar value at specified index.
const vil_nitf2_field_definitions * m_field_definitions
std::vector< field_tree * > children
Abstract class for array fields, i.e., fields that occur within a repeat loop.
void insert_field(const std::string &str, vil_nitf2_field *field)
vil_nitf2_field_formatter * formatter
vil_nitf2_field_functor< int > * repeat_functor
void set_next_dimension(const vil_nitf2_index_vector &indexes, int bound)
Given a partial index vector, set the value of the next dimension.
virtual vil_nitf2_field::field_tree * get_tree(vil_nitf2_field::field_tree *tr=nullptr) const
vil_nitf2_field_functor< bool > * condition_functor
vil_nitf2_field_definition * field_definition()
static vil_nitf2_scalar_field * read(vil_nitf2_istream &input, vil_nitf2_field_definition *definition, int variable_width=-1, bool *error=nullptr)