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

vil_nitf2_field_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_FIELD_DEFINITION_H
00006 #define VIL_NITF2_FIELD_DEFINITION_H
00007 
00008 // Do not #include this file within another header file (to avoid
00009 // potential conflicts with the macro definitions below).
00010 
00011 // These macros make definitions more concise
00012 #define NITF_LOC  new vil_nitf2_location_formatter
00013 #define NITF_INT  new vil_nitf2_integer_formatter
00014 #define NITF_DBL  new vil_nitf2_double_formatter
00015 #define NITF_EXP  new vil_nitf2_exponential_formatter
00016 #define NITF_LONG new vil_nitf2_long_long_formatter
00017 #define NITF_CHAR new vil_nitf2_char_formatter
00018 #define NITF_BIN  new vil_nitf2_binary_formatter
00019 #define NITF_STR  new vil_nitf2_string_formatter
00020 #define NITF_ENUM new vil_nitf2_enum_string_formatter
00021 #define NITF_DAT  new vil_nitf2_date_time_formatter
00022 #define NITF_TRES new vil_nitf2_tagged_record_sequence_formatter
00023 
00024 #define NITF_STR_ECS(LEN)  NITF_STR(LEN, vil_nitf2_string_formatter::ECS)
00025 #define NITF_STR_ECSA(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::ECSA)
00026 #define NITF_STR_BCS(LEN)  NITF_STR(LEN, vil_nitf2_string_formatter::BCS)
00027 #define NITF_STR_BCSA(LEN) NITF_STR(LEN, vil_nitf2_string_formatter::BCSA)
00028 
00029 #include <vcl_list.h>
00030 
00031 #include "vil_nitf2.h" // vil_nitf2_istream, vil_nitf2_ostream
00032 #include "vil_nitf2_field_functor.h"
00033 
00034 class vil_nitf2_field_definition;
00035 class vil_nitf2_field_definition_repeat_node;
00036 class vil_nitf2_field_formatter;
00037 
00038 //-----------------------------------------------------------------------------
00039 // An abstract base class that represents either
00040 // a field definition, condition, or repeat control.
00041 //
00042 class vil_nitf2_field_definition_node
00043 {
00044  public:
00045   enum node_type { type_field, type_repeat };
00046   vil_nitf2_field_definition_node(node_type type) : type(type) {}
00047   virtual ~vil_nitf2_field_definition_node() {}
00048 
00049   // Downcast test methods (for convenience)
00050   bool is_field_definition() const { return type==type_field; }
00051   bool is_repeat_node() const { return type==type_repeat; }
00052 
00053   // Downcast methods. Return 0 if conversion fails.
00054   vil_nitf2_field_definition* field_definition();
00055   vil_nitf2_field_definition_repeat_node* repeat_node();
00056 
00057   // Virtual copy method
00058   virtual vil_nitf2_field_definition_node* copy() const = 0;
00059 
00060   // Member variables
00061   node_type type;
00062 };
00063 
00064 //-----------------------------------------------------------------------------
00065 // Represents the definition of a particular field
00066 // (including a contiguous set of repeating fields) of a tagged record
00067 // extension, including the name, format, repeat count, or other condition.
00068 //
00069 class vil_nitf2_field_definition : public vil_nitf2_field_definition_node
00070 {
00071  public:
00072   // These members basically correspond to columns within a row of
00073   // a NITF tagged record spec. An instance of this class corresponds
00074   // to a row (or a sequence of contiguously repeating rows).
00075   vcl_string tag;
00076   vcl_string pretty_name;
00077   bool required;
00078   vil_nitf2_field_formatter* formatter;
00079   bool blanks_ok;
00080   vil_nitf2_field_functor<int>* width_functor;
00081   vil_nitf2_field_functor<bool>* condition_functor;
00082   vcl_string units;
00083   vcl_string description;
00084 
00085   bool is_required() const;
00086   bool is_variable_width() const;
00087 
00088   // Constructor. Assumes ownership of pointer arguments.
00089   vil_nitf2_field_definition(
00090     // field identifier, generally < 10 characters long
00091     vcl_string tag,
00092     // the field name, typically a few words long
00093     vcl_string pretty_name,
00094     // field type and format
00095     vil_nitf2_field_formatter* formatter,
00096     // whether this field may be unspecified (all blanks)
00097     bool blanks_ok = false,
00098     // function, when specified, that overrides formatter's field width.
00099     vil_nitf2_field_functor<int>* width_functor = 0,
00100     // conditional field predicate; 0 for required fields
00101     vil_nitf2_field_functor<bool>* condition_functor = 0,
00102     // additional documentation fields
00103     vcl_string units = "",
00104     vcl_string description = "");
00105 
00106   // Copy method
00107   vil_nitf2_field_definition_node* copy() const;
00108 
00109   // Destructor
00110   ~vil_nitf2_field_definition();
00111 
00112 };
00113 
00114 
00115 //-----------------------------------------------------------------------------
00116 // Represents the definition of a contiguous sequence of fields or nodes
00117 // containing other such sequences of fields. Methods field(), repeat(),
00118 // and cond() provide "syntactic sugar" for assembling the sequence.
00119 //
00120 class vil_nitf2_field_definitions : public vcl_list<vil_nitf2_field_definition_node*>
00121 {
00122  public:
00123   // Define a field and add it to this list of definitions, returning
00124   // the current list. Assumes ownership of pointer arguments.
00125   vil_nitf2_field_definitions& field(
00126     vcl_string tag,
00127     vcl_string pretty_name,
00128     vil_nitf2_field_formatter* formatter,
00129     // whether this field may be unspecified (all blank)
00130     bool blanks_ok = false,
00131     // function, when specified, that overrides formatter's field width
00132     vil_nitf2_field_functor<int>* width_functor = 0,
00133     // predicate that returns whether this conditional field is present;
00134     // 0 for required fields
00135     vil_nitf2_field_functor<bool>* condition_functor = 0,
00136     vcl_string units = "",
00137     vcl_string description = "");
00138 
00139   // Define a repeat node, with repeat count determined by repeat_functor,
00140   // and add it to this list of definitions, returning the current list.
00141   // Assumes ownership of pointer argument.
00142   vil_nitf2_field_definitions& repeat(vil_nitf2_field_functor<int>* repeat_functor,
00143                                       vil_nitf2_field_definitions& field_definitions);
00144 
00145   // Same as above where the repeat count is simply the value of a tag.
00146   vil_nitf2_field_definitions& repeat(vcl_string intTag,
00147                                       vil_nitf2_field_definitions& field_definitions)
00148   { return repeat(new vil_nitf2_field_value<int>(intTag), field_definitions); }
00149 
00150   // Copy constructor
00151   vil_nitf2_field_definitions(const vil_nitf2_field_definitions&);
00152 
00153   // Default constructor
00154   vil_nitf2_field_definitions() {};
00155 
00156   // Destructor
00157   virtual ~vil_nitf2_field_definitions();
00158 };
00159 
00160 //-----------------------------------------------------------------------------
00161 // Represents a sequence of fields that is repeated. The repeat count
00162 // is determined by a functor that evaluates previously processed tag(s).
00163 //
00164 class vil_nitf2_field_definition_repeat_node : public vil_nitf2_field_definition_node
00165 {
00166  public:
00167   // Construct a repeat node. Assumes ownership of pointer arguments.
00168   vil_nitf2_field_definition_repeat_node(vil_nitf2_field_functor<int>* repeat_functor,
00169                                          vil_nitf2_field_definitions* field_definitions)
00170     : vil_nitf2_field_definition_node(type_repeat),
00171       repeat_functor(repeat_functor),
00172       field_definitions(field_definitions) {}
00173 
00174   // Member variables
00175   vil_nitf2_field_functor<int>* repeat_functor;
00176   vil_nitf2_field_definitions* field_definitions;
00177 
00178   // Destructor
00179   ~vil_nitf2_field_definition_repeat_node();
00180 
00181   // Copy method
00182   vil_nitf2_field_definition_node* copy() const;
00183 };
00184 
00185 #endif // VIL_NITF2_FIELD_DEFINITION_H

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