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_FORMATTER_H 00006 #define VIL_NITF2_FIELD_FORMATTER_H 00007 00008 //#include "vil_nitf2_field.h" 00009 class vil_nitf2_field; 00010 00011 // not used? #include <vcl_map.h> 00012 // not used? #include <vcl_vector.h> 00013 #include <vcl_string.h> 00014 // not used? #include <vcl_sstream.h> 00015 #include <vcl_istream.h> 00016 #include <vcl_ostream.h> 00017 00018 #include "vil_nitf2.h" 00019 00020 class vil_nitf2_field; 00021 class vil_nitf2_field_definition; 00022 class vil_nitf2_date_time; 00023 class vil_nitf2_location; 00024 class vil_nitf2_scalar_field; 00025 class vil_nitf2_array_field; 00026 00027 //----------------------------------------------------------------------------- 00028 // A subclass of NITF field formatter exists for each NITF field data type. 00029 // These are used to define record extensions (as opposed to representing 00030 // values); they are used to read and write individual fields of the NITF 00031 // stream. 00032 00033 // All formatters definitions include a field width, typically a vcl_fixed width, 00034 // unless a length functor is specified which is evaluated when the file is 00035 // read. 00036 // 00037 // Some fields include "precision" (the length of mantissa). For some numeric 00038 // fields, NITF allows blanks in lieu of insignificant decimal values. 00039 // For this reason, the precision stored in a field may (once implemented) 00040 // be less than the Formatter's precision. 00041 00042 // Base class for NITF field formatters 00043 // 00044 class vil_nitf2_field_formatter 00045 { 00046 public: 00047 // Field types currently supported 00048 00049 vil_nitf2::enum_field_type field_type; 00050 int field_width; 00051 00052 vil_nitf2_field_formatter(vil_nitf2::enum_field_type field_type, int field_width) 00053 : field_type(field_type), field_width(field_width) {} 00054 00055 // Destructor 00056 virtual ~vil_nitf2_field_formatter() {} 00057 00058 // Virtual copy method 00059 virtual vil_nitf2_field_formatter* copy() const = 0; 00060 00061 // Attempts to read scalar field from stream. Returns a new instance of field if 00062 // success and 0 otherwise. Sets out_blank to whether input was entirely blank 00063 // (in which case 0 is returned). 00064 virtual vil_nitf2_scalar_field* read_field( 00065 vil_nitf2_istream& input, bool& out_blank) = 0; 00066 00067 // Initializes a vector field of specified dimensionality 00068 virtual vil_nitf2_array_field* create_array_field( 00069 int num_dimensions, vil_nitf2_field_definition*) = 0; 00070 00071 virtual bool write_field(vil_nitf2_ostream& output, const vil_nitf2_scalar_field* field) = 0; 00072 00073 // Writes a blank instance of field value to output stream. Returns 00074 // true iff successfully written. No need to overload this method. 00075 bool write_blank(vcl_ostream& output); 00076 00077 // Same as above, but writes to a vil_stream. 00078 bool write_blank(vil_stream& output); 00079 00080 // Helper function which reads the specified number characters into 00081 // a string (if possible), which it returns as a null-terminated C string, 00082 // which the caller owns. The length of the C string reflects the number 00083 // of characters read. 00084 static char* read_char_array(vcl_istream& input, int length); 00085 static bool read_c_str(vcl_istream& input, int length, 00086 char*& out_cstr, bool& all_blank); 00087 // Same as above, but returns a vcl_string. 00088 static vcl_string read_string(vcl_istream& input, int length); 00089 // Same as above, but takes a vil_stream as input 00090 static vcl_string read_string(vil_stream& input, int length); 00091 00092 // Helper function to test presence of number sign. Returns true 00093 // iff first character is consistent with flag show_sign. 00094 static bool check_sign(const char* cstr, bool show_sign); 00095 00096 // Helper function to test whether the null-terminated C vcl_string contains 00097 // all blanks 00098 static bool is_all_blank(const char* cstr); 00099 }; 00100 00101 #endif // VIL_NITF2_FIELD_FORMATTER_H
1.4.4