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_TYPED_SCALAR_FIELD_H 00006 #define VIL_NITF2_TYPED_SCALAR_FIELD_H 00007 00008 #include "vil_nitf2_scalar_field.h" 00009 #include "vil_nitf2.h" 00010 #include <vcl_iosfwd.h> 00011 00012 // Typed concrete class for scalar NITF fields. 00013 // During file reading, this class is instantiated only for non-blank 00014 // fields that are successfully parsed. Thus, every instance of 00015 // vil_nitf2_scalar_field represents a valid value. 00016 // 00017 template<class T> 00018 class vil_nitf2_typed_scalar_field : public vil_nitf2_scalar_field 00019 { 00020 public: 00021 // Constructor 00022 vil_nitf2_typed_scalar_field(T value, vil_nitf2_field_definition* definition) 00023 : vil_nitf2_scalar_field(definition), m_value(value) {} 00024 00025 // Desructor 00026 ~vil_nitf2_typed_scalar_field(){}; 00027 00028 // Set out_value to my value and return true. 00029 // (This is a partial override of overloaded method 00030 // vil_nitf2_scalar_field::value() for my specific type.) 00031 virtual bool value(T& out_value) const { 00032 out_value = m_value; 00033 return true; 00034 } 00035 00036 // Return my value 00037 // (was named value(), renamed to avoid an internal bcc compiler error) 00038 T get_value() const { return m_value; } 00039 00040 // Set value 00041 void set_value(const T& value) { m_value = value; } 00042 00043 // Output to stream. Overload as necessary. 00044 virtual vcl_ostream& output(vcl_ostream& os) const { return os << m_value; }; 00045 00046 virtual field_tree* get_tree() const { return vil_nitf2_scalar_field::get_tree(); } 00047 private: 00048 T m_value; 00049 }; 00050 00051 //============================================================================== 00052 // implementation 00053 //============================================================================== 00054 00055 #include "vil_nitf2_compound_field_value.h" 00056 00057 // Overload for vil_nitf2_location* (Necessary because it's a pointer.) 00058 template<> 00059 inline vcl_ostream& vil_nitf2_typed_scalar_field<vil_nitf2_location*>::output(vcl_ostream& os) const 00060 { 00061 if (m_value==0) { 00062 os << m_value; 00063 } else { 00064 os << *m_value; 00065 } 00066 return os; 00067 } 00068 00069 template<> 00070 inline vil_nitf2_field::field_tree* 00071 vil_nitf2_typed_scalar_field<vil_nitf2_tagged_record_sequence>::get_tree() const 00072 { 00073 field_tree* tr = new field_tree; 00074 tr->columns.push_back( "TREs" ); 00075 vil_nitf2_tagged_record_sequence::const_iterator it; 00076 for( it = m_value.begin() ; it != m_value.end() ; it++ ) { 00077 tr->children.push_back( (*it)->get_tree() ); 00078 } 00079 return tr; 00080 } 00081 00082 template<> 00083 inline vil_nitf2_typed_scalar_field<void*>::~vil_nitf2_typed_scalar_field() 00084 { 00085 // vector delete corresponds to new char[] of binary data 00086 delete[] (char*) m_value; 00087 } 00088 00089 template<> 00090 inline vil_nitf2_typed_scalar_field<vil_nitf2_location*>::~vil_nitf2_typed_scalar_field() 00091 { 00092 delete m_value; 00093 } 00094 00095 #endif // VIL_NITF2_TYPED_SCALAR_FIELD_H
1.4.4