|
| 1 | +// Copyright (c) 2023-2024 Percona and/or its affiliates. |
| 2 | +// |
| 3 | +// This program is free software; you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU General Public License, version 2.0, |
| 5 | +// as published by the Free Software Foundation. |
| 6 | +// |
| 7 | +// This program is distributed in the hope that it will be useful, |
| 8 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +// GNU General Public License, version 2.0, for more details. |
| 11 | +// |
| 12 | +// You should have received a copy of the GNU General Public License |
| 13 | +// along with this program; if not, write to the Free Software |
| 14 | +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | + |
| 16 | +#ifndef BINSRV_GTIDS_GTID_HPP |
| 17 | +#define BINSRV_GTIDS_GTID_HPP |
| 18 | + |
| 19 | +#include "binsrv/gtids/gtid_fwd.hpp" // IWYU pragma: export |
| 20 | + |
| 21 | +#include "binsrv/gtids/common_types.hpp" |
| 22 | +#include "binsrv/gtids/tag.hpp" |
| 23 | + |
| 24 | +namespace binsrv::gtids { |
| 25 | + |
| 26 | +class gtid { |
| 27 | +public: |
| 28 | + static constexpr char tag_separator{':'}; |
| 29 | + static constexpr char gno_separator{':'}; |
| 30 | + |
| 31 | + gtid() = default; |
| 32 | + |
| 33 | + // NOLINTNEXTLINE(modernize-pass-by-value) |
| 34 | + gtid(const uuid &uuid_component, const tag &tag_component, |
| 35 | + gno_t gno_component) |
| 36 | + : uuid_{uuid_component}, tag_{tag_component}, gno_{gno_component} { |
| 37 | + validate_components(); |
| 38 | + } |
| 39 | + |
| 40 | + gtid(const uuid &uuid_component, gno_t gno_component) |
| 41 | + : uuid_{uuid_component}, tag_{}, gno_{gno_component} { |
| 42 | + validate_components(); |
| 43 | + } |
| 44 | + |
| 45 | + [[nodiscard]] bool is_empty() const noexcept { return gno_ == 0ULL; } |
| 46 | + |
| 47 | + [[nodiscard]] const uuid &get_uuid() const noexcept { return uuid_; } |
| 48 | + |
| 49 | + [[nodiscard]] bool has_tag() const noexcept { return !tag_.is_empty(); } |
| 50 | + [[nodiscard]] const tag &get_tag() const noexcept { return tag_; } |
| 51 | + |
| 52 | + [[nodiscard]] gno_t get_gno() const noexcept { return gno_; } |
| 53 | + |
| 54 | + [[nodiscard]] friend bool operator==(const gtid &first, |
| 55 | + const gtid &second) noexcept = default; |
| 56 | + |
| 57 | +private: |
| 58 | + uuid uuid_{}; |
| 59 | + tag tag_{}; |
| 60 | + gno_t gno_{}; |
| 61 | + |
| 62 | + void validate_components(); |
| 63 | +}; |
| 64 | + |
| 65 | +} // namespace binsrv::gtids |
| 66 | + |
| 67 | +#endif // BINSRV_GTIDS_GTID_HPP |
0 commit comments