core/vil/file_formats/vil_nitf2_tagged_record_definition.h
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
00004 // Stellar Science Ltd. Co. (stellarscience.com) for
00005 // Air Force Research Laboratory, 2005.
00006 
00007 #ifndef VIL_NITF2_TAGGED_RECORD_DEFINITION_H
00008 #define VIL_NITF2_TAGGED_RECORD_DEFINITION_H
00009 
00010 #include <vcl_map.h>
00011 #include <vcl_string.h>
00012 
00013 #include "vil_nitf2_field_functor.h"
00014 
00015 class vil_nitf2_field_formatter;
00016 class vil_nitf2_field_definition;
00017 class vil_nitf2_field_definitions;
00018 template<typename T> class vil_nitf2_field_functor;
00019 
00020 //-----------------------------------------------------------------------------
00021 //: vil_nitf2_tagged_record_definition defines a particular tagged record extension (TRE).
00022 // It consists of its name and an ordered list of vil_nitf2_field_definitions.
00023 // It also defines a static method to look up a TRE definition by name.
00024 //
00025 // The primary goal of this class design to provide a succinct way for the
00026 // programmer to specify a NITF tagged record definition, which can be used
00027 // for both reading and writing the record. The definition must support
00028 // references to values of other fields in the record, which are needed to
00029 // define conditional and repeating fields. Please see the example definition
00030 // in method test().
00031 
00032 class vil_nitf2_tagged_record_definition
00033 {
00034   friend class vil_nitf2_tagged_record;
00035  public:
00036 
00037   //: Factory method. Assumes ownership of optional pointer argument.
00038   static vil_nitf2_tagged_record_definition& define(
00039     vcl_string name, vcl_string pretty_name);
00040 
00041   //: Define a field. Assumes ownership of pointer arguments.
00042   vil_nitf2_tagged_record_definition& field(
00043     vcl_string field_name,
00044     vcl_string pretty_name,
00045     vil_nitf2_field_formatter* formatter,
00046     // whether this field may be unspecified (all blank)
00047     bool blanks_ok = false,
00048     // function, when specified, that overrides formatter's width
00049     vil_nitf2_field_functor<int>* width_functor = 0,
00050     // predicate that returns whether this conditional field is present;
00051     // 0 for required fields
00052     vil_nitf2_field_functor<bool>* condition_functor = 0,
00053     vcl_string units = "",
00054     vcl_string description = "");
00055 
00056   //: Define a repeat node. Assumes ownership of pointer argument.
00057   vil_nitf2_tagged_record_definition& repeat(
00058     vil_nitf2_field_functor<int>* repeat_functor,
00059     vil_nitf2_field_definitions& field_definitions);
00060 
00061   //: Convenience overload where repeat count is simply the value of a tag.
00062   vil_nitf2_tagged_record_definition& repeat(
00063     vcl_string int_tag,
00064     vil_nitf2_field_definitions& field_definitions);
00065 
00066   //: Convenience overload where repeat count is a fixed value.
00067   vil_nitf2_tagged_record_definition& repeat(
00068     int repeat_count,
00069     vil_nitf2_field_definitions& field_definitions);
00070 
00071   //: Declares that definition is finished, preventing further invocations of field() or repeat().
00072   void end();
00073 
00074   //: Look up a record definition
00075   static vil_nitf2_tagged_record_definition* find(vcl_string name);
00076 
00077   //: Look up a field definition
00078   vil_nitf2_field_definition* find_field(vcl_string name);
00079 
00080   // Destructor
00081   ~vil_nitf2_tagged_record_definition();
00082 
00083   typedef vcl_map<vcl_string, vil_nitf2_tagged_record_definition*>
00084           tagged_record_definition_map;
00085   //: All tagged record definitions
00086   static tagged_record_definition_map& all_definitions();
00087 
00088   //: Return field definitions
00089   const vil_nitf2_field_definitions& field_definitions() const {
00090     return *m_field_definitions; }
00091 
00092   //: Undefines a TRE. Returns whether TRE with specified name was found.
00093   static bool undefine(vcl_string name);
00094 
00095   //: Registers some TREs for testing
00096   static void register_test_tre();
00097 
00098  private:
00099   // No copy constructor
00100   vil_nitf2_tagged_record_definition(const vil_nitf2_tagged_record_definition&);
00101 
00102   // No assignment operator
00103   vil_nitf2_tagged_record_definition& operator=(const vil_nitf2_tagged_record_definition&);
00104 
00105   // Constructor
00106   vil_nitf2_tagged_record_definition(vcl_string name, vcl_string pretty_name,
00107                                      vil_nitf2_field_definitions* defs = 0);
00108 
00109 #if 0
00110   // to implement
00111   virtual bool validate(const vil_nitf2_tagged_record*) const;
00112 #endif
00113 
00114   vcl_string m_name;
00115   vcl_string m_pretty_name;
00116   vil_nitf2_field_definitions* m_field_definitions;
00117   bool m_definition_completed;
00118 };
00119 
00120 #endif // VIL_NITF2_TAGGED_RECORD_DEFINITION_H