vil_nitf2_array_field.h
Go to the documentation of this file.
1 //:
2 // \file
3 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
4 // Stellar Science Ltd. Co. (stellarscience.com) for
5 // Air Force Research Laboratory, 2005.
6 
7 #ifndef VIL_NITF2_ARRAY_FIELD_H
8 #define VIL_NITF2_ARRAY_FIELD_H
9 
10 #include <map>
11 #include <string>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 #include "vil_nitf2_field.h"
16 #include "vil_nitf2_index_vector.h"
17 
19 
21 class vil_nitf2_location;
23 
24 //: Abstract class for array fields, i.e., fields that occur within a repeat loop.
25 // Since repeat loops can be nested, this field can be multi-dimensional.
26 // Its row dimensions don't even need to be same. One instance of this
27 // class "collects" all the values associated with a tag, even though they
28 // may be interleaved among other values in the NITF file. This class
29 // provides dimensional information and implements methods common to the
30 // type-specific subclasses.
31 
33 {
34  public:
35  // Constructor
38 
39  // Destructor
40  ~vil_nitf2_array_field() override = default;
41 
42  //: Number of dimensions.
43  // \returns this vector's number of dimensions, which equals
44  // its "repeat" nesting level.
45  int num_dimensions() const override;
46 
47  //: Given a partial index vector, set the value of the next dimension.
48  // Length of indexes must be less than num_dimensions(). See comment
49  // for member m_dimensions_map, below; indexes is its key. For example,
50  // if indexes is empty, the first dimension is set.
51  void set_next_dimension(const vil_nitf2_index_vector& indexes, int bound);
52 
53  //: Given a partial index vector, return value of next dimension (or zero if none).
54  // Length of indexes must be less than num_dimensions(). See comment
55  // for member m_dimensions_map, below; indexes is its key. For
56  // example, if indexes is empty, the first dimension is retrieved.
57  int next_dimension(const vil_nitf2_index_vector& indexes) const;
58 
59  //: Compares index vector against value dimensions.
60  bool check_index(const vil_nitf2_index_vector& indexes) const;
61 
62  //: Reads from input stream the scalar value at specified index.
63  // check_index(indexes) must be true, or this will emit an error.
64  // \returns success.
65  virtual bool read_vector_element(vil_nitf2_istream& input,
66  const vil_nitf2_index_vector& indexes,
67  int variable_width) = 0;
68 
69  //: Writes to output stream the scalar value at specified index.
70  // check_index(indexes) must be true, of this will emit an error.
71  // Returns success. Arg variable_width, if non-negative, overrides
72  // formatter's field_width.
74  const vil_nitf2_index_vector& indexes,
75  int variable_width) const = 0;
76 
77  field_tree* get_tree() const override;
78 
79  //:
80  // Sets out_value to the value of the element selected by specified
81  // index vector, which must satisfy check_index(). Returns true iff the
82  // value is defined. Note that this may return false because the value
83  // is unspecified (i.e., blank), even if the index is valid.
84  //
85  // Subclasses overload the appropriate method to set out parameter and
86  // return true. The implementation here return false. These methods are
87  // defined here for the convenience of my callers, so they don't have to
88  // downcast to the specific field type.
89 #if VXL_HAS_INT_64
90  virtual bool value(const vil_nitf2_index_vector&, vil_nitf2_long& ) const { return false; }
91 #endif
92  virtual bool value(const vil_nitf2_index_vector&, int& ) const { return false; }
93  virtual bool value(const vil_nitf2_index_vector&, double& ) const { return false; }
94  virtual bool value(const vil_nitf2_index_vector&, char& ) const { return false; }
95  virtual bool value(const vil_nitf2_index_vector&, void*& ) const { return false; }
96  virtual bool value(const vil_nitf2_index_vector&, std::string& ) const { return false; }
97  virtual bool value(const vil_nitf2_index_vector&, vil_nitf2_location*& ) const { return false; }
98  virtual bool value(const vil_nitf2_index_vector&, vil_nitf2_date_time& ) const { return false; }
99  virtual bool value(const vil_nitf2_index_vector&, vil_nitf2_tagged_record_sequence& ) const { return false; }
100 
101  protected:
102  void do_dimension( const vil_nitf2_index_vector& index,
103  vil_nitf2_field::field_tree* tr ) const;
104  std::string get_value_string(const vil_nitf2_index_vector& in_indices) const;
105 
106 
107  //: Dimensionality of vector field
109 
110  //:
111  // Because a repeating field's dimension can depend on the value of
112  // another repeating field, slices of a multi-dimensional vector field
113  // can have varying dimensions (for an example test case, see method
114  // vil_nitf2_tagged_record::test()). Dimensions are therefore stored
115  // here as follows:
116  // - m_dimensions_map[vector()] holds the first dimension;
117  // - m_dimensions_map[vector(i)] holds the second dimension of
118  // row i of a 2-or-more-dimensional vector;
119  // - m_dimensions_map[vector(i,j)] holds the third dimension of
120  // plane (i,j) of a 3-or-more-dimensional vector;
121  // and so on, according dimensionality of the field.
122  std::map<vil_nitf2_index_vector, int> m_dimensions_map;
123 };
124 
125 #endif // VIL_NITF2_ARRAY_FIELD_H
virtual bool value(const vil_nitf2_index_vector &, void *&) const
vxl_int_32 vil_nitf2_long
Definition: vil_nitf2.h:26
virtual bool value(const vil_nitf2_index_vector &, std::string &) const
int next_dimension(const vil_nitf2_index_vector &indexes) const
Given a partial index vector, return value of next dimension (or zero if none).
void do_dimension(const vil_nitf2_index_vector &index, vil_nitf2_field::field_tree *tr) const
vil_nitf2_array_field(vil_nitf2_field_definition *definition, int num_dimensions)
virtual bool value(const vil_nitf2_index_vector &, vil_nitf2_tagged_record_sequence &) const
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
bool check_index(const vil_nitf2_index_vector &indexes) const
Compares index vector against value dimensions.
virtual bool value(const vil_nitf2_index_vector &, char &) const
virtual bool value(const vil_nitf2_index_vector &, double &) 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.
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.
virtual bool value(const vil_nitf2_index_vector &, int &) const
Sets out_value to the value of the element selected by specified index vector, which must satisfy che...
Abstract class for array fields, i.e., fields that occur within a repeat loop.
std::string get_value_string(const vil_nitf2_index_vector &in_indices) const
virtual bool value(const vil_nitf2_index_vector &, vil_nitf2_date_time &) const
virtual std::ostream & output(std::ostream &os) const =0
virtual bool value(const vil_nitf2_index_vector &, vil_nitf2_location *&) const
void set_next_dimension(const vil_nitf2_index_vector &indexes, int bound)
Given a partial index vector, set the value of the next dimension.
field_tree * get_tree() const override
int m_num_dimensions
Dimensionality of vector field.
~vil_nitf2_array_field() override=default
int num_dimensions() const override
Number of dimensions.
std::map< vil_nitf2_index_vector, int > m_dimensions_map
Because a repeating field's dimension can depend on the value of another repeating field,...