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 13 #ifndef SB_ACCESSOR_H 14 #define SB_ACCESSOR_H 15 16 // $Id: sb_Accessor.h,v 1.9 2002/11/24 22:07:42 mcoletti Exp $ 17 18 #ifdef _MSC_VER 19 #pragma warning( disable : 4786 ) 20 #endif 21 22 #include <string> 23 24 25 // for converter_dictionary 26 27 #ifndef INCLUDED_SIO_8211FIELDFORMAT_H 28 #include <sdts++/io/sio_8211FieldFormat.h> 29 #endif 30 31 32 class sb_Module; 33 34 struct sb_Accessor_Imp; 35 36 /*! 37 * \class sb_Accessor 38 * 39 * \todo Currently will only handle single instances of any given module. Transfers that have more instances of a type of module are not (yet) handled by this class. 40 * 41 * \brief Convenience class for accessing SDTS modules 42 * 43 * Convenience class for accessing arbitrary SDTS modules and records 44 * without having to open up each module by hand. The CATD module is 45 * used to find a dataset's modules. 46 * 47 */ 48 class sb_Accessor 49 { 50 public: 51 52 /// 53 sb_Accessor(); 54 55 /// 56 sb_Accessor( std::string const & catd_fn ); 57 58 /// 59 ~sb_Accessor(); 60 61 /** 62 63 Set up the accessor object for use; this must be called 64 before get(). This member will use CATD information to find 65 the remaining modules to populate modules for each get() 66 call. It will fail if the given file name didn't resolve to 67 a valid CATD module. 68 */ 69 bool readCatd( std::string const & catd_fn ); 70 71 72 /// return the CATD module file name 73 std::string const & fileName() const; 74 75 /*! 76 * \fn bool get( sb_Module & module, sio_8211_converter_dictionary* cv = 0x0 ) 77 * 78 * \note 79 * Admittedly this is not an optimal design. That 80 * is, it suffers the same problems as any container that has a 81 * single internal iterator instead of allowing for separate, 82 * external iterators. However, I recognized that users of 83 * this class (or even generally the toolkit) intend to open 84 * SDTS files once, translate them to a meaningful format, and 85 * then forget about the original SDTS files. It's "read once, 86 * and only once." Given that paradigm, I felt confident to go 87 * ahead with this design. MAC. 88 * 89 * \brief read a record into a builder module 90 * 91 * Use the CATD information to find the corresponding module 92 * file, open it, read in the first record, and then use that 93 * record to populate the given module. This will return false 94 * if there are no more records, the SDTS module file didn't 95 * exist, or there were some I/O or resource problems. (E.g., 96 * out of memory or a corrupted module.) Will return true if 97 * the module was successfully populated. This can be invoked 98 * multiple times for modules with more than one record; again 99 * get() will return false if all the module records have been 100 * read. The optional converter parameter is used to provide 101 * appropriate hints for reading binary data. 102 * 103 */ 104 bool get( sb_Module & module, sio_8211_converter_dictionary* cv = 0x0 ); 105 106 107 private: 108 109 /// NOT NEEDED 110 sb_Accessor( sb_Accessor const & ); 111 112 /// NOT NEEDED 113 sb_Accessor& operator=( sb_Accessor const & ); 114 115 /// hook to hidden internal data structure 116 sb_Accessor_Imp* imp_; 117 118 }; // sb_Module 119 120 121 122 #endif 123