1 //
2 // This file is part of the SDTS++ toolkit, written by the U.S.
3 // Geological Survey. It is experimental software, written to support
4 // USGS research and cartographic data production.
5 //
6 // SDTS++ is public domain software. It may be freely copied,
7 // distributed, and modified. The USGS welcomes user feedback, but makes
8 // no committment to any level of support for this code. See the SDTS
9 // web site at http://mcmcweb.er.usgs.gov/sdts for more information,
10 // including points of contact.
11 //
12 // $Id: sb_Dq.cpp,v 1.10 2002/11/24 22:07:42 mcoletti Exp $
13 //
14
15
16
17 #ifdef _MSC_VER
18 #pragma warning( disable : 4786 )
19 #endif
20
21
22 #include <sdts++/builder/sb_Dq.h>
23
24
25 #include <iostream>
26 #include <strstream>
27
28 #include <limits.h>
29 #include <float.h>
30
31 #ifndef INCLUDED_SB_UTILS_H
32 #include <sdts++/builder/sb_Utils.h>
33 #endif
34
35 #ifndef INCLUDED_SC_RECORD_H
36 #include <sdts++/container/sc_Record.h>
37 #endif
38
39 #ifndef INCLUDED_SC_FIELD_H
40 #include <sdts++/container/sc_Field.h>
41 #endif
42
43 #ifndef INCLUDED_SC_SUBFIELD_H
44 #include <sdts++/container/sc_Subfield.h>
45 #endif
46
47 #ifndef INCLUDED_SIO_8211CONVERTER_H
48 #include <sdts++/io/sio_8211Converter.h>
49 #endif
50
51
52 using namespace std;
53
54
55 static const char* ident_ = "$Id: sb_Dq.cpp,v 1.10 2002/11/24 22:07:42 mcoletti Exp $";
56
57 // Strings and integers are initialized with these values; they are used
58 // to indicate whether a given module value has been assigned a value or not.
59
60 // (XXX I arbitrarily chose 0x4 as the sentinal value. I hate ad hoc crap.)
61
62 static const string UNVALUED_STRING(1, static_cast<string::value_type>(0x4) );
63
64 static const long UNVALUED_LONG = INT_MIN;
65
66 static const double UNVALUED_DOUBLE = DBL_MAX;
67
68 struct sb_Dq_Imp
69 {
70 string Comment_;
71
72
sb_Dq_Impsb_Dq_Imp73 sb_Dq_Imp()
74 :
75 Comment_( UNVALUED_STRING )
76 {}
77
78 };
79
80
sb_Dq()81 sb_Dq::sb_Dq()
82 : imp_( new sb_Dq_Imp() )
83 {
84 setID( 1 );
85
86
87 // insert static initializers
88
89 } // Dq ctor
90
91
~sb_Dq()92 sb_Dq::~sb_Dq()
93 {
94 delete imp_;
95 } // Dq dtor
96
97
98
99
100 static sio_8211Converter_I converter_I; // XXX should define these in
101 static sio_8211Converter_A converter_A; // XXX sio_8211Converter.h
102 static sio_8211Converter_R converter_R;
103 static sio_8211Converter_C converter_C;
104
105
106 static sio_8211Schema dqhl__schema; // module specific schema
107 static sio_8211Schema dqpa__schema;
108 static sio_8211Schema dqaa__schema;
109 static sio_8211Schema dqlc__schema;
110 static sio_8211Schema dqcg__schema;
111
112
113 static
114 void
build_schema_(sio_8211Schema & schema,string const & name,string const & mnemonic)115 build_schema_( sio_8211Schema& schema,
116 string const& name,
117 string const& mnemonic )
118 {
119 schema.push_back( sio_8211FieldFormat() );
120
121 sio_8211FieldFormat& field_format = schema.back();
122
123 field_format.setDataStructCode( sio_8211FieldFormat::vector );
124 field_format.setDataTypeCode( sio_8211FieldFormat::mixed_data_type );
125 field_format.setName( name );
126 field_format.setTag( mnemonic );
127
128
129 field_format.push_back( sio_8211SubfieldFormat() );
130
131 field_format.back().setLabel( "MODN" );
132 field_format.back().setType( sio_8211SubfieldFormat::A );
133 field_format.back().setFormat( sio_8211SubfieldFormat::variable );
134 field_format.back().setConverter( &converter_A );
135
136 field_format.push_back( sio_8211SubfieldFormat() );
137
138 field_format.back().setLabel( "RCID" );
139 field_format.back().setType( sio_8211SubfieldFormat::I );
140 field_format.back().setFormat( sio_8211SubfieldFormat::variable );
141 field_format.back().setConverter( &converter_I );
142
143 field_format.push_back( sio_8211SubfieldFormat() );
144
145 field_format.back().setLabel( "COMT" );
146 field_format.back().setType( sio_8211SubfieldFormat::A );
147 field_format.back().setFormat( sio_8211SubfieldFormat::variable );
148 field_format.back().setConverter( &converter_A );
149
150
151 } // build__schema
152
153
154 static
155 bool
ingest_record_(sb_Dq & dq,sb_Dq_Imp & dq_imp,sc_Record const & record,string const & mnemonic)156 ingest_record_( sb_Dq& dq,
157 sb_Dq_Imp &dq_imp,
158 sc_Record const& record,
159 string const& mnemonic )
160 {
161
162 // Make sure we have a record from an
163 // External Spatial Reference module.
164
165 sc_FieldCntr::const_iterator curfield;
166
167 if ( ! sb_Utils::getFieldByMnem( record, mnemonic, curfield) )
168 {
169 #ifdef SDTSXX_DEBUG
170 cerr << "sb_Dq::sb_Dq(sc_Record const&): "
171 << "Not an data quality record.";
172 cerr << endl;
173 #endif
174 return false;
175 }
176
177
178 // We have a primary field from a module. Start// picking it apart.
179
180 sc_SubfieldCntr::const_iterator cursubfield;
181
182 string tmp_str;
183 long tmp_int;
184
185
186 // MODN
187 if (sb_Utils::getSubfieldByMnem(*curfield,"MODN",cursubfield))
188 {
189 cursubfield->getA( tmp_str );
190 dq.setMnemonic( tmp_str );
191 }
192
193
194 // RCID
195 if (sb_Utils::getSubfieldByMnem(*curfield,"RCID",cursubfield))
196 {
197 cursubfield->getI( tmp_int );
198 dq.setID( tmp_int );
199 }
200
201
202 // COMT
203 if (sb_Utils::getSubfieldByMnem(*curfield,"COMT",cursubfield))
204 {
205 cursubfield->getA( dq_imp.Comment_);
206 }
207
208
209 return true;
210
211
212 } // ingest__record
213
214
215
216
217 bool
getComment(string & val) const218 sb_Dq::getComment( string& val ) const
219 {
220 if ( imp_->Comment_ == UNVALUED_STRING )
221 return false;
222
223 val = imp_->Comment_;
224
225 return true;
226 } // sb_Dq::getComment
227
228
229
230
231
232
233 bool
setComment(string const & val)234 sb_Dq::setComment( string const& val )
235 {
236 imp_->Comment_ = val;
237
238 return true;
239 } // sb_Dq::setComment
240
241
242
243
244 void
unDefineComment()245 sb_Dq::unDefineComment( )
246 {
247 imp_->Comment_ = UNVALUED_STRING;
248 } // sb_Dq::unDefineComment
249
250
251
252 //
253 //
254 //
255
256
sb_Dqhl()257 sb_Dqhl::sb_Dqhl()
258 {
259 setMnemonic( "DQHL" );
260 } // sb_Dqhl ctor
261
262
263
264 bool
getRecord(sc_Record & record) const265 sb_Dqhl::getRecord( sc_Record & record ) const
266 {
267 record.clear(); // start with a clean slate
268
269 // first field, which contains module name and record number
270
271 record.push_back( sc_Field() );
272
273 record.back().setMnemonic( "DQHL" );
274
275 record.back().setName( "Lineage" );
276
277 string tmp_str;
278
279 #ifdef WIN32
280 #pragma warning( disable : 4786 )
281 #endif
282
283
284 getMnemonic( tmp_str );
285 sb_Utils::add_subfield( record.back(), "MODN", tmp_str );
286 sb_Utils::add_subfield( record.back(), "RCID", getID() );
287
288 if ( getComment( tmp_str ) )
289 {
290 sb_Utils::add_subfield( record.back(),"COMT", tmp_str );
291 }
292 else
293 {
294 sb_Utils::add_empty_subfield( record.back(), "COMT", sc_Subfield::is_A );
295 }
296
297
298 return true;
299
300
301 } // sb_Dqhl::getRecord
302
303
304
305 bool
setRecord(sc_Record const & record)306 sb_Dqhl::setRecord( sc_Record const& record )
307 {
308 return ingest_record_( *this, getImp(), record, "DQHL" );
309 } // sb_Dqhl::setRecord
310
311
312
313 void
buildSpecificSchema_()314 sb_Dqhl::buildSpecificSchema_( )
315 {
316 build_schema_( schema_(), "Lineage", "DQHL" );
317 } // sb_Dqhl::buildSpecificSchema_( )
318
319
320 static sio_8211Schema dqhl_schema_;
321
322
323 sio_8211Schema&
schema_()324 sb_Dqhl::schema_( )
325 { return dqhl_schema_; }
326
327
328
329
330 //
331 //
332 //
333
334
sb_Dqpa()335 sb_Dqpa::sb_Dqpa()
336 {
337 setMnemonic( "DQPA" );
338 } // sb_Dqpa ctor
339
340
341
342 bool
getRecord(sc_Record & record) const343 sb_Dqpa::getRecord( sc_Record & record ) const
344 {
345 record.clear(); // start with a clean slate
346
347 // first field, which contains module name and record number
348
349 record.push_back( sc_Field() );
350
351 record.back().setMnemonic( "DQPA" );
352
353 record.back().setName( "Positional Accuracy" );
354
355 string tmp_str;
356
357 getMnemonic( tmp_str );
358 sb_Utils::add_subfield( record.back(), "MODN", tmp_str );
359 sb_Utils::add_subfield( record.back(), "RCID", getID() );
360
361 if ( getComment( tmp_str ) )
362 {
363 sb_Utils::add_subfield( record.back(),"COMT", tmp_str );
364 }
365 else
366 {
367 sb_Utils::add_empty_subfield( record.back(), "COMT", sc_Subfield::is_A );
368 }
369
370
371 return true;
372
373
374 } // sb_Dqpa::getRecord
375
376
377
378 bool
setRecord(sc_Record const & record)379 sb_Dqpa::setRecord( sc_Record const& record )
380 {
381 return ingest_record_( *this, getImp(), record, "DQPA" );
382 } // sb_Dqpa::setRecord
383
384
385
386
387
388 void
buildSpecificSchema_()389 sb_Dqpa::buildSpecificSchema_( )
390 {
391 build_schema_( schema_(), "Positional Accuracy", "DQPA" );
392 } // sb_Dqhl::buildSpecificSchema_( )
393
394
395
396
397
398 static sio_8211Schema dqpa_schema_;
399
400 sio_8211Schema&
schema_()401 sb_Dqpa::schema_( )
402 { return dqpa_schema_; }
403
404
405
406
407
408
409
410
411
412
413
414 //
415 //
416 //
417
418
sb_Dqaa()419 sb_Dqaa::sb_Dqaa()
420 {
421 setMnemonic( "DQAA" );
422 } // sb_Dqaa ctor
423
424
425
426 bool
getRecord(sc_Record & record) const427 sb_Dqaa::getRecord( sc_Record & record ) const
428 {
429 record.clear(); // start with a clean slate
430
431 // first field, which contains module name and record number
432
433 record.push_back( sc_Field() );
434
435 record.back().setMnemonic( "DQAA" );
436
437 record.back().setName( "Attribute Accuracy" );
438
439 string tmp_str;
440
441 getMnemonic( tmp_str );
442 sb_Utils::add_subfield( record.back(), "MODN", tmp_str );
443 sb_Utils::add_subfield( record.back(), "RCID", getID() );
444
445 if ( getComment( tmp_str ) )
446 {
447 sb_Utils::add_subfield( record.back(),"COMT", tmp_str );
448 }
449 else
450 {
451 sb_Utils::add_empty_subfield( record.back(), "COMT", sc_Subfield::is_A );
452 }
453
454
455 return true;
456
457
458 } // sb_Dqaa::getRecord
459
460
461
462 bool
setRecord(sc_Record const & record)463 sb_Dqaa::setRecord( sc_Record const& record )
464 {
465 return ingest_record_( *this, getImp(), record, "DQAA" );
466 } // sb_Dqaa::setRecord
467
468
469
470
471
472
473
474 void
buildSpecificSchema_()475 sb_Dqaa::buildSpecificSchema_( )
476 {
477 build_schema_( schema_(), "Attribute Accuracy", "DQAA" );
478 } // sb_Dqhl::buildSpecificSchema_( )
479
480
481
482
483
484 static sio_8211Schema dqaa_schema_;
485
486 sio_8211Schema&
schema_()487 sb_Dqaa::schema_( )
488 { return dqaa_schema_; }
489
490
491
492
493
494
495
496
497
498
499
500 //
501 //
502 //
503
504
sb_Dqlc()505 sb_Dqlc::sb_Dqlc()
506 {
507 setMnemonic( "DQLC" );
508 } // sb_Dqlc ctor
509
510
511
512 bool
getRecord(sc_Record & record) const513 sb_Dqlc::getRecord( sc_Record & record ) const
514 {
515 record.clear(); // start with a clean slate
516
517 // first field, which contains module name and record number
518
519 record.push_back( sc_Field() );
520
521 record.back().setMnemonic( "DQLC" );
522
523 record.back().setName( "Logical Consistency" );
524
525 string tmp_str;
526
527 getMnemonic( tmp_str );
528 sb_Utils::add_subfield( record.back(), "MODN", tmp_str );
529 sb_Utils::add_subfield( record.back(), "RCID", getID() );
530
531 if ( getComment( tmp_str ) )
532 {
533 sb_Utils::add_subfield( record.back(),"COMT", tmp_str );
534 }
535 else
536 {
537 sb_Utils::add_empty_subfield( record.back(), "COMT", sc_Subfield::is_A );
538 }
539
540
541 return true;
542
543
544 } // sb_Dqlc::getRecord
545
546
547
548 bool
setRecord(sc_Record const & record)549 sb_Dqlc::setRecord( sc_Record const& record )
550 {
551 return ingest_record_( *this, getImp(), record, "DQLC" );
552 } // sb_Dqlc::setRecord
553
554
555
556
557
558
559
560
561 static sio_8211Schema dqlc_schema_;
562
563
564
565 void
buildSpecificSchema_()566 sb_Dqlc::buildSpecificSchema_( )
567 {
568 build_schema_( schema_(), "Logical Consistency", "DQLC" );
569 } // sb_Dqhl::buildSpecificSchema_( )
570
571
572
573 sio_8211Schema&
schema_()574 sb_Dqlc::schema_( )
575 { return dqlc_schema_; }
576
577
578
579
580
581
582 //
583 //
584 //
585
586
sb_Dqcg()587 sb_Dqcg::sb_Dqcg()
588 {
589 setMnemonic( "DQCG" );
590 } // sb_Dqcg ctor
591
592
593
594 bool
getRecord(sc_Record & record) const595 sb_Dqcg::getRecord( sc_Record & record ) const
596 {
597 record.clear(); // start with a clean slate
598
599 // first field, which contains module name and record number
600
601 record.push_back( sc_Field() );
602
603 record.back().setMnemonic( "DQCG" );
604
605 record.back().setName( "Completeness" );
606
607 string tmp_str;
608
609 getMnemonic( tmp_str );
610 sb_Utils::add_subfield( record.back(), "MODN", tmp_str );
611 sb_Utils::add_subfield( record.back(), "RCID", getID() );
612
613 if ( getComment( tmp_str ) )
614 {
615 sb_Utils::add_subfield( record.back(),"COMT", tmp_str );
616 }
617 else
618 {
619 sb_Utils::add_empty_subfield( record.back(), "COMT", sc_Subfield::is_A );
620 }
621
622
623 return true;
624
625
626 } // sb_Dqcg::getRecord
627
628
629
630 bool
setRecord(sc_Record const & record)631 sb_Dqcg::setRecord( sc_Record const& record )
632 {
633 return ingest_record_( *this, getImp(), record, "DQCG" );
634 } // sb_Dqcg::setRecord
635
636
637
638
639
640
641
642 void
buildSpecificSchema_()643 sb_Dqcg::buildSpecificSchema_( )
644 {
645 build_schema_( schema_(), "Completeness", "DQCG" );
646 } // sb_Dqcg::buildSpecificSchema_( )
647
648
649
650
651
652 static sio_8211Schema dqcg_schema_;
653
654
655
656 sio_8211Schema&
schema_()657 sb_Dqcg::schema_( )
658 { return dqcg_schema_; }
659
660
661
662