File indexing completed on 2024-05-12 15:31:19

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 // Self
0007 #include "BBCStation.h"
0008 
0009 // Marble
0010 #include "GeoDataCoordinates.h"
0011 
0012 // Qt
0013 #include <QAtomicInt>
0014 #include <QString>
0015 
0016 namespace Marble
0017 {
0018 
0019 class BBCStationPrivate
0020 {
0021  public:
0022     BBCStationPrivate()
0023             : m_bbcId( 0 ),
0024               m_priority( 0 ),
0025               ref( 1 )
0026     {
0027     }
0028 
0029     BBCStationPrivate( const BBCStationPrivate &other )
0030             : m_name( other.m_name ),
0031               m_coordinate( other.m_coordinate ),
0032               m_bbcId( other.m_bbcId ),
0033               m_priority( other.m_priority ),
0034               ref( other.ref )
0035     {
0036     }
0037 
0038     BBCStationPrivate& operator=( const BBCStationPrivate &other )
0039     {
0040         m_name = other.m_name;
0041         m_coordinate = other.m_coordinate;
0042         m_bbcId = other.m_bbcId;
0043         m_priority = other.m_priority;
0044         ref = other.ref;
0045         return *this;
0046     }
0047 
0048     QString            m_name;
0049     GeoDataCoordinates m_coordinate;
0050     quint32            m_bbcId;
0051     quint8             m_priority;
0052 
0053     QAtomicInt ref;
0054 };
0055 
0056 BBCStation::BBCStation()
0057         : d ( new BBCStationPrivate() )
0058 {
0059 }
0060 
0061 BBCStation::BBCStation( const BBCStation& other )
0062         : d( other.d )
0063 {
0064     d->ref.ref();
0065 }
0066 
0067 BBCStation::~BBCStation()
0068 {
0069     if ( !d->ref.deref() )
0070         delete d;
0071 }
0072 
0073 void BBCStation::detach()
0074 {
0075     qAtomicDetach( d );
0076 }
0077 
0078 BBCStation& BBCStation::operator=( const BBCStation &other )
0079 {
0080     qAtomicAssign( d, other.d );
0081     return *this;
0082 }
0083 
0084 bool BBCStation::operator<( const BBCStation& other ) const
0085 {
0086     return priority() > other.priority();
0087 }
0088 
0089 QString BBCStation::name() const
0090 {
0091     return d->m_name;
0092 }
0093 
0094 void BBCStation::setName( const QString& name )
0095 {
0096     detach();
0097     d->m_name = name;
0098 }
0099 
0100 GeoDataCoordinates BBCStation::coordinate() const
0101 {
0102     return d->m_coordinate;
0103 }
0104 
0105 void BBCStation::setCoordinate( const GeoDataCoordinates& coordinate )
0106 {
0107     detach();
0108     d->m_coordinate = coordinate;
0109 }
0110 
0111 quint32 BBCStation::bbcId() const
0112 {
0113     return d->m_bbcId;
0114 }
0115 
0116 void BBCStation::setBbcId( quint32 id )
0117 {
0118     detach();
0119     d->m_bbcId = id;
0120 }
0121 
0122 quint8 BBCStation::priority() const
0123 {
0124     return d->m_priority;
0125 }
0126 
0127 void BBCStation::setPriority( quint8 priority )
0128 {
0129     detach();
0130     d->m_priority = priority;
0131 }
0132 
0133 } // namespace Marble