Cppcheck - HTML report - digiKam-nl-search-more-criteria-rev-e2466e0973

# Cppcheck report - digiKam-nl-search-more-criteria-rev-e2466e0973: ../../core/libs/album/engine/albumpointer.h

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2004-06-15
     * Description : Albums manager interface.
     *
     * SPDX-FileCopyrightText: 2006-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     * SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
     *
     * SPDX-License-Identifier: GPL-2.0-or-later
     *
     * ============================================================ */

    #pragma once

    // Qt includes

    #include <QList>

    // Local includes

    #include "album.h"
    #include "albummanager.h"

    namespace Digikam
    {

    /**
     * You can use AlbumPointer to store a guarded pointer to Album
     * or one of the subclasses (use template parameter).
     * The pointer will be set to 0 when the album object is deleted.
     */
    template <class T = Album>

    class AlbumPointer
    {
    public:

        AlbumPointer() = default;

        // cppcheck-suppress noExplicitConstructor
        AlbumPointer(T* const a)                    // krazy:exclude=explicit<--- Class 'AlbumPointer < DAlbum >' has a constructor with 1 argument that is not explicit. [+]Class 'AlbumPointer < DAlbum >' has a constructor with 1 argument that is not explicit. Such, so called "Converting constructors", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.<--- Class 'AlbumPointer < Album >' has a constructor with 1 argument that is not explicit. [+]Class 'AlbumPointer < Album >' has a constructor with 1 argument that is not explicit. Such, so called "Converting constructors", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.<--- Class 'AlbumPointer' has a constructor with 1 argument that is not explicit. [+]Class 'AlbumPointer' has a constructor with 1 argument that is not explicit. Such, so called "Converting constructors", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.
            : album(a)
        {
            AlbumManager::instance()->addGuardedPointer(album, &album);
        }

        // cppcheck-suppress noExplicitConstructor
        AlbumPointer(const AlbumPointer<T>& p)      // krazy:exclude=explicit
            : album(p.album)
        {
            AlbumManager::instance()->addGuardedPointer(album, &album);
        }

        ~AlbumPointer()
        {
            AlbumManager::instance()->removeGuardedPointer(album, &album);
        }

        AlbumPointer<T>& operator=(T* const a)
        {
            Album* const oldAlbum = album;
            album                 = a;
            AlbumManager::instance()->changeGuardedPointer(oldAlbum, album, &album);

            return *this;
        }

        AlbumPointer<T>& operator=(const AlbumPointer<T>& p)
        {
            Album* const oldAlbum = album;
            album                 = p.album;
            AlbumManager::instance()->changeGuardedPointer(oldAlbum, album, &album);

            return *this;
        }

        T* operator->() const
        {
            return static_cast<T*>(const_cast<Album*>(album));
        }

        T& operator*() const
        {
            return *static_cast<T*>(const_cast<Album*>(album));
        }

        operator T* () const
        {
            return static_cast<T*>(const_cast<Album*>(album));
        }

        bool operator!() const
        {
            return !album;
        }

    private:

        Album* album = nullptr;

        friend class AlbumManager;
    };

    // ------------------------------------------------------------------------------------

    template <class T = Album>

    class AlbumPointerList : public QList<AlbumPointer<T> >
    {
    public:

        AlbumPointerList()  = default;
        ~AlbumPointerList() = default;

        explicit AlbumPointerList(const AlbumPointerList<T>& list)
            : QList<AlbumPointer<T> >(list)
        {
        }

        explicit AlbumPointerList(const QList<T*>& list)
        {
            operator=(list);
        }

        // cppcheck-suppress operatorEqRetRefThis
        AlbumPointerList<T>& operator=(const AlbumPointerList<T>& list)<--- 'operator=' should return reference to 'this' instance.
        {
            return QList<AlbumPointer<T> >::operator=(list);
        }

        AlbumPointerList<T>& operator=(const QList<T*>& list)
        {
            for (T* const t : std::as_const(list))
            {
                this->append(AlbumPointer<T>(t));
            }

            return *this;
        }
    };

    } // namespace Digikam

    Q_DECLARE_METATYPE(Digikam::AlbumPointer<>)
    Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::PAlbum>)
    Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::TAlbum>)
    Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::SAlbum>)
    Q_DECLARE_METATYPE(Digikam::AlbumPointer<Digikam::DAlbum>)