SAGA API  v9.9
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 //---------------------------------------------------------
110 CSG_Table * SG_Create_Table(const char *File, TSG_Table_File_Type Format, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Encoding) ); }
111 CSG_Table * SG_Create_Table(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) { return( SG_Create_Table(CSG_String(File), Format, Encoding) ); }
112 CSG_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 //---------------------------------------------------------
125 CSG_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) ); }
126 CSG_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) ); }
127 CSG_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 //---------------------------------------------------------
148  : CSG_Data_Object()
149 {
151 }
152 
154 {
155  Destroy(); return( true );
156 }
157 
158 //---------------------------------------------------------
160  : CSG_Data_Object()
161 {
162  _On_Construction(); Create(Table);
163 }
164 
165 bool CSG_Table::Create(const CSG_Table &Table)
166 {
167  return( Assign((CSG_Data_Object *)&Table) );
168 }
169 
170 //---------------------------------------------------------
171 CSG_Table::CSG_Table(const char *File, TSG_Table_File_Type Format, int Encoding) : CSG_Table(CSG_String(File), Format, Encoding) {}
172 CSG_Table::CSG_Table(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) : CSG_Table(CSG_String(File), Format, Encoding) {}
173 CSG_Table::CSG_Table(const CSG_String &File, TSG_Table_File_Type Format, int Encoding)
174  : CSG_Data_Object()
175 {
176  _On_Construction(); Create(File, Format, Encoding);
177 }
178 
179 bool CSG_Table::Create(const char *File, TSG_Table_File_Type Format, int Encoding) { return( Create(CSG_String(File), Format, Encoding) ); }
180 bool CSG_Table::Create(const wchar_t *File, TSG_Table_File_Type Format, int Encoding) { return( Create(CSG_String(File), Format, Encoding) ); }
181 bool 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);
229  Set_Update_Flag();
230 
231  SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);
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 //---------------------------------------------------------
244 CSG_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) {}
245 CSG_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) {}
246 CSG_Table::CSG_Table(const CSG_String &File, TSG_Table_File_Type Format, const SG_Char Separator, int Encoding)
247  : CSG_Data_Object()
248 {
249  _On_Construction(); Create(File, Format, Separator, Encoding);
250 }
251 
252 bool 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) ); }
253 bool 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) ); }
254 bool 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 //---------------------------------------------------------
261  : CSG_Data_Object()
262 {
263  _On_Construction(); Create(pTemplate);
264 }
265 
266 bool 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 //---------------------------------------------------------
296 {
297  m_Selection.Create(sizeof(sLong), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_3);
298 
299  Set_Update_Flag();
300 }
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 //---------------------------------------------------------
353 bool 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 //---------------------------------------------------------
400 bool CSG_Table::Assign_Values(const SG_Char *FileName)
401 {
402  CSG_Table Table; return( Table.Create(FileName) && Assign_Values(&Table) );
403 }
404 
405 
407 // //
408 // Checks //
409 // //
411 
412 //---------------------------------------------------------
413 bool 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 //---------------------------------------------------------
435 bool 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 //---------------------------------------------------------
449 {
450  // nop
451 }
452 
453 //---------------------------------------------------------
455 {
456  m_Name = Name; m_Type = Type;
457 }
458 
459 //---------------------------------------------------------
461 {
462  // nop
463 }
464 
465 //---------------------------------------------------------
467 {
468  m_Statistics.Invalidate(); m_Histogram.Destroy();
469 
470  return( true );
471 }
472 
473 
475 // //
477 
478 //---------------------------------------------------------
479 bool 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 //---------------------------------------------------------
510 bool 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 //---------------------------------------------------------
542 bool 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 //---------------------------------------------------------
595 bool 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 //---------------------------------------------------------
674 int 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 
690  case SG_DATATYPE_String:
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 //---------------------------------------------------------
721 int CSG_Table::Get_Field(const char *Name) const { return( Get_Field(CSG_String(Name))); }
722 int CSG_Table::Get_Field(const wchar_t *Name) const { return( Get_Field(CSG_String(Name))); }
723 int 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 //---------------------------------------------------------
741 int 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 //---------------------------------------------------------
759 bool 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 //---------------------------------------------------------
775 bool CSG_Table::_Inc_Array(void)
776 {
777  if( m_nRecords < m_nBuffer )
778  {
779  return( true );
780  }
781 
782  CSG_Table_Record **pRecords = (CSG_Table_Record **)SG_Realloc(m_Records, (m_nBuffer + GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_Table_Record *));
783 
784  if( pRecords == NULL )
785  {
786  return( false );
787  }
788 
789  m_Records = pRecords;
791 
792  return( true );
793 }
794 
795 //---------------------------------------------------------
796 bool CSG_Table::_Dec_Array(void)
797 {
798  if( m_nRecords < 0 || m_nRecords >= m_nBuffer - GET_GROW_SIZE(m_nBuffer) )
799  {
800  return( true );
801  }
802 
803  CSG_Table_Record **pRecords = (CSG_Table_Record **)SG_Realloc(m_Records, (m_nBuffer - GET_GROW_SIZE(m_nBuffer)) * sizeof(CSG_Table_Record *));
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 //---------------------------------------------------------
824 {
825  return( Ins_Record(m_nRecords, pCopy) );
826 }
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 
877  Set_Update_Flag();
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 
925  Set_Update_Flag();
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 //---------------------------------------------------------
974 bool 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 //---------------------------------------------------------
1041 CSG_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 //---------------------------------------------------------
1054 bool 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 //---------------------------------------------------------
1121 CSG_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 //---------------------------------------------------------
1141 void CSG_Table::Set_Modified(bool bModified)
1142 {
1143  if( bModified != is_Modified() )
1144  {
1145  CSG_Data_Object::Set_Modified(bModified);
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 //---------------------------------------------------------
1159 bool 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 //---------------------------------------------------------
1172 bool 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 //---------------------------------------------------------
1185 bool 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 //---------------------------------------------------------
1203 bool 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 //---------------------------------------------------------
1239 bool 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 //---------------------------------------------------------
1252 bool 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 //---------------------------------------------------------
1299 bool 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 //---------------------------------------------------------
1352 bool CSG_Table::Sort(const char *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1353 bool CSG_Table::Sort(const wchar_t *Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1354 bool CSG_Table::Sort(const CSG_String &Field, bool bAscending) { return( Sort(Get_Field(Field), bAscending) ); }
1355 bool CSG_Table::Sort(int Field, bool bAscending)
1356 {
1357  CSG_Index Index; return( Set_Index(Index, Field, bAscending) && Sort(Index) );
1358 }
1359 
1360 //---------------------------------------------------------
1361 bool 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 //---------------------------------------------------------
1390 bool 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 //---------------------------------------------------------
1459 class CSG_Table_Record_Compare_Field : public CSG_Index::CSG_Index_Compare
1460 {
1461 public:
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 
1497 private:
1498 
1499  bool m_Ascending;
1500 
1501  int m_Field;
1502 
1503  const CSG_Table *m_pTable;
1504 
1505 };
1506 
1507 //---------------------------------------------------------
1508 bool 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 //---------------------------------------------------------
1521 class CSG_Table_Record_Compare_Fields : public CSG_Index::CSG_Index_Compare
1522 {
1523 public:
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 
1590 private:
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 //---------------------------------------------------------
1601 bool 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 //---------------------------------------------------------
1609 bool 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 //---------------------------------------------------------
1615 void 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 //---------------------------------------------------------
CSG_Index
Definition: mat_tools.h:200
CSG_Table::CSG_Table_Record
friend class CSG_Table_Record
Definition: table.h:286
CSG_Data_Object::Assign
virtual bool Assign(CSG_Data_Object *pObject, bool bProgress=false)
Definition: dataobject.cpp:797
CSG_String::BeforeFirst
CSG_String BeforeFirst(char Character) const
Definition: api_string.cpp:713
CSG_Table_Record::asDouble
double asDouble(int Field) const
Definition: table_record.cpp:527
CSG_Index::is_Okay
bool is_Okay(void) const
Definition: mat_tools.h:240
CSG_Data_Object::Get_Max_Samples
sLong Get_Max_Samples(void) const
Definition: dataobject.h:263
SG_FREE_SAFE
#define SG_FREE_SAFE(PTR)
Definition: api_core.h:205
SG_Create_Table
CSG_Table * SG_Create_Table(void)
Definition: table.cpp:65
CSG_Table::Get_Field_Type
TSG_Data_Type Get_Field_Type(int Field) const
Definition: table.h:363
CSG_Table::CSG_Field_Info::m_Histogram
CSG_Histogram m_Histogram
Definition: table.h:480
CSG_Table::Set_Count
virtual bool Set_Count(sLong nRecords)
Definition: table.cpp:954
CSG_Table::_Histogram_Update
virtual bool _Histogram_Update(int Field, size_t nClasses) const
Definition: table.cpp:1299
SG_DATATYPE_String
@ SG_DATATYPE_String
Definition: api_core.h:1009
SG_TABLE_VALUE_TYPE_String
@ SG_TABLE_VALUE_TYPE_String
Definition: table_value.h:94
_TL
#define _TL(s)
Definition: api_core.h:1559
CSG_Table::Del_Records
virtual bool Del_Records(void)
Definition: table.cpp:936
SG_DATATYPE_Binary
@ SG_DATATYPE_Binary
Definition: api_core.h:1012
CSG_Array::Get_Size
sLong Get_Size(void) const
Definition: api_core.h:327
CSG_Data_Object::Set_File_Name
void Set_File_Name(const CSG_String &FileName)
Definition: dataobject.cpp:366
CSG_String::Length
size_t Length(void) const
Definition: api_string.cpp:172
TABLE_INDEX_None
@ TABLE_INDEX_None
Definition: table.h:104
CSG_Table::Get_Value
virtual bool Get_Value(sLong Index, int Field, CSG_String &Value) const
Definition: table.cpp:1185
CSG_Data_Object::Get_Description
const SG_Char * Get_Description(void) const
Definition: dataobject.cpp:360
CSG_Table_Record
Definition: table.h:130
CSG_Data_Object::Get_NoData_Value
double Get_NoData_Value(bool bUpper=false) const
Definition: dataobject.h:253
CSG_Table::Get_ObjectType
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
SG_UI_MSG_STYLE_SUCCESS
@ SG_UI_MSG_STYLE_SUCCESS
Definition: api_core.h:1575
CSG_Index::CSG_Index_Compare
Definition: mat_tools.h:203
CSG_Table::m_Selection
CSG_Array m_Selection
Definition: table.h:491
CSG_Table::Set_Field_Type
virtual bool Set_Field_Type(int Field, TSG_Data_Type Type)
Definition: table.cpp:610
CSG_Table::is_Selected
virtual bool is_Selected(sLong Index) const
Definition: table.h:432
CSG_Table::Get_Record
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition: table.h:402
CSG_Histogram
Definition: mat_tools.h:1013
GET_GROW_SIZE
#define GET_GROW_SIZE(n)
Definition: table.cpp:772
SG_Malloc
SAGA_API_DLL_EXPORT void * SG_Malloc(size_t size)
Definition: api_memory.cpp:65
CSG_Array_Int::Get_Size
sLong Get_Size(void) const
Definition: api_core.h:436
CSG_Table::CSG_Field_Info::m_Name
CSG_String m_Name
Definition: table.h:476
CSG_Table::_Stats_Update
virtual bool _Stats_Update(int Field) const
Definition: table.cpp:1252
SG_Data_Type_Get_Size
size_t SG_Data_Type_Get_Size(TSG_Data_Type Type)
Definition: api_core.h:1064
CSG_Table::operator=
CSG_Table & operator=(const CSG_Table &Table)
Definition: table.cpp:345
CSG_Table_Record::Assign
virtual bool Assign(CSG_Table_Record *pRecord)
Definition: table_record.cpp:543
CSG_Table::CSG_Field_Info::Reset_Statistics
bool Reset_Statistics(void)
Definition: table.cpp:466
CSG_Table::~CSG_Table
virtual ~CSG_Table(void)
Definition: table.cpp:308
CSG_Tool
Definition: tool.h:135
CSG_Table::Destroy
virtual bool Destroy(void)
Definition: table.cpp:314
CSG_Data_Object::Get_Name
const SG_Char * Get_Name(void) const
Definition: dataobject.cpp:349
CSG_Tool::Execute
bool Execute(bool bAddHistory=false)
Definition: tool.cpp:258
CSG_Histogram::Create
bool Create(const CSG_Histogram &Histogram)
Definition: mat_tools.cpp:1518
SG_FILE_ENCODING_UTF32BE
@ SG_FILE_ENCODING_UTF32BE
Definition: api_core.h:556
CSG_Table::CSG_Table
CSG_Table(void)
Definition: table.cpp:147
CSG_Table::Get_Index_Order
TSG_Table_Index_Order Get_Index_Order(int i) const
Definition: table.h:456
CSG_Table::Set_Field_Name
bool Set_Field_Name(int Field, const SG_Char *Name)
Definition: table.cpp:595
CSG_Table::Get_Field_Count
int Get_Field_Count(void) const
Definition: table.h:361
CSG_Array_Int::Get_Array
int * Get_Array(void) const
Definition: api_core.h:439
CSG_Simple_Statistics::Evaluate
bool Evaluate(void)
Definition: mat_tools.cpp:473
SG_Free
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
Definition: api_memory.cpp:83
CSG_Table_Record::m_Values
class CSG_Table_Value ** m_Values
Definition: table.h:258
CSG_Table::m_Field_Info
CSG_Field_Info ** m_Field_Info
Definition: table.h:485
CSG_Table::Set_Record
virtual bool Set_Record(sLong Index, CSG_Table_Record *pCopy)
Definition: table.cpp:886
CSG_Table_Value
Definition: table_value.h:111
CSG_Table::CSG_Field_Info::~CSG_Field_Info
virtual ~CSG_Field_Info(void)
Definition: table.cpp:460
CSG_Table_Record::m_Index
sLong m_Index
Definition: table.h:256
CSG_Tool_Library_Manager::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool) const
Definition: tool_library.cpp:865
CSG_Table::Find_Record
virtual bool Find_Record(sLong &Index, int Field, const CSG_String &Value, bool bCreateIndex=false)
Definition: table.cpp:974
CSG_Data_Object::Set_Update_Flag
void Set_Update_Flag(bool bOn=true)
Definition: dataobject.h:285
CSG_Table_Record::is_NoData
bool is_NoData(int Field) const
Definition: table_record.cpp:416
CSG_Table::Set_Modified
virtual void Set_Modified(bool bModified=true)
Definition: table.cpp:1141
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
SG_FILE_ENCODING_UTF7
@ SG_FILE_ENCODING_UTF7
Definition: api_core.h:551
CSG_Table::_Stats_Invalidate
bool _Stats_Invalidate(void) const
Definition: table.cpp:1228
CSG_Table_Record::m_Flags
char m_Flags
Definition: table.h:254
CSG_Table::Find_Field
int Find_Field(const CSG_String &Name) const
Definition: table.cpp:741
CSG_Tool::Set_Parameter
bool Set_Parameter(const CSG_String &ID, CSG_Parameter *pValue)
Definition: tool.cpp:1283
SG_UI_MSG_STYLE_FAILURE
@ SG_UI_MSG_STYLE_FAILURE
Definition: api_core.h:1576
CSG_Table::is_Compatible
bool is_Compatible(const CSG_Table &Table, bool bExactMatch=false) const
Definition: table.cpp:413
SG_File_Exists
SAGA_API_DLL_EXPORT bool SG_File_Exists(const CSG_String &FileName)
Definition: api_file.cpp:1078
CSG_Table_Value::Get_Type
virtual TSG_Table_Value_Type Get_Type(void) const =0
CSG_Table_Record::asString
const SG_Char * asString(int Field, int Decimals=-99) const
Definition: table_record.cpp:461
CSG_Data_Object
Definition: dataobject.h:180
CSG_Data_Object::On_NoData_Changed
virtual bool On_NoData_Changed(void)
Definition: dataobject.cpp:601
CSG_Simple_Statistics::Get_Count
sLong Get_Count(void) const
Definition: mat_tools.h:745
CSG_Table::CSG_Field_Info::CSG_Field_Info
CSG_Field_Info(void)
Definition: table.cpp:448
CSG_Table::Get_Selection_Count
sLong Get_Selection_Count(void) const
Definition: table.h:428
CSG_Index::Invert
bool Invert(void)
Definition: mat_indexing.cpp:102
CSG_Index::Create
bool Create(sLong nValues, CSG_Index_Compare &Compare)
Definition: mat_indexing.cpp:131
SG_TABLE_REC_FLAG_Modified
#define SG_TABLE_REC_FLAG_Modified
Definition: table.h:118
CSG_Table::Get_Field_Name
const SG_Char * Get_Field_Name(int Field) const
Definition: table.h:362
TSG_Table_Index_Order
TSG_Table_Index_Order
Definition: table.h:103
CSG_Histogram::is_Okay
bool is_Okay(void) const
Definition: mat_tools.h:1047
CSG_Table::CSG_Field_Info::m_Type
TSG_Data_Type m_Type
Definition: table.h:474
sLong
signed long long sLong
Definition: api_core.h:158
SG_Get_Tool_Library_Manager
CSG_Tool_Library_Manager & SG_Get_Tool_Library_Manager(void)
Definition: tool_library.cpp:286
CSG_Table::Get_Field_Length
virtual int Get_Field_Length(int Field, int Encoding=SG_FILE_ENCODING_UNDEFINED) const
Definition: table.cpp:674
SG_Data_Type_is_Numeric
bool SG_Data_Type_is_Numeric(TSG_Data_Type Type)
Definition: api_core.cpp:198
CSG_Data_Object::On_Update
virtual bool On_Update(void)
Definition: dataobject.h:287
CSG_Table::is_Indexed
bool is_Indexed(void) const
Definition: table.h:454
CSG_Table::On_NoData_Changed
virtual bool On_NoData_Changed(void)
Definition: table.cpp:1324
SG_FILE_ENCODING_UTF32LE
@ SG_FILE_ENCODING_UTF32LE
Definition: api_core.h:555
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:400
CSG_Table_Record::_Create_Value
static CSG_Table_Value * _Create_Value(TSG_Data_Type Type)
Definition: table_record.cpp:110
CSG_Table::On_Update
virtual bool On_Update(void)
Definition: table.cpp:1332
CSG_Data_Object::is_Modified
virtual bool is_Modified(void) const
Definition: dataobject.h:228
CSG_Table::Assign_Values
bool Assign_Values(const CSG_Table &Table)
Definition: table.cpp:378
CSG_Array_Int
Definition: api_core.h:423
CSG_Simple_Statistics::is_Evaluated
int is_Evaluated(void) const
Definition: mat_tools.h:741
CSG_Table::Get_Index_Field
int Get_Index_Field(int i) const
Definition: table.h:455
CSG_Table::Del_Index
bool Del_Index(void)
Definition: table.cpp:1419
CSG_Table::m_nBuffer
sLong m_nBuffer
Definition: table.h:489
CSG_Data_Object::Set_Modified
virtual void Set_Modified(bool bOn=true)
Definition: dataobject.h:227
CSG_Array::Create
void * Create(const CSG_Array &Array)
Definition: api_memory.cpp:250
CSG_Table::Toggle_Index
bool Toggle_Index(int Field)
Definition: table.cpp:1429
CSG_Array::Get_Array
void * Get_Array(void) const
Definition: api_core.h:336
CSG_Table::Get_Record_byIndex
CSG_Table_Record * Get_Record_byIndex(sLong Index) const
Definition: table.h:407
CSG_Data_Object::asTable
class CSG_Table * asTable(bool bPolymorph=false) const
Definition: dataobject.cpp:487
SG_DATATYPE_Date
@ SG_DATATYPE_Date
Definition: api_core.h:1010
CSG_Table_Record::_Add_Field
bool _Add_Field(int add_Field)
Definition: table_record.cpp:143
CSG_Data_Object::Set_Name
void Set_Name(const CSG_String &Name)
Definition: dataobject.cpp:300
CSG_Table::m_Encoding
int m_Encoding
Definition: table.h:487
CSG_Table_Record::Set_Modified
void Set_Modified(bool bOn=true)
Definition: table_record.cpp:220
CSG_Histogram::Get_Class_Count
size_t Get_Class_Count(void) const
Definition: mat_tools.h:1049
CSG_Index::Add_Entry
bool Add_Entry(sLong Position=-1)
Definition: mat_indexing.cpp:289
CSG_Simple_Statistics::Set_Count
bool Set_Count(sLong Count)
Definition: mat_tools.cpp:424
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_Table::_Del_Selection
bool _Del_Selection(sLong Index)
Definition: table_selection.cpp:87
SG_FILE_ENCODING_UTF16LE
@ SG_FILE_ENCODING_UTF16LE
Definition: api_core.h:553
CSG_Table::Assign
virtual bool Assign(CSG_Data_Object *pTable, bool bProgress=false)
Definition: table.cpp:353
CSG_Table::Add_Field
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition: table.cpp:479
CSG_Tool_Library_Manager::Create_Tool
CSG_Tool * Create_Tool(const CSG_String &Library, int Index, bool bWithGUI=false, bool bWithCMD=true) const
Definition: tool_library.cpp:836
CSG_Table
Definition: table.h:285
CSG_String::to_UTF8
size_t to_UTF8(char **pString) const
Definition: api_string.cpp:860
SG_DATAOBJECT_TYPE_Shapes
@ SG_DATAOBJECT_TYPE_Shapes
Definition: dataobject.h:121
CSG_String::AfterFirst
CSG_String AfterFirst(char Character) const
Definition: api_string.cpp:691
CSG_Table::CSG_Field_Info::m_Statistics
CSG_Simple_Statistics m_Statistics
Definition: table.h:478
CSG_Table::Del_Record
virtual bool Del_Record(sLong Index)
Definition: table.cpp:897
SG_Char
#define SG_Char
Definition: api_core.h:536
CSG_Table::Load
bool Load(const CSG_String &File, int Format, SG_Char Separator, int Encoding=SG_FILE_ENCODING_UNDEFINED)
Definition: table_io.cpp:99
shapes.h
CSG_String
Definition: api_core.h:563
CSG_Tool::Set_Manager
bool Set_Manager(class CSG_Data_Manager *pManager)
Definition: tool.cpp:570
SG_DATAOBJECT_TYPE_Table
@ SG_DATAOBJECT_TYPE_Table
Definition: dataobject.h:120
CSG_Data_Object::Set_Description
void Set_Description(const CSG_String &Description)
Definition: dataobject.cpp:355
SG_UI_Process_Set_Progress
bool SG_UI_Process_Set_Progress(int Position, int Range)
Definition: api_callback.cpp:255
SG_FILE_ENCODING_UTF16BE
@ SG_FILE_ENCODING_UTF16BE
Definition: api_core.h:554
CSG_Table_Value::Set_Value
virtual bool Set_Value(const CSG_Bytes &Value)=0
TSG_Table_File_Type
TSG_Table_File_Type
Definition: table.h:93
CSG_Table_Record::Set_Value
bool Set_Value(int Field, const CSG_String &Value)
Definition: table_record.cpp:270
CSG_Table::Del_Field
virtual bool Del_Field(int Field)
Definition: table.cpp:510
CSG_Table::m_nFields
int m_nFields
Definition: table.h:487
GET_RECORD
#define GET_RECORD(i)
CSG_Table::Ins_Record
virtual CSG_Table_Record * Ins_Record(sLong Index, CSG_Table_Record *pCopy=NULL)
Definition: table.cpp:829
CSG_Table_Record::Get_Index
sLong Get_Index(void) const
Definition: table.h:136
TABLE_INDEX_Ascending
@ TABLE_INDEX_Ascending
Definition: table.h:105
CSG_Table::Set_Value
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition: table.cpp:1159
CSG_Table::Create
bool Create(void)
Definition: table.cpp:153
CSG_String::asDouble
double asDouble(void) const
Definition: api_string.cpp:807
CSG_Tool::On_Before_Execution
virtual bool On_Before_Execution(void)
Definition: tool.h:229
CSG_Shapes
Definition: shapes.h:772
SG_UI_ProgressAndMsg_Lock
void SG_UI_ProgressAndMsg_Lock(bool bOn)
Definition: api_callback.cpp:586
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
tool_library.h
CSG_Table_Record::Get_Value
CSG_Table_Value * Get_Value(int Field)
Definition: table.h:239
CSG_Table_Value::asString
virtual const SG_Char * asString(int Decimals=-99) const =0
TSG_Data_Type
TSG_Data_Type
Definition: api_core.h:997
CSG_Table::CSG_Field_Info
Definition: table.h:464
SG_Realloc
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
Definition: api_memory.cpp:77
CSG_Table::Set_Index
bool Set_Index(CSG_Index &Index, int Field, bool bAscending=true) const
Definition: table.cpp:1508
CSG_Index::Get_Count
sLong Get_Count(void) const
Definition: mat_tools.h:241
CSG_Table::Add_Record
virtual CSG_Table_Record * Add_Record(CSG_Table_Record *pCopy=NULL)
Definition: table.cpp:823
CSG_Table::Sort
bool Sort(const char *Field, bool bAscending=true)
Definition: table.cpp:1352
CSG_Index::Del_Entry
bool Del_Entry(sLong Position=-1)
Definition: mat_indexing.cpp:310
CSG_Table::Get_Field
int Get_Field(const CSG_String &Name) const
Definition: table.cpp:723
CSG_Array_Int::Destroy
void Destroy(void)
Definition: api_core.h:431
SG_FILE_ENCODING_UTF8
@ SG_FILE_ENCODING_UTF8
Definition: api_core.h:552
CSG_Simple_Statistics
Definition: mat_tools.h:725
CSG_Data_Object::Set_NoData_Value_Range
virtual bool Set_NoData_Value_Range(double Lower, double Upper)
Definition: dataobject.cpp:578
table.h
CSG_Index::Destroy
bool Destroy(void)
Definition: mat_indexing.cpp:83
CSG_Data_Object::Destroy
virtual bool Destroy(void)
Definition: dataobject.cpp:281
CSG_Table::_Get_New_Record
virtual CSG_Table_Record * _Get_New_Record(sLong Index)
Definition: table.cpp:817
SG_DATAOBJECT_TYPE_PointCloud
@ SG_DATAOBJECT_TYPE_PointCloud
Definition: dataobject.h:123
CSG_Table::m_nRecords
sLong m_nRecords
Definition: table.h:489
SG_UI_Msg_Add
void SG_UI_Msg_Add(const char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
Definition: api_callback.cpp:499
CSG_Table_Record::_Del_Field
bool _Del_Field(int del_Field)
Definition: table_record.cpp:167
CSG_Table::_On_Construction
virtual void _On_Construction(void)
Definition: table.cpp:295
SG_Create_Shapes
CSG_Shapes * SG_Create_Shapes(void)
Definition: shapes.cpp:85
CSG_Table::Mov_Field
virtual bool Mov_Field(int Field, int Position)
Definition: table.cpp:542