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_MODULE_H 14 #define SB_MODULE_H 15 16 // $Id: sb_Module.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 #ifndef INCLUDED_SIO8211FIELDFORMAT_H 26 #include <sdts++/io/sio_8211FieldFormat.h> 27 #endif 28 29 30 class sc_Record; 31 class sb_ForeignID; 32 33 34 /** 35 Consolidates common module attributes for the rest of the builder 36 classes 37 */ 38 39 class sb_Module 40 { 41 public: 42 sb_Module()43 sb_Module() : mnemonic_(""), id_(1), emitRecIdenField_(true) {} 44 ~sb_Module()45 virtual ~sb_Module() {} 46 47 /// getMnemonic(std::string & mnemonic)48 void getMnemonic( std::string & mnemonic ) const 49 { 50 mnemonic = mnemonic_; 51 } 52 53 /// getMnemonic()54 const std::string & getMnemonic( ) const 55 { 56 return mnemonic_; 57 } 58 59 /// getID()60 int getID( ) const 61 { 62 return id_; 63 } 64 65 /// maintained for backward compatibility getModuleName()66 std::string const & getModuleName( ) const 67 { 68 return mnemonic_; 69 } 70 71 /// maintained for backward compatibility getRecordID()72 int getRecordID( ) const 73 { 74 return id_; 75 } 76 77 /// setMnemonic(std::string const & mnemonic)78 void setMnemonic( std::string const & mnemonic ) 79 { 80 mnemonic_ = mnemonic; 81 } 82 83 /// setID(int id)84 void setID( int id ) 85 { 86 id_ = id; 87 } 88 89 /// emitRecIdenField(bool v)90 void emitRecIdenField( bool v ) { emitRecIdenField_ = v; } 91 92 /** 93 returns true if the module will emit records with the ISO 94 8211 record identifier 95 */ willEmitRecIdenField()96 bool willEmitRecIdenField( ) const { return emitRecIdenField_; } 97 98 /// returns the schema associated with the module 99 bool getSchema( sio_8211Schema& schema ); 100 101 /** 102 fills the given record with proper fields and subfields for 103 them module; returns false if a mandatory field or subfield 104 hasn't been given a proper value 105 */ 106 virtual bool getRecord( sc_Record& ) const = 0; 107 108 /** 109 sets the module with the fields and subfields found in the 110 given sc_Record; returns false if improper record for the 111 module 112 */ 113 virtual bool setRecord( sc_Record const& ) = 0; 114 115 116 /// return a foreign id representing the current module and record name 117 sb_ForeignID foreignID() const ; 118 119 protected: 120 121 /// returns reference to schema 122 virtual sio_8211Schema& schema_() = 0; 123 124 /** 125 Each builder module has its own static copy of a relevent 126 schema. For example, sb_Iden will define a schema that 127 describes the field formats necessary for creating an IDEN 128 module. However, these schemas are built only if they're 129 needed; think of it as a form of lazy evauluation. Moreover, 130 there are some "shared" attributes common to all schemas, 131 such as the format for the 0001 reserved field if 132 willEmitRecIdenField() is true. This function builds those 133 parts. The child sb_Module classes will define their local 134 behavior in the buildSpecificSchema_(), which is called by 135 this member. 136 */ 137 void buildSchema_(); 138 139 /// 140 virtual void buildSpecificSchema_() = 0; 141 142 private: 143 144 /// module mnemonic 145 std::string mnemonic_; 146 147 /// module record number 148 int id_; 149 150 /// true if to write ISO 8211 record identifierfield 151 bool emitRecIdenField_; 152 153 friend std::ostream& operator<<( std::ostream&, sb_Module const& ); 154 155 }; // sb_Module 156 157 #endif 158