core/vil/file_formats/vil_nitf2_des.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_DES_H
00006 #define VIL_NITF2_DES_H
00007 
00008 class vil_nitf2_field_definitions;
00009 class vil_stream;
00010 #include "vil_nitf2_classification.h"
00011 #include "vil_nitf2_field_sequence.h"
00012 
00013 #include <vcl_map.h>
00014 
00015 // Class for representing a single data extension segment (DES) in 
00016 // a NITF 2.x file.  This class can handle TRE overflow DES (DESID=TRE_OVERFLOW)
00017 // as well as custom defined data extension segments (DESID=<something else>).  Use
00018 // the static define() function to tell this class about custom DES' that you want
00019 // to support.
00020 // It does not,however, handle streaming DES' (DESID=STREAMING_FILE_HEADER).  I'm not
00021 // sure that those des' are relevant to the nitf files that vil supports
00022 class vil_nitf2_des 
00023 {
00024 public:
00025   vil_nitf2_des( vil_nitf2_classification::file_version version, int data_width );
00026   ///read the des starting at stream's current position
00027   ///returns false if failed
00028   virtual bool read( vil_stream* stream );
00029   //virtual bool write( vil_stream* stream );
00030 
00031   virtual ~vil_nitf2_des();
00032 
00033   // Sets out_value to the value of field specified by tag. 
00034   // Returns 0 if such a field is not found or is of the wrong type.
00035   template< class T >
00036   bool get_property(vcl_string tag, T& out_value) const
00037   {
00038     if ( ! m_field_sequence1->get_value( tag, out_value ) && m_field_sequence2 ){
00039       return m_field_sequence2->get_value( tag, out_value );
00040     }
00041   }
00042 
00043   // Sets out_value to the value of vcl_vector field element specified by tag and index.
00044   // Returns 0 if such a field is not found or is of the wrong type.
00045   template< class T >
00046   bool get_property(vcl_string tag, int i, T& out_value) const
00047   {
00048     if( ! m_field_sequence1->get_value( tag, i, out_value ) && m_field_sequence2 ){
00049       return m_field_sequence2->get_value( tag, i, out_value );
00050     }
00051   }
00052 
00053   // I allocate the return value, but you own it after I return it to you
00054   // so you need to delete it.  
00055   virtual vil_nitf2_field::field_tree* get_tree( int i = 0 ) const;
00056 
00057   // Call this function to register a DES with this class.  Once you've 
00058   // done this, then this class will be able to parse your custom DES.
00059   static vil_nitf2_field_definitions& define( vcl_string desId );
00060 protected:
00061   typedef vcl_map<vcl_string, vil_nitf2_field_definitions*> 
00062     field_definition_map;
00063   static field_definition_map & all_definitions();
00064 
00065   static void add_shared_field_defs_1( vil_nitf2_field_definitions* defs );
00066   static void add_shared_field_defs_2( vil_nitf2_field_definitions* defs, int data_width );
00067   static vil_nitf2_field_definitions* create_field_definitions( vil_nitf2_classification::file_version ver, int data_width);
00068 
00069   vil_nitf2_field_sequence* m_field_sequence1;
00070   vil_nitf2_field_sequence* m_field_sequence2;
00071 };
00072 
00073 #endif //VIL_NITF2_DES_H