libkcal

assignmentvisitor.cpp

00001 /*
00002     Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
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     kdError(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     kdError(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     kdError(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     kdError(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 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Home | KDE Accessibility Home | Description of Access Keys