vil_nitf2_tagged_record_definition.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_TAGGED_RECORD_DEFINITION_H
8 #define VIL_NITF2_TAGGED_RECORD_DEFINITION_H
9 
10 #include <map>
11 #include <string>
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
15 
17 
21 template<typename T> class vil_nitf2_field_functor;
22 
23 //-----------------------------------------------------------------------------
24 //: vil_nitf2_tagged_record_definition defines a particular tagged record extension (TRE).
25 // It consists of its name and an ordered list of vil_nitf2_field_definitions.
26 // It also defines a static method to look up a TRE definition by name.
27 //
28 // The primary goal of this class design to provide a succinct way for the
29 // programmer to specify a NITF tagged record definition, which can be used
30 // for both reading and writing the record. The definition must support
31 // references to values of other fields in the record, which are needed to
32 // define conditional and repeating fields. Please see the example definition
33 // in method test().
34 
36 {
38  public:
39 
40  //: Factory method. Assumes ownership of optional pointer argument.
42  std::string name, std::string pretty_name);
43 
44  //: Define a field. Assumes ownership of pointer arguments.
46  std::string field_name,
47  std::string pretty_name,
48  vil_nitf2_field_formatter* formatter,
49  // whether this field may be unspecified (all blank)
50  bool blanks_ok = false,
51  // function, when specified, that overrides formatter's width
52  vil_nitf2_field_functor<int>* width_functor = nullptr,
53  // predicate that returns whether this conditional field is present;
54  // 0 for required fields
55  vil_nitf2_field_functor<bool>* condition_functor = nullptr,
56  std::string units = "",
57  std::string description = "");
58 
59  //: Define a repeat node. Assumes ownership of pointer argument.
61  vil_nitf2_field_functor<int>* repeat_functor,
63 
64  //: Convenience overload where repeat count is simply the value of a tag.
66  std::string int_tag,
68 
69  //: Convenience overload where repeat count is a fixed value.
71  int repeat_count,
73 
74  //: Declares that definition is finished, preventing further invocations of field() or repeat().
75  void end();
76 
77  //: Look up a record definition
78  static vil_nitf2_tagged_record_definition* find(const std::string& name);
79 
80  //: Look up a field definition
82 
83  // Destructor
85 
86  typedef std::map<std::string, vil_nitf2_tagged_record_definition*>
88  //: All tagged record definitions
90 
91  //: Return field definitions
93  return *m_field_definitions; }
94 
95  //: Undefines a TRE. Returns whether TRE with specified name was found.
96  static bool undefine(const std::string& name);
97 
98  //: Registers some TREs for testing
99  static void register_test_tre();
100 
101  private:
102  // No copy constructor
104 
105  // No assignment operator
107 
108  // Constructor
109  vil_nitf2_tagged_record_definition(std::string name, std::string pretty_name,
110  vil_nitf2_field_definitions* defs = nullptr);
111 
112 #if 0
113  // to implement
114  virtual bool validate(const vil_nitf2_tagged_record*) const;
115 #endif
116 
117  std::string m_name;
118  std::string m_pretty_name;
121 };
122 
123 #endif // VIL_NITF2_TAGGED_RECORD_DEFINITION_H
vil_nitf2_field_definition * find_field(std::string name)
Look up a field definition.
std::map< std::string, vil_nitf2_tagged_record_definition * > tagged_record_definition_map
static void register_test_tre()
Registers some TREs for testing.
void end()
Declares that definition is finished, preventing further invocations of field() or repeat().
vil_nitf2_tagged_record_definition & field(std::string field_name, 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="")
Define a field. Assumes ownership of pointer arguments.
vil_nitf2_tagged_record_definition(const vil_nitf2_tagged_record_definition &)
static vil_nitf2_tagged_record_definition & define(std::string name, std::string pretty_name)
Factory method. Assumes ownership of optional pointer argument.
const vil_nitf2_field_definitions & field_definitions() const
Return field definitions.
vil_nitf2_tagged_record_definition & operator=(const vil_nitf2_tagged_record_definition &)
vil_nitf2_tagged_record_definition defines a particular tagged record extension (TRE).
static tagged_record_definition_map & all_definitions()
All tagged record definitions.
static bool undefine(const std::string &name)
Undefines a TRE. Returns whether TRE with specified name was found.
static vil_nitf2_tagged_record_definition * find(const std::string &name)
Look up a record definition.
Functors used by NITF classes.
vil_nitf2_tagged_record_definition & repeat(vil_nitf2_field_functor< int > *repeat_functor, vil_nitf2_field_definitions &field_definitions)
Define a repeat node. Assumes ownership of pointer argument.