SAGA API  v9.6
table_selection.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_selection.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 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
64 {
65  if( m_Selection.Inc_Array() )
66  {
67  return( _Set_Selection(iRecord, m_Selection.Get_Size() - 1) );
68  }
69 
70  return( false );
71 }
72 
73 //---------------------------------------------------------
74 bool CSG_Table::_Set_Selection(sLong Index, sLong Selected)
75 {
76  if( Selected < m_Selection.Get_Size() )
77  {
78  *((sLong *)m_Selection.Get_Entry(Selected)) = Index;
79 
80  return( true );
81  }
82 
83  return( false );
84 }
85 
86 //---------------------------------------------------------
88 {
89  for(sLong i=0; i<m_Selection.Get_Size(); i++)
90  {
91  if( Index == Get_Selection_Index(i) )
92  {
93  sLong *Selection = (sLong *)m_Selection.Get_Array();
94 
95  for(sLong j=i+1; j<m_Selection.Get_Size(); i++, j++)
96  {
97  Selection[i] = Selection[j];
98  }
99 
101 
102  return( true );
103  }
104  }
105 
106  return( false );
107 }
108 
109 
111 // //
113 
114 //---------------------------------------------------------
115 bool CSG_Table::_Destroy_Selection(void)
116 {
117  if( Get_Selection_Count() > 0 )
118  {
119  for(size_t iRecord=0; iRecord<(size_t)m_nRecords; iRecord++)
120  {
121  m_Records[iRecord]->Set_Selected(false);
122  }
123 
125  }
126 
127  return( true );
128 }
129 
130 
132 // //
134 
135 //---------------------------------------------------------
136 bool CSG_Table::Select(sLong iRecord, bool bInvert)
137 {
138  if( !bInvert )
139  {
140  _Destroy_Selection();
141  }
142 
143  CSG_Table_Record *pRecord = Get_Record(iRecord);
144 
145  if( pRecord == NULL )
146  {
147  return( false );
148  }
149 
150  if( pRecord->is_Selected() == false )
151  {
152  pRecord->Set_Selected(true);
153 
154  _Add_Selection(iRecord);
155  }
156  else // if( pRecord->is_Selected() == true )
157  {
158  pRecord->Set_Selected(false);
159 
160  _Del_Selection(iRecord);
161  }
162 
163  return( true );
164 }
165 
166 //---------------------------------------------------------
167 bool CSG_Table::Select(CSG_Table_Record *pRecord, bool bInvert)
168 {
169  return( Select(pRecord ? pRecord->Get_Index() : -1, bInvert) );
170 }
171 
172 
174 // //
176 
177 //---------------------------------------------------------
179 {
180  sLong n = 0;
181 
182  if( Get_Selection_Count() > 0 )
183  {
184  for(sLong i=m_nRecords-1; i>=0; i--)
185  {
186  if( m_Records[i]->is_Selected() )
187  {
188  m_Records[i]->Set_Selected(false);
189 
190  Del_Record(i);
191 
192  n++;
193  }
194  }
195 
197  }
198 
199  return( n );
200 }
201 
202 //---------------------------------------------------------
204 {
205  if( m_nRecords > 0 )
206  {
208 
209  for(sLong i=0, n=0; i<Get_Count(); i++)
210  {
211  CSG_Table_Record *pRecord = Get_Record(i);
212 
213  if( pRecord->is_Selected() == false )//&& n < m_Selection.Get_Size() )
214  {
215  pRecord->Set_Selected(true);
216 
217  *((sLong *)m_Selection.Get_Entry(n++)) = i;
218  }
219  else
220  {
221  pRecord->Set_Selected(false);
222  }
223  }
224  }
225 
226  return( Get_Selection_Count() );
227 }
228 
229 
231 // //
232 // //
233 // //
235 
236 //---------------------------------------------------------
CSG_Array::Set_Array
bool Set_Array(sLong nValues, bool bShrink=true)
Definition: api_memory.cpp:310
CSG_Array::Get_Size
sLong Get_Size(void) const
Definition: api_core.h:327
CSG_Table_Record
Definition: table.h:130
CSG_Table_Record::Set_Selected
void Set_Selected(bool bOn=true)
Definition: table_record.cpp:204
CSG_Table::Inv_Selection
virtual sLong Inv_Selection(void)
Definition: table_selection.cpp:203
CSG_Table::m_Selection
CSG_Array m_Selection
Definition: table.h:459
CSG_Table::is_Selected
virtual bool is_Selected(sLong Index) const
Definition: table.h:424
CSG_Table::Get_Record
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition: table.h:394
CSG_Table_Record::is_Selected
bool is_Selected(void) const
Definition: table.h:242
CSG_Table::Get_Selection_Count
sLong Get_Selection_Count(void) const
Definition: table.h:420
CSG_Table::_Set_Selection
bool _Set_Selection(sLong Index, sLong Selected)
Definition: table_selection.cpp:74
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:392
CSG_Array::Get_Array
void * Get_Array(void) const
Definition: api_core.h:336
CSG_Table::_Del_Selection
bool _Del_Selection(sLong Index)
Definition: table_selection.cpp:87
CSG_Table::_Add_Selection
bool _Add_Selection(sLong Index)
Definition: table_selection.cpp:63
CSG_Table::Del_Record
virtual bool Del_Record(sLong Index)
Definition: table.cpp:869
CSG_Array::Inc_Array
bool Inc_Array(sLong nValues=1)
Definition: api_memory.cpp:414
CSG_Array::Dec_Array
bool Dec_Array(bool bShrink=true)
Definition: api_memory.cpp:425
CSG_Table::Get_Selection_Index
sLong Get_Selection_Index(sLong Index=0) const
Definition: table.h:421
CSG_Table_Record::Get_Index
sLong Get_Index(void) const
Definition: table.h:136
CSG_Table::Select
virtual bool Select(sLong Index, bool bInvert=false)
Definition: table_selection.cpp:136
CSG_Table::Del_Selection
virtual sLong Del_Selection(void)
Definition: table_selection.cpp:178
table.h
CSG_Table::m_nRecords
sLong m_nRecords
Definition: table.h:451
CSG_Array::Get_Entry
void * Get_Entry(sLong Index) const
Returns a pointer to the memory address of the requested variable. You have to type cast and derefere...
Definition: api_core.h:331