1
/* Copyright (C) 2003 MySQL AB
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#ifndef ATTRIBUTE_OFFSET_HPP
17
#define ATTRIBUTE_OFFSET_HPP
19
class AttributeOffset {
23
static void setOffset(Uint32 & desc, Uint32 offset);
24
static void setCharsetPos(Uint32 & desc, Uint32 offset);
25
static void setNullFlagPos(Uint32 & desc, Uint32 offset);
27
static Uint32 getOffset(const Uint32 &);
28
static bool getCharsetFlag(const Uint32 &);
29
static Uint32 getCharsetPos(const Uint32 &);
30
static Uint32 getNullFlagPos(const Uint32 &);
31
static Uint32 getNullFlagOffset(const Uint32 &);
32
static Uint32 getNullFlagBitOffset(const Uint32 &);
36
friend class NdbOut& operator<<(class NdbOut&, const AttributeOffset&);
40
* Allow for 4096 attributes, all nullable, and for 128 different
43
* a = Attribute offset - 11 bits 0-10 ( addr word in 8 kb )
44
* c = Has charset flag 1 bits 11-11
45
* s = Charset pointer position - 7 bits 12-18 ( in table descriptor )
46
* f = Null flag offset in word - 5 bits 20-24 ( address 32 bits )
47
* w = Null word offset - 7 bits 25-32 ( f+w addr 4096 attrs )
49
* 1111111111222222222233
50
* 01234567890123456789012345678901
51
* aaaaaaaaaaacsssssss fffffwwwwwww
54
#define AO_ATTRIBUTE_OFFSET_SHIFT 0
55
#define AO_ATTRIBUTE_OFFSET_MASK 0x7ff
57
#define AO_CHARSET_FLAG_SHIFT 11
58
#define AO_CHARSET_POS_SHIFT 12
59
#define AO_CHARSET_POS_MASK 127
61
#define AO_NULL_FLAG_POS_MASK 0xfff // f+w
62
#define AO_NULL_FLAG_POS_SHIFT 20
64
#define AO_NULL_FLAG_WORD_MASK 31 // f
65
#define AO_NULL_FLAG_OFFSET_SHIFT 5
69
AttributeOffset::setOffset(Uint32 & desc, Uint32 offset){
70
ASSERT_MAX(offset, AO_ATTRIBUTE_OFFSET_MASK, "AttributeOffset::setOffset");
71
desc &= ~(Uint32)(AO_ATTRIBUTE_OFFSET_MASK << AO_ATTRIBUTE_OFFSET_SHIFT);
72
desc |= (offset << AO_ATTRIBUTE_OFFSET_SHIFT);
77
AttributeOffset::setCharsetPos(Uint32 & desc, Uint32 offset) {
78
ASSERT_MAX(offset, AO_CHARSET_POS_MASK, "AttributeOffset::setCharsetPos");
79
desc |= (1 << AO_CHARSET_FLAG_SHIFT);
80
desc |= (offset << AO_CHARSET_POS_SHIFT);
85
AttributeOffset::setNullFlagPos(Uint32 & desc, Uint32 pos){
86
ASSERT_MAX(pos, AO_NULL_FLAG_POS_MASK, "AttributeOffset::setNullFlagPos");
87
desc |= (pos << AO_NULL_FLAG_POS_SHIFT);
92
AttributeOffset::getOffset(const Uint32 & desc)
94
return (desc >> AO_ATTRIBUTE_OFFSET_SHIFT) & AO_ATTRIBUTE_OFFSET_MASK;
99
AttributeOffset::getCharsetFlag(const Uint32 & desc)
101
return (desc >> AO_CHARSET_FLAG_SHIFT) & 1;
106
AttributeOffset::getCharsetPos(const Uint32 & desc)
108
return (desc >> AO_CHARSET_POS_SHIFT) & AO_CHARSET_POS_MASK;
113
AttributeOffset::getNullFlagPos(const Uint32 & desc)
115
return ((desc >> AO_NULL_FLAG_POS_SHIFT) & AO_NULL_FLAG_POS_MASK);
120
AttributeOffset::getNullFlagOffset(const Uint32 & desc)
122
return (getNullFlagPos(desc) >> AO_NULL_FLAG_OFFSET_SHIFT);
127
AttributeOffset::getNullFlagBitOffset(const Uint32 & desc)
129
return (getNullFlagPos(desc) & AO_NULL_FLAG_WORD_MASK);
133
operator<<(class NdbOut&, const AttributeOffset&);