SAGA API Version 9.13
Loading...
Searching...
No Matches
table.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.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_H
54#define HEADER_INCLUDED__SAGA_API__table_H
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
72
73
75// //
76// //
77// //
79
80//---------------------------------------------------------
81#include "dataobject.h"
82#include "table_value.h"
83
84
86// //
87// //
88// //
90
91//---------------------------------------------------------
100
101//---------------------------------------------------------
109
110
112// //
113// //
114// //
116
117//---------------------------------------------------------
118#define SG_TABLE_REC_FLAG_Modified 0x01
119#define SG_TABLE_REC_FLAG_Selected 0x02
120
121
123// //
124// //
125// //
127
128//---------------------------------------------------------
130{
131 friend class CSG_Table; friend class CSG_PointCloud;
132
133public:
134
135 class CSG_Table * Get_Table (void) { return( m_pTable ); }
136 sLong Get_Index (void) const { return( m_Index ); }
137
138 virtual bool is_Valid (void) const { return( true ); }
139
140 bool Set_Value (int Field, const CSG_String &Value);
141 bool Set_Value (int Field, const char *Value) { return( Set_Value( Field , CSG_String(Value)) ); }
142 bool Set_Value (int Field, const wchar_t *Value) { return( Set_Value( Field , CSG_String(Value)) ); }
143 bool Set_Value (const CSG_String &Field, const CSG_String &Value) { return( Set_Value(_Get_Field(Field), Value ) ); }
144 bool Set_Value (const char *Field, const CSG_String &Value) { return( Set_Value(_Get_Field(Field), Value ) ); }
145 bool Set_Value (const wchar_t *Field, const CSG_String &Value) { return( Set_Value(_Get_Field(Field), Value ) ); }
146 bool Set_Value (const char *Field, const char *Value) { return( Set_Value(_Get_Field(Field), CSG_String(Value)) ); }
147 bool Set_Value (const wchar_t *Field, const wchar_t *Value) { return( Set_Value(_Get_Field(Field), CSG_String(Value)) ); }
148
149 bool Set_Value (int Field, const CSG_Bytes &Value);
150 bool Set_Value (const CSG_String &Field, const CSG_Bytes &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
151 bool Set_Value (const char *Field, const CSG_Bytes &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
152 bool Set_Value (const wchar_t *Field, const CSG_Bytes &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
153
154 bool Set_Value (int Field, const int &Value) { return( Set_Value(Field, (sLong)Value) ); }
155 bool Set_Value (const CSG_String &Field, const int &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
156 bool Set_Value (const char *Field, const int &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
157 bool Set_Value (const wchar_t *Field, const int &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
158
159 bool Set_Value (int Field, const long &Value) { return( Set_Value(Field, (sLong)Value) ); }
160 bool Set_Value (const CSG_String &Field, const long &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
161 bool Set_Value (const char *Field, const long &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
162 bool Set_Value (const wchar_t *Field, const long &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
163
164 bool Set_Value (int Field, const DWORD &Value) { return( Set_Value(Field, (uLong)Value) ); }
165 bool Set_Value (const CSG_String &Field, const DWORD &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
166 bool Set_Value (const char *Field, const DWORD &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
167 bool Set_Value (const wchar_t *Field, const DWORD &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
168
169 bool Set_Value (int Field, const sLong &Value);
170 bool Set_Value (const CSG_String &Field, const sLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
171 bool Set_Value (const char *Field, const sLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
172 bool Set_Value (const wchar_t *Field, const sLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
173
174 bool Set_Value (int Field, const uLong &Value);
175 bool Set_Value (const CSG_String &Field, const uLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
176 bool Set_Value (const char *Field, const uLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
177 bool Set_Value (const wchar_t *Field, const uLong &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
178
179 bool Set_Value (int Field, const double &Value);
180 bool Set_Value (const CSG_String &Field, const double &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
181 bool Set_Value (const char *Field, const double &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
182 bool Set_Value (const wchar_t *Field, const double &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
183
184 bool Add_Value (int Field, const double &Value);
185 bool Add_Value (const CSG_String &Field, const double &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
186 bool Add_Value (const char *Field, const double &Value) { return( Add_Value(_Get_Field(Field), Value) ); }
187 bool Add_Value (const wchar_t *Field, const double &Value) { return( Add_Value(_Get_Field(Field), Value) ); }
188
189 bool Mul_Value (int Field, const double &Value);
190 bool Mul_Value (const CSG_String &Field, const double &Value) { return( Set_Value(_Get_Field(Field), Value) ); }
191 bool Mul_Value (const char *Field, const double &Value) { return( Mul_Value(_Get_Field(Field), Value) ); }
192 bool Mul_Value (const wchar_t *Field, const double &Value) { return( Mul_Value(_Get_Field(Field), Value) ); }
193
194 bool Set_NoData (int Field);
195 bool Set_NoData (const CSG_String &Field) { return( Set_NoData(_Get_Field(Field)) ); }
196 bool Set_NoData (const char *Field) { return( Set_NoData(_Get_Field(Field)) ); }
197 bool Set_NoData (const wchar_t *Field) { return( Set_NoData(_Get_Field(Field)) ); }
198
199 bool is_NoData (int Field) const;
200 bool is_NoData (const CSG_String &Field) const { return( is_NoData(_Get_Field(Field)) ); }
201 bool is_NoData (const char *Field) const { return( is_NoData(_Get_Field(Field)) ); }
202 bool is_NoData (const wchar_t *Field) const { return( is_NoData(_Get_Field(Field)) ); }
203
204 const SG_Char * asString (int Field, int Decimals = -99) const;
205 const SG_Char * asString (const CSG_String &Field, int Decimals = -99) const { return( asString(_Get_Field(Field), Decimals) ); }
206 const SG_Char * asString (const char *Field, int Decimals = -99) const { return( asString(_Get_Field(Field), Decimals) ); }
207 const SG_Char * asString (const wchar_t *Field, int Decimals = -99) const { return( asString(_Get_Field(Field), Decimals) ); }
208
209 SG_Char asChar (int Field) const { return( (SG_Char)asLong (Field) ); }
210 SG_Char asChar (const CSG_String &Field) const { return( asChar (_Get_Field(Field)) ); }
211 SG_Char asChar (const char *Field) const { return( asChar (_Get_Field(Field)) ); }
212 SG_Char asChar (const wchar_t *Field) const { return( asChar (_Get_Field(Field)) ); }
213
214 short asShort (int Field) const { return( (short )asLong (Field) ); }
215 short asShort (const CSG_String &Field) const { return( asShort (_Get_Field(Field)) ); }
216 short asShort (const char *Field) const { return( asShort (_Get_Field(Field)) ); }
217 short asShort (const wchar_t *Field) const { return( asShort (_Get_Field(Field)) ); }
218
219 int asInt (int Field) const { return( (int )asLong (Field) ); }
220 int asInt (const CSG_String &Field) const { return( asInt (_Get_Field(Field)) ); }
221 int asInt (const char *Field) const { return( asInt (_Get_Field(Field)) ); }
222 int asInt (const wchar_t *Field) const { return( asInt (_Get_Field(Field)) ); }
223
224 DWORD asDWord (int Field) const { return( (DWORD )asULong (Field) ); }
225 DWORD asDWord (const CSG_String &Field) const { return( asDWord (_Get_Field(Field)) ); }
226 DWORD asDWord (const char *Field) const { return( asDWord (_Get_Field(Field)) ); }
227 DWORD asDWord (const wchar_t *Field) const { return( asDWord (_Get_Field(Field)) ); }
228
229 sLong asLong (int Field) const;
230 sLong asLong (const CSG_String &Field) const { return( asLong (_Get_Field(Field)) ); }
231 sLong asLong (const char *Field) const { return( asLong (_Get_Field(Field)) ); }
232 sLong asLong (const wchar_t *Field) const { return( asLong (_Get_Field(Field)) ); }
233
234 uLong asULong (int Field) const;
235 uLong asULong (const CSG_String &Field) const { return( asULong (_Get_Field(Field)) ); }
236 uLong asULong (const char *Field) const { return( asULong (_Get_Field(Field)) ); }
237 uLong asULong (const wchar_t *Field) const { return( asULong (_Get_Field(Field)) ); }
238
239 float asFloat (int Field) const { return( (float )asDouble(Field) ); }
240 float asFloat (const CSG_String &Field) const { return( asFloat (_Get_Field(Field)) ); }
241 float asFloat (const char *Field) const { return( asFloat (_Get_Field(Field)) ); }
242 float asFloat (const wchar_t *Field) const { return( asFloat (_Get_Field(Field)) ); }
243
244 double asDouble (int Field) const;
245 double asDouble (const CSG_String &Field) const { return( asDouble(_Get_Field(Field)) ); }
246 double asDouble (const char *Field) const { return( asDouble(_Get_Field(Field)) ); }
247 double asDouble (const wchar_t *Field) const { return( asDouble(_Get_Field(Field)) ); }
248
249 CSG_Table_Value * Get_Value (int Field) { return( m_Values[Field] ); }
250 CSG_Table_Value & operator [] (int Field) const { return( *m_Values[Field] ); }
251
252 virtual bool Assign (CSG_Table_Record *pRecord);
253
254 bool is_Selected (void) const { return( (m_Flags & SG_TABLE_REC_FLAG_Selected) != 0 ); }
255 bool is_Modified (void) const { return( (m_Flags & SG_TABLE_REC_FLAG_Modified) != 0 ); }
256
257
258protected:
259
260 CSG_Table_Record(class CSG_Table *pTable, sLong Index);
261 virtual ~CSG_Table_Record(void);
262
263
265
267
269
271
272
273 void Set_Selected (bool bOn = true);
274 void Set_Modified (bool bOn = true);
275
276
278
279 bool _Add_Field (int add_Field);
280 bool _Del_Field (int del_Field);
281
282 int _Get_Field (const CSG_String &Field) const;
283
284};
285
286
288// //
289// //
290// //
292
293//---------------------------------------------------------
295{
296 friend class CSG_Table_Record;
297 friend class CSG_TIN;
298
299public:
300
301 CSG_Table (void);
302 bool Create (void);
303
304 CSG_Table (const CSG_Table &Table);
305 bool Create (const CSG_Table &Table);
306
307 CSG_Table (const CSG_Table *pTemplate);
308 bool Create (const CSG_Table *pTemplate);
309
312 CSG_Table (const char *File, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined, int Encoding = SG_FILE_ENCODING_UNDEFINED);
313 bool Create (const char *File, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined, int Encoding = SG_FILE_ENCODING_UNDEFINED);
314 CSG_Table (const wchar_t *File, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined, int Encoding = SG_FILE_ENCODING_UNDEFINED);
315 bool Create (const wchar_t *File, TSG_Table_File_Type Format = TABLE_FILETYPE_Undefined, int Encoding = SG_FILE_ENCODING_UNDEFINED);
316
317 CSG_Table (const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
318 bool Create (const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
319 CSG_Table (const char *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
320 bool Create (const char *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
321 CSG_Table (const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
322 bool Create (const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
323
324 virtual ~CSG_Table(void);
325
326 virtual bool Destroy (void);
327
329
330 CSG_Table & operator = (const CSG_Table &Table);
331 virtual bool Assign (CSG_Data_Object *pTable, bool bProgress = false);
332
333 bool Assign_Values (const CSG_Table &Table);
334 bool Assign_Values ( CSG_Table *pTable);
335 bool Assign_Values (const SG_Char *File);
336
337 bool Load (const CSG_String &File, int Format, SG_Char Separator, int Encoding = SG_FILE_ENCODING_UNDEFINED);
338
339 virtual bool Save (const CSG_String &File, int Format, SG_Char Separator, int Encoding = SG_FILE_ENCODING_UNDEFINED, bool bMetaData = true);
340 virtual bool Save (const char *File, int Format, SG_Char Separator, int Encoding = SG_FILE_ENCODING_UNDEFINED, bool bMetaData = true) { return( Save(CSG_String(File), Format, Separator, Encoding, bMetaData) ); }
341 virtual bool Save (const wchar_t *File, int Format, SG_Char Separator, int Encoding = SG_FILE_ENCODING_UNDEFINED, bool bMetaData = true) { return( Save(CSG_String(File), Format, Separator, Encoding, bMetaData) ); }
342
343 virtual bool Save (const CSG_String &File, int Format = 0);
344 virtual bool Save (const char *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
345 virtual bool Save (const wchar_t *File, int Format = 0) { return( Save(CSG_String(File), Format) ); }
346
347 bool Set_File_Encoding (int Encoding);
348 int Get_File_Encoding (void) const { return( m_Encoding ); }
349
350 bool from_Text (const CSG_String &Text);
351 CSG_String to_Text (bool Selection = false, bool Header = true, bool QuoteStrings = false) const;
352
353 bool Serialize (CSG_File &Stream, bool bSave);
354
355 //-----------------------------------------------------
356 virtual bool is_Valid (void) const { return( m_nFields > 0 ); }
357
358 bool is_Compatible (const CSG_Table &Table, bool bExactMatch = false) const;
359 bool is_Compatible ( CSG_Table *pTable, bool bExactMatch = false) const;
360
361 //-----------------------------------------------------
362 virtual const CSG_Rect & Get_Extent (void) { return( m_Extent ); }
363
364 //-----------------------------------------------------
365 virtual bool Add_Field (const CSG_String &Name, TSG_Data_Type Type, int Position = -1);
366 virtual bool Add_Field (const char *Name, TSG_Data_Type Type, int Position = -1) { return( Add_Field(CSG_String(Name), Type, Position) ); }
367 virtual bool Add_Field (const wchar_t *Name, TSG_Data_Type Type, int Position = -1) { return( Add_Field(CSG_String(Name), Type, Position) ); }
368 virtual bool Del_Field (int Field);
369 virtual bool Mov_Field (int Field, int Position);
370
371 int Get_Field_Count (void) const { return( m_nFields ); }
372 const SG_Char * Get_Field_Name (int Field) const { return( Field >= 0 && Field < m_nFields ? m_Field_Info[Field]->m_Name.c_str() : NULL ); }
373 TSG_Data_Type Get_Field_Type (int Field) const { return( Field >= 0 && Field < m_nFields ? m_Field_Info[Field]->m_Type : SG_DATATYPE_Undefined ); }
374 bool is_Field_Numeric (int Field) const { return( SG_Data_Type_is_Numeric(Get_Field_Type(Field)) ); }
375 virtual int Get_Field_Length (int Field, int Encoding = SG_FILE_ENCODING_UNDEFINED) const;
376 int Get_Field (const CSG_String &Name) const; // returns the zero based position of the field named 'Name' or '-1' if there is no field with such name.
377 int Get_Field (const char *Name) const; // returns the zero based position of the field named 'Name' or '-1' if there is no field with such name.
378 int Get_Field (const wchar_t *Name) const; // returns the zero based position of the field named 'Name' or '-1' if there is no field with such name.
379
380 bool Set_Field_Name (int Field, const SG_Char *Name);
381 virtual bool Set_Field_Type (int Field, TSG_Data_Type Type);
382
383 int Find_Field (const CSG_String &Name ) const;
384 int Find_Field (const char *Name ) const { return( Find_Field(CSG_String(Name)) ); }
385 int Find_Field (const wchar_t *Name ) const { return( Find_Field(CSG_String(Name)) ); }
386 bool Find_Field (const CSG_String &Name, int &Index) const;
387 bool Find_Field (const char *Name, int &Index) const { return( Find_Field(CSG_String(Name)) ); }
388 bool Find_Field (const wchar_t *Name, int &Index) const { return( Find_Field(CSG_String(Name)) ); }
389
390 sLong Get_N (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Count () : 0 ); }
391 double Get_Minimum (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Minimum () : 0. ); }
392 double Get_Maximum (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Maximum () : 0. ); }
393 double Get_Range (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Range () : 0. ); }
394 double Get_Sum (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Sum () : 0. ); }
395 double Get_Mean (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Mean () : 0. ); }
396 double Get_StdDev (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_StdDev () : 0. ); }
397 double Get_Variance (int Field) const { return( _Stats_Update(Field) ? m_Field_Info[Field]->m_Statistics.Get_Variance() : 0. ); }
398 const CSG_Simple_Statistics & Get_Statistics (int Field) const { _Stats_Update(Field); return( m_Field_Info[Field]->m_Statistics ); }
399
400 const CSG_Histogram & Get_Histogram (int Field, size_t nClasses = 0) const { _Histogram_Update(Field, nClasses); return( m_Field_Info[Field]->m_Histogram ); }
401
402 //-----------------------------------------------------
403 virtual CSG_Table_Record * Add_Record ( CSG_Table_Record *pCopy = NULL);
404 virtual CSG_Table_Record * Ins_Record (sLong Index, CSG_Table_Record *pCopy = NULL);
405 virtual bool Set_Record (sLong Index, CSG_Table_Record *pCopy );
406 virtual bool Del_Record (sLong Index);
407 virtual bool Del_Records (void);
408
409 virtual bool Set_Count (sLong nRecords);
410 sLong Get_Count (void) const { return( m_nRecords ); }
411
412 virtual CSG_Table_Record * Get_Record (sLong Index) const { return( Index >= 0 && Index < m_nRecords ? m_Records[Index] : NULL ); }
413 virtual CSG_Table_Record & operator [] (sLong Index) const { return( *Get_Record_byIndex(Index) ); }
414
415 sLong Get_Index (sLong Index) const { return( Index >= 0 && Index < m_nRecords ? (is_Indexed() ? m_Index[Index] : Index) : -1 ); }
416
418 {
419 return( Index >= 0 && Index < m_nRecords ? Get_Record(is_Indexed() ? m_Index[Index] : Index) : NULL );
420 }
421
422 //-----------------------------------------------------
423 virtual bool Find_Record (sLong &Index, int Field, const CSG_String &Value, bool bCreateIndex = false);
424 virtual CSG_Table_Record * Find_Record ( int Field, const CSG_String &Value, bool bCreateIndex = false);
425 virtual bool Find_Record (sLong &Index, int Field, double Value, bool bCreateIndex = false);
426 virtual CSG_Table_Record * Find_Record ( int Field, double Value, bool bCreateIndex = false);
427
428 //-----------------------------------------------------
429 virtual bool Set_Value (sLong Index, int Field, const SG_Char *Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
430 virtual bool Set_Value (sLong Index, int Field, const int &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
431 virtual bool Set_Value (sLong Index, int Field, const long &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
432 virtual bool Set_Value (sLong Index, int Field, const DWORD &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
433 virtual bool Set_Value (sLong Index, int Field, const sLong &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
434 virtual bool Set_Value (sLong Index, int Field, const uLong &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
435 virtual bool Set_Value (sLong Index, int Field, const double &Value) { return( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields ? m_Records[Index]->Set_Value(Field, Value) : false ); }
436
437 virtual bool Get_Value (sLong Index, int Field, CSG_String &Value) const;
438 virtual bool Get_Value (sLong Index, int Field, sLong &Value) const;
439 virtual bool Get_Value (sLong Index, int Field, double &Value) const;
440
441 virtual void Set_Modified (bool bModified = true);
442
443 //-----------------------------------------------------
444 sLong Get_Selection_Count (void) const { return( m_Selection.Get_Size() ); }
445 sLong Get_Selection_Index (sLong Index = 0) const { return( Index >= 0 && Index < m_Selection.Get_Size() ? *((sLong *)m_Selection.Get_Entry(Index)) : Get_Count() ); }
446 virtual CSG_Table_Record * Get_Selection (sLong Index = 0) const { return( Index >= 0 && Index < m_Selection.Get_Size() ? Get_Record(Get_Selection_Index(Index)) : NULL ); }
447
448 virtual bool is_Selected (sLong Index) const { return( Index >= 0 && Index < m_nRecords ? m_Records[Index]->is_Selected() : false ); }
449
450 virtual bool Select (sLong Index , bool bInvert = false);
451 virtual bool Select (CSG_Table_Record *pRecord = NULL, bool bInvert = false);
452
453 virtual sLong Del_Selection (void);
454 virtual sLong Inv_Selection (void);
455
456 //-----------------------------------------------------
457 bool Sort (const char *Field, bool bAscending = true);
458 bool Sort (const wchar_t *Field, bool bAscending = true);
459 bool Sort (const CSG_String &Field, bool bAscending = true);
460 bool Sort (int Field, bool bAscending = true);
461 virtual bool Sort (const CSG_Index &Index);
462
463 bool Set_Index (CSG_Index &Index, int Field , bool bAscending = true) const;
464 bool Set_Index (CSG_Index &Index, int Fields[], int nFields, bool bAscending = true) const;
465 bool Set_Index (CSG_Index &Index, const CSG_Array_Int &Fields, bool bAscending = true) const;
466
467 bool Set_Index (int Field, TSG_Table_Index_Order Order = TABLE_INDEX_Ascending, int Field_2 = -1, TSG_Table_Index_Order Order_2 = TABLE_INDEX_None, int Field_3 = -1, TSG_Table_Index_Order Order_3 = TABLE_INDEX_None);
468 bool Del_Index (void);
469 bool Toggle_Index (int Field);
470 bool is_Indexed (void) const { return( m_nRecords > 0 && m_nRecords == m_Index.Get_Count() ); }
471 int Get_Index_Field (int i) const { return( i < 0 || i >= m_Index_Fields.Get_Size() ? -1 : abs(m_Index_Fields[i]) - 1 ); }
472 TSG_Table_Index_Order Get_Index_Order (int i) const { return( i < 0 || i >= m_Index_Fields.Get_Size() ? TABLE_INDEX_None : m_Index_Fields[i] > 0 ? TABLE_INDEX_Ascending : TABLE_INDEX_Descending ); }
473 int Get_Index_Field (size_t i) const { return( Get_Index_Field((int)i) ); }
474 TSG_Table_Index_Order Get_Index_Order (size_t i) const { return( Get_Index_Order((int)i) ); }
475
476
477protected:
478
480 {
481 public:
482 CSG_Field_Info(void);
483 virtual ~CSG_Field_Info(void);
484
485 CSG_Field_Info(const CSG_String &Name, TSG_Data_Type Type);
486
487 bool Reset_Statistics (void);
488
489
491
493
495
497
498 };
499
500
502
504
506
508
510
511
512 virtual void _On_Construction (void);
513
514 virtual CSG_Table_Record * _Get_New_Record (sLong Index);
515
516 bool _Add_Selection (sLong Index);
517 bool _Set_Selection (sLong Index, sLong Selected);
518 bool _Del_Selection (sLong Index);
519
520 bool _Stats_Invalidate (void) const;
521 bool _Stats_Invalidate (int Field) const;
522 virtual bool _Stats_Update (int Field) const;
523 virtual bool _Histogram_Update (int Field, size_t nClasses) const;
524
525 bool _Save_Text (const CSG_String &File, bool bHeadline, const SG_Char Separator);
526 bool _Save_DBase (const CSG_String &File);
527
528 virtual bool On_NoData_Changed (void);
529 virtual bool On_Update (void);
530
531 virtual bool On_Reload (void);
532 virtual bool On_Delete (void);
533
534
535private:
536
537 CSG_Index m_Index;
538
539 CSG_Array_Int m_Index_Fields;
540
541 CSG_Table_Record **m_Records = NULL;
542
543
544 bool _Destroy_Selection (void);
545
546 bool _Inc_Array (void);
547 bool _Dec_Array (void);
548
549 size_t _Load_Text_Trim ( CSG_String &Text, const SG_Char Separator);
550 size_t _Load_Text_EndQuote (const CSG_String &Text, const SG_Char Separator);
551
552 bool _Load_Text (const CSG_String &File, bool bHeadline, const SG_Char Separator);
553 bool _Load_DBase (const CSG_String &File);
554
555 void _Index_Update (void);
556
557};
558
559
561// //
562// //
563// //
565
566//---------------------------------------------------------
569
572
575
582
584SAGA_API_DLL_EXPORT CSG_Table * SG_Create_Table (const char *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
586SAGA_API_DLL_EXPORT CSG_Table * SG_Create_Table (const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator , int Encoding = SG_FILE_ENCODING_UNDEFINED);
589
590
592// //
593// //
594// //
596
597//---------------------------------------------------------
598#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_H
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
Definition api_core.cpp:198
unsigned long long uLong
Definition api_core.h:159
signed long long sLong
Definition api_core.h:158
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
TSG_Data_Type
Definition api_core.h:1043
@ SG_DATATYPE_Undefined
Definition api_core.h:1059
#define SG_Char
Definition api_core.h:536
@ SG_FILE_ENCODING_UTF8
Definition api_core.h:552
@ SG_FILE_ENCODING_UNDEFINED
Definition api_core.h:557
bool Reset_Statistics(void)
Definition table.cpp:466
TSG_Data_Type m_Type
Definition table.h:490
CSG_Simple_Statistics m_Statistics
Definition table.h:494
CSG_Histogram m_Histogram
Definition table.h:496
void Set_Modified(bool bOn=true)
sLong asLong(const CSG_String &Field) const
Definition table.h:230
int asInt(const CSG_String &Field) const
Definition table.h:220
SG_Char asChar(const wchar_t *Field) const
Definition table.h:212
SG_Char asChar(const char *Field) const
Definition table.h:211
const SG_Char * asString(const CSG_String &Field, int Decimals=-99) const
Definition table.h:205
sLong m_Index
Definition table.h:266
bool Add_Value(const CSG_String &Field, const double &Value)
Definition table.h:185
bool Set_Value(int Field, const CSG_String &Value)
bool Set_Value(const CSG_String &Field, const int &Value)
Definition table.h:155
class CSG_Table_Value ** m_Values
Definition table.h:268
CSG_Table_Record(class CSG_Table *pTable, sLong Index)
bool Add_Value(const wchar_t *Field, const double &Value)
Definition table.h:187
DWORD asDWord(const CSG_String &Field) const
Definition table.h:225
bool Set_Value(const char *Field, const uLong &Value)
Definition table.h:176
double asDouble(const CSG_String &Field) const
Definition table.h:245
bool Add_Value(const char *Field, const double &Value)
Definition table.h:186
SG_Char asChar(const CSG_String &Field) const
Definition table.h:210
bool Set_Value(const char *Field, const double &Value)
Definition table.h:181
bool is_NoData(const wchar_t *Field) const
Definition table.h:202
double asDouble(const wchar_t *Field) const
Definition table.h:247
bool _Del_Field(int del_Field)
bool is_NoData(const char *Field) const
Definition table.h:201
bool is_Modified(void) const
Definition table.h:255
DWORD asDWord(const char *Field) const
Definition table.h:226
void Set_Selected(bool bOn=true)
class CSG_Table * m_pTable
Definition table.h:270
bool Set_Value(const CSG_String &Field, const uLong &Value)
Definition table.h:175
sLong Get_Index(void) const
Definition table.h:136
bool Set_Value(int Field, const wchar_t *Value)
Definition table.h:142
sLong asLong(int Field) const
bool Set_Value(const char *Field, const sLong &Value)
Definition table.h:171
bool Set_Value(const wchar_t *Field, const CSG_Bytes &Value)
Definition table.h:152
bool Set_Value(const CSG_String &Field, const CSG_Bytes &Value)
Definition table.h:150
bool _Add_Field(int add_Field)
double asDouble(const char *Field) const
Definition table.h:246
const SG_Char * asString(const char *Field, int Decimals=-99) const
Definition table.h:206
bool Set_Value(const wchar_t *Field, const wchar_t *Value)
Definition table.h:147
bool Mul_Value(const wchar_t *Field, const double &Value)
Definition table.h:192
bool Set_Value(const char *Field, const CSG_Bytes &Value)
Definition table.h:151
bool is_NoData(const CSG_String &Field) const
Definition table.h:200
uLong asULong(int Field) const
bool Mul_Value(const CSG_String &Field, const double &Value)
Definition table.h:190
bool Set_Value(const char *Field, const long &Value)
Definition table.h:161
float asFloat(const wchar_t *Field) const
Definition table.h:242
friend class CSG_PointCloud
Definition table.h:131
double asDouble(int Field) const
bool Set_Value(const CSG_String &Field, const double &Value)
Definition table.h:180
short asShort(const char *Field) const
Definition table.h:216
int asInt(int Field) const
Definition table.h:219
int _Get_Field(const CSG_String &Field) const
bool Set_NoData(const CSG_String &Field)
Definition table.h:195
bool Set_Value(const wchar_t *Field, const long &Value)
Definition table.h:162
float asFloat(const char *Field) const
Definition table.h:241
const SG_Char * asString(const wchar_t *Field, int Decimals=-99) const
Definition table.h:207
bool Set_Value(const wchar_t *Field, const CSG_String &Value)
Definition table.h:145
bool is_Selected(void) const
Definition table.h:254
bool Set_Value(int Field, const int &Value)
Definition table.h:154
bool Set_Value(const wchar_t *Field, const sLong &Value)
Definition table.h:172
friend class CSG_Table
Definition table.h:131
bool Set_NoData(const char *Field)
Definition table.h:196
uLong asULong(const wchar_t *Field) const
Definition table.h:237
bool Set_Value(const CSG_String &Field, const CSG_String &Value)
Definition table.h:143
int asInt(const char *Field) const
Definition table.h:221
float asFloat(const CSG_String &Field) const
Definition table.h:240
bool Set_Value(const CSG_String &Field, const long &Value)
Definition table.h:160
class CSG_Table * Get_Table(void)
Definition table.h:135
int asInt(const wchar_t *Field) const
Definition table.h:222
DWORD asDWord(const wchar_t *Field) const
Definition table.h:227
bool Set_Value(const wchar_t *Field, const uLong &Value)
Definition table.h:177
bool Set_Value(const CSG_String &Field, const sLong &Value)
Definition table.h:170
float asFloat(int Field) const
Definition table.h:239
bool Set_Value(const CSG_String &Field, const DWORD &Value)
Definition table.h:165
bool Set_Value(const char *Field, const int &Value)
Definition table.h:156
bool Set_Value(const wchar_t *Field, const int &Value)
Definition table.h:157
SG_Char asChar(int Field) const
Definition table.h:209
short asShort(int Field) const
Definition table.h:214
short asShort(const CSG_String &Field) const
Definition table.h:215
bool Set_Value(int Field, const long &Value)
Definition table.h:159
bool Set_Value(const wchar_t *Field, const DWORD &Value)
Definition table.h:167
bool Set_Value(const char *Field, const DWORD &Value)
Definition table.h:166
bool Set_Value(const char *Field, const CSG_String &Value)
Definition table.h:144
short asShort(const wchar_t *Field) const
Definition table.h:217
bool Set_Value(int Field, const DWORD &Value)
Definition table.h:164
sLong asLong(const char *Field) const
Definition table.h:231
uLong asULong(const char *Field) const
Definition table.h:236
CSG_Table_Value * Get_Value(int Field)
Definition table.h:249
bool Set_Value(const wchar_t *Field, const double &Value)
Definition table.h:182
bool Mul_Value(const char *Field, const double &Value)
Definition table.h:191
static CSG_Table_Value * _Create_Value(TSG_Data_Type Type)
bool Set_Value(int Field, const char *Value)
Definition table.h:141
virtual bool is_Valid(void) const
Definition table.h:138
uLong asULong(const CSG_String &Field) const
Definition table.h:235
sLong asLong(const wchar_t *Field) const
Definition table.h:232
bool Set_NoData(const wchar_t *Field)
Definition table.h:197
DWORD asDWord(int Field) const
Definition table.h:224
bool Set_Value(const char *Field, const char *Value)
Definition table.h:146
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:372
virtual const CSG_Rect & Get_Extent(void)
Definition table.h:362
bool Create(void)
Definition table.cpp:153
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition table.h:429
virtual bool Set_Value(sLong Index, int Field, const DWORD &Value)
Definition table.h:432
virtual bool Save(const char *File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED, bool bMetaData=true)
Definition table.h:340
int Find_Field(const wchar_t *Name) const
Definition table.h:385
virtual bool _Stats_Update(int Field) const
Definition table.cpp:1229
virtual bool Add_Field(const wchar_t *Name, TSG_Data_Type Type, int Position=-1)
Definition table.h:367
virtual bool Set_Value(sLong Index, int Field, const double &Value)
Definition table.h:435
TSG_Table_Index_Order Get_Index_Order(size_t i) const
Definition table.h:474
sLong Get_Count(void) const
Definition table.h:410
int Find_Field(const char *Name) const
Definition table.h:384
virtual bool Destroy(void)
Definition table.cpp:314
bool _Set_Selection(sLong Index, sLong Selected)
double Get_Minimum(int Field) const
Definition table.h:391
int Get_File_Encoding(void) const
Definition table.h:348
sLong m_nRecords
Definition table.h:505
double Get_Mean(int Field) const
Definition table.h:395
virtual bool On_NoData_Changed(void)
Definition table.cpp:1301
virtual bool is_Valid(void) const
Definition table.h:356
double Get_StdDev(int Field) const
Definition table.h:396
sLong Get_N(int Field) const
Definition table.h:390
virtual bool _Histogram_Update(int Field, size_t nClasses) const
Definition table.cpp:1276
bool _Stats_Invalidate(void) const
Definition table.cpp:1205
virtual bool Set_Value(sLong Index, int Field, const uLong &Value)
Definition table.h:434
CSG_Field_Info ** m_Field_Info
Definition table.h:501
CSG_Table(void)
Definition table.cpp:147
virtual bool Save(const wchar_t *File, int Format=0)
Definition table.h:345
TSG_Table_Index_Order Get_Index_Order(int i) const
Definition table.h:472
bool is_Indexed(void) const
Definition table.h:470
virtual bool On_Delete(void)
Definition table_io.cpp:70
virtual bool On_Update(void)
Definition table.cpp:1309
friend class CSG_Table_Record
Definition table.h:296
CSG_Array m_Selection
Definition table.h:507
int Get_Index_Field(size_t i) const
Definition table.h:473
friend class CSG_TIN
Definition table.h:297
int Get_Index_Field(int i) const
Definition table.h:471
bool _Save_Text(const CSG_String &File, bool bHeadline, const SG_Char Separator)
Definition table_io.cpp:498
virtual TSG_Data_Object_Type Get_ObjectType(void) const
Returns the object type as defined by TSG_Data_Object_Type. Used for run time type checking.
Definition table.h:328
virtual bool Set_Value(sLong Index, int Field, const int &Value)
Definition table.h:430
int m_Encoding
Definition table.h:503
bool Find_Field(const char *Name, int &Index) const
Definition table.h:387
virtual CSG_Table_Record * _Get_New_Record(sLong Index)
Definition table.cpp:817
bool Find_Field(const wchar_t *Name, int &Index) const
Definition table.h:388
virtual bool Add_Field(const char *Name, TSG_Data_Type Type, int Position=-1)
Definition table.h:366
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition table.h:412
const CSG_Histogram & Get_Histogram(int Field, size_t nClasses=0) const
Definition table.h:400
virtual bool Save(const char *File, int Format=0)
Definition table.h:344
virtual CSG_Table_Record * Get_Selection(sLong Index=0) const
Definition table.h:446
int Get_Field_Count(void) const
Definition table.h:371
double Get_Range(int Field) const
Definition table.h:393
virtual bool Set_Value(sLong Index, int Field, const sLong &Value)
Definition table.h:433
bool _Save_DBase(const CSG_String &File)
Definition table_io.cpp:566
bool _Add_Selection(sLong Index)
virtual bool Save(const wchar_t *File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED, bool bMetaData=true)
Definition table.h:341
virtual bool is_Selected(sLong Index) const
Definition table.h:448
sLong m_nBuffer
Definition table.h:505
int m_nFields
Definition table.h:503
virtual bool On_Reload(void)
Definition table_io.cpp:64
CSG_Rect m_Extent
Definition table.h:509
sLong Get_Selection_Index(sLong Index=0) const
Definition table.h:445
bool is_Field_Numeric(int Field) const
Definition table.h:374
sLong Get_Selection_Count(void) const
Definition table.h:444
double Get_Sum(int Field) const
Definition table.h:394
CSG_Table_Record * Get_Record_byIndex(sLong Index) const
Definition table.h:417
const CSG_Simple_Statistics & Get_Statistics(int Field) const
Definition table.h:398
bool _Del_Selection(sLong Index)
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:373
double Get_Variance(int Field) const
Definition table.h:397
virtual bool Set_Value(sLong Index, int Field, const long &Value)
Definition table.h:431
sLong Get_Index(sLong Index) const
Definition table.h:415
virtual void _On_Construction(void)
Definition table.cpp:295
double Get_Maximum(int Field) const
Definition table.h:392
TSG_Data_Object_Type
Definition dataobject.h:117
@ SG_DATAOBJECT_TYPE_Table
Definition dataobject.h:120
SAGA_API_DLL_EXPORT CSG_Table * SG_Create_Table(void)
Definition table.cpp:65
TSG_Table_File_Type
Definition table.h:93
@ TABLE_FILETYPE_DBase
Definition table.h:97
@ TABLE_FILETYPE_Text
Definition table.h:95
@ TABLE_FILETYPE_Text_NoHeadLine
Definition table.h:96
@ TABLE_FILETYPE_Undefined
Definition table.h:94
#define SG_TABLE_REC_FLAG_Selected
Definition table.h:119
TSG_Table_Index_Order
Definition table.h:103
@ TABLE_INDEX_Descending
Definition table.h:106
@ TABLE_INDEX_Ascending
Definition table.h:105
@ TABLE_INDEX_None
Definition table.h:104
#define SG_TABLE_REC_FLAG_Modified
Definition table.h:118