1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDSImpl_AttributeTable.hxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #ifndef _SALOMEDSImpl_AttributeTable_HeaderFile
27 #define _SALOMEDSImpl_AttributeTable_HeaderFile
29 #include "SALOMEDSImpl_Defines.hxx"
31 class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTable
36 AscendingOrder, //!< The items are sorted ascending
37 DescendingOrder, //!< The items are sorted descending
40 //! Sort policy (specifies how empty cells are taken into account when sorting)
42 EmptyLowest, //!< Empty cells are considered as lowest values
43 EmptyHighest, //!< Empty cells are considered as highest values
44 EmptyFirst, //!< Empty cells are always first
45 EmptyLast, //!< Empty cells are always last
46 EmptyIgnore, //!< Empty cells are ignored (stay at initial positions)
50 template <class TTable> class TableSorter
53 SALOMEDSImpl_AttributeTable::SortOrder mySortOrder;
54 SALOMEDSImpl_AttributeTable::SortPolicy mySortPolicy;
59 TableSorter( TTable* table,
60 SALOMEDSImpl_AttributeTable::SortOrder so,
61 SALOMEDSImpl_AttributeTable::SortPolicy sp,
64 : myTable( table ), mySortOrder( so ), mySortPolicy( sp ),
65 myIndex( index ), myIsRow( sortRow ) {}
67 bool operator() ( int idx1, int idx2 )
69 bool hasValue1 = myIsRow ? myTable->HasValue( myIndex, idx1 ) : myTable->HasValue( idx1, myIndex );
70 bool hasValue2 = myIsRow ? myTable->HasValue( myIndex, idx2 ) : myTable->HasValue( idx2, myIndex );
71 if ( !hasValue1 && !hasValue2 ) {
74 else if ( !hasValue1 || !hasValue2 ) {
75 switch ( mySortPolicy ) {
76 case SALOMEDSImpl_AttributeTable::EmptyLowest:
78 (mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder) :
79 (mySortOrder == SALOMEDSImpl_AttributeTable::DescendingOrder);
80 case SALOMEDSImpl_AttributeTable::EmptyHighest:
82 (mySortOrder != SALOMEDSImpl_AttributeTable::AscendingOrder) :
83 (mySortOrder != SALOMEDSImpl_AttributeTable::DescendingOrder);
84 case SALOMEDSImpl_AttributeTable::EmptyFirst:
86 case SALOMEDSImpl_AttributeTable::EmptyLast:
88 case SALOMEDSImpl_AttributeTable::EmptyIgnore:
96 return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ?
97 myTable->GetValue( myIndex, idx1 ) < myTable->GetValue( myIndex, idx2 ) :
98 myTable->GetValue( myIndex, idx2 ) < myTable->GetValue( myIndex, idx1 );
101 return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ?
102 myTable->GetValue( idx1, myIndex ) < myTable->GetValue( idx2, myIndex ) :
103 myTable->GetValue( idx2, myIndex ) < myTable->GetValue( idx1, myIndex );
109 #endif // _SALOMEDSImpl_AttributeTable_HeaderFile