From 39927bbadf823b292fcca1fe6efa7f7870634b73 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 13 Apr 2024 09:06:51 +0200 Subject: [PATCH] Turn PgAttribute::Key into class instead of alias for a std::tuple. This improves readability as the fields are now named instead of numbered. --- pglablib/catalog/PgAttribute.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pglablib/catalog/PgAttribute.h b/pglablib/catalog/PgAttribute.h index 3898090..4e07025 100644 --- a/pglablib/catalog/PgAttribute.h +++ b/pglablib/catalog/PgAttribute.h @@ -21,7 +21,19 @@ public: Stored }; - using Key = std::tuple; + class Key { + public: + Key() = default; + Key(Oid relationId, int16_t num) + : RelationId(relationId) + , Num(num) + {} + + std::strong_ordering operator <=> (const Key &rhs) const = default; + private: + Oid RelationId = InvalidOid; + int16_t Num = 0; + }; Oid relid = InvalidOid; QString name; @@ -47,9 +59,22 @@ public: QString sername, serschema; // serial sequence name and schema QString description; ///< from pg_description - bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); } + Key key() const + { + return Key(relid, num); + } + + std::strong_ordering operator <=> (const Key& rhs) const + { + return key() <=> rhs; + } + + bool operator==(const Key &k) const + { + return key() == k; + } + bool operator==(const QString &n) const { return name == n; } - bool operator<(Key _k) const { return relid < std::get<0>(_k) || (relid == std::get<0>(_k) && num < std::get<1>(_k)); } bool operator<(const PgAttribute &rhs) const { return relid < rhs.relid || (relid == rhs.relid && num < rhs.num); } /// Return the part of the SQL create statement that can be reused for both the CREATE TABLE and ALTER TABLE ADD COLUMN