OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRpfHeader.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 // Description: This class extends the stl's string class.
10 //
11 //********************************************************************
12 // $Id: ossimRpfHeader.cpp 22702 2014-04-02 13:50:02Z gpotts $
13 
14 #include <cstring>
15 #include <iostream>
16 #include <fstream>
17 
19 #include <ossim/base/ossimCommon.h> /* ossim::byteOrder() */
20 #include <ossim/base/ossimEndian.h>
21 #include <ossim/base/ossimString.h>
24 #include <ossim/base/ossimNotify.h>
39 
40 #include <ossim/base/ossimTrace.h>
41 
42  // Static trace for debugging
43 static ossimTrace traceDebug("ossimRpfHeader:debug");
44 
45 // Keywords:
46 static const ossimString HEADER_SECTION_LENGTH_KW = "HeaderSectionLength";
47 static const ossimString NEW_REP_UP_INDICATOR_KW = "NewRepUpIndicator";
48 static const ossimString GOV_SPEC_NUMBER_KW = "GovSpecNumber";
49 static const ossimString GOV_SPEC_DATE_KW = "GovSpecDate";
50 static const ossimString SECURITY_CLASSIFICATION_KW = "SecurityClassification";
51 static const ossimString COUNTRY_CODE_KW = "CountryCode";
52 static const ossimString SECURITY_RELEASE_MARKING_KW = "SecurityReleaseMarking";
53 
54 
56  :
57  ossimNitfRegisteredTag(std::string("RPFHDR"), 48),
58  m_littleBigEndianIndicator(0x00),
59  m_headerSectionLength(48),
60  m_fileName(),
61  m_newRepUpIndicator(0),
62  m_govSpecNumber(),
63  m_govSpecDate(),
64  m_securityClassification(),
65  m_countryCode(),
66  m_securityReleaseMarking(),
67  m_locSectionLoc(0),
68  m_locationSection(new ossimRpfLocationSection)
69 {
70  memset(m_fileName, ' ' , 12);
71  memset(m_govSpecNumber, ' ', 15);
72  memset(m_govSpecDate, ' ', 8);
73  memset(m_securityClassification, ' ', 1);
74  memset(m_countryCode, ' ', 2);
75  memset(m_securityReleaseMarking, ' ', 2);
76 
77  m_fileName[12] = '\0';
78  m_govSpecNumber[15] = '\0';
79  m_govSpecDate[8] = '\0';
80  m_securityClassification[1] = '\0';
81  m_countryCode[2] = '\0';
82  m_securityReleaseMarking[2] = '\0';
83 }
84 
86  :
87  ossimNitfRegisteredTag(std::string("RPFHDR"), 48),
88  m_littleBigEndianIndicator(obj.m_littleBigEndianIndicator),
89  m_headerSectionLength(obj.m_headerSectionLength),
90  m_fileName(),
91  m_newRepUpIndicator(obj.m_newRepUpIndicator),
92  m_govSpecNumber(),
93  m_govSpecDate(),
94  m_securityClassification(),
95  m_countryCode(),
96  m_securityReleaseMarking(),
97  m_locSectionLoc(obj.m_locSectionLoc),
98  m_locationSection( new ossimRpfLocationSection( *(obj.m_locationSection) ) )
99 {
100  memcpy(m_fileName, obj.m_fileName, 13);
101  memcpy(m_govSpecNumber, obj.m_govSpecNumber, 16);
102  memcpy(m_govSpecDate, obj.m_govSpecDate, 9);
104  memcpy(m_countryCode, obj.m_countryCode, 3);
106 }
107 
109 {
110  if ( this != &rhs )
111  {
114  memcpy(m_fileName, rhs.m_fileName, 13);
116  memcpy(m_govSpecNumber, rhs.m_govSpecNumber, 16);
117  memcpy(m_govSpecDate, rhs.m_govSpecDate, 9);
119  memcpy(m_countryCode, rhs.m_countryCode, 3);
122 
124  }
125  return *this;
126 }
127 
129 {
131  {
132  delete m_locationSection;
133  m_locationSection = 0;
134  }
135 }
136 
138 {
139  if(in)
140  {
141  in.read((char*)&m_littleBigEndianIndicator, 1);
142 
143  in.read((char*)&m_headerSectionLength, 2);
144  in.read((char*)m_fileName, 12);
145  in.read((char*)&m_newRepUpIndicator, 1);
146  in.read((char*)m_govSpecNumber, 15);
147  in.read((char*)m_govSpecDate, 8);
148  in.read((char*)m_securityClassification, 1);
149  in.read((char*)m_countryCode, 2);
150  in.read((char*)m_securityReleaseMarking, 2);
151  in.read((char*)&m_locSectionLoc, 4);
152 
153  m_fileName[12] = '\0';
154  m_govSpecNumber[15] = '\0';
155  m_govSpecDate[8] = '\0';
156  m_securityClassification[1] = '\0';
157  m_countryCode[2] = '\0';
158  m_securityReleaseMarking[2] = '\0';
159 
160  //---
161  // From spec: MIL-PRF-89038CARDG m_littleBigEndianIndicator shall
162  // be 0x00 for all data denoting big endian storage. We will test
163  // anyway just in case...
164  //---
165  ossimByteOrder dataByteOrder = getByteOrder();
166 
167  if( ossim::byteOrder() != dataByteOrder )
168  {
169  ossimEndian anEndian;
170  anEndian.swap(m_headerSectionLength);
171  anEndian.swap(m_locSectionLoc);
172  }
173 
174  std::streamoff saveGet = in.tellg();
175  in.seekg(m_locSectionLoc, ios::beg);
176  m_locationSection->parseStream(in, dataByteOrder);
177  in.seekg(saveGet, ios::beg);
178  }
179 }
180 
182 {
183  // Always write in big endian.
184  if (m_littleBigEndianIndicator != 0x00)
185  {
187  << "ossimRpfHeader::writeStream writing in big endian even though"
188  << " the m_littleBigEndianIndicator is set to little endian."
189  << std::endl;
191  }
192 
193  ossimByteOrder dataByteOrder = getByteOrder();
194 
195  if( ossim::byteOrder() != dataByteOrder )
196  {
197  ossimEndian anEndian;
198  anEndian.swap(m_headerSectionLength);
199  anEndian.swap(m_locSectionLoc);
200  }
201 
202  out.write((char*)&m_littleBigEndianIndicator, 1);
203 
204  out.write((char*)&m_headerSectionLength, 2);
205  out.write((char*)m_fileName, 12);
206  out.write((char*)&m_newRepUpIndicator, 1);
207  out.write((char*)m_govSpecNumber, 15);
208  out.write((char*)m_govSpecDate, 8);
209  out.write((char*)m_securityClassification, 1);
210  out.write((char*)m_countryCode, 2);
211  out.write((char*)m_securityReleaseMarking, 2);
212  out.write((char*)&m_locSectionLoc, 4);
213 
214  if( ossim::byteOrder() != dataByteOrder )
215  {
216  // Must swap things back or we will seek to a bad location.
217  ossimEndian anEndian;
218  anEndian.swap(m_headerSectionLength);
219  anEndian.swap(m_locSectionLoc);
220  }
221 
222  if (m_locSectionLoc) // May or may not be set.
223  {
224  std::streampos pos = out.tellp();
225  out.seekp(m_locSectionLoc, ios::beg);
227  out.seekp(pos);
228  }
229 }
230 
231 std::ostream& ossimRpfHeader::print(std::ostream& out, const std::string& prefix) const
232 {
233  out << prefix << "byte_order: "
234  << (m_littleBigEndianIndicator==0x00?"big_endian\n":"little_endian\n")
235  << prefix << HEADER_SECTION_LENGTH_KW << ": "
236  << m_headerSectionLength << "\n"
237  << prefix << ossimKeywordNames::FILENAME_KW << ": "
238  << m_fileName << "\n"
239  << prefix << NEW_REP_UP_INDICATOR_KW << ": "
240  << int(m_newRepUpIndicator) << "\n"
241  << prefix << GOV_SPEC_NUMBER_KW << ": "
242  << m_govSpecNumber << "\n"
243  << prefix << GOV_SPEC_DATE_KW << ": "
244  << m_govSpecDate << "\n"
245  << prefix << SECURITY_CLASSIFICATION_KW << ": "
246  << m_securityClassification << "\n"
247  << prefix << COUNTRY_CODE_KW << ": "
248  << m_countryCode << "\n"
249  << prefix << SECURITY_RELEASE_MARKING_KW << ": "
250  << m_securityReleaseMarking << "\n";
251 
252  if ( traceDebug() )
253  {
254  out << prefix << "LocSectionLoc: "
255  << m_locSectionLoc << "\n";
256  if (m_locationSection)
257  {
258  m_locationSection->print(out, prefix);
259  }
260  }
261 
262  return out;
263 }
264 
266 {
268 }
269 
271 {
272  return m_locationSection;
273 }
274 
276 {
277  return m_locationSection;
278 }
279 
281 {
283  {
284  return m_locationSection->hasComponent(componentId);
285  }
286 
287  return false;
288 }
289 
291 {
293 }
294 
296 {
297  ossimRpfCoverageSection* result = 0;
298 
299  if(in&&m_locationSection)
300  {
302 
304  component))
305  {
306  result = new ossimRpfCoverageSection;
307 
308  in.seekg(component.m_componentLocation, ios::beg);
309 
310  if(in)
311  {
312  result->parseStream(in, getByteOrder());
313  }
314  else
315  {
316  delete result;
317  result = 0;
318  }
319  }
320  }
321  return result;
322 }
323 
325 {
326  ossimRpfMaskSubsection* result = 0;
327 
328  if(in&&m_locationSection)
329  {
331 
333  component))
334  {
335  result = new ossimRpfMaskSubsection;
336 
337  in.seekg(component.m_componentLocation, ios::beg);
338 
339  if(in)
340  {
341  if(result->parseStream(in, getByteOrder()) !=
343  {
344  delete result;
345  result = 0;
346  }
347  }
348  else
349  {
350  delete result;
351  result = 0;
352  }
353  }
354  }
355 
356  return result;
357 }
358 
359 
361 {
363 
364  if(in&&m_locationSection)
365  {
367 
369  component))
370  {
372 
373  in.seekg(component.m_componentLocation, ios::beg);
374 
375  if(in)
376  {
377  if(result->parseStream(in, getByteOrder()) !=
379  {
380  delete result;
381  result = 0;
382  }
383  }
384  else
385  {
386  delete result;
387  result = 0;
388  }
389  }
390  }
391 
392  return result;
393 }
394 
396 {
398 
399  if(in&&m_locationSection)
400  {
402 
404  component))
405  {
406  result = new ossimRpfColorGrayscaleSubheader;
407 
408  in.seekg(component.m_componentLocation, ios::beg);
409 
410  if(in)
411  {
412  if(result->parseStream(in, getByteOrder()) !=
414  {
415  delete result;
416  result = 0;
417  }
418  }
419  else
420  {
421  delete result;
422  result = 0;
423  }
424  }
425  }
426 
427  return result;
428 }
429 
431 {
432  ossimRpfCompressionSection* result = 0;
433 
434  if(in&&m_locationSection)
435  {
437 
439  component))
440  {
441  result = new ossimRpfCompressionSection;
442 
443  in.seekg(component.m_componentLocation, ios::beg);
444 
445  if(in)
446  {
447  if(result->parseStream(in, getByteOrder()) !=
449  {
450  delete result;
451  result = 0;
452  }
453  }
454  else
455  {
456  delete result;
457  result = 0;
458  }
459  }
460  }
461 
462  return result;
463 }
464 
466 {
468 
469  if(in&&m_locationSection)
470  {
472 
474  component))
475  {
477 
478  in.seekg(component.m_componentLocation, ios::beg);
479 
480  if(in)
481  {
482  if(result->parseStream(in, getByteOrder()) !=
484  {
485  delete result;
486  result = 0;
487  }
488  }
489  else
490  {
491  delete result;
492  result = 0;
493  }
494  }
495  }
496 
497  return result;
498 }
499 
500 
501 
503 {
505 
506  if(in&&m_locationSection)
507  {
509 
511  component))
512  {
514 
515  in.seekg(component.m_componentLocation, ios::beg);
516 
517  if(in)
518  {
519  if(result->parseStream(in, getByteOrder()) !=
521  {
522  delete result;
523  result = 0;
524  }
525  }
526  else
527  {
528  delete result;
529  result = 0;
530  }
531  }
532  }
533 
534  return result;
535 }
536 
538 {
540 
541  if(in&&m_locationSection)
542  {
544 
546  component))
547  {
549 
550  in.seekg(component.m_componentLocation, ios::beg);
551 
552  if(in)
553  {
554  if(result->parseStream(in, getByteOrder()) !=
556  {
557  delete result;
558  result = 0;
559  }
560  }
561  else
562  {
563  delete result;
564  result = 0;
565  }
566  }
567  }
568 
569  return result;
570 }
571 
572 
574 {
575  ossimRpfBoundaryRectTable* result = 0;
576 
577  if(in&&m_locationSection)
578  {
580 
582 
583  if(tempSubheader)
584  {
586  component))
587  {
588  result = new ossimRpfBoundaryRectTable;
589 
590  result->setNumberOfEntries(tempSubheader->getNumberOfEntries());
591  in.seekg(component.m_componentLocation, ios::beg);
592  if(in)
593  {
594  if(result->parseStream(in, getByteOrder()) !=
596  {
597  delete result;
598  result = 0;
599  }
600  }
601  else
602  {
603  delete result;
604  result = 0;
605  }
606  }
607 
608  delete tempSubheader;
609  tempSubheader = 0;
610  }
611  }
612 
613  return result;
614 }
615 
617 {
619 
620  if(in&&m_locationSection)
621  {
623 
625  component))
626  {
628 
629  in.seekg(component.m_componentLocation, ios::beg);
630 
631  if(in)
632  {
633  if(result->parseStream(in, getByteOrder()) !=
635  {
636  delete result;
637  result = 0;
638  }
639  }
640  else
641  {
642  delete result;
643  result = 0;
644  }
645  }
646  }
647 
648  return result;
649 
650 }
651 
653 {
655 
656  if(in&&m_locationSection)
657  {
659 
661  component))
662  {
664 
665  in.seekg(component.m_componentLocation, ios::beg);
666  if(in)
667  {
668  if(result->parseStream(in, getByteOrder()) !=
670  {
671  delete result;
672  result = 0;
673  }
674  }
675  else
676  {
677  delete result;
678  result = 0;
679  }
680  }
681  }
682 
683  return result;
684 }
685 
687 {
689 
690  if(in&&m_locationSection)
691  {
694 
696  component))
697  {
699 
700  result->setNumberOfFileIndexRecords(tempSubheader->getNumberOfIndexRecords());
701  result->setNumberOfPathnames(tempSubheader->getNumberOfPathnameRecords());
702  in.seekg(component.m_componentLocation, ios::beg);
703  if(in)
704  {
705  if(result->parseStream(in, getByteOrder()) !=
707  {
708  delete result;
709  result = 0;
710  }
711  }
712  else
713  {
714  delete result;
715  result = 0;
716  }
717  }
718  if(tempSubheader)
719  {
720  delete tempSubheader;
721  tempSubheader = 0;
722  }
723  }
724 
725  return result;
726 }
727 
729 {
730  ifstream in(file.c_str(), ios::in|ios::binary);
731 
732  return getNewCompressionSection(in);
733 }
734 
736 {
737  ifstream in(file.c_str(), ios::in|ios::binary);
738 
739  return getNewCoverageSection(in);
740 }
741 
743 {
744  ifstream in(file.c_str(), ios::in|ios::binary);
745 
746  return getNewBoundaryRectTable(in);
747 }
748 
750 {
751  ifstream in(file.c_str(), ios::in|ios::binary);
752 
754 }
755 
757 {
758  ifstream in(file.c_str(), ios::in|ios::binary);
759 
761 }
762 
764 {
765  ifstream in(file.c_str(), ios::in|ios::binary);
766 
767  return getNewFileIndexSubsection(in);
768 }
769 
771 {
772  return m_govSpecDate;
773 }
774 
776 {
777  return m_locSectionLoc;
778 }
779 
781 {
783 }
784 
786 {
787  if (s.size())
788  {
789  // Range check maybe??? (drb)
790  m_newRepUpIndicator = static_cast<ossim_uint8>(*s.begin());
791  }
792 }
793 
795 {
797 }
798 
800 {
802 }
803 
805 {
807 }
808 
810 {
812 }
813 
815 {
817 }
818 
820 {
821  m_locSectionLoc = static_cast<ossim_uint32>(off);
822 }
823 
824 bool ossimRpfHeader::loadState(const ossimKeywordlist& kwl, const char* prefix)
825 {
826  const char* lookup = 0;
827  ossimString s;
828 
829  lookup = kwl.find(prefix, NEW_REP_UP_INDICATOR_KW);
830  if (lookup)
831  {
832  s = lookup;
834  }
835 
836  lookup = kwl.find(prefix, GOV_SPEC_NUMBER_KW);
837  if (lookup)
838  {
839  s = lookup;
840  setGovSpecNumber(s);
841  }
842 
843  lookup = kwl.find(prefix, GOV_SPEC_DATE_KW);
844  if (lookup)
845  {
846  s = lookup;
847  setGovSpecDate(s);
848  }
849 
850  lookup = kwl.find(prefix, SECURITY_CLASSIFICATION_KW);
851  if (lookup)
852  {
853  s = lookup;
855  }
856 
857  lookup = kwl.find(prefix, COUNTRY_CODE_KW);
858  if (lookup)
859  {
860  s = lookup;
861  setCountryCode(s);
862  }
863 
864  lookup = kwl.find(prefix, SECURITY_RELEASE_MARKING_KW);
865  if (lookup)
866  {
867  s = lookup;
869  }
870 
871  return true;
872 }
ossimErrorCode parseStream(ossim::istream &in, ossimByteOrder byteOrder)
void setCountryCode(const ossimString &s)
ossimRpfFrameFileIndexSectionSubheader * getNewFrameFileIndexSectionSubheader(std::istream &in) const
void setSecurityReleaseMarking(const ossimString &s)
ossimRpfComponentId
ossimErrorCode parseStream(std::istream &in, ossimByteOrder)
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
ossimRpfLocationSection * m_locationSection
void setNewRepUpIndicator(const ossimString &s)
Represents serializable keyword/value map.
static const ossimErrorCode OSSIM_OK
ossimRpfImageDescriptionSubheader * getNewImageDescriptionSubheader(std::istream &in) const
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
void writeStream(std::ostream &out)
Write method.
const char * find(const char *key) const
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
ossimRpfImageDisplayParameterSubheader * getNewImageDisplayParameterSubheader(std::istream &in) const
ossim_uint32 m_locSectionLoc
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
bool hasComponent(ossimRpfComponentId componentId) const
ossim_uint32 getLocationSectionLocation() const
returns the byte position of the location section.
bool getComponent(ossimRpfComponentId componentId, ossimRpfComponentLocationRecord &result) const
const ossimRpfLocationSection * getLocationSection() const
ossimString getDate() const
ossimErrorCode parseStream(ossim::istream &in, ossimByteOrder byteOrder)
ossimRpfHeader()
default constructor
virtual ~ossimRpfHeader()
void setGovSpecDate(const ossimString &s)
virtual ossimErrorCode parseStream(std::istream &in, ossimByteOrder endianOrder)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void setNumberOfFileIndexRecords(ossim_uint32 numberOfIndexRecords)
ossimRpfBoundaryRectSectionSubheader * getNewBoundaryRectSectSubheader(std::istream &in) const
ossimRpfBoundaryRectTable * getNewBoundaryRectTable(std::istream &in) const
char m_securityReleaseMarking[3]
std::string::size_type size() const
Definition: ossimString.h:405
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
const ossimRpfHeader & operator=(const ossimRpfHeader &rhs)
assignment operator
std::string::iterator begin()
Definition: ossimString.h:420
unsigned int ossim_uint32
ossim_uint8 m_littleBigEndianIndicator
0x00 = big, 0xff = little
char m_fileName[13]
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
ossimErrorCode parseStream(ossim::istream &in, ossimByteOrder byteOrder)
bool hasComponent(ossimRpfComponentId componentId) const
char m_govSpecDate[9]
ossimByteOrder
ossim_uint8 m_newRepUpIndicator
std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
print method that outputs a key/value type format adding prefix to keys.
void setLocationSectionPos(std::streamoff off)
char m_govSpecNumber[16]
virtual void parseStream(std::istream &in)
Parse method.
char m_securityClassification[2]
1 byte field that can have the values
ossimString getSecurityClassification() const
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossimErrorCode parseStream(ossim::istream &in, ossimByteOrder byteOrder)
virtual ossimByteOrder getByteOrder() const
ossimRpfFrameFileIndexSubsection * getNewFileIndexSubsection(std::istream &in) const
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.
char m_countryCode[3]
void setNumberOfPathnames(ossim_uint32 numberOfPathnames)
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
ossimRpfMaskSubsection * getNewMaskSubsection(std::istream &in) const
ossimRpfCoverageSection * getNewCoverageSection(const ossimFilename &file) const
void setSecurityClassification(const ossimString &s)
virtual void writeStream(std::ostream &out)
Write method.
ossimRpfColorGrayscaleSubheader * getNewColorGrayscaleSubheader(std::istream &in) const
ossimErrorCode parseStream(ossim::istream &in, ossimByteOrder byteOrder)
void setFilename(const ossimString &file)
ossim_uint16 m_headerSectionLength
ossimRpfAttributeSectionSubheader * getNewAttributeSectionSubheader(std::istream &in) const
static const char * FILENAME_KW
void setNumberOfEntries(ossim_uint32 numberOfEntries)
ossimRpfCompressionSectionSubheader * getNewCompressionSectionSubheader(std::istream &in) const
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26
void setGovSpecNumber(const ossimString &s)
unsigned char ossim_uint8
ossimErrorCode parseStream(std::istream &in, ossimByteOrder byteOrder)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossimRpfCompressionSection * getNewCompressionSection(std::istream &in) const
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23