1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_AttributeTable.hxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
23 #ifndef _SALOMEDSImpl_AttributeTable_HeaderFile
24 #define _SALOMEDSImpl_AttributeTable_HeaderFile
26 #include "SALOMEDSImpl_Defines.hxx"
28 class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTable
33 AscendingOrder, //!< The items are sorted ascending
34 DescendingOrder, //!< The items are sorted descending
37 //! Sort policy (specifies how empty cells are taken into account when sorting)
39 EmptyLowest, //!< Empty cells are considered as lowest values
40 EmptyHighest, //!< Empty cells are considered as highest values
41 EmptyFirst, //!< Empty cells are always first
42 EmptyLast, //!< Empty cells are always last
43 EmptyIgnore, //!< Empty cells are ignored (stay at initial positions)
47 template <class TTable> class TableSorter
50 SALOMEDSImpl_AttributeTable::SortOrder mySortOrder;
51 SALOMEDSImpl_AttributeTable::SortPolicy mySortPolicy;
56 TableSorter( TTable* table,
57 SALOMEDSImpl_AttributeTable::SortOrder so,
58 SALOMEDSImpl_AttributeTable::SortPolicy sp,
61 : myTable( table ), mySortOrder( so ), mySortPolicy( sp ),
62 myIndex( index ), myIsRow( sortRow ) {}
64 bool operator() ( int idx1, int idx2 )
66 bool hasValue1 = myIsRow ? myTable->HasValue( myIndex, idx1 ) : myTable->HasValue( idx1, myIndex );
67 bool hasValue2 = myIsRow ? myTable->HasValue( myIndex, idx2 ) : myTable->HasValue( idx2, myIndex );
68 if ( !hasValue1 && !hasValue2 ) {
71 else if ( !hasValue1 || !hasValue2 ) {
72 switch ( mySortPolicy ) {
73 case SALOMEDSImpl_AttributeTable::EmptyLowest:
75 (mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder) :
76 (mySortOrder == SALOMEDSImpl_AttributeTable::DescendingOrder);
77 case SALOMEDSImpl_AttributeTable::EmptyHighest:
79 (mySortOrder != SALOMEDSImpl_AttributeTable::AscendingOrder) :
80 (mySortOrder != SALOMEDSImpl_AttributeTable::DescendingOrder);
81 case SALOMEDSImpl_AttributeTable::EmptyFirst:
83 case SALOMEDSImpl_AttributeTable::EmptyLast:
85 case SALOMEDSImpl_AttributeTable::EmptyIgnore:
93 return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ?
94 myTable->GetValue( myIndex, idx1 ) < myTable->GetValue( myIndex, idx2 ) :
95 myTable->GetValue( myIndex, idx2 ) < myTable->GetValue( myIndex, idx1 );
98 return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ?
99 myTable->GetValue( idx1, myIndex ) < myTable->GetValue( idx2, myIndex ) :
100 myTable->GetValue( idx2, myIndex ) < myTable->GetValue( idx1, myIndex );
106 #endif // _SALOMEDSImpl_AttributeTable_HeaderFile