OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimNitfXmlDataContentDes.cpp
Go to the documentation of this file.
3 #include <iomanip>
4 #include <iostream>
5 #include <sstream>
6 
7 //<CHILDCLASSCPP>
8 
10  : ossimNitfRegisteredDes(std::string("XML_DATA_CONTENT"), 0),
11  m_xmlString()
12 {
13  clearFields();
14 }
15 
17 {
18  clearFields();
19 
20  in.read(m_descrc, DESCRC_SIZE);
21  in.read(m_desshft, DESSHFT_SIZE);
22  in.read(m_desshdt, DESSHDT_SIZE);
23  in.read(m_desshrp, DESSHRP_SIZE);
24  in.read(m_desshsi, DESSHSI_SIZE);
25  in.read(m_desshsv, DESSHSV_SIZE);
26  in.read(m_desshsd, DESSHSD_SIZE);
27  in.read(m_desshtn, DESSHTN_SIZE);
28  in.read(m_desshlpg, DESSHLPG_SIZE);
29  in.read(m_desshlpt, DESSHLPT_SIZE);
30  in.read(m_desshli, DESSHLI_SIZE);
31  in.read(m_desshlin, DESSHLIN_SIZE);
32  in.read(m_desshabs, DESSHABS_SIZE);
33 
34  if(getSizeInBytes())
35  {
36  char* c = new char[getSizeInBytes()+1];
37  in.read(c, getSizeInBytes());
38  c[getSizeInBytes()] = '\0';
39  m_xmlString.string().resize(getSizeInBytes());
40  m_xmlString = c;
42  std::istringstream xmlStringStream(m_xmlString.string());
43  m_xmlDocument->read(xmlStringStream);
44  delete [] c;
45  c = 0;
46  }
47 }
48 
50 {
51  out.write(m_desshl, DESSHL_SIZE);
52  out.write(m_descrc, DESCRC_SIZE);
53  out.write(m_desshft, DESSHFT_SIZE);
54  out.write(m_desshdt, DESSHDT_SIZE);
55  out.write(m_desshrp, DESSHRP_SIZE);
56  out.write(m_desshsi, DESSHSI_SIZE);
57  out.write(m_desshsv, DESSHSV_SIZE);
58  out.write(m_desshsd, DESSHSD_SIZE);
59  out.write(m_desshtn, DESSHTN_SIZE);
60  out.write(m_desshlpg, DESSHLPG_SIZE);
61  out.write(m_desshlpt, DESSHLPT_SIZE);
62  out.write(m_desshli, DESSHLI_SIZE);
63  out.write(m_desshlin, DESSHLIN_SIZE);
64  out.write(m_desshabs, DESSHABS_SIZE);
65 }
66 
68  const std::string& prefix) const
69 {
70  bool typeinfo = ossimString(ossimPreferences::instance()->findPreference("kwl_type_info")).toBool();
71 
72  std::string pfx = prefix;
73  pfx += getDesName() + ".";
74 
75  out << setiosflags(ios::left)
76  << pfx << std::setw(24) << "DESCRC:" << ((typeinfo) ? "(string)" : "") << m_descrc << "\n"
77  << pfx << std::setw(24) << "DESSHFT:" << ((typeinfo) ? "(string)" : "") << m_desshft << "\n"
78  << pfx << std::setw(24) << "DESSHDT:" << ((typeinfo) ? "(string)" : "") << m_desshdt << "\n"
79  << pfx << std::setw(24) << "DESSHRP:" << ((typeinfo) ? "(string)" : "") << m_desshrp << "\n"
80  << pfx << std::setw(24) << "DESSHSI:" << ((typeinfo) ? "(string)" : "") << m_desshsi << "\n"
81  << pfx << std::setw(24) << "DESSHSV:" << ((typeinfo) ? "(string)" : "") << m_desshsv << "\n"
82  << pfx << std::setw(24) << "DESSHSD:" << ((typeinfo) ? "(string)" : "") << m_desshsd << "\n"
83  << pfx << std::setw(24) << "DESSHTN:" << ((typeinfo) ? "(string)" : "") << m_desshtn << "\n"
84  << pfx << std::setw(24) << "DESSHLPG:" << ((typeinfo) ? "(string)" : "") << m_desshlpg << "\n"
85  << pfx << std::setw(24) << "DESSHLPT:" << ((typeinfo) ? "(string)" : "") << m_desshlpt << "\n"
86  << pfx << std::setw(24) << "DESSHLI:" << ((typeinfo) ? "(string)" : "") << m_desshli << "\n"
87  << pfx << std::setw(24) << "DESSHABS:" << ((typeinfo) ? "(string)" : "") << m_desshabs << "\n"
88  // Quick hack to print on one line, this will leave extra spaces in CDATA sections
89  << pfx << std::setw(24) << "XML:" << m_xmlString.substitute(ossimString("\n"), " ", true) << "\n"
90  ;
91  return out;
92 }
93 
95 {
96  memset(m_descrc, ' ', DESCRC_SIZE);
97  m_descrc[DESCRC_SIZE] = '\0';
98  memset(m_desshft, ' ', DESSHFT_SIZE);
99  m_desshft[DESSHFT_SIZE] = '\0';
100  memset(m_desshdt, ' ', DESSHDT_SIZE);
101  m_desshdt[DESSHDT_SIZE] = '\0';
102  memset(m_desshrp, ' ', DESSHRP_SIZE);
103  m_desshrp[DESSHRP_SIZE] = '\0';
104  memset(m_desshsi, ' ', DESSHSI_SIZE);
105  m_desshsi[DESSHSI_SIZE] = '\0';
106  memset(m_desshsv, ' ', DESSHSV_SIZE);
107  m_desshsv[DESSHSV_SIZE] = '\0';
108  memset(m_desshsd, ' ', DESSHSD_SIZE);
109  m_desshsd[DESSHSD_SIZE] = '\0';
110  memset(m_desshtn, ' ', DESSHTN_SIZE);
111  m_desshtn[DESSHTN_SIZE] = '\0';
112  memset(m_desshlpg, ' ', DESSHLPG_SIZE);
113  m_desshlpg[DESSHLPG_SIZE] = '\0';
114  memset(m_desshlpt, ' ', DESSHLPT_SIZE);
115  m_desshlpt[DESSHLPT_SIZE] = '\0';
116  memset(m_desshli, ' ', DESSHLI_SIZE);
117  m_desshli[DESSHLI_SIZE] = '\0';
118  memset(m_desshlin, ' ', DESSHLIN_SIZE);
119  m_desshlin[DESSHLIN_SIZE] = '\0';
120  memset(m_desshabs, ' ', DESSHABS_SIZE);
121  m_desshabs[DESSHABS_SIZE] = '\0';
122 }
123 
124 bool ossimNitfXmlDataContentDes::loadState(const ossimKeywordlist& kwl, const char* prefix)
125 {
126  const char* lookup;
127  lookup = kwl.find(prefix, "DESCRC");
128  {
129  strcpy(m_descrc, lookup);
130  }
131  lookup = kwl.find(prefix, "DESSHFT");
132  {
133  strcpy(m_desshft, lookup);
134  }
135  lookup = kwl.find(prefix, "DESSHDT");
136  {
137  strcpy(m_desshdt, lookup);
138  }
139  lookup = kwl.find(prefix, "DESSHRP");
140  {
141  strcpy(m_desshrp, lookup);
142  }
143  lookup = kwl.find(prefix, "DESSHSI");
144  {
145  strcpy(m_desshsi, lookup);
146  }
147  lookup = kwl.find(prefix, "DESSHSV");
148  {
149  strcpy(m_desshsv, lookup);
150  }
151  lookup = kwl.find(prefix, "DESSHSD");
152  {
153  strcpy(m_desshsd, lookup);
154  }
155  lookup = kwl.find(prefix, "DESSHTN");
156  {
157  strcpy(m_desshtn, lookup);
158  }
159 
160  return true;
161 }
162 
164 {
165  bool result = false;
166  if (xml->getErrorStatus()) return result;
167  std::vector<ossimRefPtr<ossimXmlNode> > xml_nodes;
168  xml->findNodes(xpath, xml_nodes);
169  if (xml_nodes.size())
170  {
171  target = xml_nodes[0]->getText();
172  result = true;
173  }
174 
175  return result;
176 }
177 
179 {
180  return ossimString(m_descrc);
181 }
182 
184 {
185  return ossimString(m_desshft);
186 }
187 
189 {
190  return ossimString(m_desshdt);
191 }
192 
194 {
195  return ossimString(m_desshrp);
196 }
197 
199 {
200  return ossimString(m_desshsi);
201 }
202 
204 {
205  return ossimString(m_desshsv);
206 }
207 
209 {
210  return ossimString(m_desshsd);
211 }
212 
214 {
215  return ossimString(m_desshtn);
216 }
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
Represents serializable keyword/value map.
virtual void parseStream(std::istream &in)
This will allow the user defined data to parse the stream.
const char * find(const char *key) const
bool loadValueFromXml(const ossimRefPtr< ossimXmlDocument >, const ossimString &xpath, ossimString &target) const
bool loadState(const ossimKeywordlist &kwl, const char *prefix)
bool toBool() const
String to numeric methods.
virtual const std::string & getDesName() const
This will return the name of the registered des for this user defined header.
static ossimPreferences * instance()
virtual std::ostream & print(std::ostream &out, const std::string &prefix=std::string()) const
Pure virtual print method that outputs a key/value type format adding prefix to keys.
ossimRefPtr< ossimXmlDocument > m_xmlDocument
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
virtual ossimErrorCode getErrorStatus() const
virtual void writeStream(std::ostream &out)
bool read(std::istream &in)
void findNodes(const ossimString &xpath, std::vector< ossimRefPtr< ossimXmlNode > > &nodelist) const
Appends any matching nodes to the list supplied (should be empty):
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
virtual ossim_uint32 getSizeInBytes() const
Returns the length in bytes of the des from the CEL or REL field.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
const std::string & string() const
Definition: ossimString.h:414