SAGA API Version 9.13
Loading...
Searching...
No Matches
table.cpp
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.cpp //
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#include "table.h"
54#include "shapes.h"
55#include "tool_library.h"
56
57
59// //
60// //
61// //
63
64//---------------------------------------------------------
66{
67 return( new CSG_Table );
68}
69
70//---------------------------------------------------------
72{
73 switch( Table.Get_ObjectType() )
74 {
76 return( new CSG_Table(Table) );
77
80 return( SG_Create_Shapes(*((CSG_Shapes *)&Table)) );
81
82 default:
83 return( NULL );
84 }
85}
86
87//---------------------------------------------------------
89{
90 if( pTemplate )
91 {
92 switch( pTemplate->Get_ObjectType() )
93 {
95 return( new CSG_Table(pTemplate) );
96
99 return( SG_Create_Shapes((CSG_Shapes *)pTemplate) );
100
101 default:
102 break;
103 }
104 }
105
106 return( new CSG_Table() );
107}
108
109//---------------------------------------------------------
110CSG_Table * SG_Create_Table(const char *File, TSG_Table_File_Type Format, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Encoding) ); }
111CSG_Table * SG_Create_Table(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Encoding) ); }
112CSG_Table * SG_Create_Table(const CSG_String &File, TSG_Table_File_Type Format, int Encoding)
113{
114 CSG_Table *pTable = new CSG_Table();
115
116 if( pTable->Create(File, Format, Encoding) )
117 {
118 return( pTable );
119 }
120
121 delete(pTable); return( NULL );
122}
123
124//---------------------------------------------------------
125CSG_Table * SG_Create_Table(const char *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Separator, Encoding) ); }
126CSG_Table * SG_Create_Table(const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Separator, Encoding) ); }
127CSG_Table * SG_Create_Table(const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding)
128{
129 CSG_Table *pTable = new CSG_Table();
130
131 if( pTable->Create(File, Format, Separator, Encoding) )
132 {
133 return( pTable );
134 }
135
136 delete(pTable); return( NULL );
137}
138
139
141// //
142// //
143// //
145
146//---------------------------------------------------------
152
154{
155 Destroy(); return( true );
156}
157
158//---------------------------------------------------------
161{
162 _On_Construction(); Create(Table);
163}
164
165bool CSG_Table::Create(const CSG_Table &Table)
166{
167 return( Assign((CSG_Data_Object *)&Table) );
168}
169
170//---------------------------------------------------------
171CSG_Table::CSG_Table(const char *File, TSG_Table_File_Type Format, int Encoding) : CSG_Table(CSG_String(File), Format, Encoding) {}
172CSG_Table::CSG_Table(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) : CSG_Table(CSG_String(File), Format, Encoding) {}
173CSG_Table::CSG_Table(const CSG_String &File, TSG_Table_File_Type Format, int Encoding)
175{
176 _On_Construction(); Create(File, Format, Encoding);
177}
178
179bool CSG_Table::Create(const char *File, TSG_Table_File_Type Format, int Encoding) { return( Create(CSG_String(File), Format, Encoding) ); }
180bool CSG_Table::Create(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) { return( Create(CSG_String(File), Format, Encoding) ); }
181bool CSG_Table::Create(const CSG_String &File, TSG_Table_File_Type Format, int Encoding)
182{
183 Destroy();
184
185 SG_UI_Msg_Add(CSG_String::Format("%s %s: %s...", _TL("Loading"), _TL("table"), File.c_str()), true);
186
187 //-----------------------------------------------------
188 bool bResult = File.BeforeFirst(':').Cmp("PGSQL") && SG_File_Exists(File) && Load(File, (int)Format, '\0', Encoding);
189
190 if( bResult )
191 {
192 Set_File_Name(File, true);
193 }
194
195 //-----------------------------------------------------
196 else if( File.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source
197 {
198 CSG_String s(File);
199
200 s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':'));
201 s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':'));
202 s = s.AfterFirst(':'); CSG_String DBase(s.BeforeFirst(':'));
203 s = s.AfterFirst(':'); CSG_String Table(s.BeforeFirst(':'));
204
205 CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Create_Tool("db_pgsql", 12, true); // CPGIS_Table_Load
206
207 if( pTool )
208 {
210
211 CSG_String Connection(DBase + " [" + Host + ":" + Port + "]");
212
213 bResult = pTool->Set_Manager(NULL) && pTool->On_Before_Execution()
214 && pTool->Set_Parameter("CONNECTION", Connection)
215 && pTool->Set_Parameter("DB_TABLE" , Table )
216 && pTool->Set_Parameter("TABLE" , this )
217 && pTool->Execute();
218
220
222 }
223 }
224
225 //-----------------------------------------------------
226 if( bResult )
227 {
228 Set_Modified(false);
230
232
233 return( true );
234 }
235
236 Destroy();
237
238 SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
239
240 return( false );
241}
242
243//---------------------------------------------------------
244CSG_Table::CSG_Table(const char *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) : CSG_Table(CSG_String(File), Format, Separator, Encoding) {}
245CSG_Table::CSG_Table(const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) : CSG_Table(CSG_String(File), Format, Separator, Encoding) {}
246CSG_Table::CSG_Table(const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding)
248{
249 _On_Construction(); Create(File, Format, Separator, Encoding);
250}
251
252bool CSG_Table::Create(const char *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) { return( Create(CSG_String(File), Format, Separator, Encoding) ); }
253bool CSG_Table::Create(const wchar_t *File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding) { return( Create(CSG_String(File), Format, Separator, Encoding) ); }
254bool CSG_Table::Create(const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding)
255{
256 return( Load(File, (int)Format, Separator, Encoding) );
257}
258
259//---------------------------------------------------------
262{
263 _On_Construction(); Create(pTemplate);
264}
265
266bool CSG_Table::Create(const CSG_Table *pTemplate)
267{
268 if( !pTemplate || pTemplate->Get_Field_Count() < 1 )
269 {
270 return( false );
271 }
272
273 Destroy();
274
275 Set_Name (pTemplate->Get_Name ());
276 Set_Description (pTemplate->Get_Description());
277 Set_NoData_Value_Range(pTemplate->Get_NoData_Value(), pTemplate->Get_NoData_Value(true));
278
279 m_Encoding = pTemplate->m_Encoding;
280
281 for(int i=0; i<pTemplate->Get_Field_Count(); i++)
282 {
283 Add_Field(pTemplate->Get_Field_Name(i), pTemplate->Get_Field_Type(i));
284 }
285
286 return( true );
287}
288
289
291// //
293
294//---------------------------------------------------------
301
302
304// //
306
307//---------------------------------------------------------
309{
310 Destroy();
311}
312
313//---------------------------------------------------------
315{
316 _Destroy_Selection();
317
318 Del_Records();
319
320 if( m_nFields > 0 )
321 {
322 for(int i=0; i<m_nFields; i++)
323 {
324 delete(m_Field_Info[i]);
325 }
326
328
329 m_nFields = 0;
330 }
331
333
334 return( true );
335}
336
337
339// //
340// Assign //
341// //
343
344//---------------------------------------------------------
346{
347 Create(Table);
348
349 return( *this );
350}
351
352//---------------------------------------------------------
353bool CSG_Table::Assign(CSG_Data_Object *pObject, bool bProgress)
354{
355 if( pObject && pObject->asTable(true) && CSG_Data_Object::Assign(pObject) )
356 {
357 CSG_Table *pTable = pObject->asTable(true);
358
359 m_Encoding = pTable->m_Encoding;
360
361 for(int i=0; i<pTable->Get_Field_Count(); i++)
362 {
363 Add_Field(pTable->Get_Field_Name(i), pTable->Get_Field_Type(i));
364 }
365
366 for(sLong i=0; i<pTable->Get_Count() && (!bProgress || SG_UI_Process_Set_Progress(i, pTable->Get_Count())); i++)
367 {
368 Add_Record(pTable->Get_Record(i));
369 }
370
371 return( true );
372 }
373
374 return( false );
375}
376
377//---------------------------------------------------------
379{
380 if( is_Compatible(Table) && Set_Count(Table.Get_Count()) )
381 {
382 for(sLong i=0; i<Table.Get_Count(); i++)
383 {
384 Get_Record(i)->Assign(Table.Get_Record(i));
385 }
386
387 return( true );
388 }
389
390 return( false );
391}
392
393//---------------------------------------------------------
395{
396 return( pTable && Assign_Values(*pTable) );
397}
398
399//---------------------------------------------------------
401{
402 CSG_Table Table; return( Table.Create(FileName) && Assign_Values(&Table) );
403}
404
405
407// //
408// Checks //
409// //
411
412//---------------------------------------------------------
413bool CSG_Table::is_Compatible(const CSG_Table &Table, bool bExactMatch) const
414{
415 if( Get_Field_Count() == Table.Get_Field_Count() )
416 {
417 if( bExactMatch )
418 {
419 for(int i=0; i<Get_Field_Count(); i++)
420 {
421 if( Get_Field_Type(i) != Table.Get_Field_Type(i) )
422 {
423 return( false );
424 }
425 }
426 }
427
428 return( true );
429 }
430
431 return( false );
432}
433
434//---------------------------------------------------------
435bool CSG_Table::is_Compatible(CSG_Table *pTable, bool bExactMatch) const
436{
437 return( pTable && is_Compatible(*pTable, bExactMatch) );
438}
439
440
442// //
443// Fields //
444// //
446
447//---------------------------------------------------------
452
453//---------------------------------------------------------
455{
456 m_Name = Name; m_Type = Type;
457}
458
459//---------------------------------------------------------
464
465//---------------------------------------------------------
467{
468 m_Statistics.Invalidate(); m_Histogram.Destroy();
469
470 return( true );
471}
472
473
475// //
477
478//---------------------------------------------------------
479bool CSG_Table::Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position)
480{
481 if( Position < 0 || Position > m_nFields )
482 {
483 Position = m_nFields;
484 }
485
486 //-----------------------------------------------------
487 m_nFields++;
488
490
491 for(int i=m_nFields-1; i>Position; i--)
492 {
493 m_Field_Info[i] = m_Field_Info[i - 1];
494 }
495
496 m_Field_Info[Position] = new CSG_Field_Info(Name, Type);
497
498 //-----------------------------------------------------
499 for(sLong i=0; i<m_nRecords; i++)
500 {
501 m_Records[i]->_Add_Field(Position);
502 }
503
504 Set_Modified();
505
506 return( true );
507}
508
509//---------------------------------------------------------
510bool CSG_Table::Del_Field(int Field)
511{
512 if( Field < 0 || Field >= m_nFields )
513 {
514 return( false );
515 }
516
517 //-----------------------------------------------------
518 delete(m_Field_Info[Field]);
519
520 m_nFields--;
521
522 for(int i=Field; i<m_nFields; i++)
523 {
524 m_Field_Info[i] = m_Field_Info[i + 1];
525 }
526
527 //-----------------------------------------------------
529
530 //-----------------------------------------------------
531 for(sLong i=0; i<m_nRecords; i++)
532 {
533 m_Records[i]->_Del_Field(Field);
534 }
535
536 Set_Modified();
537
538 return( true );
539}
540
541//---------------------------------------------------------
542bool CSG_Table::Mov_Field(int Field, int Position)
543{
544 if( Position < 0 )
545 {
546 Position = 0;
547 }
548 else if( Position >= m_nFields - 1 )
549 {
550 Position = m_nFields - 1;
551 }
552
553 if( Field < 0 || Field >= m_nFields || Field == Position )
554 {
555 return( false );
556 }
557
558 //-----------------------------------------------------
559 if( Position > Field )
560 {
561 Position++;
562 }
563
564 if( !Add_Field(m_Field_Info[Field]->m_Name, m_Field_Info[Field]->m_Type, Position) )
565 {
566 return( false );
567 }
568
569 if( Position < Field )
570 {
571 Field++;
572 }
573
574 #pragma omp parallel for
575 for(sLong i=0; i<m_nRecords; i++)
576 {
577 *m_Records[i]->Get_Value(Position) = *m_Records[i]->Get_Value(Field);
578 }
579
580 if( !Del_Field(Field) )
581 {
582 return( false );
583 }
584
585 //-----------------------------------------------------
586 return( true );
587}
588
589
591// //
593
594//---------------------------------------------------------
595bool CSG_Table::Set_Field_Name(int Field, const SG_Char *Name)
596{
597 if( Field >= 0 && Field < m_nFields && Name && *Name )
598 {
599 m_Field_Info[Field]->m_Name = Name;
600
601 Set_Modified();
602
603 return( true );
604 }
605
606 return( false );
607}
608
609//---------------------------------------------------------
611{
612 if( Field < 0 || Field >= m_nFields )
613 {
614 return( false );
615 }
616
617 if( m_Field_Info[Field]->m_Type == Type )
618 {
619 return( true );
620 }
621
622 #pragma omp parallel for
623 for(sLong i=0; i<m_nRecords; i++)
624 {
625 CSG_Table_Record *pRecord = m_Records[i];
626
627 bool bNoData = pRecord->is_NoData(Field);
628
629 CSG_Table_Value *pValue = pRecord->m_Values[Field];
630
631 pRecord->m_Values[Field] = CSG_Table_Record::_Create_Value(Type);
632
633 if( bNoData )
634 {
635 if( Type != SG_DATATYPE_String && Type != SG_DATATYPE_Binary )
636 {
637 pRecord->m_Values[Field]->Set_Value(Get_NoData_Value());
638 }
639 }
640 else if( pValue->Get_Type() == SG_TABLE_VALUE_TYPE_String && SG_Data_Type_is_Numeric(Type) )
641 {
642 CSG_String String(pValue->asString()); double Value;
643
644 if( !String.asDouble(Value) )
645 {
646 Value = Get_NoData_Value();
647 }
648
649 pRecord->m_Values[Field]->Set_Value(Value);
650 }
651 else
652 {
653 *(pRecord->m_Values[Field]) = *pValue;
654 }
655
656 delete(pValue);
657
659 }
660
661 m_Field_Info[Field]->m_Type = Type;
662
664
665 return( true );
666}
667
668//---------------------------------------------------------
673//---------------------------------------------------------
674int CSG_Table::Get_Field_Length(int Field, int Encoding) const
675{
676 size_t Length = 0;
677
678 if( Field >= 0 && Field < m_nFields )
679 {
680 switch( m_Field_Info[Field]->m_Type )
681 {
682 default:
683 Length = SG_Data_Type_Get_Size(m_Field_Info[Field]->m_Type);
684 break;
685
686 case SG_DATATYPE_Date:
687 Length = 10; // => YYYY-MM-DD
688 break;
689
691 for(sLong i=0; i<m_nRecords; i++)
692 {
693 CSG_String s(m_Records[i]->asString(Field));
694
695 size_t nBytes;
696
697 switch( Encoding )
698 {
699 default :
700 case SG_FILE_ENCODING_UTF7 : nBytes = s.Length() ; break;
701 case SG_FILE_ENCODING_UTF8 : nBytes = s.to_UTF8().Get_Size(); break;
703 case SG_FILE_ENCODING_UTF16BE: nBytes = s.Length() * 2 ; break;
705 case SG_FILE_ENCODING_UTF32BE: nBytes = s.Length() * 4 ; break;
706 }
707
708 if( Length < nBytes )
709 {
710 Length = nBytes;
711 }
712 }
713 break;
714 }
715 }
716
717 return( (int)Length );
718}
719
720//---------------------------------------------------------
721int CSG_Table::Get_Field(const char *Name) const { return( Get_Field(CSG_String(Name))); }
722int CSG_Table::Get_Field(const wchar_t *Name) const { return( Get_Field(CSG_String(Name))); }
723int CSG_Table::Get_Field(const CSG_String &Name) const
724{
725 for(int Field=0; Field<Get_Field_Count(); Field++)
726 {
727 if( !Name.Cmp(Get_Field_Name(Field)) )
728 {
729 return( Field );
730 }
731 }
732
733 return( -1 );
734}
735
736//---------------------------------------------------------
741int CSG_Table::Find_Field(const CSG_String &Name) const
742{
743 for(int i=0; i<Get_Field_Count(); i++)
744 {
745 if( !Name.Cmp(Get_Field_Name(i)) )
746 {
747 return( i );
748 }
749 }
750
751 return( -1 );
752}
753
754//---------------------------------------------------------
759bool CSG_Table::Find_Field(const CSG_String &Name, int &Index) const
760{
761 return( (Index = Find_Field(Name)) >= 0 );
762}
763
764
766// //
767// Records //
768// //
770
771//---------------------------------------------------------
772#define GET_GROW_SIZE(n) (n < 256 ? 1 : (n < 8192 ? 128 : 1024))
773
774//---------------------------------------------------------
775bool CSG_Table::_Inc_Array(void)
776{
777 if( m_nRecords < m_nBuffer )
778 {
779 return( true );
780 }
781
783
784 if( pRecords == NULL )
785 {
786 return( false );
787 }
788
789 m_Records = pRecords;
791
792 return( true );
793}
794
795//---------------------------------------------------------
796bool CSG_Table::_Dec_Array(void)
797{
799 {
800 return( true );
801 }
802
804
805 if( pRecords == NULL )
806 {
807 return( false );
808 }
809
810 m_Records = pRecords;
812
813 return( true );
814}
815
816//---------------------------------------------------------
818{
819 return( new CSG_Table_Record(this, Index) );
820}
821
822//---------------------------------------------------------
827
828//---------------------------------------------------------
830{
831 if( iRecord < 0 ) { iRecord = 0; } else if( iRecord > m_nRecords ) { iRecord = m_nRecords; }
832
833 CSG_Table_Record *pRecord = _Inc_Array() ? _Get_New_Record(m_nRecords) : NULL;
834
835 if( pRecord )
836 {
837 if( pCopy )
838 {
839 pRecord->Assign(pCopy);
840 }
841
842 //-------------------------------------------------
843 if( iRecord < m_nRecords )
844 {
845 if( Get_Selection_Count() > 0 ) // update selection index
846 {
847 sLong *Selection = (sLong *)m_Selection.Get_Array();
848
849 for(sLong i=0; i<m_Selection.Get_Size(); i++)
850 {
851 if( Selection[i] > iRecord )
852 {
853 Selection[i]++;
854 }
855 }
856 }
857
858 for(sLong i=m_nRecords; i>iRecord; i--)
859 {
860 m_Records[i] = m_Records[i - 1]; m_Records[i]->m_Index = i;
861 }
862
863 pRecord->m_Index = iRecord;
864 }
865
866 m_Records[iRecord] = pRecord;
867 m_nRecords++;
868
869 //-------------------------------------------------
870 if( m_Index.is_Okay() )
871 {
872 m_Index.Add_Entry(iRecord);
873 }
874
875 Set_Modified();
876
878
880 }
881
882 return( pRecord );
883}
884
885//---------------------------------------------------------
887{
888 if( iRecord >= 0 && iRecord < m_nRecords && pCopy )
889 {
890 return( m_Records[iRecord]->Assign(pCopy) );
891 }
892
893 return( false );
894}
895
896//---------------------------------------------------------
898{
899 if( iRecord >= 0 && iRecord < m_nRecords )
900 {
901 if( m_Records[iRecord]->is_Selected() )
902 {
903 _Del_Selection(iRecord);
904 }
905
906 delete(m_Records[iRecord]);
907
908 m_nRecords--;
909
910 for(sLong i=iRecord; i<m_nRecords; i++)
911 {
912 m_Records[i] = m_Records[i + 1]; m_Records[i]->m_Index = i;
913 }
914
915 _Dec_Array();
916
917 //-------------------------------------------------
918 if( m_Index.is_Okay() )
919 {
920 m_Index.Del_Entry(iRecord);
921 }
922
923 Set_Modified();
924
926
928
929 return( true );
930 }
931
932 return( false );
933}
934
935//---------------------------------------------------------
937{
938 Del_Index();
939
940 for(sLong iRecord=0; iRecord<m_nRecords; iRecord++)
941 {
942 delete(m_Records[iRecord]);
943 }
944
945 SG_FREE_SAFE(m_Records);
946
947 m_nRecords = 0;
948 m_nBuffer = 0;
949
950 return( true );
951}
952
953//---------------------------------------------------------
955{
956 if( m_nRecords < nRecords )
957 {
958 while( m_nRecords < nRecords && Add_Record() != NULL ) {}
959 }
960 else if( nRecords >= 0 && m_nRecords > nRecords )
961 {
962 while( m_nRecords > nRecords && Del_Record(m_nRecords - 1) ) {}
963 }
964
965 return( m_nRecords == nRecords );
966}
967
968
970// //
972
973//---------------------------------------------------------
974bool CSG_Table::Find_Record(sLong &iRecord, int Field, const CSG_String &Value, bool bCreateIndex)
975{
976 if( Field < 0 || Field >= m_nFields || m_nRecords < 1 )
977 {
978 return( false );
979 }
980
981 if( m_nRecords == 1 )
982 {
983 return( Value.Cmp(m_Records[iRecord = 0]->asString(Field)) == 0 );
984 }
985
986 if( bCreateIndex && Field != Get_Index_Field(0) )
987 {
989 }
990
991 //-----------------------------------------------------
992 if( Field != Get_Index_Field(0) )
993 {
994 for(iRecord=0; iRecord<m_nRecords; iRecord++)
995 {
996 if( Value.Cmp(m_Records[iRecord]->asString(Field)) == 0 )
997 {
998 return( true );
999 }
1000 }
1001 }
1002
1003 //-----------------------------------------------------
1004 else // indexed search
1005 {
1006 #define GET_RECORD(i) Get_Record_byIndex(bAscending ? (i) : m_nRecords - 1 - (i))
1007
1008 double d; bool bAscending = Get_Index_Order(0) == TABLE_INDEX_Ascending;
1009
1010 if( (d = Value.Cmp(GET_RECORD(0 )->asString(Field))) < 0 ) { return( false ); } else if( d == 0 ) { iRecord = GET_RECORD(0 )->Get_Index(); return( true ); }
1011 if( (d = Value.Cmp(GET_RECORD(m_nRecords - 1)->asString(Field))) > 0 ) { return( false ); } else if( d == 0 ) { iRecord = GET_RECORD(m_nRecords - 1)->Get_Index(); return( true ); }
1012
1013 for(sLong a=0, b=m_nRecords-1; b-a>1; )
1014 {
1015 d = Value.Cmp(GET_RECORD(iRecord = a + (b - a) / 2)->asString(Field));
1016
1017 if( d > 0. )
1018 {
1019 a = iRecord;
1020 }
1021 else if( d < 0. )
1022 {
1023 b = iRecord;
1024 }
1025 else
1026 {
1027 iRecord = GET_RECORD(iRecord)->Get_Index();
1028
1029 return( true );
1030 }
1031 }
1032
1033 #undef GET_RECORD
1034 }
1035
1036 //-----------------------------------------------------
1037 return( false );
1038}
1039
1040//---------------------------------------------------------
1041CSG_Table_Record * CSG_Table::Find_Record(int Field, const CSG_String &Value, bool bCreateIndex)
1042{
1043 sLong iRecord;
1044
1045 if( Find_Record(iRecord, Field, Value, bCreateIndex) )
1046 {
1047 return( Get_Record(iRecord) );
1048 }
1049
1050 return( NULL );
1051}
1052
1053//---------------------------------------------------------
1054bool CSG_Table::Find_Record(sLong &iRecord, int Field, double Value, bool bCreateIndex)
1055{
1056 if( Field < 0 || Field >= m_nFields || m_nRecords < 1 )
1057 {
1058 return( false );
1059 }
1060
1061 if( m_nRecords == 1 )
1062 {
1063 return( Value == m_Records[iRecord = 0]->asDouble(Field) );
1064 }
1065
1066 if( bCreateIndex && Field != Get_Index_Field(0) )
1067 {
1069 }
1070
1071 //-----------------------------------------------------
1072 if( Field != Get_Index_Field(0) )
1073 {
1074 for(iRecord=0; iRecord<m_nRecords; iRecord++)
1075 {
1076 if( Value == m_Records[iRecord]->asDouble(Field) )
1077 {
1078 return( true );
1079 }
1080 }
1081 }
1082
1083 //-----------------------------------------------------
1084 else // indexed search
1085 {
1086 #define GET_RECORD(i) Get_Record_byIndex(bAscending ? (i) : m_nRecords - 1 - (i))
1087
1088 double d; bool bAscending = Get_Index_Order(0) == TABLE_INDEX_Ascending;
1089
1090 if( (d = Value - GET_RECORD(0 )->asDouble(Field)) < 0. ) { return( false ); } else if( d == 0. ) { iRecord = GET_RECORD(0 )->Get_Index(); return( true ); }
1091 if( (d = Value - GET_RECORD(m_nRecords - 1)->asDouble(Field)) > 0. ) { return( false ); } else if( d == 0. ) { iRecord = GET_RECORD(m_nRecords - 1)->Get_Index(); return( true ); }
1092
1093 for(sLong a=0, b=m_nRecords-1; b-a > 1; )
1094 {
1095 d = Value - GET_RECORD(iRecord = a + (b - a) / 2)->asDouble(Field);
1096
1097 if( d > 0. )
1098 {
1099 a = iRecord;
1100 }
1101 else if( d < 0. )
1102 {
1103 b = iRecord;
1104 }
1105 else
1106 {
1107 iRecord = GET_RECORD(iRecord)->Get_Index();
1108
1109 return( true );
1110 }
1111 }
1112
1113 #undef GET_RECORD
1114 }
1115
1116 //-----------------------------------------------------
1117 return( false );
1118}
1119
1120//---------------------------------------------------------
1121CSG_Table_Record * CSG_Table::Find_Record(int Field, double Value, bool bCreateIndex)
1122{
1123 sLong iRecord;
1124
1125 if( Find_Record(iRecord, Field, Value, bCreateIndex) )
1126 {
1127 return( Get_Record(iRecord) );
1128 }
1129
1130 return( NULL );
1131}
1132
1133
1135// //
1136// Value Access //
1137// //
1139
1140//---------------------------------------------------------
1141void CSG_Table::Set_Modified(bool bModified)
1142{
1143 if( bModified != is_Modified() )
1144 {
1146
1147 if( bModified == false )
1148 {
1149 #pragma omp parallel for
1150 for(sLong i=0; i<m_nRecords; i++)
1151 {
1152 m_Records[i]->Set_Modified(false);
1153 }
1154 }
1155 }
1156}
1157
1158//---------------------------------------------------------
1159bool CSG_Table::Get_Value(sLong Index, int Field, CSG_String &Value) const
1160{
1161 if( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields )
1162 {
1163 Value = m_Records[Index]->asString(Field);
1164
1165 return( true );
1166 }
1167
1168 return( false );
1169}
1170
1171//---------------------------------------------------------
1172bool CSG_Table::Get_Value(sLong Index, int Field, sLong &Value) const
1173{
1174 if( Index >= 0 && Index < m_nRecords && Field >= 0 && Field < m_nFields )
1175 {
1176 Value = m_Records[Index]->asLong(Field);
1177
1178 return( m_Records[Index]->is_NoData(Field) == false );
1179 }
1180
1181 return( false );
1182}
1183
1184//---------------------------------------------------------
1185bool CSG_Table::Get_Value(sLong Index, int Field, double &Value) const
1186{
1187 if( Field >= 0 && Field < m_nFields )
1188 {
1189 Value = m_Records[Index]->asDouble(Field);
1190
1191 return( m_Records[Index]->is_NoData(Field) == false );
1192 }
1193
1194 return( false );
1195}
1196
1197
1199// //
1200// Statistics //
1201// //
1203
1204//---------------------------------------------------------
1206{
1207 for(int Field=0; Field<m_nFields; Field++)
1208 {
1209 _Stats_Invalidate(Field);
1210 }
1211
1212 return( true );
1213}
1214
1215//---------------------------------------------------------
1216bool CSG_Table::_Stats_Invalidate(int Field) const
1217{
1218 if( Field >= 0 && Field < m_nFields )
1219 {
1220 m_Field_Info[Field]->Reset_Statistics();
1221
1222 return( true );
1223 }
1224
1225 return( false );
1226}
1227
1228//---------------------------------------------------------
1229bool CSG_Table::_Stats_Update(int Field) const
1230{
1231 if( Field < 0 || Field >= m_nFields || Get_Count() < 1 )
1232 {
1233 return( false );
1234 }
1235
1236 CSG_Simple_Statistics &Statistics = m_Field_Info[Field]->m_Statistics;
1237
1238 if( Statistics.is_Evaluated() )
1239 {
1240 return( true );
1241 }
1242
1243 if( Get_Max_Samples() > 0 && Get_Max_Samples() < Get_Count() )
1244 {
1245 double Value, d = (double)Get_Count() / (double)Get_Max_Samples();
1246
1247 for(double i=0; i<(double)Get_Count(); i+=d)
1248 {
1249 if( Get_Value((sLong)i, Field, Value) )
1250 {
1251 Statistics += Value;
1252 }
1253 }
1254
1255 Statistics.Set_Count(Statistics.Get_Count() >= Get_Max_Samples() ? Get_Count() // any no-data cells ?
1256 : (sLong)(Get_Count() * (double)Statistics.Get_Count() / (double)Get_Max_Samples())
1257 );
1258 }
1259 else
1260 {
1261 double Value;
1262
1263 for(sLong i=0; i<Get_Count(); i++)
1264 {
1265 if( Get_Value(i, Field, Value) )
1266 {
1267 Statistics += Value;
1268 }
1269 }
1270 }
1271
1272 return( Statistics.Evaluate() ); // evaluate! prevent values to be added more than once!
1273}
1274
1275//---------------------------------------------------------
1276bool CSG_Table::_Histogram_Update(int Field, size_t nClasses) const
1277{
1278 if( Field < 0 || Field >= m_nFields || Get_Count() < 1 )
1279 {
1280 return( false );
1281 }
1282
1283 CSG_Histogram &Histogram = m_Field_Info[Field]->m_Histogram;
1284
1285 if( Histogram.is_Okay() && (!nClasses || nClasses == Histogram.Get_Class_Count()) )
1286 {
1287 return( true );
1288 }
1289
1290 return( Histogram.Create(nClasses ? nClasses : 256, (CSG_Table *)this, Field, 0., 0., Get_Max_Samples()) );
1291}
1292
1293
1295// //
1296// //
1297// //
1299
1300//---------------------------------------------------------
1302{
1304
1306}
1307
1308//---------------------------------------------------------
1310{
1312
1313 if( m_Index.is_Okay() )
1314 {
1315 _Index_Update();
1316 }
1317
1318 return( CSG_Data_Object::On_Update() );
1319}
1320
1321
1323// //
1324// Sort //
1325// //
1327
1328//---------------------------------------------------------
1329bool CSG_Table::Sort(const char *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1330bool CSG_Table::Sort(const wchar_t *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1331bool CSG_Table::Sort(const CSG_String &Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1332bool CSG_Table::Sort(int Field, bool bAscending)
1333{
1334 CSG_Index Index; return( Set_Index(Index, Field, bAscending) && Sort(Index) );
1335}
1336
1337//---------------------------------------------------------
1338bool CSG_Table::Sort(const CSG_Index &Index)
1339{
1340 if( Get_Count() > 0 && Get_Count() == Index.Get_Count() )
1341 {
1342 CSG_Table_Record **Records = m_Records; m_Records = (CSG_Table_Record **)SG_Malloc(m_nBuffer * sizeof(CSG_Table_Record *));
1343
1344 for(sLong i=0; i<Get_Count(); i++)
1345 {
1346 m_Records[i] = Records[Index[i]];
1347 }
1348
1349 SG_Free(Records);
1350
1351 Del_Index();
1352
1353 return( true );
1354 }
1355
1356 return( false );
1357}
1358
1359
1361// //
1362// Index //
1363// //
1365
1366//---------------------------------------------------------
1367bool CSG_Table::Set_Index(int Field_1, TSG_Table_Index_Order Order_1, int Field_2, TSG_Table_Index_Order Order_2, int Field_3, TSG_Table_Index_Order Order_3)
1368{
1369 m_Index_Fields.Destroy();
1370
1371 if( Field_1 >= 0 && Field_1 < m_nFields && Order_1 != TABLE_INDEX_None )
1372 {
1373 Field_1++; m_Index_Fields += Order_1 == TABLE_INDEX_Ascending ? Field_1 : -Field_1;
1374
1375 if( Field_2 >= 0 && Field_2 < m_nFields && Order_2 != TABLE_INDEX_None )
1376 {
1377 Field_2++; m_Index_Fields += Order_2 == TABLE_INDEX_Ascending ? Field_2 : -Field_2;
1378
1379 if( Field_3 >= 0 && Field_3 < m_nFields && Order_3 != TABLE_INDEX_None )
1380 {
1381 Field_3++; m_Index_Fields += Order_3 == TABLE_INDEX_Ascending ? Field_3 : -Field_3;
1382 }
1383 }
1384
1385 _Index_Update();
1386 }
1387 else
1388 {
1389 Del_Index();
1390 }
1391
1392 return( is_Indexed() );
1393}
1394
1395//---------------------------------------------------------
1397{
1398 m_Index.Destroy();
1399
1400 m_Index_Fields.Destroy();
1401
1402 return( true );
1403}
1404
1405//---------------------------------------------------------
1407{
1408 if( Field < 0 || Field >= m_nFields )
1409 {
1410 return( false );
1411 }
1412
1413 if( Field != Get_Index_Field(0) )
1414 {
1415 Del_Index();
1416
1417 return( Set_Index(Field, TABLE_INDEX_Ascending) );
1418 }
1419
1421 {
1422 m_Index_Fields[0] = -m_Index_Fields[0]; m_Index.Invert();
1423
1424 return( true );
1425 }
1426
1427 return( Del_Index() );
1428}
1429
1430
1432// //
1434
1435//---------------------------------------------------------
1436class CSG_Table_Record_Compare_Field : public CSG_Index::CSG_Index_Compare
1437{
1438public:
1439 CSG_Table_Record_Compare_Field(const CSG_Table *pTable, int Field, bool Ascending)
1440 {
1441 m_pTable = pTable;
1442 m_Field = Field;
1443 m_Ascending = Ascending;
1444
1445 if( !m_pTable || m_Field < 0 || m_Field >= m_pTable->Get_Field_Count() )
1446 {
1447 m_pTable = NULL;
1448 }
1449 }
1450
1451 bool is_Okay (void) const { return( m_pTable != NULL ); }
1452
1453 virtual int Compare (const sLong _a, const sLong _b)
1454 {
1455 sLong a = m_Ascending ? _a : _b;
1456 sLong b = m_Ascending ? _b : _a;
1457
1458 switch( m_pTable->Get_Field_Type(m_Field) )
1459 {
1460 default: { double Value[2] = { 0., 0. };
1461 m_pTable->Get_Value(a, m_Field, Value[0]);
1462 m_pTable->Get_Value(b, m_Field, Value[1]);
1463 return( Value[0] < Value[1] ? -1 : Value[0] > Value[1] ? 1 : 0 ); }
1464
1465 case SG_DATATYPE_String:
1466 case SG_DATATYPE_Date : { CSG_String Value[2];
1467 m_pTable->Get_Value(a, m_Field, Value[0]);
1468 m_pTable->Get_Value(b, m_Field, Value[1]);
1469 return( Value[0].Cmp(Value[1]) ); }
1470 }
1471 }
1472
1473
1474private:
1475
1476 bool m_Ascending;
1477
1478 int m_Field;
1479
1480 const CSG_Table *m_pTable;
1481
1482};
1483
1484//---------------------------------------------------------
1485bool CSG_Table::Set_Index(CSG_Index &Index, int Field, bool bAscending) const
1486{
1487 CSG_Table_Record_Compare_Field Compare(this, Field, bAscending);
1488
1489 return( Compare.is_Okay() && Index.Create(Get_Count(), &Compare) );
1490}
1491
1492
1494// //
1496
1497//---------------------------------------------------------
1498class CSG_Table_Record_Compare_Fields : public CSG_Index::CSG_Index_Compare
1499{
1500public:
1501 CSG_Table_Record_Compare_Fields(const CSG_Table *pTable, int Fields[], int nFields, bool Ascending)
1502 : m_Fields(Fields), m_nFields(nFields), m_pTable(pTable)
1503 {
1504 m_Ascending.Create(nFields);
1505
1506 for(int i=0; m_pTable && i<m_nFields; i++)
1507 {
1508 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1509 {
1510 m_pTable = NULL;
1511 }
1512
1513 m_Ascending[i] = Ascending ? 1 : 0;
1514 }
1515 }
1516
1517 CSG_Table_Record_Compare_Fields(const CSG_Table *pTable, int Fields[], int nFields, int Ascending[])
1518 : m_Fields(Fields), m_nFields(nFields), m_pTable(pTable)
1519 {
1520 m_Ascending.Create(nFields);
1521
1522 for(int i=0; m_pTable && i<m_nFields; i++)
1523 {
1524 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1525 {
1526 m_pTable = NULL;
1527 }
1528
1529 m_Ascending[i] = Ascending[i] > 0 ? 1 : 0;
1530 }
1531 }
1532
1533 bool is_Okay (void) const { return( m_pTable != NULL ); }
1534
1535 virtual int Compare (const sLong _a, const sLong _b)
1536 {
1537 int Difference = 0;
1538
1539 for(int i=0; !Difference && i<m_nFields; i++)
1540 {
1541 int Field = m_Fields[i];
1542
1543 sLong a = m_Ascending[i] ? _a : _b;
1544 sLong b = m_Ascending[i] ? _b : _a;
1545
1546 switch( m_pTable->Get_Field_Type(Field) )
1547 {
1548 default: { double Value[2] = { 0., 0. };
1549 m_pTable->Get_Value(a, Field, Value[0]);
1550 m_pTable->Get_Value(b, Field, Value[1]);
1551 Difference = Value[0] < Value[1] ? -1 : Value[0] > Value[1] ? 1 : 0;
1552 break; }
1553
1554 case SG_DATATYPE_String:
1555 case SG_DATATYPE_Date : { CSG_String Value[2];
1556 m_pTable->Get_Value(a, Field, Value[0]);
1557 m_pTable->Get_Value(b, Field, Value[1]);
1558 Difference = Value[0].Cmp(Value[1]);
1559 break; }
1560 }
1561 }
1562
1563 return( Difference );
1564 }
1565
1566
1567private:
1568
1569 int *m_Fields, m_nFields;
1570
1571 CSG_Array_Int m_Ascending;
1572
1573 const CSG_Table *m_pTable;
1574
1575};
1576
1577//---------------------------------------------------------
1578bool CSG_Table::Set_Index(CSG_Index &Index, int Fields[], int nFields, bool bAscending) const
1579{
1580 CSG_Table_Record_Compare_Fields Compare(this, Fields, nFields, bAscending);
1581
1582 return( Compare.is_Okay() && Index.Create(Get_Count(), &Compare) );
1583}
1584
1585//---------------------------------------------------------
1586bool CSG_Table::Set_Index(CSG_Index &Index, const CSG_Array_Int &Fields, bool bAscending) const
1587{
1588 return( Set_Index(Index, Fields.Get_Array(), (int)Fields.Get_Size(), bAscending) );
1589}
1590
1591//---------------------------------------------------------
1592void CSG_Table::_Index_Update(void)
1593{
1594 if( m_Index_Fields.Get_Size() < 1 )
1595 {
1596 Del_Index();
1597 }
1598
1599 CSG_Array_Int Fields, Ascending;
1600
1601 for(sLong i=0; i<m_Index_Fields.Get_Size(); i++)
1602 {
1603 Fields += abs(m_Index_Fields[i]) - 1;
1604 Ascending += m_Index_Fields[i] > 0 ? 1 : 0;
1605 }
1606
1607 CSG_Table_Record_Compare_Fields Compare(this, Fields.Get_Array(), (int)Fields.Get_Size(), Ascending.Get_Array());
1608
1609 if( !Compare.is_Okay() || !m_Index.Create(Get_Count(), &Compare) )
1610 {
1611 Del_Index();
1612 }
1613}
1614
1615
1617// //
1618// //
1619// //
1621
1622//---------------------------------------------------------
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
bool SG_UI_Process_Set_Progress(int Position, int Range)
void SG_UI_ProgressAndMsg_Lock(bool bOn)
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
Definition api_core.cpp:198
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
@ SG_UI_MSG_STYLE_FAILURE
Definition api_core.h:1635
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1634
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
signed long long sLong
Definition api_core.h:158
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
#define SG_FREE_SAFE(PTR)
Definition api_core.h:205
TSG_Data_Type
Definition api_core.h:1043
@ SG_DATATYPE_Binary
Definition api_core.h:1058
@ SG_DATATYPE_String
Definition api_core.h:1055
@ SG_DATATYPE_Date
Definition api_core.h:1056
#define SG_Char
Definition api_core.h:536
#define _TL(s)
Definition api_core.h:1618
@ SG_FILE_ENCODING_UTF16LE
Definition api_core.h:553
@ SG_FILE_ENCODING_UTF16BE
Definition api_core.h:554
@ SG_FILE_ENCODING_UTF8
Definition api_core.h:552
@ SG_FILE_ENCODING_UTF7
Definition api_core.h:551
@ SG_FILE_ENCODING_UTF32BE
Definition api_core.h:556
@ SG_FILE_ENCODING_UTF32LE
Definition api_core.h:555
size_t SG_Data_Type_Get_Size(TSG_Data_Type Type)
Definition api_core.h:1110
sLong Get_Size(void) const
Definition api_core.h:436
int * Get_Array(void) const
Definition api_core.h:439
const SG_Char * Get_Name(void) const
virtual bool is_Modified(void) const
Definition dataobject.h:231
virtual bool On_NoData_Changed(void)
void Set_Name(const CSG_String &Name)
void Set_Update_Flag(bool bOn=true)
Definition dataobject.h:288
double Get_NoData_Value(bool bUpper=false) const
Definition dataobject.h:256
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
virtual bool Destroy(void)
void Set_Description(const CSG_String &Description)
virtual void Set_Modified(bool bOn=true)
Definition dataobject.h:230
virtual bool Assign(CSG_Data_Object *pObject, bool bProgress=false)
const SG_Char * Get_Description(void) const
sLong Get_Max_Samples(void) const
Definition dataobject.h:266
virtual bool On_Update(void)
Definition dataobject.h:290
void Set_File_Name(const CSG_String &FileName)
class CSG_Table * asTable(bool bPolymorph=false) const
size_t Get_Class_Count(void) const
Definition mat_tools.h:1049
bool is_Okay(void) const
Definition mat_tools.h:1047
bool Create(const CSG_Histogram &Histogram)
bool Destroy(void)
sLong Get_Count(void) const
Definition mat_tools.h:241
bool Create(sLong nValues, CSG_Index_Compare &Compare)
int is_Evaluated(void) const
Definition mat_tools.h:741
bool Set_Count(sLong Count)
sLong Get_Count(void) const
Definition mat_tools.h:745
size_t Length(void) const
CSG_String AfterFirst(char Character) const
int Cmp(const CSG_String &String) const
size_t to_UTF8(char **pString) const
CSG_String BeforeFirst(char Character) const
static CSG_String Format(const char *Format,...)
bool asDouble(double &Value) const
const SG_Char * c_str(void) const
bool Reset_Statistics(void)
Definition table.cpp:466
virtual ~CSG_Field_Info(void)
Definition table.cpp:460
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
sLong m_Index
Definition table.h:266
class CSG_Table_Value ** m_Values
Definition table.h:268
bool is_NoData(int Field) const
virtual bool Assign(CSG_Table_Record *pRecord)
static CSG_Table_Value * _Create_Value(TSG_Data_Type Type)
virtual const SG_Char * asString(int Decimals=-99) const =0
virtual const TSG_Table_Value_Type Get_Type(void) const =0
virtual bool Set_Value(const sLong &Value)=0
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:372
bool Create(void)
Definition table.cpp:153
virtual CSG_Table_Record * Ins_Record(sLong Index, CSG_Table_Record *pCopy=NULL)
Definition table.cpp:829
bool Toggle_Index(int Field)
Definition table.cpp:1406
int Find_Field(const CSG_String &Name) const
Definition table.cpp:741
virtual bool Find_Record(sLong &Index, int Field, const CSG_String &Value, bool bCreateIndex=false)
Definition table.cpp:974
virtual bool _Stats_Update(int Field) const
Definition table.cpp:1229
sLong Get_Count(void) const
Definition table.h:410
bool Set_Field_Name(int Field, const SG_Char *Name)
Definition table.cpp:595
virtual bool Destroy(void)
Definition table.cpp:314
virtual bool Assign(CSG_Data_Object *pTable, bool bProgress=false)
Definition table.cpp:353
sLong m_nRecords
Definition table.h:505
virtual bool On_NoData_Changed(void)
Definition table.cpp:1301
virtual bool Set_Record(sLong Index, CSG_Table_Record *pCopy)
Definition table.cpp:886
bool is_Compatible(const CSG_Table &Table, bool bExactMatch=false) const
Definition table.cpp:413
virtual bool _Histogram_Update(int Field, size_t nClasses) const
Definition table.cpp:1276
bool _Stats_Invalidate(void) const
Definition table.cpp:1205
bool Load(const CSG_String &File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED)
Definition table_io.cpp:99
virtual bool Set_Count(sLong nRecords)
Definition table.cpp:954
CSG_Field_Info ** m_Field_Info
Definition table.h:501
virtual bool Del_Records(void)
Definition table.cpp:936
CSG_Table(void)
Definition table.cpp:147
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 Get_Value(sLong Index, int Field, CSG_String &Value) const
Definition table.cpp:1159
virtual bool On_Update(void)
Definition table.cpp:1309
friend class CSG_Table_Record
Definition table.h:296
int Get_Field(const CSG_String &Name) const
Definition table.cpp:723
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition table.cpp:823
CSG_Array m_Selection
Definition table.h:507
virtual ~CSG_Table(void)
Definition table.cpp:308
int Get_Index_Field(int i) const
Definition table.h:471
bool Set_Index(CSG_Index &Index, int Field, bool bAscending=true) const
Definition table.cpp:1485
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
bool Assign_Values(const CSG_Table &Table)
Definition table.cpp:378
virtual bool Mov_Field(int Field, int Position)
Definition table.cpp:542
int m_Encoding
Definition table.h:503
virtual CSG_Table_Record * _Get_New_Record(sLong Index)
Definition table.cpp:817
CSG_Table & operator=(const CSG_Table &Table)
Definition table.cpp:345
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition table.h:412
virtual bool Del_Record(sLong Index)
Definition table.cpp:897
virtual int Get_Field_Length(int Field, int Encoding=SG_FILE_ENCODING_UNDEFINED) const
Definition table.cpp:674
bool Sort(const char *Field, bool bAscending=true)
Definition table.cpp:1329
int Get_Field_Count(void) const
Definition table.h:371
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 Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition table.cpp:479
sLong Get_Selection_Count(void) const
Definition table.h:444
bool Del_Index(void)
Definition table.cpp:1396
bool _Del_Selection(sLong Index)
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:373
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
Definition table.cpp:610
virtual void Set_Modified(bool bModified=true)
Definition table.cpp:1141
virtual bool Del_Field(int Field)
Definition table.cpp:510
virtual void _On_Construction(void)
Definition table.cpp:295
bool Delete_Tool(CSG_Tool *pTool) const
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false, bool bWithCMD=true) const
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition tool.cpp:874
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition tool.cpp:1584
virtual bool On_Before_Execution(void)
Definition tool.h:239
bool Execute(bool bAddHistory=false)
Definition tool.cpp:560
@ SG_DATAOBJECT_TYPE_PointCloud
Definition dataobject.h:123
@ SG_DATAOBJECT_TYPE_Shapes
Definition dataobject.h:121
@ SG_DATAOBJECT_TYPE_Table
Definition dataobject.h:120
#define GET_GROW_SIZE(n)
CSG_Shapes * SG_Create_Shapes(void)
Definition shapes.cpp:85
CSG_Table * SG_Create_Table(void)
Definition table.cpp:65
#define GET_RECORD(i)
TSG_Table_File_Type
Definition table.h:93
TSG_Table_Index_Order
Definition table.h:103
@ TABLE_INDEX_Ascending
Definition table.h:105
@ TABLE_INDEX_None
Definition table.h:104
#define SG_TABLE_REC_FLAG_Modified
Definition table.h:118
@ SG_TABLE_VALUE_TYPE_String
Definition table_value.h:94
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)