Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vil_nitf2_tagged_record_definition.h

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

Generated on Thu Jan 10 14:40:00 2008 for core/vil by  doxygen 1.4.4