~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dbtup/AttributeOffset.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef ATTRIBUTE_OFFSET_HPP
 
17
#define ATTRIBUTE_OFFSET_HPP
 
18
 
 
19
class AttributeOffset {
 
20
  friend class Dbtup;
 
21
  
 
22
private:
 
23
  static void   setOffset(Uint32 & desc, Uint32 offset);
 
24
  static void   setCharsetPos(Uint32 & desc, Uint32 offset);
 
25
  static void   setNullFlagPos(Uint32 & desc, Uint32 offset);
 
26
 
 
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 &);
 
33
  
 
34
  Uint32 m_data;
 
35
 
 
36
  friend class NdbOut& operator<<(class NdbOut&, const AttributeOffset&);
 
37
};
 
38
 
 
39
/**
 
40
 * Allow for 4096 attributes, all nullable, and for 128 different
 
41
 * character sets.
 
42
 *
 
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 )
 
48
 *
 
49
 *           1111111111222222222233
 
50
 * 01234567890123456789012345678901
 
51
 * aaaaaaaaaaacsssssss fffffwwwwwww
 
52
 */
 
53
 
 
54
#define AO_ATTRIBUTE_OFFSET_SHIFT       0
 
55
#define AO_ATTRIBUTE_OFFSET_MASK        0x7ff
 
56
 
 
57
#define AO_CHARSET_FLAG_SHIFT           11
 
58
#define AO_CHARSET_POS_SHIFT            12
 
59
#define AO_CHARSET_POS_MASK             127
 
60
 
 
61
#define AO_NULL_FLAG_POS_MASK           0xfff   // f+w
 
62
#define AO_NULL_FLAG_POS_SHIFT          20
 
63
 
 
64
#define AO_NULL_FLAG_WORD_MASK          31      // f
 
65
#define AO_NULL_FLAG_OFFSET_SHIFT       5
 
66
 
 
67
inline
 
68
void
 
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);
 
73
}
 
74
 
 
75
inline
 
76
void
 
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);
 
81
}
 
82
 
 
83
inline
 
84
void
 
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);
 
88
}
 
89
 
 
90
inline
 
91
Uint32
 
92
AttributeOffset::getOffset(const Uint32 & desc)
 
93
{
 
94
  return (desc >> AO_ATTRIBUTE_OFFSET_SHIFT) & AO_ATTRIBUTE_OFFSET_MASK;
 
95
}
 
96
 
 
97
inline
 
98
bool
 
99
AttributeOffset::getCharsetFlag(const Uint32 & desc)
 
100
{
 
101
  return (desc >> AO_CHARSET_FLAG_SHIFT) & 1;
 
102
}
 
103
 
 
104
inline
 
105
Uint32
 
106
AttributeOffset::getCharsetPos(const Uint32 & desc)
 
107
{
 
108
  return (desc >> AO_CHARSET_POS_SHIFT) & AO_CHARSET_POS_MASK;
 
109
}
 
110
 
 
111
inline 
 
112
Uint32
 
113
AttributeOffset::getNullFlagPos(const Uint32 & desc)
 
114
{
 
115
  return ((desc >> AO_NULL_FLAG_POS_SHIFT) & AO_NULL_FLAG_POS_MASK);
 
116
}
 
117
 
 
118
inline
 
119
Uint32
 
120
AttributeOffset::getNullFlagOffset(const Uint32 & desc)
 
121
{
 
122
  return (getNullFlagPos(desc) >> AO_NULL_FLAG_OFFSET_SHIFT);
 
123
}
 
124
 
 
125
inline
 
126
Uint32
 
127
AttributeOffset::getNullFlagBitOffset(const Uint32 & desc)
 
128
{
 
129
  return (getNullFlagPos(desc) & AO_NULL_FLAG_WORD_MASK);
 
130
}
 
131
 
 
132
class NdbOut&
 
133
operator<<(class NdbOut&, const AttributeOffset&);
 
134
 
 
135
#endif