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
44AssignmentVisitor::~AssignmentVisitor()
45{
46 delete d;
47}
48
49bool AssignmentVisitor::assign( IncidenceBase *target, const IncidenceBase *source )
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
63bool AssignmentVisitor::visit( Event *event )
64{
65 Q_ASSERT( event != 0 );
66
67 const Event *source = dynamic_cast<const Event*>( d->mSource );
68 if ( source == 0 ) {
69 kError() << "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
78bool AssignmentVisitor::visit( Todo *todo )
79{
80 Q_ASSERT( todo != 0 );
81
82 const Todo *source = dynamic_cast<const Todo*>( d->mSource );
83 if ( source == 0 ) {
84 kError() << "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
93bool AssignmentVisitor::visit( Journal *journal )
94{
95 Q_ASSERT( journal != 0 );
96
97 const Journal *source = dynamic_cast<const Journal*>( d->mSource );
98 if ( source == 0 ) {
99 kError() << "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
108bool AssignmentVisitor::visit( FreeBusy *freebusy )
109{
110 Q_ASSERT( freebusy != 0 );
111
112 const FreeBusy *source = dynamic_cast<const FreeBusy*>( d->mSource );
113 if ( source == 0 ) {
114 kError() << "Type mismatch: source is" << d->mSource->type()
115 << "target is" << freebusy->type();
116 return false;
117 }
118
119 *freebusy = *source;
120 return true;
121}
122
123// kate: space-indent on; indent-width 2; replace-tabs on;
124