SAGA API  v9.7
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  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  //-----------------------------------------------------
105  int Get_Field_Count (void)
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 
147 private:
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 
167 private:
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  void Header_Write (void);
185  bool Header_Read (void);
186 
187  void Init_Record (void);
188 
189 };
190 
191 
193 // //
194 // //
195 // //
197 
198 //---------------------------------------------------------
199 #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:105
CSG_Table_DBase::Get_Field_Decimals
int Get_Field_Decimals(int iField)
Definition: table_dbase.h:117
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:114
CSG_Table_DBase::Get_File_Length
int Get_File_Length(void)
Definition: table_dbase.h:123
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::is_Open
bool is_Open(void) const
Definition: table_dbase.h:102
CSG_Table_DBase::Get_Count
int Get_Count(void)
Definition: table_dbase.h:124
CSG_Table_DBase::Get_Field_Type
char Get_Field_Type(int iField)
Definition: table_dbase.h:111
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:285
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:108
SG_FILE_ENCODING_ANSI
@ SG_FILE_ENCODING_ANSI
Definition: api_core.h:550