1 | /* |
2 | Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at> |
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_ASSIGNMENTVISITOR_H |
21 | #define KCAL_ASSIGNMENTVISITOR_H |
22 | |
23 | #include "kcal_export.h" |
24 | |
25 | #include "incidencebase.h" |
26 | |
27 | namespace KCal { |
28 | |
29 | /** |
30 | Helper for type correct assignment of incidences via pointers. |
31 | |
32 | This class provides a way of correctly assigning one incidence to another, |
33 | given two IncidenceBase derived pointers. It effectively provides a virtual |
34 | assignment method which first type checks the two pointers to ensure they |
35 | reference the same incidence type, before performing the assignment. |
36 | |
37 | Usage example: |
38 | @code |
39 | KCal::Incidence *currentIncidence; // assume this is set somewhere else |
40 | KCal::Incidence *updatedIncidence; // assume this is set somewhere else |
41 | |
42 | KCal::AssignmentVisitor visitor; |
43 | |
44 | // assign |
45 | if ( !visitor.assign(currentIncidence, updatedIncidence) ) { |
46 | // not of same type |
47 | } |
48 | @endcode |
49 | |
50 | @author Kevin Krammer \<kevin.krammer@gmx.at\> |
51 | |
52 | @since 4.3 |
53 | */ |
54 | class KCAL_DEPRECATED_EXPORT AssignmentVisitor : public IncidenceBase::Visitor |
55 | { |
56 | public: |
57 | /** |
58 | Creates a visitor instance. |
59 | */ |
60 | AssignmentVisitor(); |
61 | |
62 | /** |
63 | Destroys the instance. |
64 | */ |
65 | virtual ~AssignmentVisitor(); |
66 | |
67 | /** |
68 | Assigns the incidence referenced by @p source to the incidence referenced |
69 | by @p target, first ensuring that the @p source incidence can be cast to |
70 | the same class as the @p target incidence. |
71 | |
72 | Basically it is a virtual equivalent of |
73 | @code |
74 | *target = *source |
75 | @endcode |
76 | |
77 | @param target pointer to the instance to assign to |
78 | @param source pointer to the instance to assign from |
79 | |
80 | @return @c false if the two objects are of different type |
81 | */ |
82 | bool assign( IncidenceBase *target, const IncidenceBase *source ); |
83 | |
84 | /** |
85 | Tries to assign to the given @p event, using the source passed to |
86 | assign(). |
87 | |
88 | @return @c false if the source passed to assign() is not an Event |
89 | */ |
90 | virtual bool visit( Event *event ); |
91 | |
92 | /** |
93 | Tries to assign to the given @p todo, using the source passed to |
94 | assign(). |
95 | |
96 | @return @c false if the source passed to assign() is not a Todo |
97 | */ |
98 | virtual bool visit( Todo *todo ); |
99 | |
100 | /** |
101 | Tries to assign to the given @p journal, using the source passed to |
102 | assign(). |
103 | |
104 | @return @c false if the source passed to assign() is not a Journal |
105 | */ |
106 | virtual bool visit( Journal *journal ); |
107 | |
108 | /** |
109 | Tries to assign to the given @p freebusy, using the source passed to |
110 | assign(). |
111 | |
112 | @return @c false if the source passed to assign() is not a FreeBusy |
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( AssignmentVisitor ) |
123 | }; |
124 | |
125 | } |
126 | |
127 | #endif |
128 | // kate: space-indent on; indent-width 2; replace-tabs on; |
129 | |