vil_nitf2_field_sequence.h
Go to the documentation of this file.
1 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
2 // Stellar Science Ltd. Co. (stellarscience.com) for
3 // Air Force Research Laboratory, 2005.
4 
5 #ifndef VIL_NITF2_FIELD_SEQUENCE_H
6 #define VIL_NITF2_FIELD_SEQUENCE_H
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 // not used? #include <iostream>
15 
16 #include "vil_nitf2.h" // vil_nitf2_istream, vil_nitf2_ostream
17 #include "vil_nitf2_index_vector.h"
18 #include "vil_nitf2_field.h"
19 
22 class vil_nitf2_location;
25 
26 //-----------------------------------------------------------------------------
27 // vil_nitf2_field_sequence represents the values of a contiguous list of fields,
28 // such as found in a NITF file header, image subheader, or tagged record extension.
29 //
31 {
32  public:
33  // Constructor
35  : m_field_definitions(&field_definitions) {}
36 
37  // Destructor
38  virtual ~vil_nitf2_field_sequence();
39 
40  // Sets out_value to the value of field specified by tag.
41  // Returns 0 if such a field is not found or is of the wrong type.
42  bool get_value(std::string tag, int& out_value) const;
43  bool get_value(std::string tag, double& out_value) const;
44  bool get_value(std::string tag, char& out_value) const;
45  bool get_value(std::string tag, void*& out_value) const;
46  bool get_value(std::string tag, std::string& out_value) const;
47  bool get_value(std::string tag, vil_nitf2_location*& out_value) const;
48  bool get_value(std::string tag, vil_nitf2_date_time& out_value) const;
49  bool get_value(std::string tag, vil_nitf2_tagged_record_sequence& out_value) const;
50 #if VXL_HAS_INT_64
51  bool get_value(std::string tag, vil_nitf2_long& out_value) const;
52 #endif
53 
54  // Sets out_value to the value of the array field element specified by tag and index.
55  // Returns 0 if such a field is not found or is of the wrong type. If ignore_extra_indexes
56  // is true, then it trims indexes, if necessary to match the dimensionality of the vector.
57  // This option is used by vil_nitf2_field_functor so that when in a repeat loop, the
58  // value in the nearest enclosing scope will be used. For instance, if called with
59  // indexes (i,j), and if tag dimensionality equals 1, then value(i) will be returned.
60  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
61  int& out_value, bool ignore_extra_indexes = false) const;
62  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
63  double& out_value, bool ignore_extra_indexes = false) const;
64  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
65  char& out_value, bool ignore_extra_indexes = false) const;
66  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
67  void*& out_value, bool ignore_extra_indexes = false) const;
68  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
69  std::string& out_value, bool ignore_extra_indexes = false) const;
70  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
71  vil_nitf2_location*& out_value, bool ignore_extra_indexes = false) const;
72  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
73  vil_nitf2_date_time& out_value, bool ignore_extra_indexes = false) const;
74 #if VXL_HAS_INT_64
75  bool get_value(std::string tag, const vil_nitf2_index_vector& indexes,
76  vil_nitf2_long& out_value, bool ignore_extra_indexes = false) const;
77 #endif
78 
79  // Sets out_value to a flattened list of the values of the array field element
80  // specified by tag and index. If index is the empty vector, then out_values
81  // hold all instances of the field. If index partially specifies value instances,
82  // the out_values hold all instances of the field selected by the partial index.
83  // Appends to, instead of clearing, out_values if clear_out_values is false.
84  // Returns 0 if such a field is not found or is of the wrong type.
85  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
86  std::vector<int>& out_values, bool clear_out_values = true) const;
87  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
88  std::vector<double>& out_values, bool clear_out_values = true) const;
89  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
90  std::vector<char>& out_values, bool clear_out_values = true) const;
91  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
92  std::vector<void*>& out_values, bool clear_out_values = true) const;
93  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
94  std::vector<std::string>& out_values, bool clear_out_values = true) const;
95  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
96  std::vector<vil_nitf2_location*>& out_values, bool clear_out_values = true) const;
97  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
98  std::vector<vil_nitf2_date_time>& out_values, bool clear_out_values = true) const;
99 #if VXL_HAS_INT_64
100  bool get_values(std::string tag, const vil_nitf2_index_vector& indexes,
101  std::vector<vil_nitf2_long>& out_values, bool clear_out_values = true) const;
102 #endif
103 
104  // Convenience overload of preceding methods, that set out_values to all
105  // instances of array field element.
106  bool get_values(std::string tag, std::vector<int>& out_values) const;
107  bool get_values(std::string tag, std::vector<double>& out_values) const;
108  bool get_values(std::string tag, std::vector<char>& out_values) const;
109  bool get_values(std::string tag, std::vector<void*>& out_values) const;
110  bool get_values(std::string tag, std::vector<std::string>& out_values) const;
111  bool get_values(std::string tag, std::vector<vil_nitf2_location*>& out_values) const;
112  bool get_values(std::string tag, std::vector<vil_nitf2_date_time>& out_values) const;
113 #if VXL_HAS_INT_64
114  bool get_values(std::string tag, std::vector<vil_nitf2_long>& out_values) const;
115 #endif
116 
117 #if 0 //Not yet implemented.
118  // Sets the value of the integer-valued field specified by tag to value.
119  bool set_value(std::string tag, int value) { return false; }
120 #endif // 0
121 
122  // Returns a field with specified tag, or 0 if not found.
123  vil_nitf2_field* get_field(const std::string& tag) const;
124 
125  // Removes the field with the specified tag, returning whether successful.
126  // Not yet implemented.
127  //bool remove_field(std::string tag) { return false; }
128 
129  // Read field definition sequence from input stream. If this is called within
130  // a repeat node, then indexes must equal the indexes must equal the
131  // current repeat iteration(s) and field_defs must equal the repeat node's
132  // field definitions only.
133  bool read(vil_nitf2_istream& input,
134  const vil_nitf2_field_definitions* field_defs = nullptr,
136 
137  // Attempts to write field sequence to the output stream. Arg
138  // 'indexes' is used only during recursive calls to write nested sequences.
139  virtual bool write(vil_nitf2_ostream&,
140  const vil_nitf2_field_definitions* field_defs = nullptr,
142 
143  // Create vector fields for the specified field definitions with specified
144  // number of dimensions. Return success.
145  bool create_array_fields(const vil_nitf2_field_definitions* field_defs,
146  int num_dimensions);
147 
148  // Recursively set the specified dimension for vector fields to repeat_count.
150  const vil_nitf2_index_vector& index, int repeat_count);
151 
152  // Returns field definition if found
153  vil_nitf2_field_definition* find_field_definition(const std::string& tag);
154 
155  // I allocate the return value, but you own it after I return it to you
156  // so you need to delete it. If you pass in 'tr', then I'll add my stuff to that.
157  // otherwise I'll add a new one and return it. Either way, you own it.
158  virtual vil_nitf2_field::field_tree* get_tree( vil_nitf2_field::field_tree* tr = nullptr ) const;
159 
160  private:
161  void insert_field( const std::string& str, vil_nitf2_field* field);
162 
163  // Map of fields, indexed by field name
164  typedef std::map<std::string, vil_nitf2_field*> field_map;
166 
167  // Keeps track of the order in which fields are inserted into fields_map
168  std::vector<vil_nitf2_field*> fields_vector;
169 
171 };
172 
173 #endif // VIL_NITF2_FIELD_SEQUENCE_H
vxl_int_32 vil_nitf2_long
Definition: vil_nitf2.h:26
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)
void set_array_fields_dimension(const vil_nitf2_field_definitions *field_defs, const vil_nitf2_index_vector &index, int repeat_count)
vil_nitf2_field_definition * find_field_definition(const std::string &tag)
virtual bool write(vil_nitf2_ostream &, const vil_nitf2_field_definitions *field_defs=nullptr, vil_nitf2_index_vector indexes=vil_nitf2_index_vector())
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
std::vector< vil_nitf2_field * > fields_vector
std::map< std::string, vil_nitf2_field * > field_map
vil_nitf2_field * get_field(const std::string &tag) const
bool get_values(std::string tag, const vil_nitf2_index_vector &indexes, std::vector< int > &out_values, bool clear_out_values=true) const
const vil_nitf2_field_definitions * m_field_definitions
void insert_field(const std::string &str, vil_nitf2_field *field)
bool get_value(std::string tag, int &out_value) const
vil_nitf2_field_sequence(const vil_nitf2_field_definitions &field_definitions)
virtual vil_nitf2_field::field_tree * get_tree(vil_nitf2_field::field_tree *tr=nullptr) const