SAGA API v9.10
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 ? (iRecord = i) : m_nRecords - 1 - (iRecord = 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 ) { return( true ); }
1011 if( (d = Value.Cmp(GET_RECORD(m_nRecords - 1)->asString(Field))) > 0 ) { return( false ); } else if( d == 0 ) { return( true ); }
1012
1013 for(sLong a=0, b=m_nRecords-1; b-a > 1; )
1014 {
1015 d = Value.Cmp(GET_RECORD(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_byIndex(bAscending ? iRecord : m_nRecords - 1 - iRecord)->Get_Index();
1028
1029 return( true );
1030 }
1031 }
1032
1033 iRecord = Get_Record_byIndex(bAscending ? iRecord : m_nRecords - 1 - iRecord)->Get_Index();
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 ? (iRecord = i) : m_nRecords - 1 - (iRecord = 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. ) { return( true ); }
1091 if( (d = Value - GET_RECORD(m_nRecords - 1)->asDouble(Field)) > 0. ) { return( false ); } else if( d == 0. ) { return( true ); }
1092
1093 for(sLong a=0, b=m_nRecords-1; b-a > 1; )
1094 {
1095 d = Value - GET_RECORD(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_byIndex(bAscending ? iRecord : m_nRecords - 1 - iRecord)->Get_Index();
1108
1109 return( true );
1110 }
1111 }
1112
1113 iRecord = Get_Record_byIndex(bAscending ? iRecord : m_nRecords - 1 - iRecord)->Get_Index();
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 iRecord=0; iRecord<m_nRecords; iRecord++)
1151 {
1152 m_Records[iRecord]->Set_Modified(false);
1153 }
1154 }
1155 }
1156}
1157
1158//---------------------------------------------------------
1159bool CSG_Table::Set_Value(sLong iRecord, int Field, const SG_Char *Value)
1160{
1161 if( Field >= 0 && Field < m_nFields )
1162 {
1163 CSG_Table_Record *pRecord = Get_Record(iRecord);
1164
1165 return( pRecord && pRecord->Set_Value(Field, Value) );
1166 }
1167
1168 return( false );
1169}
1170
1171//---------------------------------------------------------
1172bool CSG_Table::Set_Value(sLong iRecord, int Field, double Value)
1173{
1174 if( Field >= 0 && Field < m_nFields )
1175 {
1176 CSG_Table_Record *pRecord = Get_Record(iRecord);
1177
1178 return( pRecord && pRecord->Set_Value(Field, Value) );
1179 }
1180
1181 return( false );
1182}
1183
1184//---------------------------------------------------------
1185bool CSG_Table::Get_Value(sLong iRecord, int Field, CSG_String &Value) const
1186{
1187 if( Field >= 0 && Field < m_nFields )
1188 {
1189 CSG_Table_Record *pRecord = Get_Record(iRecord);
1190
1191 if( pRecord )
1192 {
1193 Value = pRecord->asString(Field);
1194
1195 return( true );
1196 }
1197 }
1198
1199 return( false );
1200}
1201
1202//---------------------------------------------------------
1203bool CSG_Table::Get_Value(sLong iRecord, int Field, double &Value) const
1204{
1205 if( Field >= 0 && Field < m_nFields )
1206 {
1207 CSG_Table_Record *pRecord = Get_Record(iRecord);
1208
1209 if( pRecord )
1210 {
1211 Value = pRecord->asDouble(Field);
1212
1213 return( pRecord->is_NoData(Field) == false );
1214 }
1215 }
1216
1217 return( false );
1218}
1219
1220
1222// //
1223// Statistics //
1224// //
1226
1227//---------------------------------------------------------
1229{
1230 for(int Field=0; Field<m_nFields; Field++)
1231 {
1232 _Stats_Invalidate(Field);
1233 }
1234
1235 return( true );
1236}
1237
1238//---------------------------------------------------------
1239bool CSG_Table::_Stats_Invalidate(int Field) const
1240{
1241 if( Field >= 0 && Field < m_nFields )
1242 {
1243 m_Field_Info[Field]->Reset_Statistics();
1244
1245 return( true );
1246 }
1247
1248 return( false );
1249}
1250
1251//---------------------------------------------------------
1252bool CSG_Table::_Stats_Update(int Field) const
1253{
1254 if( Field < 0 || Field >= m_nFields || Get_Count() < 1 )
1255 {
1256 return( false );
1257 }
1258
1259 CSG_Simple_Statistics &Statistics = m_Field_Info[Field]->m_Statistics;
1260
1261 if( Statistics.is_Evaluated() )
1262 {
1263 return( true );
1264 }
1265
1266 if( Get_Max_Samples() > 0 && Get_Max_Samples() < Get_Count() )
1267 {
1268 double Value, d = (double)Get_Count() / (double)Get_Max_Samples();
1269
1270 for(double i=0; i<(double)Get_Count(); i+=d)
1271 {
1272 if( Get_Value((sLong)i, Field, Value) )
1273 {
1274 Statistics += Value;
1275 }
1276 }
1277
1278 Statistics.Set_Count(Statistics.Get_Count() >= Get_Max_Samples() ? Get_Count() // any no-data cells ?
1279 : (sLong)(Get_Count() * (double)Statistics.Get_Count() / (double)Get_Max_Samples())
1280 );
1281 }
1282 else
1283 {
1284 double Value;
1285
1286 for(sLong i=0; i<Get_Count(); i++)
1287 {
1288 if( Get_Value(i, Field, Value) )
1289 {
1290 Statistics += Value;
1291 }
1292 }
1293 }
1294
1295 return( Statistics.Evaluate() ); // evaluate! prevent values to be added more than once!
1296}
1297
1298//---------------------------------------------------------
1299bool CSG_Table::_Histogram_Update(int Field, size_t nClasses) const
1300{
1301 if( Field < 0 || Field >= m_nFields || Get_Count() < 1 )
1302 {
1303 return( false );
1304 }
1305
1306 CSG_Histogram &Histogram = m_Field_Info[Field]->m_Histogram;
1307
1308 if( Histogram.is_Okay() && (!nClasses || nClasses == Histogram.Get_Class_Count()) )
1309 {
1310 return( true );
1311 }
1312
1313 return( Histogram.Create(nClasses ? nClasses : 256, (CSG_Table *)this, Field, 0., 0., Get_Max_Samples()) );
1314}
1315
1316
1318// //
1319// //
1320// //
1322
1323//---------------------------------------------------------
1325{
1327
1329}
1330
1331//---------------------------------------------------------
1333{
1335
1336 if( m_Index.is_Okay() )
1337 {
1338 _Index_Update();
1339 }
1340
1341 return( CSG_Data_Object::On_Update() );
1342}
1343
1344
1346// //
1347// Sort //
1348// //
1350
1351//---------------------------------------------------------
1352bool CSG_Table::Sort(const char *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1353bool CSG_Table::Sort(const wchar_t *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1354bool CSG_Table::Sort(const CSG_String &Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1355bool CSG_Table::Sort(int Field, bool bAscending)
1356{
1357 CSG_Index Index; return( Set_Index(Index, Field, bAscending) && Sort(Index) );
1358}
1359
1360//---------------------------------------------------------
1361bool CSG_Table::Sort(const CSG_Index &Index)
1362{
1363 if( Get_Count() > 0 && Get_Count() == Index.Get_Count() )
1364 {
1365 CSG_Table_Record **Records = m_Records; m_Records = (CSG_Table_Record **)SG_Malloc(m_nBuffer * sizeof(CSG_Table_Record *));
1366
1367 for(sLong i=0; i<Get_Count(); i++)
1368 {
1369 m_Records[i] = Records[Index[i]];
1370 }
1371
1372 SG_Free(Records);
1373
1374 Del_Index();
1375
1376 return( true );
1377 }
1378
1379 return( false );
1380}
1381
1382
1384// //
1385// Index //
1386// //
1388
1389//---------------------------------------------------------
1390bool 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)
1391{
1392 m_Index_Fields.Destroy();
1393
1394 if( Field_1 >= 0 && Field_1 < m_nFields && Order_1 != TABLE_INDEX_None )
1395 {
1396 Field_1++; m_Index_Fields += Order_1 == TABLE_INDEX_Ascending ? Field_1 : -Field_1;
1397
1398 if( Field_2 >= 0 && Field_2 < m_nFields && Order_2 != TABLE_INDEX_None )
1399 {
1400 Field_2++; m_Index_Fields += Order_2 == TABLE_INDEX_Ascending ? Field_2 : -Field_2;
1401
1402 if( Field_3 >= 0 && Field_3 < m_nFields && Order_3 != TABLE_INDEX_None )
1403 {
1404 Field_3++; m_Index_Fields += Order_3 == TABLE_INDEX_Ascending ? Field_3 : -Field_3;
1405 }
1406 }
1407
1408 _Index_Update();
1409 }
1410 else
1411 {
1412 Del_Index();
1413 }
1414
1415 return( is_Indexed() );
1416}
1417
1418//---------------------------------------------------------
1420{
1421 m_Index.Destroy();
1422
1423 m_Index_Fields.Destroy();
1424
1425 return( true );
1426}
1427
1428//---------------------------------------------------------
1430{
1431 if( Field < 0 || Field >= m_nFields )
1432 {
1433 return( false );
1434 }
1435
1436 if( Field != Get_Index_Field(0) )
1437 {
1438 Del_Index();
1439
1440 return( Set_Index(Field, TABLE_INDEX_Ascending) );
1441 }
1442
1444 {
1445 m_Index_Fields[0] = -m_Index_Fields[0]; m_Index.Invert();
1446
1447 return( true );
1448 }
1449
1450 return( Del_Index() );
1451}
1452
1453
1455// //
1457
1458//---------------------------------------------------------
1459class CSG_Table_Record_Compare_Field : public CSG_Index::CSG_Index_Compare
1460{
1461public:
1462 CSG_Table_Record_Compare_Field(const CSG_Table *pTable, int Field, bool Ascending)
1463 {
1464 m_pTable = pTable;
1465 m_Field = Field;
1466 m_Ascending = Ascending;
1467
1468 if( !m_pTable || m_Field < 0 || m_Field >= m_pTable->Get_Field_Count() )
1469 {
1470 m_pTable = NULL;
1471 }
1472 }
1473
1474 bool is_Okay (void) const { return( m_pTable != NULL ); }
1475
1476 virtual int Compare (const sLong _a, const sLong _b)
1477 {
1478 sLong a = m_Ascending ? _a : _b;
1479 sLong b = m_Ascending ? _b : _a;
1480
1481 switch( m_pTable->Get_Field_Type(m_Field) )
1482 {
1483 default: { double Value[2] = { 0., 0. };
1484 m_pTable->Get_Value(a, m_Field, Value[0]);
1485 m_pTable->Get_Value(b, m_Field, Value[1]);
1486 return( Value[0] < Value[1] ? -1 : Value[0] > Value[1] ? 1 : 0 ); }
1487
1488 case SG_DATATYPE_String:
1489 case SG_DATATYPE_Date : { CSG_String Value[2];
1490 m_pTable->Get_Value(a, m_Field, Value[0]);
1491 m_pTable->Get_Value(b, m_Field, Value[1]);
1492 return( Value[0].Cmp(Value[1]) ); }
1493 }
1494 }
1495
1496
1497private:
1498
1499 bool m_Ascending;
1500
1501 int m_Field;
1502
1503 const CSG_Table *m_pTable;
1504
1505};
1506
1507//---------------------------------------------------------
1508bool CSG_Table::Set_Index(CSG_Index &Index, int Field, bool bAscending) const
1509{
1510 CSG_Table_Record_Compare_Field Compare(this, Field, bAscending);
1511
1512 return( Compare.is_Okay() && Index.Create(Get_Count(), &Compare) );
1513}
1514
1515
1517// //
1519
1520//---------------------------------------------------------
1521class CSG_Table_Record_Compare_Fields : public CSG_Index::CSG_Index_Compare
1522{
1523public:
1524 CSG_Table_Record_Compare_Fields(const CSG_Table *pTable, int Fields[], int nFields, bool Ascending)
1525 : m_Fields(Fields), m_nFields(nFields), m_pTable(pTable)
1526 {
1527 m_Ascending.Create(nFields);
1528
1529 for(int i=0; m_pTable && i<m_nFields; i++)
1530 {
1531 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1532 {
1533 m_pTable = NULL;
1534 }
1535
1536 m_Ascending[i] = Ascending ? 1 : 0;
1537 }
1538 }
1539
1540 CSG_Table_Record_Compare_Fields(const CSG_Table *pTable, int Fields[], int nFields, int Ascending[])
1541 : m_Fields(Fields), m_nFields(nFields), m_pTable(pTable)
1542 {
1543 m_Ascending.Create(nFields);
1544
1545 for(int i=0; m_pTable && i<m_nFields; i++)
1546 {
1547 if( m_Fields[i] >= m_pTable->Get_Field_Count() )
1548 {
1549 m_pTable = NULL;
1550 }
1551
1552 m_Ascending[i] = Ascending[i] > 0 ? 1 : 0;
1553 }
1554 }
1555
1556 bool is_Okay (void) const { return( m_pTable != NULL ); }
1557
1558 virtual int Compare (const sLong _a, const sLong _b)
1559 {
1560 int Difference = 0;
1561
1562 for(int i=0; !Difference && i<m_nFields; i++)
1563 {
1564 int Field = m_Fields[i];
1565
1566 sLong a = m_Ascending[i] ? _a : _b;
1567 sLong b = m_Ascending[i] ? _b : _a;
1568
1569 switch( m_pTable->Get_Field_Type(Field) )
1570 {
1571 default: { double Value[2] = { 0., 0. };
1572 m_pTable->Get_Value(a, Field, Value[0]);
1573 m_pTable->Get_Value(b, Field, Value[1]);
1574 Difference = Value[0] < Value[1] ? -1 : Value[0] > Value[1] ? 1 : 0;
1575 break; }
1576
1577 case SG_DATATYPE_String:
1578 case SG_DATATYPE_Date : { CSG_String Value[2];
1579 m_pTable->Get_Value(a, Field, Value[0]);
1580 m_pTable->Get_Value(b, Field, Value[1]);
1581 Difference = Value[0].Cmp(Value[1]);
1582 break; }
1583 }
1584 }
1585
1586 return( Difference );
1587 }
1588
1589
1590private:
1591
1592 int *m_Fields, m_nFields;
1593
1594 CSG_Array_Int m_Ascending;
1595
1596 const CSG_Table *m_pTable;
1597
1598};
1599
1600//---------------------------------------------------------
1601bool CSG_Table::Set_Index(CSG_Index &Index, int Fields[], int nFields, bool bAscending) const
1602{
1603 CSG_Table_Record_Compare_Fields Compare(this, Fields, nFields, bAscending);
1604
1605 return( Compare.is_Okay() && Index.Create(Get_Count(), &Compare) );
1606}
1607
1608//---------------------------------------------------------
1609bool CSG_Table::Set_Index(CSG_Index &Index, const CSG_Array_Int &Fields, bool bAscending) const
1610{
1611 return( Set_Index(Index, Fields.Get_Array(), (int)Fields.Get_Size(), bAscending) );
1612}
1613
1614//---------------------------------------------------------
1615void CSG_Table::_Index_Update(void)
1616{
1617 if( m_Index_Fields.Get_Size() < 1 )
1618 {
1619 Del_Index();
1620 }
1621
1622 CSG_Array_Int Fields, Ascending;
1623
1624 for(sLong i=0; i<m_Index_Fields.Get_Size(); i++)
1625 {
1626 Fields += abs(m_Index_Fields[i]) - 1;
1627 Ascending += m_Index_Fields[i] > 0 ? 1 : 0;
1628 }
1629
1630 CSG_Table_Record_Compare_Fields Compare(this, Fields.Get_Array(), (int)Fields.Get_Size(), Ascending.Get_Array());
1631
1632 if( !Compare.is_Okay() || !m_Index.Create(Get_Count(), &Compare) )
1633 {
1634 Del_Index();
1635 }
1636}
1637
1638
1640// //
1641// //
1642// //
1644
1645//---------------------------------------------------------
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:1585
@ SG_UI_MSG_STYLE_SUCCESS
Definition api_core.h:1584
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:997
@ SG_DATATYPE_Binary
Definition api_core.h:1012
@ SG_DATATYPE_String
Definition api_core.h:1009
@ SG_DATATYPE_Date
Definition api_core.h:1010
#define SG_Char
Definition api_core.h:536
#define _TL(s)
Definition api_core.h:1568
@ 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:1064
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:228
virtual bool On_NoData_Changed(void)
void Set_Name(const CSG_String &Name)
void Set_Update_Flag(bool bOn=true)
Definition dataobject.h:285
double Get_NoData_Value(bool bUpper=false) const
Definition dataobject.h:253
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:227
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:263
virtual bool On_Update(void)
Definition dataobject.h:287
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,...)
const SG_Char * c_str(void) const
double asDouble(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:474
CSG_Simple_Statistics m_Statistics
Definition table.h:478
CSG_Histogram m_Histogram
Definition table.h:480
sLong m_Index
Definition table.h:256
bool Set_Value(int Field, const CSG_String &Value)
class CSG_Table_Value ** m_Values
Definition table.h:258
bool is_NoData(int Field) const
sLong Get_Index(void) const
Definition table.h:136
double asDouble(int Field) const
virtual bool Assign(CSG_Table_Record *pRecord)
const SG_Char * asString(int Field, int Decimals=-99) const
static CSG_Table_Value * _Create_Value(TSG_Data_Type Type)
virtual const SG_Char * asString(int Decimals=-99) const =0
virtual bool Set_Value(const CSG_Bytes &Value)=0
virtual TSG_Table_Value_Type Get_Type(void) const =0
const SG_Char * Get_Field_Name(int Field) const
Definition table.h:362
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:1429
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:1252
sLong Get_Count(void) const
Definition table.h:400
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:489
virtual bool On_NoData_Changed(void)
Definition table.cpp:1324
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:1299
bool _Stats_Invalidate(void) const
Definition table.cpp:1228
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:485
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:456
bool is_Indexed(void) const
Definition table.h:454
virtual bool Get_Value(sLong Index, int Field, CSG_String &Value) const
Definition table.cpp:1185
virtual bool On_Update(void)
Definition table.cpp:1332
friend class CSG_Table_Record
Definition table.h:286
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:491
virtual ~CSG_Table(void)
Definition table.cpp:308
int Get_Index_Field(int i) const
Definition table.h:455
bool Set_Index(CSG_Index &Index, int Field, bool bAscending=true) const
Definition table.cpp:1508
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:318
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:487
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:402
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:1352
int Get_Field_Count(void) const
Definition table.h:361
virtual bool is_Selected(sLong Index) const
Definition table.h:432
sLong m_nBuffer
Definition table.h:489
int m_nFields
Definition table.h:487
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:428
bool Del_Index(void)
Definition table.cpp:1419
CSG_Table_Record * Get_Record_byIndex(sLong Index) const
Definition table.h:407
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition table.cpp:1159
bool _Del_Selection(sLong Index)
TSG_Data_Type Get_Field_Type(int Field) const
Definition table.h:363
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:570
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition tool.cpp:1284
virtual bool On_Before_Execution(void)
Definition tool.h:229
bool Execute(bool bAddHistory=false)
Definition tool.cpp:258
@ 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)