SAGA API  v9.5
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 {
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  //-----------------------------------------------------
103  int Get_Field_Count (void)
104  { return( m_nFields ); }
105 
106  const char * Get_Field_Name (int iField)
107  { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Name : NULL ); }
108 
109  char Get_Field_Type (int iField)
110  { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Type : DBF_FT_NONE ); }
111 
112  int Get_Field_Width (int iField)
113  { return( iField >= 0 && iField < m_nFields ? m_Fields[iField].Width : 0 ); }
114 
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);
121  int Get_File_Length (void) { return( m_nFileBytes ); }
122  int Get_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 
191 // //
192 // //
193 // //
195 
196 //---------------------------------------------------------
197 #endif // #ifndef HEADER_INCLUDED__SAGA_API__table_dbase_H
CSG_Table_DBase::~CSG_Table_DBase
virtual ~CSG_Table_DBase(void)
Definition: table_dbase.cpp:92
CSG_Table_DBase::asInt
bool asInt(int iField, int &Value)
Definition: table_dbase.cpp:652
CSG_Table_DBase::Get_File_Position
int Get_File_Position(void)
Definition: table_dbase.cpp:552
CSG_Table_DBase::isDeleted
bool isDeleted(void)
Definition: table_dbase.cpp:646
CSG_Table_DBase::Get_Field_Count
int Get_Field_Count(void)
Definition: table_dbase.h:103
CSG_Table_DBase::Get_Field_Decimals
int Get_Field_Decimals(int iField)
Definition: table_dbase.h:115
api_core.h
CSG_Table_DBase::Open_Write
bool Open_Write(const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Save=true)
Definition: table_dbase.cpp:307
CSG_Table_DBase::Get_Field_Width
int Get_Field_Width(int iField)
Definition: table_dbase.h:112
CSG_Table_DBase::Get_File_Length
int Get_File_Length(void)
Definition: table_dbase.h:121
CSG_Table_DBase::Move_Next
bool Move_Next(void)
Definition: table_dbase.cpp:585
CSG_Table_DBase::asString
CSG_String asString(int iField)
Definition: table_dbase.cpp:713
CSG_Table_DBase::Move_First
bool Move_First(void)
Definition: table_dbase.cpp:563
CSG_Table_DBase
Definition: table_dbase.h:91
CSG_Table_DBase::Open_Read
bool Open_Read(const SG_Char *FileName, class CSG_Table *pTable, bool bRecords_Load=true)
Definition: table_dbase.cpp:127
CSG_Table_DBase::Get_Count
int Get_Count(void)
Definition: table_dbase.h:122
CSG_Table_DBase::Get_Field_Type
char Get_Field_Type(int iField)
Definition: table_dbase.h:109
CSG_Table_DBase::Add_Record
void Add_Record(void)
Definition: table_dbase.cpp:612
CSG_Table_DBase::Flush_Record
void Flush_Record(void)
Definition: table_dbase.cpp:630
CSG_Table
Definition: table.h:283
DBF_FT_NONE
#define DBF_FT_NONE
Definition: table_dbase.h:74
SG_Char
#define SG_Char
Definition: api_core.h:536
CSG_Table_DBase::Set_Value
bool Set_Value(int iField, double Value)
Definition: table_dbase.cpp:771
CSG_String
Definition: api_core.h:563
CSG_Table_DBase::CSG_Table_DBase
CSG_Table_DBase(int Encoding=SG_FILE_ENCODING_ANSI)
Definition: table_dbase.cpp:82
CSG_Table_DBase::Close
void Close(void)
Definition: table_dbase.cpp:98
CSG_Table_DBase::asDouble
bool asDouble(int iField, double &Value)
Definition: table_dbase.cpp:667
CSG_Table_DBase::Set_NoData
bool Set_NoData(int iField)
Definition: table_dbase.cpp:904
CSG_Table_DBase::Get_Field_Name
const char * Get_Field_Name(int iField)
Definition: table_dbase.h:106
SG_FILE_ENCODING_ANSI
@ SG_FILE_ENCODING_ANSI
Definition: api_core.h:550