core/vil/file_formats/vil_nitf2_header.h
Go to the documentation of this file.
00001 // vil_nitf2: Written by Rob Radtke (rob@) and Harry Voorhees (hlv@) of
00002 // Stellar Science Ltd. Co. (stellarscience.com) for 
00003 // Air Force Research Laboratory, 2005.
00004 
00005 #ifndef VIL_NITF2_HEADER_H
00006 #define VIL_NITF2_HEADER_H
00007 
00008 #include "vil_nitf2_tagged_record.h"
00009 #include "vil_nitf2_classification.h"
00010 #include "vil_nitf2.h"
00011 
00012 class vil_stream;
00013 
00014 
00015 /// Parses a NITF 2.1 file header for vil_nitf2_image. 
00016 /// Use get_property() to get a field value.
00017 //
00018 class vil_nitf2_header 
00019 {
00020 public:
00021   vil_nitf2_header();
00022 
00023   virtual ~vil_nitf2_header();
00024   
00025   enum portion_type { 
00026     enum_subheader, 
00027     enum_data 
00028   };
00029   enum section_type { 
00030     enum_file_header = 0, 
00031     enum_image_segments, 
00032     enum_graphic_segments, 
00033     enum_label_segments,
00034     enum_text_segments, 
00035     enum_data_extension_segments, 
00036     enum_reserved_extension_segments 
00037   };
00038   static vcl_string section_num_tag(section_type sec);
00039   static vcl_string section_len_header_tag(section_type sec);
00040   static vcl_string section_len_data_tag(section_type sec);
00041   
00042   // Read the image header starting at stream's current position. Return success.
00043   virtual bool read( vil_stream* stream );
00044   //virtual bool write( vil_stream* stream );
00045 
00046   // Sets out_value to the value of field specified by tag. 
00047   // Returns 0 if such a field is not found or is of the wrong type.
00048   template< class T >
00049   bool get_property(vcl_string tag, T& out_value) const
00050   {
00051     if ( m_field_sequence_classification && m_field_sequence_classification->get_value(tag, out_value) ) return true;
00052     else if ( m_field_sequence2 && m_field_sequence2->get_value(tag, out_value) ) return true;
00053     else return m_field_sequence1.get_value(tag, out_value);
00054   }
00055 
00056   // Sets out_value to the value of vcl_vector field element specified by tag and index.
00057   // Returns 0 if such a field is not found or is of the wrong type.
00058   template< class T >
00059   bool get_property(vcl_string tag, int i, T& out_value) const
00060   {
00061     if ( m_field_sequence_classification && m_field_sequence_classification->get_value(tag, i, out_value) ) return true;
00062     else if ( m_field_sequence2 && m_field_sequence2->get_value(tag, i, out_value) ) return true;
00063     else return m_field_sequence1.get_value(tag, i, out_value);
00064   }
00065 
00066   vil_nitf2_classification::file_version file_version() const;
00067 
00068   // I allocate the return value, but you own it after I return it to you
00069   // so you need to delete it.  
00070   virtual vil_nitf2_field::field_tree* get_tree() const;
00071 
00072 protected:
00073   // Field sequences for different parts of this header.
00074   vil_nitf2_field_sequence m_field_sequence1;
00075   vil_nitf2_field_sequence* m_field_sequence2;
00076   vil_nitf2_field_sequence* m_field_sequence_classification;
00077 
00078   // Returns field definitions, which I own, for different parts of the header.
00079   static vil_nitf2_field_definitions* get_field_definitions_1();
00080   static vil_nitf2_field_definitions* get_field_definitions_2( vil_nitf2_classification::file_version version );
00081 
00082 private:
00083   static vil_nitf2_field_definitions* s_field_definitions_1;
00084   static vil_nitf2_field_definitions* s_field_definitions_21;
00085   static vil_nitf2_field_definitions* s_field_definitions_20;
00086 
00087   // so these static members can be cleaned up when the program is done 
00088   // using nitf files
00089   friend void vil_nitf2::cleanup_static_members();
00090 };
00091 
00092 #endif // VIL_NITF2_HEADER_H