SAGA API v9.10
Loading...
Searching...
No Matches
table_dbase.h
Go to the documentation of this file.
1
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// //
51
52//---------------------------------------------------------
53#ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H
54#define HEADER_INCLUDED__SAGA_API__table_dbase_H
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
64#include "api_core.h"
65
66
68// //
69// //
70// //
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
84// //
85// //
86// //
88
89//---------------------------------------------------------
91{
92public:
94 virtual ~CSG_Table_DBase(void);
95
96 //-----------------------------------------------------
97 bool Open_Read (const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Load = true);
98 bool Open_Write (const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Save = true);
99
100 void Close (void);
101
102 bool is_Open (void) const { return( m_hFile != NULL ); }
103
104 //-----------------------------------------------------
106 { return( m_nFields ); }
107
108 const char * Get_Field_Name (int iField)
109 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Name : NULL ); }
110
111 char Get_Field_Type (int iField)
112 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Type : DBF_FT_NONE ); }
113
114 int Get_Field_Width (int iField)
115 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Width : 0 ); }
116
117 int Get_Field_Decimals (int iField)
118 { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Decimals : 0 ); }
119
120
121 //-----------------------------------------------------
122 int Get_File_Position (void);
123 int Get_File_Length (void) { return( m_nFileBytes ); }
124 int Get_Count (void) { return( m_nRecords ); }
125
126 //-----------------------------------------------------
127 bool Move_First (void);
128 bool Move_Next (void);
129
130 //-----------------------------------------------------
131 void Add_Record (void);
132 void Flush_Record (void);
133
134 //-----------------------------------------------------
135 bool isDeleted (void);
136
137 bool asInt (int iField, int &Value);
138 bool asDouble (int iField, double &Value);
139 CSG_String asString (int iField);
140
141 //-----------------------------------------------------
142 bool Set_Value (int iField, double Value);
143 bool Set_Value (int iField, const CSG_String &Value);
144 bool Set_NoData (int iField);
145
146
147private:
148 typedef struct
149 {
150 char Name[12], Type, Displacement[4], WorkAreaID, ProductionIdx;
151
152 unsigned char Width, Decimals;
153
154 int Offset;
155 }
156 TDBF_Field;
157
158 typedef struct
159 {
160 char LastUpdate[3], Transaction, LanguageDrvID, ProductionIdx;
161
162 unsigned char FileType, bEncrypted;
163 }
164 TDBF_Header;
165
166
167private:
168
169 bool m_bReadOnly, m_bModified;
170
171 char *m_Record;
172
173 short m_nHeaderBytes, m_nRecordBytes;
174
175 int m_nFields, m_nRecords, m_Encoding;
176
177 long m_nFileBytes;
178
179 FILE *m_hFile;
180
181 TDBF_Field *m_Fields;
182
183
184 bool Write (void *buffer, size_t size, size_t count);
185 bool Read (void *buffer, size_t size, size_t count);
186
187 void Header_Write (void);
188 bool Header_Read (void);
189
190 void Init_Record (void);
191
192};
193
194
196// //
197// //
198// //
200
201//---------------------------------------------------------
202#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H
#define SG_Char
Definition api_core.h:536
@ SG_FILE_ENCODING_ANSI
Definition api_core.h:550
bool is_Open(void) const
virtual ~CSG_Table_DBase(void)
int Get_Field_Width(int iField)
bool asInt(int iField, int &Value)
void Close(void)
int Get_Count(void)
int Get_File_Position(void)
int Get_File_Length(void)
bool Move_First(void)
bool asDouble(int iField, double &Value)
void Flush_Record(void)
const char * Get_Field_Name(int iField)
bool Set_Value(int iField, double Value)
int Get_Field_Count(void)
bool isDeleted(void)
bool Open_Write(const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Save=true)
void Add_Record(void)
int Get_Field_Decimals(int iField)
char Get_Field_Type(int iField)
CSG_String asString(int iField)
CSG_Table_DBase(int Encoding=SG_FILE_ENCODING_ANSI)
bool Set_NoData(int iField)
bool Move_Next(void)
bool Open_Read(const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Load=true)
#define DBF_FT_NONE
Definition table_dbase.h:74