My Project
table_id.h
00001 /* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
00015 
00016 #ifndef TABLE_ID_INCLUDED
00017 #define TABLE_ID_INCLUDED
00018 
00019 #include "my_global.h"
00020 
00021 /*
00022   Each table share has a table id, it is mainly used for row based replication.
00023   Meanwhile it is used as table's version too.
00024 */
00025 class Table_id
00026 {
00027 private:
00028   /* In table map event and rows events, table id is 6 bytes.*/
00029   static const ulonglong TABLE_ID_MAX= (~0ULL >> 16);
00030   ulonglong m_id;
00031 
00032 public:
00033   Table_id() : m_id(0) {}
00034   Table_id(ulonglong id) : m_id(id) {}
00035 
00036   ulonglong id() const { return m_id; }
00037   bool is_valid() const { return m_id <= TABLE_ID_MAX; }
00038   bool is_invalid() const { return m_id > TABLE_ID_MAX; }
00039 
00040   void operator=(const Table_id &tid) { m_id = tid.m_id; }
00041   void operator=(ulonglong id) { m_id = id; }
00042 
00043   bool operator==(const Table_id &tid) const { return m_id == tid.m_id; }
00044   bool operator!=(const Table_id &tid) const { return m_id != tid.m_id; }
00045 
00046   /* Support implicit type converting from Table_id to ulonglong */
00047   operator ulonglong() const { return m_id; }
00048 
00049   Table_id operator++(int)
00050   {
00051     Table_id id(m_id);
00052 
00053     /* m_id is reset to 0, when it exceeds the max value. */
00054     m_id = (m_id == TABLE_ID_MAX ? 0 : m_id + 1);
00055 
00056     DBUG_ASSERT(m_id <= TABLE_ID_MAX );
00057     return id;
00058   }
00059 };
00060 
00061 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines