1 | /* |
2 | Copyright 2009 Ingo Klöcker <kloecker@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KCAL_COMPARISONVISITOR_H |
21 | #define KCAL_COMPARISONVISITOR_H |
22 | |
23 | #include "kcal_export.h" |
24 | #include "incidencebase.h" |
25 | |
26 | namespace KCal { |
27 | |
28 | /** |
29 | Helper for type correct comparison of incidences via pointers. |
30 | |
31 | This class provides a way of correctly comparing one incidence to another, |
32 | given two IncidenceBase derived pointers. It effectively provides a virtual |
33 | comparison method which first type checks the two pointers to ensure they |
34 | reference the same incidence type, before performing the comparison. |
35 | |
36 | Usage example: |
37 | @code |
38 | KCal::Incidence *incidence; // assume this is set somewhere else |
39 | KCal::Incidence *referenceIncidence; // assume this is set somewhere else |
40 | |
41 | KCal::ComparisonVisitor visitor; |
42 | |
43 | // compare |
44 | if ( visitor.compare( incidence, referenceIncidence ) ) { |
45 | // incidence and referenceIncidence point to identical incidences |
46 | } |
47 | @endcode |
48 | |
49 | @author Ingo Klöcker <kloecker@kde.org> |
50 | |
51 | @since 4.3 |
52 | */ |
53 | class KCAL_DEPRECATED_EXPORT ComparisonVisitor : public IncidenceBase::Visitor |
54 | { |
55 | public: |
56 | /** |
57 | Creates a visitor instance. |
58 | */ |
59 | ComparisonVisitor(); |
60 | |
61 | /** |
62 | Destroys the instance. |
63 | */ |
64 | virtual ~ComparisonVisitor(); |
65 | |
66 | /** |
67 | Compares the incidence referenced by @p incidence to the incidence |
68 | referenced by @p reference. Returns true, if the incidence referenced |
69 | by @p incidence is identical to the incidence referenced by @p reference. |
70 | Also returns true, if @p incidence and @p reference are both @c 0. |
71 | |
72 | Basically it is a virtual equivalent of |
73 | @code |
74 | *incidence == *reference |
75 | @endcode |
76 | |
77 | @param incidence pointer to the incidence to compare with the reference incidence |
78 | @param reference pointer to the reference incidence |
79 | |
80 | @return @c true if the two incidences are identical or both @c 0 |
81 | */ |
82 | bool compare( IncidenceBase *incidence, const IncidenceBase *reference ); |
83 | |
84 | /** |
85 | Compares the event referenced by @p event to the incidence passed to |
86 | compare(). |
87 | |
88 | @return @c true if the event is identical to the reference incidence |
89 | */ |
90 | virtual bool visit( Event *event ); |
91 | |
92 | /** |
93 | Compares the todo referenced by @p todo to the incidence passed to |
94 | compare(). |
95 | |
96 | @return @c true if the todo is identical to the reference incidence |
97 | */ |
98 | virtual bool visit( Todo *todo ); |
99 | |
100 | /** |
101 | Compares the journal referenced by @p journal to the incidence passed to |
102 | compare(). |
103 | |
104 | @return @c true if the journal is identical to the reference incidence |
105 | */ |
106 | virtual bool visit( Journal *journal ); |
107 | |
108 | /** |
109 | Compares the freebusy object referenced by @p freebusy to the incidence passed to |
110 | compare(). |
111 | |
112 | @return @c true if the freebusy object is identical to the reference incidence |
113 | */ |
114 | virtual bool visit( FreeBusy *freebusy ); |
115 | |
116 | private: |
117 | //@cond PRIVATE |
118 | class Private; |
119 | Private *const d; |
120 | //@endcond |
121 | |
122 | Q_DISABLE_COPY( ComparisonVisitor ) |
123 | }; |
124 | |
125 | } |
126 | |
127 | #endif // KCAL_COMPARISONVISITOR_H |
128 | |