KCal Library
comparisonvisitor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "comparisonvisitor.h"
00021 #include "event.h"
00022 #include "freebusy.h"
00023 #include "journal.h"
00024 #include "todo.h"
00025
00026 using namespace KCal;
00027
00028 class ComparisonVisitor::Private
00029 {
00030 public:
00031 Private() : mReference( 0 ) {}
00032
00033 public:
00034 const IncidenceBase *mReference;
00035 };
00036
00037 ComparisonVisitor::ComparisonVisitor() : d( new Private() )
00038 {
00039 }
00040
00041 ComparisonVisitor::~ComparisonVisitor()
00042 {
00043 delete d;
00044 }
00045
00046 bool ComparisonVisitor::compare( IncidenceBase *incidence, const IncidenceBase *reference )
00047 {
00048 d->mReference = reference;
00049
00050 const bool result = incidence ? incidence->accept( *this ) : reference == 0;
00051
00052 d->mReference = 0;
00053
00054 return result;
00055 }
00056
00057 bool ComparisonVisitor::visit( Event *event )
00058 {
00059 Q_ASSERT( event != 0 );
00060
00061 const Event *refEvent = dynamic_cast<const Event*>( d->mReference );
00062 if ( refEvent ) {
00063 return *event == *refEvent;
00064 } else {
00065
00066 return false;
00067 }
00068 }
00069
00070 bool ComparisonVisitor::visit( Todo *todo )
00071 {
00072 Q_ASSERT( todo != 0 );
00073
00074 const Todo *refTodo = dynamic_cast<const Todo*>( d->mReference );
00075 if ( refTodo ) {
00076 return *todo == *refTodo;
00077 } else {
00078
00079 return false;
00080 }
00081 }
00082
00083 bool ComparisonVisitor::visit( Journal *journal )
00084 {
00085 Q_ASSERT( journal != 0 );
00086
00087 const Journal *refJournal = dynamic_cast<const Journal*>( d->mReference );
00088 if ( refJournal ) {
00089 return *journal == *refJournal;
00090 } else {
00091
00092 return false;
00093 }
00094 }
00095
00096 bool ComparisonVisitor::visit( FreeBusy *freebusy )
00097 {
00098 Q_ASSERT( freebusy != 0 );
00099
00100 const FreeBusy *refFreeBusy = dynamic_cast<const FreeBusy*>( d->mReference );
00101 if ( refFreeBusy ) {
00102 return *freebusy == *refFreeBusy;
00103 } else {
00104
00105 return false;
00106 }
00107 }