core/vil/file_formats/vil_nitf2_compound_field_value.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_COMPOUND_FIELD_VALUE_H
00006 #define VIL_NITF2_COMPOUND_FIELD_VALUE_H
00007 
00008 #include <vcl_iostream.h>
00009 #include <vcl_string.h>
00010 #include <vcl_istream.h>
00011 #include <vcl_ostream.h>
00012 
00013 //-----------------------------------------------------------------------------
00014 // NITF compound field types
00015 //
00016 // NITF fields can represent built-in types like integer or vcl_string, and
00017 // compound types like date_time. Subclasses of vil_nitf2_compound_field_value, along with
00018 // built-in types, represent all the types of values that are passed back to 
00019 // clients. These types implement operator << (ostream&) to output themselves 
00020 // in human-readable form. Some compound fields keep track of their precision.
00021 // By contrast, NITF file i/o is handled by corresponding Formatter classes, 
00022 // which clients should not need to know about.
00023 
00024 // Base class for NITF compound field types.
00025 // Each class is expected to define operator << which should call output().
00026 //
00027 class vil_nitf2_compound_field_value
00028 {
00029 public:
00030   // To be called by operator << to pretty-print field to stream
00031   virtual vcl_ostream& output(vcl_ostream&) const = 0;
00032 
00033   // Returns true iff all members lie within their expected ranges
00034   virtual bool is_valid() const = 0;
00035 
00036   virtual ~vil_nitf2_compound_field_value() {}
00037 };
00038 
00039 // A date and time, down to the second or decimal fraction thereof.
00040 //
00041 class vil_nitf2_date_time : public vil_nitf2_compound_field_value
00042 {
00043   friend class vil_nitf2_date_time_formatter;
00044 public:
00045   int year;
00046   int month;        // 1-12
00047   int day;          // 1-31
00048   int hour;         // 0-23
00049   int minute;       // 0-59
00050   double second;    // 0-59.999...
00051   int sec_precision; // second's significant decimal places
00052   vil_nitf2_date_time() : year(0), month(0), day(0), hour(0), minute(0), second(0), sec_precision(0) {}
00053   vil_nitf2_date_time(vcl_string format);
00054   virtual ~vil_nitf2_date_time() {}
00055   bool is_valid() const;
00056   bool read(vcl_istream& input, int field_width, bool& out_blank);
00057   bool write(vcl_ostream& output, int field_width) const;
00058   vcl_ostream& output(vcl_ostream& os) const;
00059 };
00060 
00061 vcl_ostream& operator << (vcl_ostream& os, const vil_nitf2_date_time& dateTime);
00062 
00063 // Base class for geodetic location field type
00064 
00065 class vil_nitf2_location : public vil_nitf2_compound_field_value
00066 {
00067   friend class vil_nitf2_location_formatter;
00068 public:
00069   enum format_type { format_degrees, format_dmsh };
00070   format_type format;
00071   vil_nitf2_location(format_type format) : format(format) {}
00072   virtual ~vil_nitf2_location() {}
00073   virtual bool read(vcl_istream& input, int field_width, bool& out_blank) = 0;
00074   virtual bool write(vcl_ostream& output, int field_width) = 0;
00075 };
00076 
00077 // Geodetic location represented as a pair of signed degrees, with a 
00078 // specified precision.
00079 
00080 struct vil_nitf2_location_degrees : public vil_nitf2_location
00081 {
00082 public:
00083   vil_nitf2_location_degrees(int precision) 
00084     : vil_nitf2_location(format_degrees), precision(precision) {}
00085   bool read(vcl_istream& input, int field_width, bool& out_blank);
00086   bool write(vcl_ostream& output, int field_width);
00087   double lat_degrees; 
00088   double lon_degrees;
00089   int precision;
00090   vcl_ostream& output(vcl_ostream&) const;
00091   bool is_valid() const;
00092 };
00093 
00094 vcl_ostream& operator << (vcl_ostream& os, const vil_nitf2_location& loc);
00095 
00096 // Geodetic location represented as unsigned degrees, minutes, seconds, and
00097 // hemisphere, to a specified precision. (Currently this class assumes that
00098 // the coarsest precision is integer seconds, although that restriction
00099 // could easily be lifted.)
00100 
00101 struct vil_nitf2_location_dmsh : public vil_nitf2_location
00102 {
00103 public:
00104   vil_nitf2_location_dmsh(int sec_precision)
00105     : vil_nitf2_location(format_dmsh), sec_precision(sec_precision) {}
00106   bool read(vcl_istream& input, int field_width, bool& out_blank);
00107   bool write(vcl_ostream& output, int field_width);
00108   int lat_degrees; int lat_minutes; double lat_seconds; char lat_hemisphere;
00109   int lon_degrees; int lon_minutes; double lon_seconds; char lon_hemisphere;
00110   int sec_precision; // second's significant decimal places
00111   vcl_ostream& output(vcl_ostream&) const;
00112   bool is_valid() const;
00113 };
00114 
00115 vcl_ostream& operator << (vcl_ostream& os, const vil_nitf2_location_dmsh& loc);
00116 
00117 #endif // VIL_NITF2_COMPOUND_FIELD_VALUE_H