File indexing completed on 2024-05-19 04:49:28
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef AMAROK_METAKEYS_H 0018 #define AMAROK_METAKEYS_H 0019 0020 #include "core/amarokcore_export.h" 0021 #include "core/meta/forward_declarations.h" 0022 0023 #include <QHash> 0024 #include <QString> 0025 0026 class TestMetaAlbumKey; 0027 class TestMetaTrackKey; 0028 0029 namespace Meta 0030 { 0031 0032 /** The AlbumKey can be used when an album needs to be identified independent of a collection */ 0033 class AMAROKCORE_EXPORT AlbumKey 0034 { 0035 public: 0036 AlbumKey(); 0037 explicit AlbumKey( const QString &name, const QString &artistName ); 0038 explicit AlbumKey( const AlbumPtr &album ); 0039 0040 AlbumKey& operator=( const AlbumKey &o ); 0041 bool operator<( const AlbumKey &other ) const; 0042 0043 QString albumName() const 0044 { return m_albumName; } 0045 0046 QString artistName() const 0047 { return m_artistName; } 0048 0049 private: 0050 QString m_albumName; 0051 QString m_artistName; 0052 0053 friend bool operator==( const AlbumKey &k1, const AlbumKey &k2 ); 0054 friend uint qHash( const AlbumKey &key ); 0055 0056 // Required for unit testing 0057 friend class ::TestMetaAlbumKey; 0058 }; 0059 0060 /** The TrackKey can be used when an album needs to be identified independent of a collection */ 0061 class AMAROKCORE_EXPORT TrackKey 0062 { 0063 public: 0064 TrackKey(); 0065 explicit TrackKey( const TrackPtr &track ); 0066 0067 TrackKey& operator=( const TrackKey &o ); 0068 0069 private: 0070 QString m_trackName; 0071 int m_discNumber; 0072 int m_trackNumber; 0073 QString m_albumName; 0074 QString m_artistName; 0075 0076 friend bool operator==( const TrackKey &k1, const TrackKey &k2 ); 0077 friend uint qHash( const TrackKey &key ); 0078 0079 // Required for unit testing 0080 friend class ::TestMetaTrackKey; 0081 }; 0082 0083 0084 inline bool 0085 operator==( const TrackKey &k1, const TrackKey &k2 ) 0086 { 0087 return k1.m_trackName == k2.m_trackName && 0088 k1.m_discNumber == k2.m_discNumber && 0089 k1.m_trackNumber == k2.m_trackNumber && 0090 k1.m_albumName == k2.m_albumName && 0091 k1.m_artistName == k2.m_artistName; 0092 } 0093 0094 inline uint 0095 qHash( const TrackKey &key ) 0096 { 0097 return qHash( key.m_trackName ) + 17 * qHash( key.m_albumName ) + 0098 31 * qHash( key.m_artistName ) + 13 * key.m_discNumber + 11 * key.m_trackNumber; 0099 } 0100 0101 inline bool 0102 operator==( const AlbumKey &k1, const AlbumKey &k2 ) 0103 { 0104 return k1.m_albumName == k2.m_albumName && k1.m_artistName == k2.m_artistName; 0105 } 0106 0107 inline uint 0108 qHash( const AlbumKey &key ) 0109 { 0110 return qHash( key.m_albumName ) + 17 * qHash( key.m_artistName ); 0111 } 0112 0113 } 0114 0115 #endif