forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossimNitfDesInformation.cpp
323 lines (287 loc) · 10.2 KB
/
ossimNitfDesInformation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//*******************************************************************
//
// LICENSE: LGPL see top level LICENSE.txt
//
// Author:
// Description: Nitf support class
//
//********************************************************************
// $Id: ossimNitfDesInformation.cpp 23569 2015-10-05 19:32:00Z dburken $
#include <ossim/support_data/ossimNitfDesInformation.h>
#include <ossim/base/ossimCommon.h>
#include <ossim/base/ossimNotify.h>
#include <ossim/support_data/ossimNitfDesFactoryRegistry.h>
#include <ossim/base/ossimPreferences.h>
#include <sstream>
#include <iomanip>
#include <cstring> // for memset
ossimNitfDesInformation::ossimNitfDesInformation(ossimRefPtr<ossimNitfRegisteredDes> desData)
{
clearFields();
setDesData(desData);
}
ossimNitfDesInformation::~ossimNitfDesInformation()
{
}
void ossimNitfDesInformation::parseStream(std::istream &in, ossim_uint64 dataLength)
{
if(in)
{
clearFields();
m_desOffset = in.tellg();
in.read(m_de, DE_SIZE);
in.read(m_desid, DESID_SIZE);
in.read(m_desver, DESVER_SIZE);
in.read(m_declas, DECLAS_SIZE);
in.read(m_desclsy, DESCLSY_SIZE);
in.read(m_descode, DESCODE_SIZE);
in.read(m_desctlh, DESCTLH_SIZE);
in.read(m_desrel, DESREL_SIZE);
in.read(m_desdctp, DESDCTP_SIZE);
in.read(m_desdcdt, DESDCDT_SIZE);
in.read(m_desdcxm, DESDCXM_SIZE);
in.read(m_desdg, DESDG_SIZE);
in.read(m_desdgdt, DESDGDT_SIZE);
in.read(m_descltx, DESCLTX_SIZE);
in.read(m_descatp, DESCATP_SIZE);
in.read(m_descaut, DESCAUT_SIZE);
in.read(m_descrsn, DESCRSN_SIZE);
in.read(m_dessrdt, DESSRDT_SIZE);
in.read(m_desctln, DESCTLN_SIZE);
if (getDesId() == "TRE_OVERFLOW")
{
in.read(m_desoflw, DESOFLW_SIZE);
in.read(m_desitem, DESITEM_SIZE);
}
in.read(m_desshl, DESSHL_SIZE);
m_desDataOffset = in.tellg();
m_desData = ossimNitfDesFactoryRegistry::instance()->create(getDesId());
if (m_desData.valid())
{
/*
if (m_desData->getClassName() == "ossimNitfUnknownDes")
{
// Unknown des doesn't know his des name yet.
m_desData->setDesName( getDesId() );
}
*/
//---
// Dess with dynamic des length construct with 0 length.
// Set if 0.
//---
if ( m_desData->getDesLength() == 0 )
{
m_desData->setDesLength( dataLength );
}
// Sanity check fixed length in code with length from CEL field:
else if ( m_desData->getDesLength() != getDesLength() )
{
ossimNotify(ossimNotifyLevel_WARN)
<< "ossimNitfDesInformation::parseStream WARNING!"
<< "\nCEL field length does not match fixed des length for des: "
<< m_desData->getDesName().c_str()
<< "\nCEL: " << getDesLength()
<< "\nDes: " << m_desData->getDesLength()
<< std::endl;
}
m_desData->parseStream(in);
}
else
{
m_desData = (ossimNitfRegisteredDes*)NULL;
}
}
}
void ossimNitfDesInformation::writeStream(std::ostream &out)
{
m_desOffset = out.tellp(); // Capture the offset.
out.write(m_de, DE_SIZE);
out.write(m_desid, DESID_SIZE);
out.write(m_desver, DESVER_SIZE);
out.write(m_declas, DECLAS_SIZE);
out.write(m_desclsy, DESCLSY_SIZE);
out.write(m_descode, DESCODE_SIZE);
out.write(m_desctlh, DESCTLH_SIZE);
out.write(m_desrel, DESREL_SIZE);
out.write(m_desdctp, DESDCTP_SIZE);
out.write(m_desdcdt, DESDCDT_SIZE);
out.write(m_desdcxm, DESDCXM_SIZE);
out.write(m_desdg, DESDG_SIZE);
out.write(m_desdgdt, DESDGDT_SIZE);
out.write(m_descltx, DESCLTX_SIZE);
out.write(m_descatp, DESCATP_SIZE);
out.write(m_descaut, DESCAUT_SIZE);
out.write(m_descrsn, DESCRSN_SIZE);
out.write(m_dessrdt, DESSRDT_SIZE);
out.write(m_desctln, DESCTLN_SIZE);
if (getDesId() == "TRE_OVERFLOW")
{
out.write(m_desoflw, DESOFLW_SIZE);
out.write(m_desitem, DESITEM_SIZE);
}
out.write(m_desshl, DESSHL_SIZE);
//out.write(m_desLength, 5);
/*
if(m_desData.valid())
{
m_desData = out.tellp();
m_desData->writeStream(out);
}
*/
}
ossim_uint32 ossimNitfDesInformation::getTotalDesLength()const
{
return (getDesLength() + (ossim_uint32)11);
}
ossim_uint32 ossimNitfDesInformation::getDesLength()const
{
return ossimString(m_desLength).toUInt32();
}
ossim_uint64 ossimNitfDesInformation::getDesOffset()const
{
return m_desOffset;
}
ossim_uint64 ossimNitfDesInformation::getDesDataOffset()const
{
return m_desDataOffset;
}
ossimString ossimNitfDesInformation::getDesId()const
{
return ossimString(m_desid).trim();
}
std::ostream& ossimNitfDesInformation::print(std::ostream& out,
const std::string& prefix)const
{
ossimString pfx = prefix;
bool typeinfo = ossimString(ossimPreferences::instance()->findPreference("kwl_type_info")).toBool();
out
<< pfx << "DE:" << ((typeinfo) ? "(string)" : "") << m_de << "\n"
<< pfx << std::setw(24) << "DESID:" << ((typeinfo) ? "(string)" : "") << m_desid << "\n"
<< pfx << std::setw(24) << "DESVER:" << ((typeinfo) ? "(string)" : "") << m_desver << "\n"
<< pfx << std::setw(24) << "DECLAS:" << ((typeinfo) ? "(string)" : "") << m_declas << "\n"
<< pfx << std::setw(24) << "DESCLSY:" << ((typeinfo) ? "(string)" : "") << m_desclsy << "\n"
<< pfx << std::setw(24) << "DESCODE:" << ((typeinfo) ? "(string)" : "") << m_descode << "\n"
<< pfx << std::setw(24) << "DESCTLH:" << ((typeinfo) ? "(string)" : "") << m_desctlh << "\n"
<< pfx << std::setw(24) << "DESREL:" << ((typeinfo) ? "(string)" : "") << m_desrel << "\n"
<< pfx << std::setw(24) << "DESDCTP:" << ((typeinfo) ? "(string)" : "") << m_desdctp << "\n"
<< pfx << std::setw(24) << "DESDCDT:" << ((typeinfo) ? "(string)" : "") << m_desdcdt << "\n"
<< pfx << std::setw(24) << "DESDCXM:" << ((typeinfo) ? "(string)" : "") << m_desdcxm << "\n"
<< pfx << std::setw(24) << "DESDG:" << ((typeinfo) ? "(string)" : "") << m_desdg << "\n"
<< pfx << std::setw(24) << "DESDGDT:" << ((typeinfo) ? "(string)" : "") << m_desdgdt << "\n"
<< pfx << std::setw(24) << "DESCLTX:" << ((typeinfo) ? "" : "") << m_descltx << "\n"
<< pfx << std::setw(24) << "DESCATP:" << ((typeinfo) ? "(string)" : "") << m_descatp << "\n"
<< pfx << std::setw(24) << "DESCAUT:" << ((typeinfo) ? "(string)" : "") << m_descaut << "\n"
<< pfx << std::setw(24) << "DESCRSN:" << ((typeinfo) ? "(string)" : "") << m_descrsn << "\n"
<< pfx << std::setw(24) << "DESSRDT:" << ((typeinfo) ? "(string)" : "") << m_dessrdt << "\n"
<< pfx << std::setw(24) << "DESCTLN:" << ((typeinfo) ? "(string)" : "") << m_desctln << "\n"
;
if (getDesId() == "TRE_OVERFLOW")
{
out
<< pfx << std::setw(24) << "DESOFLW:" << ((typeinfo) ? "(string)" : "") << m_desoflw << "\n"
<< pfx << std::setw(24) << "DESITEM:" << ((typeinfo) ? "(string)" : "") << m_desitem << "\n"
;
}
out
<< pfx << std::setw(24) << "DESSHL:" << ((typeinfo) ? "(string)" : "") << m_desshl << "\n"
;
if (getDesData().valid())
{
getDesData()->print(out, prefix);
}
return out;
}
void ossimNitfDesInformation::clearFields()
{
memset(m_de, ' ', DE_SIZE);
m_de[DE_SIZE] = '\0';
memset(m_desid, ' ', DESID_SIZE);
m_desid[DESID_SIZE] = '\0';
memset(m_desver, ' ', DESVER_SIZE);
m_desver[DESVER_SIZE] = '\0';
memset(m_declas, ' ', DECLAS_SIZE);
m_declas[DECLAS_SIZE] = '\0';
memset(m_desclsy, ' ', DESCLSY_SIZE);
m_desclsy[DESCLSY_SIZE] = '\0';
memset(m_descode, ' ', DESCODE_SIZE);
m_descode[DESCODE_SIZE] = '\0';
memset(m_desctlh, ' ', DESCTLH_SIZE);
m_desctlh[DESCTLH_SIZE] = '\0';
memset(m_desrel, ' ', DESREL_SIZE);
m_desrel[DESREL_SIZE] = '\0';
memset(m_desdctp, ' ', DESDCTP_SIZE);
m_desdctp[DESDCTP_SIZE] = '\0';
memset(m_desdcdt, ' ', DESDCDT_SIZE);
m_desdcdt[DESDCDT_SIZE] = '\0';
memset(m_desdcxm, ' ', DESDCXM_SIZE);
m_desdcxm[DESDCXM_SIZE] = '\0';
memset(m_desdg, ' ', DESDG_SIZE);
m_desdg[DESDG_SIZE] = '\0';
memset(m_desdgdt, ' ', DESDGDT_SIZE);
m_desdgdt[DESDGDT_SIZE] = '\0';
memset(m_descltx, ' ', DESCLTX_SIZE);
m_descltx[DESCLTX_SIZE] = '\0';
memset(m_descatp, ' ', DESCATP_SIZE);
m_descatp[DESCATP_SIZE] = '\0';
memset(m_descaut, ' ', DESCAUT_SIZE);
m_descaut[DESCAUT_SIZE] = '\0';
memset(m_descrsn, ' ', DESCRSN_SIZE);
m_descrsn[DESCRSN_SIZE] = '\0';
memset(m_dessrdt, ' ', DESSRDT_SIZE);
m_dessrdt[DESSRDT_SIZE] = '\0';
memset(m_desctln, ' ', DESCTLN_SIZE);
m_desctln[DESCTLN_SIZE] = '\0';
memset(m_desoflw, ' ', DESOFLW_SIZE);
m_desoflw[DESOFLW_SIZE] = '\0';
memset(m_desitem, ' ', DESITEM_SIZE);
m_desitem[DESITEM_SIZE] = '\0';
memset(m_desshl, ' ', DESSHL_SIZE);
m_desshl[DESSHL_SIZE] = '\0';
m_desOffset = 0;
m_desDataOffset = 0;
}
void ossimNitfDesInformation::setDesName(const ossimString& desName)
{
memset(m_desid, ' ', DESID_SIZE);
std::ostringstream out;
out << std::setw(DESID_SIZE)
<< std::setfill(' ')
<< m_desid;
memcpy(m_desid, out.str().c_str(), DESID_SIZE);
}
void ossimNitfDesInformation::setDesLength(ossim_uint32 desLength)
{
/*
memset(m_desLength, 0, 5);
if(desLength > 99999)
{
desLength = 99999;
}
std::ostringstream out;
out << std::setw(5)
<< std::setfill('0')
<< desLength;
memcpy(m_desLength, out.str().c_str(), 5);
*/
}
ossimRefPtr<ossimNitfRegisteredDes> ossimNitfDesInformation::getDesData()
{
return m_desData;
}
const ossimRefPtr<ossimNitfRegisteredDes> ossimNitfDesInformation::getDesData()const
{
return m_desData;
}
void ossimNitfDesInformation::setDesData(ossimRefPtr<ossimNitfRegisteredDes> desData)
{
m_desData = desData;
/*
memset(m_desid, ' ', DESID_SIZE);
memset(m_desLength, ' ', 5);
if(m_desData.valid())
{
setDesName(m_desData->getRegisterDesName());
setDesLength(m_desData->getSizeInBytes());
}
*/
}