libkcal

comparisonvisitor.cpp
1 /*
2  Copyright 2009 Ingo Klöcker <kloecker@kde.org>
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 "comparisonvisitor.h"
21 #include "event.h"
22 #include "freebusy.h"
23 #include "journal.h"
24 #include "todo.h"
25 
26 using namespace KCal;
27 
28 class ComparisonVisitor::Private
29 {
30  public:
31  Private() : mReference( 0 ) {}
32 
33  public:
34  const IncidenceBase *mReference;
35 };
36 
38 {
39 }
40 
42 {
43  delete d;
44 }
45 
46 bool ComparisonVisitor::compare( IncidenceBase *incidence, const IncidenceBase *reference )
47 {
48  d->mReference = reference;
49 
50  const bool result = incidence ? incidence->accept( *this ) : reference == 0;
51 
52  d->mReference = 0;
53 
54  return result;
55 }
56 
58 {
59  Q_ASSERT( event != 0 );
60 
61  const Event *refEvent = dynamic_cast<const Event*>( d->mReference );
62  if ( refEvent ) {
63  return *event == *refEvent;
64  } else {
65  // refEvent is no Event and thus cannot be equal to event
66  return false;
67  }
68 }
69 
71 {
72  Q_ASSERT( todo != 0 );
73 
74  const Todo *refTodo = dynamic_cast<const Todo*>( d->mReference );
75  if ( refTodo ) {
76  return *todo == *refTodo;
77  } else {
78  // refTodo is no Todo and thus cannot be equal to todo
79  return false;
80  }
81 }
82 
84 {
85  Q_ASSERT( journal != 0 );
86 
87  const Journal *refJournal = dynamic_cast<const Journal*>( d->mReference );
88  if ( refJournal ) {
89  return *journal == *refJournal;
90  } else {
91  // refJournal is no Journal and thus cannot be equal to journal
92  return false;
93  }
94 }
95 
97 {
98  Q_ASSERT( freebusy != 0 );
99 
100  const FreeBusy *refFreeBusy = dynamic_cast<const FreeBusy*>( d->mReference );
101  if ( refFreeBusy ) {
102  return *freebusy == *refFreeBusy;
103  } else {
104  // refFreeBusy is no FreeBusy and thus cannot be equal to freebusy
105  return false;
106  }
107 }
ComparisonVisitor()
Creates a visitor instance.
virtual ~ComparisonVisitor()
Destroys the instance.
virtual bool visit(Event *event)
Compares the event referenced by event to the incidence passed to compare().
bool compare(IncidenceBase *incidence, const IncidenceBase *reference)
Compares the incidence referenced by incidence to the incidence referenced by reference.
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