KCal Library
assignmentvisitor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "assignmentvisitor.h"
00021
00022 #include "event.h"
00023 #include "freebusy.h"
00024 #include "journal.h"
00025 #include "todo.h"
00026
00027 #include <kdebug.h>
00028
00029 using namespace KCal;
00030
00031 class AssignmentVisitor::Private
00032 {
00033 public:
00034 Private() : mSource( 0 ) {}
00035
00036 public:
00037 const IncidenceBase *mSource;
00038 };
00039
00040 AssignmentVisitor::AssignmentVisitor() : d( new Private() )
00041 {
00042 }
00043
00044 AssignmentVisitor::~AssignmentVisitor()
00045 {
00046 delete d;
00047 }
00048
00049 bool AssignmentVisitor::assign( IncidenceBase *target, const IncidenceBase *source )
00050 {
00051 Q_ASSERT( target != 0 );
00052 Q_ASSERT( source != 0 );
00053
00054 d->mSource = source;
00055
00056 bool result = target->accept( *this );
00057
00058 d->mSource = 0;
00059
00060 return result;
00061 }
00062
00063 bool AssignmentVisitor::visit( Event *event )
00064 {
00065 Q_ASSERT( event != 0 );
00066
00067 const Event *source = dynamic_cast<const Event*>( d->mSource );
00068 if ( source == 0 ) {
00069 kError(5800) << "Type mismatch: source is" << d->mSource->type()
00070 << "target is" << event->type();
00071 return false;
00072 }
00073
00074 *event = *source;
00075 return true;
00076 }
00077
00078 bool AssignmentVisitor::visit( Todo *todo )
00079 {
00080 Q_ASSERT( todo != 0 );
00081
00082 const Todo *source = dynamic_cast<const Todo*>( d->mSource );
00083 if ( source == 0 ) {
00084 kError(5800) << "Type mismatch: source is" << d->mSource->type()
00085 << "target is" << todo->type();
00086 return false;
00087 }
00088
00089 *todo = *source;
00090 return true;
00091 }
00092
00093 bool AssignmentVisitor::visit( Journal *journal )
00094 {
00095 Q_ASSERT( journal != 0 );
00096
00097 const Journal *source = dynamic_cast<const Journal*>( d->mSource );
00098 if ( source == 0 ) {
00099 kError(5800) << "Type mismatch: source is" << d->mSource->type()
00100 << "target is" << journal->type();
00101 return false;
00102 }
00103
00104 *journal = *source;
00105 return true;
00106 }
00107
00108 bool AssignmentVisitor::visit( FreeBusy *freebusy )
00109 {
00110 Q_ASSERT( freebusy != 0 );
00111
00112 const FreeBusy *source = dynamic_cast<const FreeBusy*>( d->mSource );
00113 if ( source == 0 ) {
00114 kError(5800) << "Type mismatch: source is" << d->mSource->type()
00115 << "target is" << freebusy->type();
00116 return false;
00117 }
00118
00119 *freebusy = *source;
00120 return true;
00121 }
00122
00123