1 /* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 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 #ifndef TABLE_ID_INCLUDED 24 #define TABLE_ID_INCLUDED 25 26 #include "my_global.h" 27 28 /* 29 Each table share has a table id, it is mainly used for row based replication. 30 Meanwhile it is used as table's version too. 31 */ 32 class Table_id 33 { 34 private: 35 /* In table map event and rows events, table id is 6 bytes.*/ 36 static const ulonglong TABLE_ID_MAX= (~0ULL >> 16); 37 ulonglong m_id; 38 39 public: Table_id()40 Table_id() : m_id(0) {} Table_id(ulonglong id)41 Table_id(ulonglong id) : m_id(id) {} 42 id()43 ulonglong id() const { return m_id; } is_valid()44 bool is_valid() const { return m_id <= TABLE_ID_MAX; } is_invalid()45 bool is_invalid() const { return m_id > TABLE_ID_MAX; } 46 47 void operator=(const Table_id &tid) { m_id = tid.m_id; } 48 void operator=(ulonglong id) { m_id = id; } 49 50 bool operator==(const Table_id &tid) const { return m_id == tid.m_id; } 51 bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; } 52 53 /* Support implicit type converting from Table_id to ulonglong */ ulonglong()54 operator ulonglong() const { return m_id; } 55 56 Table_id operator++(int) 57 { 58 Table_id id(m_id); 59 60 /* m_id is reset to 0, when it exceeds the max value. */ 61 m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1); 62 63 DBUG_ASSERT(m_id <= TABLE_ID_MAX ); 64 return id; 65 } 66 }; 67 68 #endif 69