Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
description.h
1 #ifndef HAMCRESTQT_DESCRIPTION_H
2 #define HAMCRESTQT_DESCRIPTION_H
3 
4 #include <QString>
5 #include "tostring_p.h"
6 
7 namespace HamcrestQt {
8 
9 class SelfDescribing;
10 
18 {
19 public:
20  virtual ~Description() {}
21 
25  virtual Description &appendText(const QString &text) = 0;
26 
30  virtual Description &appendDescriptionOf(const SelfDescribing &value) = 0;
31 
35  template <typename T>
36  Description &appendValue(const T &value);
37 
38  Description &appendValue(short value);
39  Description &appendValue(long value);
40  Description &appendValue(float value);
41  Description &appendValue(double value);
42 
43  Description &appendValue(const char *value);
44  Description &appendValue(const QString &value);
45 
46  Description &appendValue(char value);
47  Description &appendValue(const QChar &value);
48 
53  template <typename Iterator>
54  Description &appendList(const QString &start, const QString &separator, const QString &end,
55  Iterator startIterator, Iterator endIterator)
56  {
57  bool separate = false;
58 
59  appendString(start);
60  while (startIterator != endIterator) {
61  if (separate) appendString(separator);
62  SelfDescribing &selfDescribing = dynamic_cast<SelfDescribing&>(**startIterator);
63  appendDescriptionOf(selfDescribing);
64  startIterator++;
65  separate = true;
66  }
67  appendString(end);
68 
69  return *this;
70  }
71 
75  virtual QString toString() const = 0;
76 
77  class NullDescription;
78  static Description &NONE();
79 
80 protected:
81  virtual void appendString(const QString &str) = 0;
82  virtual void append(const QChar &c) = 0;
83 
84  virtual void toCppSyntaxString(const QString &unformatted);
85  virtual void toCppSyntax(const QChar &ch);
86 };
87 
88 
89 template <typename T>
91 {
92  appendString("<");
93  appendString(QTest::toString(value));
94  appendString(">");
95  return *this;
96 }
97 
98 } // namespace HamcrestQt
99 
100 #endif // HAMCRESTQT_DESCRIPTION_H
A description of a Matcher.
Definition: description.h:17
Description & appendValue(const T &value)
Appends an arbitrary value to the description.
Definition: description.h:90
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
virtual QString toString() const =0
Converts the description into a QString value.
virtual Description & appendText(const QString &text)=0
Appends some plain text to the description.
virtual Description & appendDescriptionOf(const SelfDescribing &value)=0
Appends the description of a SelfDescribing value to this description.
The ability of an object to describe itself.
Definition: selfdescribing.h:11