MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttributeOffset.hpp
1 /*
2  Copyright (C) 2003-2007 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef ATTRIBUTE_OFFSET_HPP
20 #define ATTRIBUTE_OFFSET_HPP
21 
23  friend class Dbtup;
24 
25 public:
26  static void setOffset(Uint32 & desc, Uint32 offset);
27  static void setCharsetPos(Uint32 & desc, Uint32 offset);
28  static void setNullFlagPos(Uint32 & desc, Uint32 offset);
29 
30  static Uint32 getOffset(const Uint32 &);
31  static bool getCharsetFlag(const Uint32 &);
32  static Uint32 getCharsetPos(const Uint32 &);
33  static Uint32 getNullFlagPos(const Uint32 &);
34  static Uint32 getNullFlagOffset(const Uint32 &);
35  static Uint32 getNullFlagByteOffset(const Uint32 & desc);
36  static Uint32 getNullFlagBitOffset(const Uint32 &);
37 
38  static Uint32 getMaxOffset();
39 
40  Uint32 m_data;
41 
42  friend class NdbOut& operator<<(class NdbOut&, const AttributeOffset&);
43 };
44 
60 #define AO_ATTRIBUTE_OFFSET_SHIFT 0
61 #define AO_ATTRIBUTE_OFFSET_MASK 0x7ff
62 
63 #define AO_CHARSET_FLAG_SHIFT 11
64 #define AO_CHARSET_POS_SHIFT 12
65 #define AO_CHARSET_POS_MASK 127
66 
67 #define AO_NULL_FLAG_POS_MASK 0xfff // f+w
68 #define AO_NULL_FLAG_POS_SHIFT 20
69 
70 #define AO_NULL_FLAG_WORD_MASK 31 // f
71 #define AO_NULL_FLAG_OFFSET_SHIFT 5
72 #define AO_NULL_FLAG_BYTE_OFFSET_SHIFT 3
73 
74 inline
75 void
76 AttributeOffset::setOffset(Uint32 & desc, Uint32 offset){
77  ASSERT_MAX(offset, AO_ATTRIBUTE_OFFSET_MASK, "AttributeOffset::setOffset");
78  desc &= ~(Uint32)(AO_ATTRIBUTE_OFFSET_MASK << AO_ATTRIBUTE_OFFSET_SHIFT);
79  desc |= (offset << AO_ATTRIBUTE_OFFSET_SHIFT);
80 }
81 
82 inline
83 void
84 AttributeOffset::setCharsetPos(Uint32 & desc, Uint32 offset) {
85  ASSERT_MAX(offset, AO_CHARSET_POS_MASK, "AttributeOffset::setCharsetPos");
86  desc |= (1 << AO_CHARSET_FLAG_SHIFT);
87  desc |= (offset << AO_CHARSET_POS_SHIFT);
88 }
89 
90 inline
91 void
92 AttributeOffset::setNullFlagPos(Uint32 & desc, Uint32 pos){
93  ASSERT_MAX(pos, AO_NULL_FLAG_POS_MASK, "AttributeOffset::setNullFlagPos");
94  desc |= (pos << AO_NULL_FLAG_POS_SHIFT);
95 }
96 
97 inline
98 Uint32
99 AttributeOffset::getOffset(const Uint32 & desc)
100 {
101  return (desc >> AO_ATTRIBUTE_OFFSET_SHIFT) & AO_ATTRIBUTE_OFFSET_MASK;
102 }
103 
104 inline
105 bool
106 AttributeOffset::getCharsetFlag(const Uint32 & desc)
107 {
108  return (desc >> AO_CHARSET_FLAG_SHIFT) & 1;
109 }
110 
111 inline
112 Uint32
113 AttributeOffset::getCharsetPos(const Uint32 & desc)
114 {
115  return (desc >> AO_CHARSET_POS_SHIFT) & AO_CHARSET_POS_MASK;
116 }
117 
118 inline
119 Uint32
120 AttributeOffset::getNullFlagPos(const Uint32 & desc)
121 {
122  return ((desc >> AO_NULL_FLAG_POS_SHIFT) & AO_NULL_FLAG_POS_MASK);
123 }
124 
125 /* Offset of NULL bit in 32-bit words. */
126 inline
127 Uint32
128 AttributeOffset::getNullFlagOffset(const Uint32 & desc)
129 {
130  return (getNullFlagPos(desc) >> AO_NULL_FLAG_OFFSET_SHIFT);
131 }
132 
133 /* Offset of NULL bit in bytes. */
134 inline
135 Uint32
136 AttributeOffset::getNullFlagByteOffset(const Uint32 & desc)
137 {
138  return (getNullFlagPos(desc) >> AO_NULL_FLAG_BYTE_OFFSET_SHIFT);
139 }
140 
141 inline
142 Uint32
143 AttributeOffset::getNullFlagBitOffset(const Uint32 & desc)
144 {
145  return (getNullFlagPos(desc) & AO_NULL_FLAG_WORD_MASK);
146 }
147 
148 inline
149 Uint32
150 AttributeOffset::getMaxOffset()
151 {
152  return AO_ATTRIBUTE_OFFSET_MASK;
153 }
154 
155 class NdbOut&
156 operator<<(class NdbOut&, const AttributeOffset&);
157 
158 #endif