OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfUnknownTag.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: David Burken
8 //
9 // Description: Unknown tag class declaration.
10 //
11 // Note: By "unknown" this means that the tag name was not found in any of
12 // the tag factories.
13 //
14 //----------------------------------------------------------------------------
15 // $Id: ossimNitfUnknownTag.cpp 22013 2012-12-19 17:37:20Z dburken $
16 
17 #include <ostream>
18 #include <iomanip>
19 #include <cctype> /* for isascii */
20 
23 
25 
27  : m_tagData(0)
28 {
29 }
30 
32 {
33  if (m_tagData)
34  {
35  delete [] m_tagData;
36  m_tagData = 0;
37  }
38 }
39 
41 {
42  if (m_tagLength)
43  {
44  if (m_tagData)
45  {
46  delete [] m_tagData;
47  }
48 
49  m_tagData = new char[m_tagLength+1];
50 
51  in.read(m_tagData, m_tagLength);
52 
53  m_tagData[m_tagLength] = '\0';
54  }
55 }
56 
58 {
59  if (m_tagLength && m_tagData)
60  {
61  out.write(m_tagData, m_tagLength);
62  }
63 }
64 
66 {
67  if (m_tagData)
68  {
69  delete [] m_tagData;
70  m_tagData = 0;
71  }
72 }
73 
75  const std::string& prefix) const
76 {
77  std::string pfx = prefix;
78  pfx += getTagName();
79  pfx += ".";
80 
81  out << setiosflags(std::ios::left)
82  << pfx << std::setw(24) << "CETAG:" << getTagName() << "\n"
83  << pfx << std::setw(24) << "CEL:" << getTagLength() << "\n"
84  << pfx << std::setw(24) << "unformatted_tag_data: ";
85 
86  if (tagDataIsAscii())
87  {
88  if (tagDataIsXml())
89  out << "<![CDATA[" << m_tagData << "]]>" << "\n";
90  else
91  out << m_tagData << "\n";
92  }
93  else
94  {
95  out << "binary not displayed\n";
96  }
97 
98  return out;
99 }
100 
102 {
103  ossimString xmlTest = "<?xml";
104  ossim_uint32 len = xmlTest.length();
105  if ( (m_tagLength < len) || !m_tagData )
106  {
107  return false;
108  }
109 
110  ossimString tagDataString = ossimString(m_tagData).substr(0, len);
111  if (tagDataString == xmlTest) return true;
112  return false;
113 }
114 
116 {
117  if (m_tagData)
118  {
119  delete [] m_tagData;
120  m_tagData = 0;
121  }
122  m_tagLength = length;
123 }
124 
126 {
127  if ( (m_tagLength == 0) || !m_tagData )
128  {
129  return false;
130  }
131 
132  for (ossim_uint32 i = 0; i < m_tagLength; ++i)
133  {
134  int c = m_tagData[i];
135  if (isascii(c) == false)
136  {
137  return false;
138  }
139  }
140 
141  return true;
142 }
virtual void clearFields()
Clears all string fields within the record to some default nothingness.
virtual const std::string & getTagName() const
This will return the name of the registered tag for this user defined header.
ossimNitfUnknownTag()
default constructor
char * m_tagData
Holds entire tag data(theTagLength) plus one byte for null terminator.
virtual void parseStream(std::istream &in)
Parse method.
virtual ossim_uint32 getTagLength() const
Returns the length in bytes of the tag from the CEL or REL field.
std::string::size_type length() const
Definition: ossimString.h:408
unsigned int ossim_uint32
virtual void setTagLength(ossim_uint32 length)
virtual 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.
RTTI_DEF1(ossimNitfUnknownTag, "ossimNitfUnknownTag", ossimNitfRegisteredTag)
virtual void writeStream(std::ostream &out)
Write method.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
virtual ~ossimNitfUnknownTag()
destructor
std::string substr(std::string::size_type pos=0, std::string::size_type n=std::string::npos) const
Equivalent to basic_string(*this, pos, n).
Definition: ossimString.h:910
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23