OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfTagInformation.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // LICENSE: MIT
4 //
5 // Author: Garrett Potts
6 // Description: Nitf support class
7 //
8 //********************************************************************
9 // $Id$
10 
12 #include <ossim/base/ossimCommon.h>
14 #include <ossim/base/ossimNotify.h>
17 #include <sstream>
18 #include <iomanip>
19 #include <cstring> // for memset
20 
22 {
23  clearFields();
24  setTagData(tagData);
25 }
26 
28 {
29 }
30 
32 {
33  if(in)
34  {
35  clearFields();
36  theTagOffset = in.tellg();
37  in.read(theTagName, 6);
38  in.read(theTagLength, 5);
39  theTagDataOffset = in.tellg();
40 
42 
43  if (theTagData.valid())
44  {
45  if (theTagData->getClassName() == "ossimNitfUnknownTag")
46  {
47  // Unknown tag doesn't know his tag name yet.
49  }
50 
51  //---
52  // Tags with dynamic tag length construct with 0 length.
53  // Set if 0.
54  //---
55  if ( theTagData->getTagLength() == 0 )
56  {
58  }
59  // Sanity check fixed length in code with length from CEL field:
60  else if ( theTagData->getTagLength() != getTagLength() )
61  {
63  << "ossimNitfTagInformation::parseStream WARNING!"
64  << "\nCEL field length does not match fixed tag length for tag: "
65  << theTagData->getTagName().c_str()
66  << "\nCEL: " << getTagLength()
67  << "\nTag: " << theTagData->getTagLength()
68  << std::endl;
69  }
70 
72  }
73  else
74  {
76  }
77  }
78 }
79 
81 {
82  theTagOffset = out.tellp(); // Capture the offset.
83  out.write(theTagName, 6);
84  out.write(theTagLength, 5);
85  if(theTagData.valid())
86  {
87  theTagDataOffset = out.tellp();
88  theTagData->writeStream(out);
89  }
90 }
91 
93 {
94  return (getTagLength() + (ossim_uint32)11);
95 }
96 
98 {
100 }
101 
103 {
104  return theTagOffset;
105 }
106 
108 {
109  return theTagDataOffset;
110 }
111 
113 {
114  return ossimString(theTagName).trim();
115 }
116 
118 {
119  out << "theTagName: " << theTagName
120  << "\ntheTagLength: " << theTagLength
121  << "\ntheTagType: " << theTagType
122  << "\ntheTagOffset: " << theTagOffset
123  << "\ntheTagDataOffset: " << theTagDataOffset
124  << std::endl;
125 
126  return out;
127 }
128 
130 {
131  memset(theTagName, ' ', 6);
132  memset(theTagLength, 0, 5);
133  strcpy(theTagType, "IXSHD ");
134 
135  theTagName[6] = '\0';
136  theTagLength[5] = '\0';
137 
138  theTagOffset = 0;
139  theTagDataOffset = 0;
140 }
141 
143 {
144  memset(theTagName, ' ', 6);
145 
146  std::ostringstream out;
147 
148  out << std::setw(6)
149  << std::setfill(' ')
150  << tagName;
151  memcpy(theTagName, out.str().c_str(), 6);
152 }
153 
155 {
156  memset(theTagLength, 0, 5);
157 
158  if(tagLength > 99999)
159  {
160  tagLength = 99999;
161  }
162 
163  std::ostringstream out;
164 
165  out << std::setw(5)
166  << std::setfill('0')
167  << tagLength;
168 
169  memcpy(theTagLength, out.str().c_str(), 5);
170 }
171 
173 {
174  return theTagData;
175 }
176 
178 {
179  return theTagData;
180 }
181 
183 {
184  theTagData = tagData;
185 
186  memset(theTagName, ' ', 6);
187  memset(theTagLength, ' ', 5);
188 
189  if(theTagData.valid())
190  {
193  }
194 }
196 {
197  return ossimString(theTagType).trim();
198 }
199 
201 {
202  std::ostringstream out;
203  out << std::setw(6)
204  << std::setfill(' ')
205  << std::setiosflags(std::ios::left)
206  << tagType;
207  memcpy(theTagType, out.str().c_str(), 6);
208  theTagType[6] = 0;
209 }
210 
virtual const std::string & getTagName() const
This will return the name of the registered tag for this user defined header.
ossimRefPtr< ossimNitfRegisteredTag > theTagData
Used to hold the tag data.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void writeStream(ossim::ostream &out)=0
bool valid() const
Definition: ossimRefPtr.h:75
ossim_uint64 getTagDataOffset() const
virtual void parseStream(ossim::istream &in)=0
This will allow the user defined data to parse the stream.
virtual void parseStream(ossim::istream &in)
virtual std::string getRegisterTagName() const
This will return the name of the registered tag for this user defined header.
char theTagLength[6]
This is a 5 byte field.
void setTagType(const ossimString &tagType) const
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
ossim_uint32 toUInt32() const
virtual void setTagLength(ossim_uint32 length)
Set the tag length.
virtual ossim_uint32 getTagLength() const
Returns the length in bytes of the tag from the CEL or REL field.
void setTagData(ossimRefPtr< ossimNitfRegisteredTag > tagData)
virtual void setTagName(const std::string &tagName)
ossimRefPtr< ossimNitfRegisteredTag > getTagData()
ossimNitfTagInformation(ossimRefPtr< ossimNitfRegisteredTag > tagData=0)
unsigned long long ossim_uint64
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
static ossimNitfTagFactoryRegistry * instance()
virtual void writeStream(ossim::ostream &out)
void setTagName(const ossimString &tagName)
ossim_uint32 getTotalTagLength() const
Length of the 5 byte tag length the 6 byte tag name and the data length.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossim_uint64 theTagOffset
This will hold the offset to the start of the above information This is just a work variable...
virtual ossim_uint32 getSizeInBytes() const
Returns the length in bytes of the tag from the CEL or REL field.
char theTagName[7]
This is a 6 byte field.
ossim_uint64 theTagDataOffset
This will hold the start to the data.
char theTagType[7]
This is a 6 byte field which should be UDHD, UDID, XHD, IXSHD, SXSHD, or TXSHD.
void setTagLength(ossim_uint32 tagLength)
ossim_uint32 getTagLength() const
Should return the value of theTagLength which is the length of the data in bytes. ...
ossimRefPtr< ossimNitfRegisteredTag > create(const ossimString &tagName) const
virtual std::ostream & print(std::ostream &out) const
Generic print method.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23