1 2 /////////////////////////////////////////////////////////// 3 // // 4 // SAGA // 5 // // 6 // System for Automated Geoscientific Analyses // 7 // // 8 // Application Programming Interface // 9 // // 10 // Library: SAGA_API // 11 // // 12 //-------------------------------------------------------// 13 // // 14 // table_dbase.h // 15 // // 16 // Copyright (C) 2005 by Olaf Conrad // 17 // // 18 //-------------------------------------------------------// 19 // // 20 // This file is part of 'SAGA - System for Automated // 21 // Geoscientific Analyses'. // 22 // // 23 // This library is free software; you can redistribute // 24 // it and/or modify it under the terms of the GNU Lesser // 25 // General Public License as published by the Free // 26 // Software Foundation, either version 2.1 of the // 27 // License, or (at your option) any later version. // 28 // // 29 // This library is distributed in the hope that it will // 30 // be useful, but WITHOUT ANY WARRANTY; without even the // 31 // implied warranty of MERCHANTABILITY or FITNESS FOR A // 32 // PARTICULAR PURPOSE. See the GNU Lesser General Public // 33 // License for more details. // 34 // // 35 // You should have received a copy of the GNU Lesser // 36 // General Public License along with this program; if // 37 // not, see <http://www.gnu.org/licenses/>. // 38 // // 39 //-------------------------------------------------------// 40 // // 41 // contact: Olaf Conrad // 42 // Institute of Geography // 43 // University of Goettingen // 44 // Goldschmidtstr. 5 // 45 // 37077 Goettingen // 46 // Germany // 47 // // 48 // e-mail: oconrad@saga-gis.org // 49 // // 50 /////////////////////////////////////////////////////////// 51 52 //--------------------------------------------------------- 53 #ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H 54 #define HEADER_INCLUDED__SAGA_API__table_dbase_H 55 56 57 /////////////////////////////////////////////////////////// 58 // // 59 // // 60 // // 61 /////////////////////////////////////////////////////////// 62 63 //--------------------------------------------------------- 64 #include "api_core.h" 65 66 67 /////////////////////////////////////////////////////////// 68 // // 69 // // 70 // // 71 /////////////////////////////////////////////////////////// 72 73 //--------------------------------------------------------- 74 #define DBF_FT_NONE '\0' 75 #define DBF_FT_CHARACTER 'C' 76 #define DBF_FT_DATE 'D' 77 #define DBF_FT_FLOAT 'F' 78 #define DBF_FT_NUMERIC 'N' 79 #define DBF_FT_LOGICAL 'L' 80 #define DBF_FT_MEMO 'M' 81 82 83 /////////////////////////////////////////////////////////// 84 // // 85 // // 86 // // 87 /////////////////////////////////////////////////////////// 88 89 //--------------------------------------------------------- 90 class CSG_Table_DBase 91 { 92 public: 93 CSG_Table_DBase(int Encoding = SG_FILE_ENCODING_ANSI); 94 virtual ~CSG_Table_DBase(void); 95 96 //----------------------------------------------------- 97 void Close (void); 98 99 bool Open_Read (const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Load = true); 100 bool Open_Write (const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Save = true); 101 102 //----------------------------------------------------- Get_Field_Count(void)103 int Get_Field_Count (void) 104 { return( m_nFields ); } 105 Get_Field_Name(int iField)106 const char * Get_Field_Name (int iField) 107 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Name : NULL ); } 108 Get_Field_Type(int iField)109 char Get_Field_Type (int iField) 110 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Type : DBF_FT_NONE ); } 111 Get_Field_Width(int iField)112 int Get_Field_Width (int iField) 113 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Width : 0 ); } 114 Get_Field_Decimals(int iField)115 int Get_Field_Decimals (int iField) 116 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Decimals : 0 ); } 117 118 119 //----------------------------------------------------- 120 int Get_File_Position (void); Get_File_Length(void)121 int Get_File_Length (void) { return( m_nFileBytes ); } Get_Record_Count(void)122 int Get_Record_Count (void) { return( m_nRecords ); } 123 124 //----------------------------------------------------- 125 bool Move_First (void); 126 bool Move_Next (void); 127 128 //----------------------------------------------------- 129 void Add_Record (void); 130 void Flush_Record (void); 131 132 //----------------------------------------------------- 133 bool isDeleted (void); 134 135 bool asInt (int iField, int &Value); 136 bool asDouble (int iField, double &Value); 137 CSG_String asString (int iField); 138 139 //----------------------------------------------------- 140 bool Set_Value (int iField, double Value); 141 bool Set_Value (int iField, const CSG_String &Value); 142 bool Set_NoData (int iField); 143 144 145 private: 146 typedef struct 147 { 148 char Name[12], Type, Displacement[4], WorkAreaID, ProductionIdx; 149 150 unsigned char Width, Decimals; 151 152 int Offset; 153 } 154 TDBF_Field; 155 156 typedef struct 157 { 158 char LastUpdate[3], Transaction, LanguageDrvID, ProductionIdx; 159 160 unsigned char FileType, bEncrypted; 161 } 162 TDBF_Header; 163 164 165 private: 166 167 bool m_bReadOnly, m_bModified; 168 169 char *m_Record; 170 171 short m_nHeaderBytes, m_nRecordBytes; 172 173 int m_nFields, m_nRecords, m_Encoding; 174 175 long m_nFileBytes; 176 177 FILE *m_hFile; 178 179 TDBF_Field *m_Fields; 180 181 182 void Header_Write (void); 183 bool Header_Read (void); 184 185 void Init_Record (void); 186 187 }; 188 189 190 /////////////////////////////////////////////////////////// 191 // // 192 // // 193 // // 194 /////////////////////////////////////////////////////////// 195 196 //--------------------------------------------------------- 197 #endif // #ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H 198