Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
anyof.h
1 #ifndef HAMCRESTQT_ANYOF_H
2 #define HAMCRESTQT_ANYOF_H
3 
4 #include <QList>
5 #include <QSharedPointer>
6 
7 #include "shortcutcombination.h"
8 
9 namespace HamcrestQt {
10 
15 template <typename T>
16 class AnyOf : public ShortcutCombination<T>
17 {
18 public:
19  explicit AnyOf(const QList<QSharedPointer<Matcher<T> > > &m) : ShortcutCombination<T>(m) {}
20 
21  virtual bool matches(const T &item) const
22  {
23  return matches(item, true);
24  }
25 
26  virtual void describeTo(Description &description) const
27  {
28  describeTo(description, QStringLiteral("or"));
29  }
30 
33 };
34 
41 template <typename T>
42 QSharedPointer<Matcher<T> > anyOf(const QList<QSharedPointer<Matcher<T> > > &matchers)
43 {
44  return QSharedPointer<Matcher<T> >(new AnyOf<T>(matchers));
45 }
46 
47 template <typename T>
48 QSharedPointer<Matcher<T> > anyOf(const QSharedPointer<Matcher<T> > &first,
49  const QSharedPointer<Matcher<T> > &second)
50 {
51  QList<QSharedPointer<Matcher<T> > > matchers;
52  matchers.append(first);
53  matchers.append(second);
54  return anyOf(matchers);
55 }
56 
57 template <typename T>
58 QSharedPointer<Matcher<T> > anyOf(const QSharedPointer<Matcher<T> > &first,
59  const QSharedPointer<Matcher<T> > &second,
60  const QSharedPointer<Matcher<T> > &third)
61 {
62  QList<QSharedPointer<Matcher<T> > > matchers;
63  matchers.append(first);
64  matchers.append(second);
65  matchers.append(third);
66  return anyOf(matchers);
67 }
68 
69 template <typename T>
70 QSharedPointer<Matcher<T> > anyOf(const QSharedPointer<Matcher<T> > &first,
71  const QSharedPointer<Matcher<T> > &second,
72  const QSharedPointer<Matcher<T> > &third,
73  const QSharedPointer<Matcher<T> > &fourth)
74 {
75  QList<QSharedPointer<Matcher<T> > > matchers;
76  matchers.append(first);
77  matchers.append(second);
78  matchers.append(third);
79  matchers.append(fourth);
80  return anyOf(matchers);
81 }
82 
83 template <typename T>
84 QSharedPointer<Matcher<T> > anyOf(const QSharedPointer<Matcher<T> > &first,
85  const QSharedPointer<Matcher<T> > &second,
86  const QSharedPointer<Matcher<T> > &third,
87  const QSharedPointer<Matcher<T> > &fourth,
88  const QSharedPointer<Matcher<T> > &fifth)
89 {
90  QList<QSharedPointer<Matcher<T> > > matchers;
91  matchers.append(first);
92  matchers.append(second);
93  matchers.append(third);
94  matchers.append(fourth);
95  matchers.append(fifth);
96  return anyOf(matchers);
97 }
98 
99 template <typename T>
100 QSharedPointer<Matcher<T> > anyOf(const QSharedPointer<Matcher<T> > &first,
101  const QSharedPointer<Matcher<T> > &second,
102  const QSharedPointer<Matcher<T> > &third,
103  const QSharedPointer<Matcher<T> > &fourth,
104  const QSharedPointer<Matcher<T> > &fifth,
105  const QSharedPointer<Matcher<T> > &sixth)
106 {
107  QList<QSharedPointer<Matcher<T> > > matchers;
108  matchers.append(first);
109  matchers.append(second);
110  matchers.append(third);
111  matchers.append(fourth);
112  matchers.append(fifth);
113  matchers.append(sixth);
114  return anyOf(matchers);
115 }
116 
117 } // namespace HamcrestQt
118 
119 #endif // HAMCRESTQT_ANYOF_H
QSharedPointer< Matcher< T > > anyOf(const QList< QSharedPointer< Matcher< T > > > &matchers)
Creates a matcher that matches if the examined object matches ANY of the specified matchers...
Definition: anyof.h:42
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: anyof.h:26
A description of a Matcher.
Definition: description.h:17
Calculates the logical disjunction of multiple matchers.
Definition: anyof.h:16
A matcher over acceptable values.
Definition: matcher.h:21
virtual bool matches(const T &item) const
Evaluates the matcher for argument item.
Definition: anyof.h:21
Definition: shortcutcombination.h:12