Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
shortcutcombination.h
1 #ifndef HAMCRESTQT_SHORTCUTCOMBINATION_H
2 #define HAMCRESTQT_SHORTCUTCOMBINATION_H
3 
4 #include <QList>
5 #include <QSharedPointer>
6 
7 #include "basematcher.h"
8 
9 namespace HamcrestQt {
10 
11 template <typename T>
13 {
14 public:
15  explicit ShortcutCombination(const QList<QSharedPointer<Matcher<T> > > &m) : matchers(m) {}
16 
17  void describeTo(Description &description, const QString &op) const
18  {
19  description.appendList(QStringLiteral("("), QString(" %1 ").arg(op), QStringLiteral(")"),
20  matchers.begin(), matchers.end());
21  }
22 
23 protected:
24  virtual bool matches(const T &item, bool shortcut) const
25  {
26  foreach (const QSharedPointer<Matcher<T> > &matcher, matchers) {
27  if (matcher->matches(item) == shortcut) {
28  return shortcut;
29  }
30  }
31 
32  return !shortcut;
33  }
34 
35 private:
36  QList<QSharedPointer<Matcher<T> > > matchers;
37 };
38 
39 } // namespace HamcrestQt
40 
41 #endif // HAMCRESTQT_SHORTCUTCOMBINATION_H
A description of a Matcher.
Definition: description.h:17
A matcher over acceptable values.
Definition: matcher.h:21
Description & appendList(const QString &start, const QString &separator, const QString &end, Iterator startIterator, Iterator endIterator)
Appends a list of SelfDescribing objects to the description.
Definition: description.h:54
BaseClass for all Matcher implementations.
Definition: basematcher.h:17
Definition: shortcutcombination.h:12