core/vil/file_formats/vil_nitf2_scalar_field.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_SCALAR_FIELD_H
00006 #define VIL_NITF2_SCALAR_FIELD_H
00007 
00008 #include "vil_nitf2_field.h"
00009 
00010 class vil_nitf2_field_definition;
00011 class vil_nitf2_tagged_record_sequence;
00012 
00013 // An abstract class that represents a scalar field, i.e., one that
00014 // is not within a repeat loop. Subclasses store the type-specific
00015 // value.
00016 
00017 class vil_nitf2_scalar_field : public vil_nitf2_field
00018 {
00019  public:
00020   vil_nitf2_scalar_field(vil_nitf2_field_definition* definition)
00021     : vil_nitf2_field(definition) {}
00022 
00023   virtual ~vil_nitf2_scalar_field() {}
00024 
00025   virtual int num_dimensions() const { return 0; }
00026 
00027   // Sets output argument to the value of field. Subclasses overload the
00028   // appropriate method to set out parameter and return true. These methods
00029   // are defined here for the convenience of my callers, so they don't
00030   // have to downcast to the specific field type.
00031 #if VXL_HAS_INT_64
00032   virtual bool value(vil_nitf2_long&) const { return false; }
00033 #endif
00034   virtual bool value(int&) const { return false; }
00035   virtual bool value(double&) const { return false; }
00036   virtual bool value(char&) const { return false; }
00037   virtual bool value(void*&) const { return false; }
00038   virtual bool value(vcl_string&) const { return false; }
00039   virtual bool value(vil_nitf2_location*&) const { return false; }
00040   virtual bool value(vil_nitf2_date_time&) const { return false; }
00041   virtual bool value(vil_nitf2_tagged_record_sequence&) const { return false; }
00042 
00043   // Attempts to read a scalar field from input stream, using specified
00044   // definition. Returns field if successfully created.  May set arg
00045   // error to true even if field is returned; for example, if it's a
00046   // required (non-blank) field that is all blank. If variable_width
00047   // is non-negative, it overrides the formatter's field width.
00048   static vil_nitf2_scalar_field* read(vil_nitf2_istream& input,
00049                                       vil_nitf2_field_definition* definition,
00050                                       int variable_width = -1,
00051                                       bool* error = 0);
00052 
00053   virtual field_tree* get_tree() const;
00054 
00055   // Write to NITF stream. Arg variable_width, if non-negative, overrides
00056   // formatter's field_width.
00057   bool write(vil_nitf2_ostream& output, int variable_width = -1) const;
00058 };
00059 
00060 #endif // VIL_NITF2_SCALAR_FIELD_H