MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_id.h
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 as published by
5  the Free Software Foundation; version 2 of the License.
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 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 TABLE_ID_INCLUDED
17 #define TABLE_ID_INCLUDED
18 
19 #include "my_global.h"
20 
21 /*
22  Each table share has a table id, it is mainly used for row based replication.
23  Meanwhile it is used as table's version too.
24 */
25 class Table_id
26 {
27 private:
28  /* In table map event and rows events, table id is 6 bytes.*/
29  static const ulonglong TABLE_ID_MAX= (~0ULL >> 16);
30  ulonglong m_id;
31 
32 public:
33  Table_id() : m_id(0) {}
34  Table_id(ulonglong id) : m_id(id) {}
35 
36  ulonglong id() const { return m_id; }
37  bool is_valid() const { return m_id <= TABLE_ID_MAX; }
38  bool is_invalid() const { return m_id > TABLE_ID_MAX; }
39 
40  void operator=(const Table_id &tid) { m_id = tid.m_id; }
41  void operator=(ulonglong id) { m_id = id; }
42 
43  bool operator==(const Table_id &tid) const { return m_id == tid.m_id; }
44  bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; }
45 
46  /* Support implicit type converting from Table_id to ulonglong */
47  operator ulonglong() const { return m_id; }
48 
49  Table_id operator++(int)
50  {
51  Table_id id(m_id);
52 
53  /* m_id is reset to 0, when it exceeds the max value. */
54  m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1);
55 
56  DBUG_ASSERT(m_id <= TABLE_ID_MAX );
57  return id;
58  }
59 };
60 
61 #endif