Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
isnot.h
1 #ifndef HAMCRESTQT_ISNOT_H
2 #define HAMCRESTQT_ISNOT_H
3 
4 #include <QSharedPointer>
5 
6 #include "basematcher.h"
7 #include "isequal.h"
8 
9 namespace HamcrestQt {
10 
14 template <typename T>
15 class IsNot : public BaseMatcher<T>
16 {
17 public:
18  explicit IsNot(const QSharedPointer<Matcher<T> > &m) : matcher(m) {}
19 
20  virtual bool matches(const T &item) const
21  {
22  return !matcher->matches(item);
23  }
24 
25  virtual void describeTo(Description &description) const
26  {
27  description.appendText("not ").appendDescriptionOf(*matcher);
28  }
29 
30 private:
31  QSharedPointer<Matcher<T> > matcher;
32 };
33 
34 
45 template <typename T>
46 QSharedPointer<Matcher<T> > _not(const QSharedPointer<Matcher<T> > &matcher)
47 {
48  return QSharedPointer<Matcher<T> >(new IsNot<T>(matcher));
49 }
50 
62 template <typename T>
63 QSharedPointer<Matcher<T> > _not(const T &operand)
64 {
65  return _not(equalTo(operand));
66 }
67 
68 // template specialization for c-style string
69 inline QSharedPointer<Matcher<const char*> > _not(const char *operand)
70 {
71  return QSharedPointer<Matcher<const char*> >(new IsNot<const char*>(equalTo(operand)));
72 }
73 
74 } // namespace HamcrestQt
75 
76 #endif // HAMCRESTQT_ISNOT_H
A description of a Matcher.
Definition: description.h:17
A matcher over acceptable values.
Definition: matcher.h:21
virtual bool matches(const T &item) const
Evaluates the matcher for argument item.
Definition: isnot.h:20
BaseClass for all Matcher implementations.
Definition: basematcher.h:17
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: isnot.h:25
virtual Description & appendText(const QString &text)=0
Appends some plain text to the description.
Calculates the logical negation of a matcher.
Definition: isnot.h:15
virtual Description & appendDescriptionOf(const SelfDescribing &value)=0
Appends the description of a SelfDescribing value to this description.
QSharedPointer< Matcher< T > > _not(const QSharedPointer< Matcher< T > > &matcher)
Creates a matcher that wraps an existing matcher, but inverts the logic by which it will match...
Definition: isnot.h:46