00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef NITFTREPARSER_H 00011 #define NITFTREPARSER_H 00012 00013 #include <iostream> 00014 00015 #include "EnumWrapper.h" 00016 00017 class DynamicObject; 00018 class ossimNitfRegisteredTag; 00019 class RasterDataDescriptor; 00020 class RasterFileDescriptor; 00021 00022 namespace Nitf 00023 { 00024 /** 00025 * The state of a given TRE. 00026 * 00027 * @see TreParser::isTreValid() 00028 */ 00029 enum TreStateEnum 00030 { 00031 VALID = 0, /**< A TRE is valid if all fields are present (and the correct type) and 00032 the values of each field are within their prescribed ranges. */ 00033 SUSPECT = 1, /**< A TRE is suspect if all of its fields are present (and the correct type) 00034 but the values of one or more fields are outside their prescribed ranges. */ 00035 INVALID = 2, /**< A TRE is invalid if fields are missing. */ 00036 UNTESTED = 3 /**< A TRE has not been tested. */ 00037 }; 00038 00039 /** 00040 * @EnumWrapper Nitf::TreStateEnum. 00041 */ 00042 typedef EnumWrapper<TreStateEnum> TreState; 00043 00044 /** 00045 * The status of a TRE export. 00046 * 00047 * @see TreParser::exportMetadata() 00048 */ 00049 enum TreExportStatusEnum 00050 { 00051 REMOVE, /**< Remove any existing TRE of the name without adding any generated ones. */ 00052 REPLACE, /**< Remove any existing TRE of the name while adding the one populated by 00053 TreParser::exportMetadata(). */ 00054 UNCHANGED /**< Let any TREs of the same name be exported without modifications. */ 00055 }; 00056 00057 /** 00058 * @EnumWrapper Nitf::TreExportStatusEnum. 00059 */ 00060 typedef EnumWrapper<TreExportStatusEnum> TreExportStatus; 00061 00062 /** 00063 * A plug-in interface used to read and write TREs while importing or exporting a NITF file. 00064 * 00065 * In order for the NITF importer and exporter to find your plug-in, you should ensure that the 00066 * plug-in name is the same 6-character string as the CETAG as the TRE. 00067 * 00068 * Implementers of this interface can use an existing OSSIM TRE plug-in by implementing 00069 * ossimTagToDynamicObject(ossimNitfRegisteredTag&, DynamicObject&) const and 00070 * ossimTagFromDynamicObject(const DynamicObject&, ossimNitfRegisteredTag&) const. The ossimNitfRegisteredTag 00071 * object will be that registered with OSSIM. 00072 * 00073 * Implementers can also simply perform stream operations for TRE import and export. In that case, 00074 * implement toDynamicObject(std::istream&, size_t, DynamicObject&) const and 00075 * fromDynamicObject(const DynamicObject&, std::ostream&, size_t&) const. 00076 * 00077 * @warning 00078 * The toDynamicObject and fromDynamicObject methods may be called multiple times during the life of the object. 00079 */ 00080 class TreParser 00081 { 00082 public: 00083 /** 00084 * The type that should be returned from PlugIn::getType() 00085 * for TRE parser plug-ins. 00086 * 00087 * @return Returns the type used for TRE parser plug-ins. 00088 */ 00089 static std::string Type() 00090 { 00091 return "NITF Tagged Record Extension Parser"; 00092 } 00093 00094 /** 00095 * The type that should be returned from PlugIn::getSubtype() 00096 * for TRE parser plug-ins which do not implement TreParser::exportMetadata(). 00097 * 00098 * @return Returns the subtype used for TRE parser plug-ins which do not 00099 * implement TreParser::exportMetadata(). 00100 * 00101 * @see TreParser::exportMetadata() 00102 */ 00103 static std::string NormalSubtype() 00104 { 00105 return ""; 00106 } 00107 00108 /** 00109 * The type that should be returned from PlugIn::getSubtype() 00110 * for TRE parser plug-ins which do implement TreParser::exportMetadata(). 00111 * 00112 * @return Returns the subtype used for TRE parser plug-ins which do 00113 * implement TreParser::exportMetadata(). 00114 * 00115 * @see TreParser::exportMetadata() 00116 */ 00117 static std::string CreateOnExportSubtype() 00118 { 00119 return "Create on export"; 00120 } 00121 00122 /** 00123 * Examine the TRE to determine if it is valid. 00124 * 00125 * @param tre 00126 * The TRE to examine. 00127 * @param reporter 00128 * Write to this ostream with information regarding a TreState::SUSPECT or TreState::INVALID 00129 * TRE. 00130 * 00131 * @return The TreState for the given TRE. 00132 */ 00133 virtual TreState isTreValid(const DynamicObject& tre, std::ostream& reporter) const = 0; 00134 00135 /** 00136 * Load the TRE directly from an ossimNitfRegisteredTag. 00137 * 00138 * Implementers should implement either this function or toDynamicObject(std::istream&, size_t, DynamicObject&) const 00139 * to load the TRE. 00140 * 00141 * @param input 00142 * The ossimNitfRegisteredTag to read from. 00143 * @param output 00144 * The DynamicObject to write to. 00145 * @param errorMessage 00146 * If this is modified by the function, it will be displayed to the 00147 * user as a warning that imported TREs might be incomplete, missing, etc. 00148 * 00149 * @warning This method may be called multiple times during the life of the object. 00150 * 00151 * @return True if the operation succeeded, false otherwise. 00152 */ 00153 virtual bool ossimTagToDynamicObject(const ossimNitfRegisteredTag& input, DynamicObject& output, 00154 std::string &errorMessage) const = 0; 00155 00156 /** 00157 * Load the TRE from an istream. 00158 * 00159 * Implementers should implement either this function or ossimTagToDynamicObject(ossimNitfRegisteredTag&, DynamicObject&) const 00160 * to load the TRE. This function will only be called if the other returned false. 00161 * 00162 * @param input 00163 * The istream to read from. The data within does not include the CETAG or CEL fields. 00164 * @param numBytes 00165 * The number of bytes to read. 00166 * @param output 00167 * The DynamicObject to write to. 00168 * @param errorMessage 00169 * If this is modified by the function, it will be displayed to the 00170 * user as a warning that imported TREs might be incomplete, missing, etc. 00171 * 00172 * @warning This method may be called multiple times during the life of the object. 00173 * 00174 * @return True if the operation succeeded, false otherwise. 00175 */ 00176 virtual bool toDynamicObject(std::istream& input, size_t numBytes, DynamicObject& output, 00177 std::string &errorMessage) const = 0; 00178 00179 /** 00180 * Write the TRE directly to an ossimNitfRegisteredTag. 00181 * 00182 * Implementers should implement either this function or fromDynamicObject(const DynamicObject&, std::ostream&, size_t&) const 00183 * to write the TRE. 00184 * 00185 * @param input 00186 * The DynamicObject to read from. 00187 * @param tre 00188 * The ossimNitfRegisteredTag to write to. 00189 * @param errorMessage 00190 * If this is modified by the function, it will be displayed to the 00191 * user as a warning that exported TREs might be incomplete, missing, etc. 00192 * 00193 * @warning This method may be called multiple times during the life of the object. 00194 * 00195 * @return True if the operation succeeded, false otherwise. 00196 */ 00197 virtual bool ossimTagFromDynamicObject(const DynamicObject& input, ossimNitfRegisteredTag& tre, 00198 std::string &errorMessage) const = 0; 00199 00200 /** 00201 * Write the TRE from a DynamicObject into an ostream. 00202 * 00203 * Implementers should implement either this function or ossimTagFromDynamicObject(const DynamicObject&, ossimNitfRegisteredTag&) const 00204 * to write the TRE. This function will only be called if the other returned false. 00205 * 00206 * @param input 00207 * The DynamicObject to read from. 00208 * @param output 00209 * The ostream to write to. Do not write the CETAG or CEL. 00210 * @param numBytesWritten 00211 * The number of bytes written. 00212 * @param errorMessage 00213 * If this is modified by the function, it will be displayed to the 00214 * user as a warning that exported TREs might be incomplete, missing, etc. 00215 * 00216 * @warning This method may be called multiple times during the life of the object. 00217 * 00218 * @return True if the operation succeeded, false otherwise. 00219 */ 00220 virtual bool fromDynamicObject(const DynamicObject& input, std::ostream& output, size_t& numBytesWritten, 00221 std::string &errorMessage) const = 0; 00222 00223 /** 00224 * Import contents of the TRE to specific fields within the descriptor. 00225 * 00226 * For example, a TRE might contain wavelength data which would be 00227 * appropriately represented in the \ref specialmetadata. 00228 * 00229 * @param tre 00230 * The parsed TRE to place copies of data within the descriptor. 00231 * @param descriptor 00232 * The descriptor to place copies of data within. 00233 * @param errorMessage 00234 * If this is modified by the function, it will be displayed to the 00235 * user as a warning that imported TREs might be incomplete, missing, etc. 00236 * 00237 * @return \c true if the operation successfully populated the descriptor, 00238 * \c false otherwise. This method should return \c false if there 00239 * is no need to import metadata into the descriptor. 00240 */ 00241 virtual bool importMetadata(const DynamicObject &tre, 00242 RasterDataDescriptor &descriptor, std::string &errorMessage) const = 0; 00243 00244 /** 00245 * Export contents descriptor into a tre. 00246 * 00247 * For example, a TRE might contain wavelength data which would be 00248 * appropriately represented in the \ref specialmetadata. 00249 * 00250 * This method can also be used to modify or create new TREs on export. 00251 * This might be desired if the TRE must be modified when chipping, 00252 * or to create a TRE for a dataset not initially loaded as a NITF. 00253 * 00254 * @param descriptor 00255 * The data descriptor to export from. 00256 * @param exportDescriptor 00257 * The descriptor which specifies which portion is to be exported. 00258 * @param tre 00259 * On return, this should contain the TRE to export with a 00260 * future call to fromDynamicObject(). 00261 * @param ownerIndex 00262 * When returning TreExportStatus::REPLACE, specifies the index of the owner of this tag. 00263 * This should be set to 0 for the file header and 1 for the image subheader. 00264 * If this value is unspecified, it will default to the image subheader. 00265 * @param tagType 00266 * When returning TreExportStatus::REPLACE, specifies the type of this tag. 00267 * Valid values are "UDHD" "UDID", "XHD", and "IXSHD". 00268 * If this value is unspecified, it will default to "IXSHD". 00269 * @param errorMessage 00270 * If this is modified by the function, it will be displayed to the 00271 * user as a warning that exported TREs might be incomplete, missing, etc. 00272 * 00273 * @return A TreExportStatus which indicates what to do with existing and created 00274 * TREs that this parser handles. 00275 * 00276 * @see CreateOnExportSubtype() 00277 */ 00278 virtual TreExportStatus exportMetadata(const RasterDataDescriptor &descriptor, 00279 const RasterFileDescriptor &exportDescriptor, 00280 DynamicObject &tre, unsigned int &ownerIndex, std::string &tagType, std::string &errorMessage) const = 0; 00281 }; 00282 } 00283 00284 #endif