libyui-ncurses
NCTableSort.h
1 /*
2  Copyright (C) 2020 SUSE LLC
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 #ifndef NCTableSort_h
18 #define NCTableSort_h
19 
20 #include <string>
21 #include <vector>
22 #include <yui/YItem.h>
23 
24 class NCTableLine;
25 
26 
36 {
37 public:
38 
39  NCTableSortStrategyBase( int sortCol = 0, bool reverse = false )
40  : _sortCol( sortCol )
41  , _reverse( reverse )
42  {}
43 
44  virtual ~NCTableSortStrategyBase()
45  {}
46 
52  virtual void sort( YItemIterator begin, YItemIterator end ) = 0;
53 
54 
55  int sortCol() const { return _sortCol; }
56  void setSortCol( int col ) { _sortCol = col; }
57 
58  bool reverse() const { return _reverse; }
59  void setReverse( bool reverse ) { _reverse = reverse; }
60 
61 
62 private:
63 
64  int _sortCol;
65  bool _reverse;
66 };
67 
68 
73 {
74 public:
75  virtual void sort( YItemIterator begin, YItemIterator end ) override;
76 
77 private:
78 
87  class Compare
88  {
89  public:
90  Compare( int sortCol, bool reverse )
91  : _sortCol( sortCol )
92  , _reverse( reverse )
93  {}
94 
98  bool operator() ( YItem * item1, YItem * item2 ) const;
99 
100  protected:
101 
106  std::wstring smartSortKey( YItem * item ) const;
107 
112  long long toNumber( const std::wstring& str, bool * ok ) const;
113 
114 
115  // Data members
116 
117  const int _sortCol;
118  const bool _reverse;
119  };
120 
121 };
122 
123 
124 #endif // NCTableSort_h
Definition: NCTableSort.h:35
virtual void sort(YItemIterator begin, YItemIterator end) override
Definition: NCTableSort.cc:30
Definition: NCTableSort.h:72
Definition: NCTableItem.h:67
virtual void sort(YItemIterator begin, YItemIterator end)=0