1 // Copyright 2010 Jochen Becher
3 // This file is part of MovieSchedule.
5 // MovieSchedule is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // MovieSchedule is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with MovieSchedule. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef CINEMASCHEDULE_H
19 #define CINEMASCHEDULE_H
22 #include "cinemakey.h"
24 #include "scheduleentrykey.h"
25 #include "scheduleentry.h"
26 #include "utils/assertedlock.h"
30 #include <QReadWriteLock>
37 Q_DISABLE_COPY(CinemaSchedule);
39 typedef QHash<CinemaKey, Cinema *> Cinemas;
40 typedef QHash<MovieKey, Movie *> Movies;
41 typedef QSet<QDate> ScheduleDates;
42 typedef QSet<ScheduleEntry> Schedules;
43 typedef QSet<ScheduleEntryKey> ScheduleKeys;
47 AssertedLock *GetLock() const { return const_cast<AssertedLock *>(&_lock); }
51 bool AreAllCinemasLoaded() const { _lock.AssertLockedForRead(); return _all_cinemas_loaded; }
52 void SetAllCinemasLoaded(bool all_cinemas_loaded) { _lock.AssertLockedForWrite(); _all_cinemas_loaded = all_cinemas_loaded; }
53 const Cinemas GetCinemas() const { _lock.AssertLockedForRead(); return _cinemas; }
54 Cinema *FindCinema(const CinemaKey &);
55 const Cinema *FindCinema(const CinemaKey &) const;
56 Cinema *AddCinema(const CinemaKey &);
58 bool AreAllMoviesLoaded() const { _lock.AssertLockedForRead(); return _all_movies_loaded; }
59 void SetAllMoviesLoaded(bool all_movies_loaded) { _lock.AssertLockedForWrite(); _all_movies_loaded = all_movies_loaded; }
60 const Movies GetMovies() const { _lock.AssertLockedForRead(); return _movies; }
61 Movie *FindMovie(const MovieKey &);
62 const Movie *FindMovie(const MovieKey &) const;
63 Movie *AddMovie(const MovieKey &);
65 const ScheduleDates GetScheduleDates() const;
66 const ScheduleDates GetScheduleDates(const Cinema *) const;
67 const ScheduleDates GetScheduleDates(const Movie *) const;
68 ScheduleEntry FindScheduleEntry(const ScheduleEntryKey &) const;
69 const Schedules GetSchedules() const { _lock.AssertLockedForRead(); return _schedules; }
70 const Schedules GetSchedules(const Cinema *) const;
71 const Schedules GetSchedules(const Movie *) const;
72 const ScheduleKeys GetScheduleKeys(const CinemaKey &) const;
73 const ScheduleKeys GetScheduleKeys(const MovieKey &) const;
74 void AddSchedule(const Cinema *, const Movie *, const QTime &start_time, const QDate &date);
78 bool _all_cinemas_loaded;
80 bool _all_movies_loaded;
85 inline int qHash(const QDate &date) { return qHash(date.toJulianDay()); }
87 #endif // CINEMASCHEDULE_H