libkcal

assignmentvisitor.cpp
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#include "assignmentvisitor.h"
21
22#include "event.h"
23#include "freebusy.h"
24#include "journal.h"
25#include "todo.h"
26
27#include <kdebug.h>
28
29using namespace KCal;
30
31class AssignmentVisitor::Private
32{
33 public:
34 Private() : mSource( 0 ) {}
35
36 public:
37 const IncidenceBase *mSource;
38};
39
40AssignmentVisitor::AssignmentVisitor() : d( new Private() )
41{
42}
43
45{
46 delete d;
47}
48
50{
51 Q_ASSERT( target != 0 );
52 Q_ASSERT( source != 0 );
53
54 d->mSource = source;
55
56 bool result = target->accept( *this );
57
58 d->mSource = 0;
59
60 return result;
61}
62
64{
65 Q_ASSERT( event != 0 );
66
67 const Event *source = dynamic_cast<const Event*>( d->mSource );
68 if ( source == 0 ) {
69 kdError(5800) << "Type mismatch: source is" << d->mSource->type()
70 << "target is" << event->type();
71 return false;
72 }
73
74 *event = *source;
75 return true;
76}
77
79{
80 Q_ASSERT( todo != 0 );
81
82 const Todo *source = dynamic_cast<const Todo*>( d->mSource );
83 if ( source == 0 ) {
84 kdError(5800) << "Type mismatch: source is" << d->mSource->type()
85 << "target is" << todo->type();
86 return false;
87 }
88
89 *todo = *source;
90 return true;
91}
92
94{
95 Q_ASSERT( journal != 0 );
96
97 const Journal *source = dynamic_cast<const Journal*>( d->mSource );
98 if ( source == 0 ) {
99 kdError(5800) << "Type mismatch: source is" << d->mSource->type()
100 << "target is" << journal->type();
101 return false;
102 }
103
104 *journal = *source;
105 return true;
106}
107
109{
110 Q_ASSERT( freebusy != 0 );
111
112 const FreeBusy *source = dynamic_cast<const FreeBusy*>( d->mSource );
113 if ( source == 0 ) {
114 kdError(5800) << "Type mismatch: source is" << d->mSource->type()
115 << "target is" << freebusy->type();
116 return false;
117 }
118
119 *freebusy = *source;
120 return true;
121}
virtual ~AssignmentVisitor()
Destroys the instance.
bool assign(IncidenceBase *target, const IncidenceBase *source)
Assigns the incidence referenced by source to the incidence referenced by target, first ensuring that...
virtual bool visit(Event *event)
Tries to assign to the given event, using the source passed to assign().
This class provides an Event in the sense of RFC2445.
Definition: event.h:33
This class provides information about free/busy time of a calendar user.
Definition: freebusy.h:41
This class provides the base class common to all calendar components.
Definition: incidencebase.h:46
virtual bool accept(Visitor &)
Accept IncidenceVisitor.
This class provides a Journal in the sense of RFC2445.
Definition: journal.h:34
This class provides a Todo in the sense of RFC2445.
Definition: todo.h:32
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38