vil_nitf2_field_formatter.h
Go to the documentation of this file.
1 // vil_nitf2: Written by Harry Voorhees (hlv@) and Rob Radtke (rob@) of
2 // Stellar Science Ltd. Co. (stellarscience.com) for
3 // Air Force Research Laboratory, 2005.
4 
5 #ifndef VIL_NITF2_FIELD_FORMATTER_H
6 #define VIL_NITF2_FIELD_FORMATTER_H
7 
8 #include <string>
9 #include <istream>
10 #include <ostream>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 #include "vil_nitf2.h"
16 class vil_nitf2_field;
19 class vil_nitf2_location;
22 
23 //-----------------------------------------------------------------------------
24 // A subclass of NITF field formatter exists for each NITF field data type.
25 // These are used to define record extensions (as opposed to representing
26 // values); they are used to read and write individual fields of the NITF
27 // stream.
28 
29 // All formatters definitions include a field width, typically a std::fixed width,
30 // unless a length functor is specified which is evaluated when the file is
31 // read.
32 //
33 // Some fields include "precision" (the length of mantissa). For some numeric
34 // fields, NITF allows blanks in lieu of insignificant decimal values.
35 // For this reason, the precision stored in a field may (once implemented)
36 // be less than the Formatter's precision.
37 
38 // Base class for NITF field formatters
39 //
41 {
42  public:
43  // Field types currently supported
44 
47 
50 
51  // Destructor
52  virtual ~vil_nitf2_field_formatter() = default;
53 
54  // Virtual copy method
55  virtual vil_nitf2_field_formatter* copy() const = 0;
56 
57  // Attempts to read scalar field from stream. Returns a new instance of field if
58  // success and 0 otherwise. Sets out_blank to whether input was entirely blank
59  // (in which case 0 is returned).
61  vil_nitf2_istream& input, bool& out_blank) = 0;
62 
63  // Initializes a vector field of specified dimensionality
65  int num_dimensions, vil_nitf2_field_definition*) = 0;
66 
67  virtual bool write_field(vil_nitf2_ostream& output, const vil_nitf2_scalar_field* field) = 0;
68 
69  // Writes a blank instance of field value to output stream. Returns
70  // true iff successfully written. No need to overload this method.
71  bool write_blank(std::ostream& output);
72 
73  // Same as above, but writes to a vil_stream.
74  bool write_blank(vil_stream& output);
75 
76  // Helper function which reads the specified number characters into
77  // a string (if possible), which it returns as a null-terminated C string,
78  // which the caller owns. The length of the C string reflects the number
79  // of characters read.
80  static char* read_char_array(std::istream& input, int length);
81  static bool read_c_str(std::istream& input, int length,
82  char*& out_cstr, bool& all_blank);
83  // Same as above, but returns a std::string.
84  static std::string read_string(std::istream& input, int length);
85  // Same as above, but takes a vil_stream as input
86  static std::string read_string(vil_stream& input, int length);
87 
88  // Helper function to test presence of number sign. Returns true
89  // iff first character is consistent with flag show_sign.
90  static bool check_sign(const char* cstr, bool show_sign);
91 
92  // Helper function to test whether the null-terminated C std::string contains
93  // all blanks
94  static bool is_all_blank(const char* cstr);
95 };
96 
97 #endif // VIL_NITF2_FIELD_FORMATTER_H
static bool is_all_blank(const char *cstr)
static std::string read_string(std::istream &input, int length)
virtual vil_nitf2_scalar_field * read_field(vil_nitf2_istream &input, bool &out_blank)=0
virtual bool write_field(vil_nitf2_ostream &output, const vil_nitf2_scalar_field *field)=0
virtual vil_nitf2_field_formatter * copy() const =0
vil_nitf2_field_formatter(vil_nitf2::enum_field_type field_type, int field_width)
static bool check_sign(const char *cstr, bool show_sign)
static char * read_char_array(std::istream &input, int length)
virtual ~vil_nitf2_field_formatter()=default
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
enum_field_type
Definition: vil_nitf2.h:36
bool write_blank(std::ostream &output)
virtual vil_nitf2_array_field * create_array_field(int num_dimensions, vil_nitf2_field_definition *)=0
vil_nitf2::enum_field_type field_type
static bool read_c_str(std::istream &input, int length, char *&out_cstr, bool &all_blank)
Abstract class for array fields, i.e., fields that occur within a repeat loop.