vil_nitf2_typed_scalar_field.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_TYPED_SCALAR_FIELD_H
6 #define VIL_NITF2_TYPED_SCALAR_FIELD_H
7 
8 #include <iosfwd>
9 #include <utility>
10 #include "vil_nitf2.h"
11 #include "vil_nitf2_scalar_field.h"
13 #ifdef _MSC_VER
14 # include <vcl_msvc_warnings.h>
15 #endif
16 
17 // Typed concrete class for scalar NITF fields.
18 // During file reading, this class is instantiated only for non-blank
19 // fields that are successfully parsed. Thus, every instance of
20 // vil_nitf2_scalar_field represents a valid value.
21 //
22 template<class T>
24 {
25  public:
26  // Constructor
28  : vil_nitf2_scalar_field(definition), m_value(std::move(value)) {}
29 
30  // Destructor
32 
33  // Set out_value to my value and return true.
34  // (This is a partial override of overloaded method
35  // vil_nitf2_scalar_field::value() for my specific type.)
36  bool value(T& out_value) const override {
37  out_value = m_value;
38  return true;
39  }
40 
41  // Return my value
42  // (was named value(), renamed to avoid an internal bcc compiler error)
43  T get_value() const { return m_value; }
44 
45  // Set value
46  void set_value(const T& value) { m_value = value; }
47 
48  // Output to stream. Overload as necessary.
49  std::ostream& output(std::ostream& os) const override { return os << m_value; }
50 
51  field_tree* get_tree() const override { return vil_nitf2_scalar_field::get_tree(); }
52  private:
54 };
55 
56 //==============================================================================
57 // implementation
58 //==============================================================================
59 
61 
62 // Overload for vil_nitf2_location* (Necessary because it's a pointer.)
63 template<>
64 inline std::ostream& vil_nitf2_typed_scalar_field<vil_nitf2_location*>::output(std::ostream& os) const
65 {
66  if (m_value==0) {
67  os << m_value;
68  }
69  else {
70  os << *m_value;
71  }
72  return os;
73 }
74 
75 template<>
78 {
79  field_tree* tr = new field_tree;
80  tr->columns.emplace_back("TREs" );
81  vil_nitf2_tagged_record_sequence::const_iterator it;
82  for ( it = m_value.begin() ; it != m_value.end() ; it++ ) {
83  tr->children.push_back( (*it)->get_tree() );
84  }
85  return tr;
86 }
87 
88 template<>
90 {
91  // vector delete corresponds to new char[] of binary data
92  delete[] (char*) m_value;
93 }
94 
95 template<>
97 {
98  delete m_value;
99 }
100 
101 template<typename T>
103 {
104  // NO operations needed for pod types
105 }
106 
107 #endif // VIL_NITF2_TYPED_SCALAR_FIELD_H
std::ostream & output(std::ostream &os) const override
std::vector< std::string > columns
vil_nitf2_typed_scalar_field(T value, vil_nitf2_field_definition *definition)
field_tree * get_tree() const override
field_tree * get_tree() const override
std::vector< field_tree * > children
bool value(T &out_value) const override