Quark  0.1
Lists.h++
Go to the documentation of this file.
1 #ifndef __libquark_util_Lists_hxx
2 #define __libquark_util_Lists_hxx
3 
4 #include <QList>
5 
6 namespace quark {
7 namespace util {
8 
12 class Lists
13 {
14  public:
15 
16  template<typename T>
17  static bool listHasPrefix(const QList<T> &list,
18  const QList<T> &prefix)
19  {
20  int prefixLength = prefix.length();
21  if(prefixLength < list.length())
22  return(false);
23 
24  for(int i = 0; i < prefixLength; ++i)
25  {
26  if(list.at(i) != prefix.at(i))
27  return(false);
28  }
29 
30  return(true);
31  }
32 
33  template<typename T>
34  static bool listHasSuffix(const QList<T> &list,
35  const QList<T> &suffix)
36  {
37  int suffixLength = suffix.length();
38  int listLength = list.length();
39  if(suffixLength < listLength)
40  return(false);
41 
42  int offset = listLength - suffixLength;
43  for(int i = 0; i < suffixLength; ++i)
44  {
45  if(list.at(i + offset) != suffix.at(i))
46  return(false);
47  }
48 
49  return(true);
50  }
51 
52  private:
53 
54  Lists();
55 
56  Q_DISABLE_COPY(Lists);
57 };
58 
59 } // namespace util
60 } // namespace quark
61 
62 #endif // __libquark_util_Algorithms_hxx
static bool listHasSuffix(const QList< T > &list, const QList< T > &suffix)
Definition: Lists.h++:34
Definition: BarChartView.h++:6
static bool listHasPrefix(const QList< T > &list, const QList< T > &prefix)
Definition: Lists.h++:17
A collection of list operations.
Definition: Lists.h++:12