Cppcheck - HTML report - digiKam-master-rev-960d3ce42d

# Cppcheck report - digiKam-master-rev-960d3ce42d: ../../core/utilities/geolocation/engine/geodata/data/GeoDataGeometry.cpp

      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
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    /* ============================================================
     *
     * This file is a part of digiKam project
     * https://www.digikam.org
     *
     * Date        : 2023-05-15
     * Description : geolocation engine based on Marble.
     *               (c) 2007-2022 Marble Team
     *               https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
     *
     * SPDX-FileCopyrightText: 2023-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
     *
     * SPDX-License-Identifier: LGPL-2.1-or-later
     *
     * ============================================================ */

    #include "GeoDataGeometry.h"
    #include "GeoDataGeometry_p.h"

    // Qt includes

    #include <QDataStream>

    // Local includes

    #include "GeoDataLinearRing.h"
    #include "GeoDataLineString.h"
    #include "GeoDataModel.h"
    #include "GeoDataMultiGeometry.h"
    #include "GeoDataMultiTrack.h"
    #include "GeoDataPoint.h"
    #include "GeoDataPolygon.h"
    #include "GeoDataTrack.h"
    #include "GeoDataTypes.h"
    #include "digikam_debug.h"

    namespace Marble
    {

    GeoDataGeometry::GeoDataGeometry(const GeoDataGeometry& other)
        : GeoDataObject(),
          d_ptr        (other.d_ptr)
    {
        d_ptr->ref.ref();
    }

    GeoDataGeometry::GeoDataGeometry(GeoDataGeometryPrivate* priv)
        : GeoDataObject(),
          d_ptr        (priv)
    {
        d_ptr->ref.ref();
    }

    GeoDataGeometry::~GeoDataGeometry()
    {
        if (!d_ptr->ref.deref())
        {
            delete d_ptr;
        }
    }

    void GeoDataGeometry::detach()
    {
        if (d_ptr->ref.fetchAndAddRelaxed(0) == 1)
        {
            return;
        }

        GeoDataGeometryPrivate* new_d = d_ptr->copy();

        if (!d_ptr->ref.deref())
        {
            delete d_ptr;
        }

        d_ptr = new_d;
        d_ptr->ref.ref();
    }

    GeoDataGeometry& GeoDataGeometry::operator=(const GeoDataGeometry& other)
    {
        if (this == &other)
        {
            return *this;
        }

        GeoDataObject::operator=(other);

        if (!d_ptr->ref.deref())
        {
            delete d_ptr;
        }

        d_ptr = other.d_ptr;
        d_ptr->ref.ref();

        return *this;
    }

    bool GeoDataGeometry::operator==(const GeoDataGeometry& other) const
    {
        if (nodeType() != other.nodeType())
        {
            return false;
        }

        if      (nodeType() == GeoDataTypes::GeoDataPolygonType)
        {
            const GeoDataPolygon& thisPoly  = static_cast<const GeoDataPolygon&>(*this);
            const GeoDataPolygon& otherPoly = static_cast<const GeoDataPolygon&>(other);

            return (thisPoly == otherPoly);
        }
        else if (nodeType() == GeoDataTypes::GeoDataLinearRingType)
        {
            const GeoDataLinearRing& thisRing  = static_cast<const GeoDataLinearRing&>(*this);
            const GeoDataLinearRing& otherRing = static_cast<const GeoDataLinearRing&>(other);

            return (thisRing == otherRing);
        }
        else if (nodeType() == GeoDataTypes::GeoDataLineStringType)
        {
            const GeoDataLineString& thisLine  = static_cast<const GeoDataLineString&>(*this);
            const GeoDataLineString& otherLine = static_cast<const GeoDataLineString&>(other);

            return (thisLine == otherLine);
        }
        else if (nodeType() == GeoDataTypes::GeoDataModelType)
        {
            const GeoDataModel& thisModel  = static_cast<const GeoDataModel&>(*this);
            const GeoDataModel& otherModel = static_cast<const GeoDataModel&>(other);

            return (thisModel == otherModel);
        }
        else if (nodeType() == GeoDataTypes::GeoDataMultiGeometryType)
        {
            const GeoDataMultiGeometry& thisMG  = static_cast<const GeoDataMultiGeometry&>(*this);
            const GeoDataMultiGeometry& otherMG = static_cast<const GeoDataMultiGeometry&>(other);

            return (thisMG == otherMG);
        }
        else if (nodeType() == GeoDataTypes::GeoDataTrackType)
        {
            const GeoDataTrack& thisTrack  = static_cast<const GeoDataTrack&>(*this);
            const GeoDataTrack& otherTrack = static_cast<const GeoDataTrack&>(other);

            return (thisTrack == otherTrack);
        }
        else if (nodeType() == GeoDataTypes::GeoDataMultiTrackType)
        {
            const GeoDataMultiTrack& thisMT  = static_cast<const GeoDataMultiTrack&>(*this);
            const GeoDataMultiTrack& otherMT = static_cast<const GeoDataMultiTrack&>(other);

            return (thisMT == otherMT);
        }
        else if (nodeType() == GeoDataTypes::GeoDataPointType)
        {
            const GeoDataPoint& thisPoint  = static_cast<const GeoDataPoint&>(*this);
            const GeoDataPoint& otherPoint = static_cast<const GeoDataPoint&>(other);

            return (thisPoint == otherPoint);
        }

        return false;
    }

    bool GeoDataGeometry::extrude() const
    {
        return d_ptr->m_extrude;
    }

    void GeoDataGeometry::setExtrude(bool extrude)<--- Shadow argument
    {
        detach();
        d_ptr->m_extrude = extrude;
    }

    AltitudeMode GeoDataGeometry::altitudeMode() const
    {
        return d_ptr->m_altitudeMode;
    }

    void GeoDataGeometry::setAltitudeMode(const AltitudeMode altitudeMode)<--- Shadow argument
    {
        detach();
        d_ptr->m_altitudeMode = altitudeMode;
    }

    const GeoDataLatLonAltBox& GeoDataGeometry::latLonAltBox() const
    {
        return d_ptr->m_latLonAltBox;
    }

    void GeoDataGeometry::pack(QDataStream& stream) const
    {
        GeoDataObject::pack(stream);

        stream << d_ptr->m_extrude;
        stream << d_ptr->m_altitudeMode;
    }

    void GeoDataGeometry::unpack(QDataStream& stream)
    {
        detach();
        GeoDataObject::unpack(stream);

        int am;
        stream >> d_ptr->m_extrude;
        stream >> am;
        d_ptr->m_altitudeMode = (AltitudeMode) am;
    }

    bool GeoDataGeometry::equals(const GeoDataGeometry& other) const
    {
        return (
                GeoDataObject::equals(other) &&
                (d_ptr->m_extrude      == other.d_ptr->m_extrude) &&
                (d_ptr->m_altitudeMode == other.d_ptr->m_altitudeMode)
               );
    }

    } // namespace Marble