Version: 8.3.0
SALOMEDSImpl_AttributeTable.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 // File : SALOMEDSImpl_AttributeTable.hxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 //
23 #ifndef _SALOMEDSImpl_AttributeTable_HeaderFile
24 #define _SALOMEDSImpl_AttributeTable_HeaderFile
25 
26 #include "SALOMEDSImpl_Defines.hxx"
27 
29 {
30 public:
32  typedef enum {
35  } SortOrder;
36 
38  typedef enum {
44  } SortPolicy;
45 };
46 
47 template <class TTable> class TableSorter
48 {
49  TTable* myTable;
52  int myIndex;
53  bool myIsRow;
54 
55 public:
56  TableSorter( TTable* table,
59  int index,
60  bool sortRow)
61  : myTable( table ), mySortOrder( so ), mySortPolicy( sp ),
62  myIndex( index ), myIsRow( sortRow ) {}
63 
64  bool operator() ( int idx1, int idx2 )
65  {
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 ) {
69  return false;
70  }
71  else if ( !hasValue1 || !hasValue2 ) {
72  switch ( mySortPolicy ) {
74  return (!hasValue1) ?
78  return (!hasValue1) ?
82  return (!hasValue1);
84  return hasValue1;
86  default:
87  // should not go here
88  return false;
89  }
90  }
91  else {
92  if ( myIsRow ) {
94  myTable->GetValue( myIndex, idx1 ) < myTable->GetValue( myIndex, idx2 ) :
95  myTable->GetValue( myIndex, idx2 ) < myTable->GetValue( myIndex, idx1 );
96  }
97  else {
99  myTable->GetValue( idx1, myIndex ) < myTable->GetValue( idx2, myIndex ) :
100  myTable->GetValue( idx2, myIndex ) < myTable->GetValue( idx1, myIndex );
101  }
102  }
103  }
104 };
105 
106 #endif // _SALOMEDSImpl_AttributeTable_HeaderFile