1 /* Copyright (c) 2013, 2021, Oracle 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 also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 /** 23 @file table_id.h 24 25 @brief Contains the class Table_id, mainly used for row based replication. 26 */ 27 28 #ifndef TABLE_ID_INCLUDED 29 #define TABLE_ID_INCLUDED 30 #include <stdint.h> 31 #include "wrapper_functions.h" 32 33 /** 34 @class Table_id 35 36 @brief Each table share has a table id, it is mainly used for row based 37 replication. Meanwhile it is used as table's version too. 38 */ 39 class Table_id 40 { 41 private: 42 /* In table map event and rows events, table id is 6 bytes.*/ 43 static const unsigned long long TABLE_ID_MAX= (~0ULL >> 16); 44 uint64_t m_id; 45 46 public: Table_id()47 Table_id() : m_id(0) {} Table_id(unsigned long long id)48 explicit Table_id(unsigned long long id) : m_id(id) {} 49 id()50 unsigned long long id() const { return m_id; } is_valid()51 bool is_valid() const { return m_id <= TABLE_ID_MAX; } 52 53 void operator=(const Table_id &tid) { m_id = tid.m_id; } 54 void operator=(unsigned long long id) { m_id = id; } 55 56 bool operator==(const Table_id &tid) const { return m_id == tid.m_id; } 57 bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; } 58 59 /* Support implicit type converting from Table_id to unsigned long long */ 60 operator unsigned long long() const { return m_id; } 61 62 Table_id operator++(int) 63 { 64 Table_id id(m_id); 65 66 /* m_id is reset to 0, when it exceeds the max value. */ 67 m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1); 68 69 BAPI_ASSERT(m_id <= TABLE_ID_MAX ); 70 return id; 71 } 72 }; 73 74 #endif 75