File indexing completed on 2024-04-28 15:39:59
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Tuomas Suutari <thsuut@utu.fi> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 This program is distributed in the hope that it will be useful, but 0007 WITHOUT ANY WARRANTY; without even the implied warranty of 0008 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0009 General Public License for more details. 0010 0011 You should have received a copy of the GNU General Public License 0012 along with this program (see the file COPYING); if not, write to the 0013 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 0014 MA 02110-1301 USA. 0015 */ 0016 0017 #ifndef DB_RAWID_H 0018 #define DB_RAWID_H 0019 0020 #include <QDebug> 0021 #include <QVariant> 0022 0023 #ifndef DB_RAWID_IS_PLAIN_INTEGER 0024 0025 namespace DB 0026 { 0027 class RawId; 0028 } 0029 0030 inline int toInt(const DB::RawId rawId); 0031 0032 inline unsigned int qHash(const DB::RawId rawId); 0033 0034 namespace DB 0035 { 0036 0037 class RawId 0038 { 0039 friend inline int ::toInt(const DB::RawId rawId); 0040 friend inline unsigned int ::qHash(const DB::RawId rawId); 0041 0042 public: 0043 RawId() 0044 : m_value(nullValue) 0045 { 0046 } 0047 0048 explicit RawId(int value) 0049 : m_value(value) 0050 { 0051 Q_ASSERT(m_value != nullValue); 0052 Q_ASSERT(m_value > 0); 0053 } 0054 0055 bool operator==(const RawId other) const 0056 { 0057 return m_value == other.m_value; 0058 } 0059 0060 bool operator!=(const RawId other) const 0061 { 0062 return m_value != other.m_value; 0063 } 0064 0065 bool operator<(const RawId other) const 0066 { 0067 return m_value < other.m_value; 0068 } 0069 0070 operator QVariant() const 0071 { 0072 return QVariant(m_value); 0073 } 0074 0075 private: 0076 static const int nullValue = -1; 0077 0078 int m_value; 0079 }; 0080 0081 } // end of namespace DB 0082 0083 inline int toInt(const DB::RawId rawId) 0084 { 0085 Q_ASSERT(rawId != DB::RawId()); 0086 return rawId.m_value; 0087 } 0088 0089 inline unsigned int qHash(const DB::RawId rawId) 0090 { 0091 return rawId.m_value; 0092 } 0093 0094 inline QDebug operator<<(QDebug d, const DB::RawId rawId) 0095 { 0096 return (d << toInt(rawId)); 0097 } 0098 0099 #else 0100 0101 namespace DB 0102 { 0103 0104 typedef int RawId; 0105 0106 } // end of namespace DB 0107 0108 inline int toInt(const DB::RawId rawId) 0109 { 0110 return rawId; 0111 } 0112 0113 #endif 0114 0115 #endif // DB_RAWID_H 0116 // vi:expandtab:tabstop=4 shiftwidth=4: