OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfDataExtensionSegmentV2_1.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 // Description: Nitf support class
9 //
10 //********************************************************************
11 // $Id: ossimNitfDataExtensionSegmentV2_1.cpp 9094 2006-06-13 19:12:40Z dburken $
12 
13 #include <iostream>
14 
18 
23 
24 
36 
39 {
40  out << "theFilePartType: " << data.theFilePartType
41  << "\ntheUniqueDataExtTypeId: " << data.theUniqueDataExtTypeId
42  << "\ntheVersionDataFieldDef: " << data.theVersionDataFieldDef
43  << "\ntheDataExtSecurityClass: " << data.theDataExtSecurityClass
44  << "\ntheDataExtClassSystem: " << data.theDataExtClassSystem
45  << "\ntheDataExtCodewords: " << data.theDataExtCodewords
46  << "\ntheDataExtControlAndHand: " << data.theDataExtControlAndHand
47  << "\ntheDataExtReleasingInst: " << data.theDataExtReleasingInst
48  << "\ntheDataExtDeclassType: " << data.theDataExtDeclassType
49  << "\ntheDataExtDeclassDate: " << data.theDataExtDeclassDate
50  << "\ntheDataExtDeclassExempt: " << data.theDataExtDeclassExempt
51  << "\ntheDataExtSecurityDowngrade: " << data.theDataExtSecurityDowngrade
52  << "\ntheDataExtSecurityDowngradeDate:" << data.theDataExtSecurityDowngradeDate
53  << "\ntheDataExtSecurityClassText: " << data.theDataExtSecurityClassText
54  << "\ntheDataExtClassAuthType: " << data.theDataExtClassAuthType
55  << "\ntheDataExtClassAuthority: " << data.theDataExtClassAuthority
56  << "\ntheDataExtClassReason: " << data.theDataExtClassReason
57  << "\ntheDataExtSecuritySourceDate: " << data.theDataExtSecuritySourceDate
58  << "\ntheDataExtSecurityConNum: " << data.theDataExtSecurityConNum
59  << std::endl;
60 
61  return out;
62 }
63 
65  theUserDefinedSubheaderFields(0),
66  theData(0)
67 {
68  clearFields();
69 }
70 
72 {
73 
74 }
75 
77 {
78  if(in)
79  {
80  clearFields();
81 
82  in.read(theIdentSecurityChunk.theFilePartType, 2); // 2 byte alpha
83  in.read(theIdentSecurityChunk.theUniqueDataExtTypeId, 25); // 25 byte alpha numeric
84  in.read(theIdentSecurityChunk.theVersionDataFieldDef, 2); // 2 byte numeric
85  in.read(theIdentSecurityChunk.theDataExtSecurityClass, 1); // 1 byte alpha
87  in.read(theIdentSecurityChunk.theDataExtCodewords, 11); // 11 byte alpha numeric
88  in.read(theIdentSecurityChunk.theDataExtControlAndHand, 2); // 2 byte alpha numeric
89  in.read(theIdentSecurityChunk.theDataExtReleasingInst, 20); // 20 byte alpha numeric
90  in.read(theIdentSecurityChunk.theDataExtDeclassType, 2); // 2 byte alph num
91  in.read(theIdentSecurityChunk.theDataExtDeclassDate, 8); // 8 byte alph num
92  in.read(theIdentSecurityChunk.theDataExtDeclassExempt, 4); // 4 byte alpha num
93  in.read(theIdentSecurityChunk.theDataExtSecurityDowngrade, 1); // 1 byte alpha num
94  in.read(theIdentSecurityChunk.theDataExtSecurityDowngradeDate, 8); // 8 byte alpha num
95  in.read(theIdentSecurityChunk.theDataExtSecurityClassText, 43); // 43 byte alpha num
96  in.read(theIdentSecurityChunk.theDataExtClassAuthType, 1); // 1 byte alpha num
97  in.read(theIdentSecurityChunk.theDataExtClassAuthority, 40); // 40 byte alpha num
98  in.read(theIdentSecurityChunk.theDataExtClassReason, 1); // 1 byte alpha num
99  in.read(theIdentSecurityChunk.theDataExtSecuritySourceDate, 8); // 8 byte alpha num
100  in.read(theIdentSecurityChunk.theDataExtSecurityConNum, 15); // 15 byte alpha num
101 
102  bool overflow = ossimString(theIdentSecurityChunk.theUniqueDataExtTypeId).trim().upcase() == "TRE_OVERFLOW";
103  if (overflow)
104  {
105  in.read(theOverflowedHeaderType, 6);
106  in.read(theDataItemOverflowed, 3);
107  }
108 
110 
111  // look to see if there is any data and if so read the tag
112  // to see what it is
114  if (length > 0)
115  {
116  theUserDefinedSubheaderFields.resize(length);
117  in.read(reinterpret_cast<char*>(&theUserDefinedSubheaderFields.front()), theUserDefinedSubheaderFields.size());
118  }
119 
120  if (dataLength != 0)
121  {
122  if (overflow)
123  {
124  std::streamoff dataBegin = in.tellg();
125  std::streamoff dataEnd = dataBegin + static_cast<std::streamoff>(dataLength);
126 
127  // dataBegin + static_cast<istream::pos_type>(dataLength))
128  while (in.good() && (in.tellg() < dataEnd) )
129  {
131  tag.clearFields();
132  tag.parseStream(in);
133  theTagList.push_back(tag);
134  }
135 
136  ossimIFStream64::seekg64(in, dataBegin, ios::beg);
137  in.clear();
138  }
139 
140  theData.resize(dataLength);
141  in.read(reinterpret_cast<char*>(&theData.front()), theData.size());
142  }
143  }
144 }
145 
147 {
148  if (out)
149  {
169 
170  bool overflow = ossimString(theIdentSecurityChunk.theUniqueDataExtTypeId).trim().upcase() == "TRE_OVERFLOW";
171  if (overflow)
172  {
173  out.write(theOverflowedHeaderType, 6);
174  out.write(theDataItemOverflowed, 3);
175  }
176 
178  for (unsigned int i = 0; i < theUserDefinedSubheaderFields.size(); i++)
179  {
180  out.write(reinterpret_cast<char*>(&theUserDefinedSubheaderFields.front()), theUserDefinedSubheaderFields.size());
181  }
182 
183  if (overflow && theTagList.empty() == false)
184  {
185  for (std::vector<ossimNitfTagInformation>::iterator iter = theTagList.begin();
186  iter != theTagList.end(); ++iter)
187  {
188  iter->writeStream(out);
189  }
190  }
191  else
192  {
193  out.write(reinterpret_cast<char*>(&theData.front()), theData.size());
194  }
195  }
196 }
197 
199 {
200  memset(theIdentSecurityChunk.theFilePartType, ' ', 2);
219 
220  memset(theOverflowedHeaderType, ' ', 6);
221  memset(theDataItemOverflowed, '0', 3);
223 
243 
244  theOverflowedHeaderType[6] = '\0';
245  theDataItemOverflowed[3] = '\0';
248  theData.clear();
249  theTagList.clear();
250 }
251 
252 void ossimNitfDataExtensionSegmentV2_1::setTagList(const std::vector<ossimNitfTagInformation> &tagList)
253 {
254  theTagList = tagList;
255  theData.clear();
256 }
257 
259 {
276 }
277 
279 {
280  out << "theIdentSecurityChunk: "
282  << "\ntheOverflowedHeaderType: "
284  << "\ntheDataItemOverflowed: "
286  << "\ntheLengthOfUserDefinedSubheaderFields: "
288  << "\ntag count: "
289  << theTagList.size() << std::endl;
290  return out;
291 }
292 
294 {
296  {
297  return 209;
298  }
299 
300  return 200 + theUserDefinedSubheaderFields.size();
301 }
302 
304 {
305  ossim_uint64 totalDataLength = 0;
306  if (theTagList.empty() == true)
307  {
308  totalDataLength = theData.size();
309  }
310  else
311  {
312  for (std::vector<ossimNitfTagInformation>::const_iterator iter = theTagList.begin();
313  iter != theTagList.end(); iter++)
314  {
315  totalDataLength += iter->getTotalTagLength();
316  }
317  }
318 
319  return totalDataLength;
320 }
321 
323 {
324  if (property.get() == NULL)
325  {
326  return;
327  }
328 
329  const ossimString& name = property->getName();
330  if (name == DE_KW)
331  {
333  }
334  else if (name == DESID_KW)
335  {
337  }
338  else if (name == DESVER_KW)
339  {
341  }
342  else if (name == DECLAS_KW)
343  {
345  }
346  else if (name == DESCLSY_KW)
347  {
349  }
350  else if (name == DESCODE_KW)
351  {
353  }
354  else if (name == DESCTLH_KW)
355  {
357  }
358  else if (name == DESREL_KW)
359  {
361  }
362  else if (name == DESDCTP_KW)
363  {
365  }
366  else if (name == DESDCDT_KW)
367  {
369  }
370  else if (name == DESDCXM_KW)
371  {
373  }
374  else if (name == DESDG_KW)
375  {
377  }
378  else if (name == DESDGDT_KW)
379  {
381  }
382  else if (name == DESCLTX_KW)
383  {
385  }
386  else if (name == DESCATP_KW)
387  {
389  }
390  else if (name == DESCAUT_KW)
391  {
393  }
394  else if (name == DESCRSN_KW)
395  {
397  }
398  else if (name == DESSRDT_KW)
399  {
401  }
402  else if (name == DESCTLN_KW)
403  {
405  }
406  else if (name == DESOFLW_KW)
407  {
409  }
410  else if (name == DESITEM_KW)
411  {
412  ossimNitfCommon::setField(theDataItemOverflowed, property->valueToString(), 3, ios::right, '0');
413  }
414  else if (name == DESSHL_KW)
415  {
417  }
418  else if (name == DESSHF_KW)
419  {
420  ossimBinaryDataProperty* pBinaryData = PTR_CAST(ossimBinaryDataProperty, property.get());
421  if (pBinaryData != NULL)
422  {
424  }
425  }
426  else if (name == DESDATA_KW)
427  {
428  ossimBinaryDataProperty* pBinaryData = PTR_CAST(ossimBinaryDataProperty, property.get());
429  if (pBinaryData != NULL)
430  {
431  theData = pBinaryData->getBinaryData();
432  }
433  }
434 }
435 
437 {
438  ossimProperty* property = 0;
439  if (name == DE_KW)
440  {
442  }
443  else if (name == DESID_KW)
444  {
446  }
447  else if (name == DESVER_KW)
448  {
450  }
451  else if (name == DECLAS_KW)
452  {
454  }
455  else if (name == DESCLSY_KW)
456  {
458  }
459  else if (name == DESCODE_KW)
460  {
462  }
463  else if (name == DESCTLH_KW)
464  {
466  }
467  else if (name == DESREL_KW)
468  {
470  }
471  else if (name == DESDCTP_KW)
472  {
474  }
475  else if (name == DESDCDT_KW)
476  {
478  }
479  else if (name == DESDCXM_KW)
480  {
482  }
483  else if (name == DESDG_KW)
484  {
486  }
487  else if (name == DESDGDT_KW)
488  {
490  }
491  else if (name == DESCLTX_KW)
492  {
494  }
495  else if (name == DESCATP_KW)
496  {
498  }
499  else if (name == DESCAUT_KW)
500  {
502  }
503  else if (name == DESCRSN_KW)
504  {
506  }
507  else if (name == DESSRDT_KW)
508  {
510  }
511  else if (name == DESCTLN_KW)
512  {
514  }
515  else if (name == DESOFLW_KW)
516  {
517  property = new ossimStringProperty(name, ossimString(theOverflowedHeaderType).trim());
518  }
519  else if (name == DESITEM_KW)
520  {
521  property = new ossimStringProperty(name, ossimString(theDataItemOverflowed).trim());
522  }
523  else if (name == DESSHL_KW)
524  {
526  }
527  else if (name == DESSHF_KW)
528  {
530  }
531  else if (name == DESDATA_KW)
532  {
533  // Only valid if setTagList has not been called on this object.
534  property = new ossimBinaryDataProperty(name, theData);
535  }
536 
537  return property;
538 }
539 
540 void ossimNitfDataExtensionSegmentV2_1::getPropertyNames(std::vector<ossimString>& propertyNames)const
541 {
543  propertyNames.push_back(DESID_KW);
544  propertyNames.push_back(DESCLSY_KW);
545  propertyNames.push_back(DESDCTP_KW);
546  propertyNames.push_back(DESDCDT_KW);
547  propertyNames.push_back(DESDCXM_KW);
548  propertyNames.push_back(DESDG_KW);
549  propertyNames.push_back(DESDGDT_KW);
550  propertyNames.push_back(DESCLTX_KW);
551  propertyNames.push_back(DESCATP_KW);
552  propertyNames.push_back(DESCRSN_KW);
553  propertyNames.push_back(DESSRDT_KW);
554 }
virtual void valueToString(ossimString &valueResult) const =0
virtual std::ostream & print(std::ostream &out) const
Generic print method.
std::vector< ossimNitfTagInformation > theTagList
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
virtual ossimString getClassificationAuthority() const
virtual ossimString getDowngrade() const
virtual ossimString getClassificationReason() const
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual void parseStream(ossim::istream &in)
virtual ossimString getSecurityClassification() const
virtual ossimString getSecuritySourceDate() const
const vector< unsigned char > & getBinaryData() const
virtual ossimString getClassificationAuthorityType() const
virtual ossimString getCodeWords() const
virtual void parseStream(std::istream &in, ossim_uint64 dataLength)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual ossimString getSecurityControlNumber() const
virtual ossimString getDowngradingDate() const
virtual ossimString getClassificationText() const
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual ossimString getSecurityClassificationSys() const
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.
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual ossimString getControlAndHandling() const
virtual ossimString getDeclassificationDate() const
virtual ossimString getDeclassificationExemption() const
virtual void setTagList(const std::vector< ossimNitfTagInformation > &tagList)
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual ossimString getDeclassificationType() const
std::ostream & operator<<(std::ostream &out, const ossimNitfDataExtIdentSecurityChunkV2_1 &data)
ossimNitfDataExtIdentSecurityChunkV2_1 theIdentSecurityChunk
std::vector< unsigned char > theUserDefinedSubheaderFields
void seekg64(off_type off, ios_base::seekdir way)
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
long toLong() const
toLong&#39;s deprecated, please use the toInts...
virtual ossimString getReleasingInstructions() const
virtual void setSecurityMarkings(const ossimNitfFileHeaderV2_1 &fileHeader)
static void setField(void *fieldDestination, const ossimString &src, std::streamsize width, std::ios_base::fmtflags ioflags=std::ios::left, char fill=' ')
Sets a field with a given string, width, and IOS flags.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23