MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttributeDescriptor.hpp
1 /*
2  Copyright (C) 2003-2007 MySQL AB, 2009 Sun Microsystems, Inc.
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_DESCRIPTOR_HPP
20 #define ATTRIBUTE_DESCRIPTOR_HPP
21 
23  friend class Dbdict;
24  friend class Dbtc;
25  friend class Dbacc;
26  friend class Dbtup;
27  friend class Dbtux;
28  friend class Dblqh;
29  friend class SimulatedBlock;
30 
31 public:
32  static void setType(Uint32 &, Uint32 type);
33  static void setSize(Uint32 &, Uint32 size);
34  static void setArrayType(Uint32 &, Uint32 arrayType);
35  static void setArraySize(Uint32 &, Uint32 arraySize);
36  static void setNullable(Uint32 &, Uint32 nullable);
37  static void setDKey(Uint32 &, Uint32 dkey);
38  static void setPrimaryKey(Uint32 &, Uint32 dkey);
39  static void setDynamic(Uint32 &, Uint32 dynamicInd);
40  static void setDiskBased(Uint32 &, Uint32 val);
41 
42  static Uint32 getType(const Uint32 &);
43  static Uint32 getSize(const Uint32 &);
44  static Uint32 getSizeInBytes(const Uint32 &);
45  static Uint32 getSizeInWords(const Uint32 &);
46  static Uint32 getArrayType(const Uint32 &);
47  static Uint32 getArraySize(const Uint32 &);
48  static Uint32 getNullable(const Uint32 &);
49  static Uint32 getDKey(const Uint32 &);
50  static Uint32 getPrimaryKey(const Uint32 &);
51  static Uint32 getDynamic(const Uint32 &);
52  static Uint32 getDiskBased(const Uint32 &);
53 
54  static void clearArrayType(Uint32 &);
55 
56  Uint32 m_data;
57 };
58 
84 #define AD_ARRAY_TYPE_SHIFT (0)
85 #define AD_ARRAY_TYPE_MASK (3)
86 
87 #define AD_TYPE_SHIFT (2)
88 #define AD_TYPE_MASK (31)
89 
90 #define AD_SIZE_SHIFT (8)
91 #define AD_SIZE_MASK (7)
92 
93 #define AD_SIZE_IN_BYTES_SHIFT (3)
94 #define AD_SIZE_IN_WORDS_OFFSET (31)
95 #define AD_SIZE_IN_WORDS_SHIFT (5)
96 
97 #define AD_DISK_SHIFT (11)
98 #define AD_NULLABLE_SHIFT (12)
99 #define AD_DISTR_KEY_SHIFT (13)
100 #define AD_PRIMARY_KEY (14)
101 #define AD_DYNAMIC (15)
102 
103 #define AD_ARRAY_SIZE_SHIFT (16)
104 #define AD_ARRAY_SIZE_MASK (65535)
105 
106 inline
107 void
108 AttributeDescriptor::setType(Uint32 & desc, Uint32 type){
109  assert(type <= AD_TYPE_MASK);
110  desc |= (type << AD_TYPE_SHIFT);
111 }
112 
113 inline
114 void
115 AttributeDescriptor::setSize(Uint32 & desc, Uint32 size){
116  assert(size <= AD_SIZE_MASK);
117  desc |= (size << AD_SIZE_SHIFT);
118 }
119 
120 inline
121 void
122 AttributeDescriptor::setArrayType(Uint32 & desc, Uint32 arrayType){
123  assert(arrayType <= AD_ARRAY_TYPE_MASK);
124  desc |= (arrayType << AD_ARRAY_TYPE_SHIFT);
125 }
126 
127 inline
128 void
129 AttributeDescriptor::clearArrayType(Uint32 & desc)
130 {
131  desc &= ~Uint32(AD_ARRAY_TYPE_MASK << AD_ARRAY_TYPE_SHIFT);
132 }
133 
134 inline
135 void
136 AttributeDescriptor::setArraySize(Uint32 & desc, Uint32 arraySize){
137  assert(arraySize <= AD_ARRAY_SIZE_MASK);
138  desc |= (arraySize << AD_ARRAY_SIZE_SHIFT);
139 }
140 
141 inline
142 void
143 AttributeDescriptor::setNullable(Uint32 & desc, Uint32 nullable){
144  assert(nullable <= 1);
145  desc |= (nullable << AD_NULLABLE_SHIFT);
146 }
147 
148 inline
149 void
150 AttributeDescriptor::setDKey(Uint32 & desc, Uint32 dkey){
151  assert(dkey <= 1);
152  desc |= (dkey << AD_DISTR_KEY_SHIFT);
153 }
154 
155 inline
156 void
157 AttributeDescriptor::setPrimaryKey(Uint32 & desc, Uint32 dkey){
158  assert(dkey <= 1);
159  desc |= (dkey << AD_PRIMARY_KEY);
160 }
161 
162 inline
163 void
164 AttributeDescriptor::setDynamic(Uint32 & desc, Uint32 dynamic){
165  assert(dynamic <= 1);
166  desc |= (dynamic << AD_DYNAMIC);
167 }
168 
169 inline
170 void
171 AttributeDescriptor::setDiskBased(Uint32 & desc, Uint32 val)
172 {
173  assert(val <= 1);
174  desc |= (val << AD_DISK_SHIFT);
175 }
176 
180 inline
181 Uint32
182 AttributeDescriptor::getType(const Uint32 & desc){
183  return (desc >> AD_TYPE_SHIFT) & AD_TYPE_MASK;
184 }
185 
186 inline
187 Uint32
188 AttributeDescriptor::getSize(const Uint32 & desc){
189  return (desc >> AD_SIZE_SHIFT) & AD_SIZE_MASK;
190 }
191 
192 inline
193 Uint32
194 AttributeDescriptor::getSizeInBytes(const Uint32 & desc){
195  return (getArraySize(desc) << getSize(desc))
196  >> AD_SIZE_IN_BYTES_SHIFT;
197 }
198 
199 inline
200 Uint32
201 AttributeDescriptor::getSizeInWords(const Uint32 & desc){
202  return ((getArraySize(desc) << getSize(desc))
203  + AD_SIZE_IN_WORDS_OFFSET)
204  >> AD_SIZE_IN_WORDS_SHIFT;
205 }
206 
207 inline
208 Uint32
209 AttributeDescriptor::getArrayType(const Uint32 & desc){
210  return (desc >> AD_ARRAY_TYPE_SHIFT) & AD_ARRAY_TYPE_MASK;
211 }
212 
213 inline
214 Uint32
215 AttributeDescriptor::getArraySize(const Uint32 & desc){
216  return (desc >> AD_ARRAY_SIZE_SHIFT) & AD_ARRAY_SIZE_MASK;
217 }
218 
219 inline
220 Uint32
221 AttributeDescriptor::getNullable(const Uint32 & desc){
222  return (desc >> AD_NULLABLE_SHIFT) & 1;
223 }
224 
225 inline
226 Uint32
227 AttributeDescriptor::getDKey(const Uint32 & desc){
228  return (desc >> AD_DISTR_KEY_SHIFT) & 1;
229 }
230 
231 inline
232 Uint32
233 AttributeDescriptor::getPrimaryKey(const Uint32 & desc){
234  return (desc >> AD_PRIMARY_KEY) & 1;
235 }
236 
237 inline
238 Uint32
239 AttributeDescriptor::getDynamic(const Uint32 & desc){
240  return (desc >> AD_DYNAMIC) & 1;
241 }
242 
243 inline
244 Uint32
245 AttributeDescriptor::getDiskBased(const Uint32 & desc)
246 {
247  return (desc >> AD_DISK_SHIFT) & 1;
248 }
249 
250 class NdbOut&
251 operator<<(class NdbOut&, const AttributeDescriptor&);
252 
253 #endif