From cf56b60fd340dc62f90b5b8d3c86d68da347abee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 8 Jul 2017 12:36:08 +0200 Subject: =?UTF-8?q?Remove=20all=20the=20empty=20=E2=80=9Coptions=E2=80=9D?= =?UTF-8?q?=20members=20in=20Column=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using SFINAE to use that member only when it exists. --- src/database/database.hpp | 57 ++++++++++++++--------------------------------- src/database/table.hpp | 14 ++++++++++-- 2 files changed, 29 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/database/database.hpp b/src/database/database.hpp index 8364abc..b5f2ff0 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -20,79 +20,56 @@ class Database public: using time_point = std::chrono::system_clock::time_point; - struct Uuid: Column { static constexpr auto name = "uuid_"; - static constexpr auto options = ""; }; + struct Uuid: Column { static constexpr auto name = "uuid_"; }; - struct Owner: Column { static constexpr auto name = "owner_"; - static constexpr auto options = ""; }; + struct Owner: Column { static constexpr auto name = "owner_"; }; - struct IrcChanName: Column { static constexpr auto name = "ircChanName_"; - static constexpr auto options = ""; }; + struct IrcChanName: Column { static constexpr auto name = "ircChanName_"; }; - struct Channel: Column { static constexpr auto name = "channel_"; - static constexpr auto options = ""; }; + struct Channel: Column { static constexpr auto name = "channel_"; }; - struct IrcServerName: Column { static constexpr auto name = "ircServerName_"; - static constexpr auto options = ""; }; + struct IrcServerName: Column { static constexpr auto name = "ircServerName_"; }; - struct Server: Column { static constexpr auto name = "server_"; - static constexpr auto options = ""; }; + struct Server: Column { static constexpr auto name = "server_"; }; - struct Date: Column { static constexpr auto name = "date_"; - static constexpr auto options = ""; }; + struct Date: Column { static constexpr auto name = "date_"; }; - struct Body: Column { static constexpr auto name = "body_"; - static constexpr auto options = ""; }; + struct Body: Column { static constexpr auto name = "body_"; }; - struct Nick: Column { static constexpr auto name = "nick_"; - static constexpr auto options = ""; }; + struct Nick: Column { static constexpr auto name = "nick_"; }; - struct Pass: Column { static constexpr auto name = "pass_"; - static constexpr auto options = ""; }; + struct Pass: Column { static constexpr auto name = "pass_"; }; struct Ports: Column { static constexpr auto name = "ports_"; - static constexpr auto options = ""; Ports(): Column("6667") {} }; struct TlsPorts: Column { static constexpr auto name = "tlsPorts_"; - static constexpr auto options = ""; TlsPorts(): Column("6697;6670") {} }; - struct Username: Column { static constexpr auto name = "username_"; - static constexpr auto options = ""; }; + struct Username: Column { static constexpr auto name = "username_"; }; - struct Realname: Column { static constexpr auto name = "realname_"; - static constexpr auto options = ""; }; + struct Realname: Column { static constexpr auto name = "realname_"; }; - struct AfterConnectionCommand: Column { static constexpr auto name = "afterConnectionCommand_"; - static constexpr auto options = ""; }; + struct AfterConnectionCommand: Column { static constexpr auto name = "afterConnectionCommand_"; }; - struct TrustedFingerprint: Column { static constexpr auto name = "trustedFingerprint_"; - static constexpr auto options = ""; }; + struct TrustedFingerprint: Column { static constexpr auto name = "trustedFingerprint_"; }; - struct EncodingOut: Column { static constexpr auto name = "encodingOut_"; - static constexpr auto options = ""; }; + struct EncodingOut: Column { static constexpr auto name = "encodingOut_"; }; - struct EncodingIn: Column { static constexpr auto name = "encodingIn_"; - static constexpr auto options = ""; }; + struct EncodingIn: Column { static constexpr auto name = "encodingIn_"; }; struct MaxHistoryLength: Column { static constexpr auto name = "maxHistoryLength_"; - static constexpr auto options = ""; MaxHistoryLength(): Column(20) {} }; struct RecordHistory: Column { static constexpr auto name = "recordHistory_"; - static constexpr auto options = ""; RecordHistory(): Column(true) {}}; - struct RecordHistoryOptional: Column { static constexpr auto name = "recordHistory_"; - static constexpr auto options = ""; }; + struct RecordHistoryOptional: Column { static constexpr auto name = "recordHistory_"; }; struct VerifyCert: Column { static constexpr auto name = "verifyCert_"; - static constexpr auto options = ""; VerifyCert(): Column(true) {} }; struct Persistent: Column { static constexpr auto name = "persistent_"; - static constexpr auto options = ""; Persistent(): Column(false) {} }; using MucLogLineTable = Table; diff --git a/src/database/table.hpp b/src/database/table.hpp index 411ac6a..f2f70bb 100644 --- a/src/database/table.hpp +++ b/src/database/table.hpp @@ -28,6 +28,17 @@ void add_column_to_table(sqlite3* db, const std::string& table_name) } } + +template +void append_option(std::string& s) +{ + s += " "s + ColumnType::options; +} + +template +void append_option(...) +{ } + template class Table { @@ -110,14 +121,13 @@ class Table str += ColumnType::name; str += " "; str += TypeToSQLType::type; - str += " "s + ColumnType::options; + append_option(str); if (N != sizeof...(T) - 1) str += ","; str += "\n"; add_column_create(str); } - template typename std::enable_if::type add_column_create(std::string&) -- cgit v1.2.3