digiKam
albumpointer.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2004-06-15
7  * Description : Albums manager interface.
8  *
9  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_ALBUM_POINTER_H
26 #define DIGIKAM_ALBUM_POINTER_H
27 
28 // Qt includes
29 
30 #include <QList>
31 
32 // Local includes
33 
34 #include "album.h"
35 #include "albummanager.h"
36 
37 namespace Digikam
38 {
39 
45 template <class T = Album>
46 
48 {
49 public:
50 
52  : album(nullptr)
53  {
54  }
55 
56  // cppcheck-suppress noExplicitConstructor
57  AlbumPointer(T* const a) // krazy:exclude=explicit
58  : album(a)
59  {
60  AlbumManager::instance()->addGuardedPointer(album, &album);
61  }
62 
63  // cppcheck-suppress noExplicitConstructor
64  AlbumPointer(const AlbumPointer<T>& p) // krazy:exclude=explicit
65  : album(p.album)
66  {
67  AlbumManager::instance()->addGuardedPointer(album, &album);
68  }
69 
71  {
72  AlbumManager::instance()->removeGuardedPointer(album, &album);
73  }
74 
76  {
77  Album* const oldAlbum = album;
78  album = a;
79  AlbumManager::instance()->changeGuardedPointer(oldAlbum, album, &album);
80 
81  return *this;
82  }
83 
85  {
86  Album* const oldAlbum = album;
87  album = p.album;
88  AlbumManager::instance()->changeGuardedPointer(oldAlbum, album, &album);
89 
90  return *this;
91  }
92 
93  T* operator->() const
94  {
95  return static_cast<T*>(const_cast<Album*>(album));
96  }
97 
98  T& operator*() const
99  {
100  return *static_cast<T*>(const_cast<Album*>(album));
101  }
102 
103  operator T* () const
104  {
105  return static_cast<T*>(const_cast<Album*>(album));
106  }
107 
108  bool operator!() const
109  {
110  return !album;
111  }
112 
113 private:
114 
115  friend class AlbumManager;
116  Album* album;
117 };
118 
119 // ------------------------------------------------------------------------------------
120 
121 template <class T = Album>
122 
123 class AlbumPointerList : public QList<AlbumPointer<T> >
124 {
125 public:
126 
128  {
129  }
130 
131  explicit AlbumPointerList(const AlbumPointerList<T>& list)
132  : QList<AlbumPointer<T> >(list)
133  {
134  }
135 
136  explicit AlbumPointerList(const QList<T*>& list)
137  {
138  operator=(list);
139  }
140 
141  // cppcheck-suppress operatorEqRetRefThis
143  {
144  return QList<AlbumPointer<T> >::operator=(list);
145  }
146 
148  {
149  foreach (T* const t, list)
150  {
151  this->append(AlbumPointer<T>(t));
152  }
153 
154  return *this;
155  }
156 };
157 
158 } // namespace Digikam
159 
160 Q_DECLARE_METATYPE(Digikam::AlbumPointer<>)
161 Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::PAlbum>)
162 Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::TAlbum>)
163 Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::SAlbum>)
164 Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::DAlbum>)
165 
166 #endif // DIGIKAM_ALBUM_POINTER_H
Definition: albummanager.h:73
static AlbumManager * instance()
Definition: albummanager.cpp:39
Definition: albumpointer.h:124
AlbumPointerList()
Definition: albumpointer.h:127
AlbumPointerList(const QList< T * > &list)
Definition: albumpointer.h:136
AlbumPointerList< T > & operator=(const QList< T * > &list)
Definition: albumpointer.h:147
AlbumPointerList(const AlbumPointerList< T > &list)
Definition: albumpointer.h:131
AlbumPointerList< T > & operator=(const AlbumPointerList< T > &list)
Definition: albumpointer.h:142
Definition: albumpointer.h:48
AlbumPointer()
Definition: albumpointer.h:51
T * operator->() const
Definition: albumpointer.h:93
~AlbumPointer()
Definition: albumpointer.h:70
AlbumPointer(T *const a)
Definition: albumpointer.h:57
AlbumPointer(const AlbumPointer< T > &p)
Definition: albumpointer.h:64
AlbumPointer< T > & operator=(T *const a)
Definition: albumpointer.h:75
T & operator*() const
Definition: albumpointer.h:98
AlbumPointer< T > & operator=(const AlbumPointer< T > &p)
Definition: albumpointer.h:84
bool operator!() const
Definition: albumpointer.h:108
Abstract base class for all album types.
Definition: album.h:67
Definition: piwigotalker.h:48
#define T
Definition: datefolderview.cpp:43