1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
/* Copyright (c) 2003-2005 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
#ifndef ATTRIBUTE_DESCRIPTOR_HPP
#define ATTRIBUTE_DESCRIPTOR_HPP
class AttributeDescriptor {
friend class Dbdict;
friend class Dbtc;
friend class Dbacc;
friend class Dbtup;
friend class Dbtux;
friend class Dblqh;
friend class SimulatedBlock;
public:
static void setType(Uint32 &, Uint32 type);
static void setSize(Uint32 &, Uint32 size);
static void setArrayType(Uint32 &, Uint32 arrayType);
static void setArraySize(Uint32 &, Uint32 arraySize);
static void setNullable(Uint32 &, Uint32 nullable);
static void setDKey(Uint32 &, Uint32 dkey);
static void setPrimaryKey(Uint32 &, Uint32 dkey);
static void setDynamic(Uint32 &, Uint32 dynamicInd);
static void setDiskBased(Uint32 &, Uint32 val);
static Uint32 getType(const Uint32 &);
static Uint32 getSize(const Uint32 &);
static Uint32 getSizeInBytes(const Uint32 &);
static Uint32 getSizeInWords(const Uint32 &);
static Uint32 getArrayType(const Uint32 &);
static Uint32 getArraySize(const Uint32 &);
static Uint32 getNullable(const Uint32 &);
static Uint32 getDKey(const Uint32 &);
static Uint32 getPrimaryKey(const Uint32 &);
static Uint32 getDynamic(const Uint32 &);
static Uint32 getDiskBased(const Uint32 &);
Uint32 m_data;
};
/**
*
* a = Array type - 2 Bits -> Max 3 (Bit 0-1)
* t = Attribute type - 5 Bits -> Max 31 (Bit 2-6)
* s = Attribute size - 3 Bits -> Max 7 (Bit 8-10)
* d = Disk based - 1 Bit 11
* n = Nullable - 1 Bit 12
* k = Distribution Key Ind - 1 Bit 13
* p = Primary key attribute - 1 Bit 14
* y = Dynamic attribute - 1 Bit 15
* z = Array size - 16 Bits -> Max 65535 (Bit 16-31)
*
* 1111111111222222222233
* 01234567890123456789012345678901
* aattttt sssdnkpyzzzzzzzzzzzzzzzz
* aattsss n d k pyzzzzzzzzzzzzzzzz [ old format ]
*
*/
#define AD_ARRAY_TYPE_SHIFT (0)
#define AD_ARRAY_TYPE_MASK (3)
#define AD_TYPE_SHIFT (2)
#define AD_TYPE_MASK (31)
#define AD_SIZE_SHIFT (8)
#define AD_SIZE_MASK (7)
#define AD_SIZE_IN_BYTES_SHIFT (3)
#define AD_SIZE_IN_WORDS_OFFSET (31)
#define AD_SIZE_IN_WORDS_SHIFT (5)
#define AD_DISK_SHIFT (11)
#define AD_NULLABLE_SHIFT (12)
#define AD_DISTR_KEY_SHIFT (13)
#define AD_PRIMARY_KEY (14)
#define AD_DYNAMIC (15)
#define AD_ARRAY_SIZE_SHIFT (16)
#define AD_ARRAY_SIZE_MASK (65535)
inline
void
AttributeDescriptor::setType(Uint32 & desc, Uint32 type){
assert(type <= AD_TYPE_MASK);
desc |= (type << AD_TYPE_SHIFT);
}
inline
void
AttributeDescriptor::setSize(Uint32 & desc, Uint32 size){
assert(size <= AD_SIZE_MASK);
desc |= (size << AD_SIZE_SHIFT);
}
inline
void
AttributeDescriptor::setArrayType(Uint32 & desc, Uint32 arrayType){
assert(arrayType <= AD_ARRAY_TYPE_MASK);
desc |= (arrayType << AD_ARRAY_TYPE_SHIFT);
}
inline
void
AttributeDescriptor::setArraySize(Uint32 & desc, Uint32 arraySize){
assert(arraySize <= AD_ARRAY_SIZE_MASK);
desc |= (arraySize << AD_ARRAY_SIZE_SHIFT);
}
inline
void
AttributeDescriptor::setNullable(Uint32 & desc, Uint32 nullable){
assert(nullable <= 1);
desc |= (nullable << AD_NULLABLE_SHIFT);
}
inline
void
AttributeDescriptor::setDKey(Uint32 & desc, Uint32 dkey){
assert(dkey <= 1);
desc |= (dkey << AD_DISTR_KEY_SHIFT);
}
inline
void
AttributeDescriptor::setPrimaryKey(Uint32 & desc, Uint32 dkey){
assert(dkey <= 1);
desc |= (dkey << AD_PRIMARY_KEY);
}
inline
void
AttributeDescriptor::setDynamic(Uint32 & desc, Uint32 dynamic){
assert(dynamic <= 1);
desc |= (dynamic << AD_DYNAMIC);
}
inline
void
AttributeDescriptor::setDiskBased(Uint32 & desc, Uint32 val)
{
assert(val <= 1);
desc |= (val << AD_DISK_SHIFT);
}
/**
* Getters
*/
inline
Uint32
AttributeDescriptor::getType(const Uint32 & desc){
return (desc >> AD_TYPE_SHIFT) & AD_TYPE_MASK;
}
inline
Uint32
AttributeDescriptor::getSize(const Uint32 & desc){
return (desc >> AD_SIZE_SHIFT) & AD_SIZE_MASK;
}
inline
Uint32
AttributeDescriptor::getSizeInBytes(const Uint32 & desc){
return (getArraySize(desc) << getSize(desc))
>> AD_SIZE_IN_BYTES_SHIFT;
}
inline
Uint32
AttributeDescriptor::getSizeInWords(const Uint32 & desc){
return ((getArraySize(desc) << getSize(desc))
+ AD_SIZE_IN_WORDS_OFFSET)
>> AD_SIZE_IN_WORDS_SHIFT;
}
inline
Uint32
AttributeDescriptor::getArrayType(const Uint32 & desc){
return (desc >> AD_ARRAY_TYPE_SHIFT) & AD_ARRAY_TYPE_MASK;
}
inline
Uint32
AttributeDescriptor::getArraySize(const Uint32 & desc){
return (desc >> AD_ARRAY_SIZE_SHIFT) & AD_ARRAY_SIZE_MASK;
}
inline
Uint32
AttributeDescriptor::getNullable(const Uint32 & desc){
return (desc >> AD_NULLABLE_SHIFT) & 1;
}
inline
Uint32
AttributeDescriptor::getDKey(const Uint32 & desc){
return (desc >> AD_DISTR_KEY_SHIFT) & 1;
}
inline
Uint32
AttributeDescriptor::getPrimaryKey(const Uint32 & desc){
return (desc >> AD_PRIMARY_KEY) & 1;
}
inline
Uint32
AttributeDescriptor::getDynamic(const Uint32 & desc){
return (desc >> AD_DYNAMIC) & 1;
}
inline
Uint32
AttributeDescriptor::getDiskBased(const Uint32 & desc)
{
return (desc >> AD_DISK_SHIFT) & 1;
}
class NdbOut&
operator<<(class NdbOut&, const AttributeDescriptor&);
#endif
|