vil_nitf2_field_definition.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_DEFINITION_H
6 #define VIL_NITF2_FIELD_DEFINITION_H
7 
8 // Do not #include this file within another header file (to avoid
9 // potential conflicts with the macro definitions below).
10 
11 // These macros make definitions more concise
12 #define NITF_LOC new vil_nitf2_location_formatter
13 #define NITF_INT new vil_nitf2_integer_formatter
14 #define NITF_DBL new vil_nitf2_double_formatter
15 #define NITF_EXP new vil_nitf2_exponential_formatter
16 #define NITF_LONG new vil_nitf2_long_long_formatter
17 #define NITF_CHAR new vil_nitf2_char_formatter
18 #define NITF_BIN new vil_nitf2_binary_formatter
19 #define NITF_STR new vil_nitf2_string_formatter
20 #define NITF_ENUM new vil_nitf2_enum_string_formatter
21 #define NITF_DAT new vil_nitf2_date_time_formatter
22 #define NITF_TRES new vil_nitf2_tagged_record_sequence_formatter
23 
24 #define NITF_STR_ECS(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::ECS)
25 #define NITF_STR_ECSA(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::ECSA)
26 #define NITF_STR_BCS(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::BCS)
27 #define NITF_STR_BCSA(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::BCSA)
28 
29 #include <list>
30 #ifdef _MSC_VER
31 # include <vcl_msvc_warnings.h>
32 #endif
33 
34 #include "vil_nitf2.h" // vil_nitf2_istream, vil_nitf2_ostream
36 
40 
41 //-----------------------------------------------------------------------------
42 // An abstract base class that represents either
43 // a field definition, condition, or repeat control.
44 //
46 {
47  public:
50  virtual ~vil_nitf2_field_definition_node() = default;
51 
52  // Downcast test methods (for convenience)
53  bool is_field_definition() const { return type==type_field; }
54  bool is_repeat_node() const { return type==type_repeat; }
55 
56  // Downcast methods. Return 0 if conversion fails.
59 
60  // Virtual copy method
61  virtual vil_nitf2_field_definition_node* copy() const = 0;
62 
63  // Member variables
65 };
66 
67 //-----------------------------------------------------------------------------
68 // Represents the definition of a particular field
69 // (including a contiguous set of repeating fields) of a tagged record
70 // extension, including the name, format, repeat count, or other condition.
71 //
73 {
74  public:
75  // These members basically correspond to columns within a row of
76  // a NITF tagged record spec. An instance of this class corresponds
77  // to a row (or a sequence of contiguously repeating rows).
78  std::string tag;
79  std::string pretty_name;
80  bool required;
82  bool blanks_ok;
85  std::string units;
86  std::string description;
87 
88  bool is_required() const;
89  bool is_variable_width() const;
90 
91  // Constructor. Assumes ownership of pointer arguments.
93  // field identifier, generally < 10 characters long
94  std::string tag,
95  // the field name, typically a few words long
96  std::string pretty_name,
97  // field type and format
99  // whether this field may be unspecified (all blanks)
100  bool blanks_ok = false,
101  // function, when specified, that overrides formatter's field width.
103  // conditional field predicate; 0 for required fields
105  // additional documentation fields
106  std::string units = "",
107  std::string description = "");
108 
109  // Copy method
110  vil_nitf2_field_definition_node* copy() const override;
111 
112  // Destructor
113  ~vil_nitf2_field_definition() override;
114 };
115 
116 
117 //-----------------------------------------------------------------------------
118 // Represents the definition of a contiguous sequence of fields or nodes
119 // containing other such sequences of fields. Methods field(), repeat(),
120 // and cond() provide "syntactic sugar" for assembling the sequence.
121 //
122 class vil_nitf2_field_definitions : public std::list<vil_nitf2_field_definition_node*>
123 {
124  public:
125  // Define a field and add it to this list of definitions, returning
126  // the current list. Assumes ownership of pointer arguments.
128  std::string tag,
129  std::string pretty_name,
130  vil_nitf2_field_formatter* formatter,
131  // whether this field may be unspecified (all blank)
132  bool blanks_ok = false,
133  // function, when specified, that overrides formatter's field width
134  vil_nitf2_field_functor<int>* width_functor = nullptr,
135  // predicate that returns whether this conditional field is present;
136  // 0 for required fields
137  vil_nitf2_field_functor<bool>* condition_functor = nullptr,
138  std::string units = "",
139  std::string description = "");
140 
141  // Define a repeat node, with repeat count determined by repeat_functor,
142  // and add it to this list of definitions, returning the current list.
143  // Assumes ownership of pointer argument.
145  vil_nitf2_field_definitions& field_definitions);
146 
147  // Same as above where the repeat count is simply the value of a tag.
148  vil_nitf2_field_definitions& repeat(std::string intTag,
149  vil_nitf2_field_definitions& field_definitions)
150  { return repeat(new vil_nitf2_field_value<int>(intTag), field_definitions); }
151 
152  // Copy constructor
154 
155  // Default constructor
156  vil_nitf2_field_definitions() = default;
157 
158  // Destructor
160 };
161 
162 //-----------------------------------------------------------------------------
163 // Represents a sequence of fields that is repeated. The repeat count
164 // is determined by a functor that evaluates previously processed tag(s).
165 //
167 {
168  public:
169  // Construct a repeat node. Assumes ownership of pointer arguments.
175 
176  // Member variables
179 
180  // Destructor
182 
183  // Copy method
184  vil_nitf2_field_definition_node* copy() const override;
185 };
186 
187 #endif // VIL_NITF2_FIELD_DEFINITION_H
Functor vil_nitf2_field_value defines a function that sets its out parameter to a value of a field fr...
vil_nitf2_field_functor< int > * width_functor
vil_nitf2_field_definition_node * copy() const override
vil_nitf2_field_definitions & repeat(std::string intTag, vil_nitf2_field_definitions &field_definitions)
virtual vil_nitf2_field_definition_node * copy() const =0
vil_nitf2_field_definitions & repeat(vil_nitf2_field_functor< int > *repeat_functor, vil_nitf2_field_definitions &field_definitions)
vil_nitf2_field_definitions & field(std::string tag, std::string pretty_name, vil_nitf2_field_formatter *formatter, bool blanks_ok=false, vil_nitf2_field_functor< int > *width_functor=nullptr, vil_nitf2_field_functor< bool > *condition_functor=nullptr, std::string units="", std::string description="")
vil_nitf2_field_definition_node * copy() const override
vil_nitf2_field_definition_repeat_node * repeat_node()
vil_nitf2_field_definition_repeat_node(vil_nitf2_field_functor< int > *repeat_functor, vil_nitf2_field_definitions *field_definitions)
vil_nitf2_field_formatter * formatter
Functors used by NITF classes.
vil_nitf2_field_functor< int > * repeat_functor
virtual ~vil_nitf2_field_definition_node()=default
vil_nitf2_field_definition(std::string tag, std::string pretty_name, vil_nitf2_field_formatter *formatter, bool blanks_ok=false, vil_nitf2_field_functor< int > *width_functor=nullptr, vil_nitf2_field_functor< bool > *condition_functor=nullptr, std::string units="", std::string description="")
vil_nitf2_field_functor< bool > * condition_functor
vil_nitf2_field_definition * field_definition()