00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifndef ATTRIBUTE_HEADER 00018 #define ATTRIBUTE_HEADER 00019 00024 class AttributeHeader { 00025 friend class Dbtup; 00026 friend class Backup; 00027 friend class NdbOperation; 00028 friend class DbUtil; 00029 friend class Suma; 00030 00031 public: 00035 STATIC_CONST( PSEUDO = 0x8000 ); 00036 STATIC_CONST( FRAGMENT = 0xFFFE ); // Read fragment no 00037 STATIC_CONST( ROW_COUNT = 0xFFFD ); // Read row count (committed) 00038 STATIC_CONST( COMMIT_COUNT = 0xFFFC ); // Read commit count 00039 STATIC_CONST( RANGE_NO = 0xFFFB ); // Read range no (when batched ranges) 00040 00041 STATIC_CONST( ROW_SIZE = 0xFFFA ); 00042 STATIC_CONST( FRAGMENT_FIXED_MEMORY= 0xFFF9 ); 00043 00044 STATIC_CONST( RECORDS_IN_RANGE = 0xFFF8 ); 00045 STATIC_CONST( DISK_REF = 0xFFF7 ); 00046 STATIC_CONST( ROWID = 0xFFF6 ); 00047 STATIC_CONST( ROW_GCI = 0xFFF5 ); 00048 STATIC_CONST( FRAGMENT_VARSIZED_MEMORY = 0xFFF4 ); 00049 00050 // NOTE: in 5.1 ctors and init take size in bytes 00051 00053 static AttributeHeader& init(void* aHeaderPtr, Uint32 anAttributeId, 00054 Uint32 aByteSize); 00055 00057 Uint32 getHeaderSize() const; // In 32-bit words 00058 00060 void insertHeader(Uint32*); 00061 00063 AttributeHeader* getNext() const; 00064 00066 Uint32* getDataPtr() const; 00067 00069 Uint32 getAttributeId() const; 00070 void setAttributeId(Uint32); 00071 Uint32 getByteSize() const; 00072 void setByteSize(Uint32); 00073 Uint32 getDataSize() const; // In 32-bit words, rounded up 00074 void setDataSize(Uint32); // Set size to multiple of word size 00075 bool isNULL() const; 00076 void setNULL(); 00077 00079 //void print(NdbOut&); 00080 void print(FILE*); 00081 00082 static Uint32 getByteSize(Uint32); 00083 static Uint32 getDataSize(Uint32); 00084 00085 public: 00086 AttributeHeader(Uint32 = 0); 00087 AttributeHeader(Uint32 anAttributeId, Uint32 aByteSize); 00088 ~AttributeHeader(); 00089 00090 Uint32 m_value; 00091 }; 00092 00113 inline 00114 AttributeHeader& AttributeHeader::init(void* aHeaderPtr, Uint32 anAttributeId, 00115 Uint32 aByteSize) 00116 { 00117 return * new (aHeaderPtr) AttributeHeader(anAttributeId, aByteSize); 00118 } 00119 00120 inline 00121 AttributeHeader::AttributeHeader(Uint32 aHeader) 00122 { 00123 m_value = aHeader; 00124 } 00125 00126 inline 00127 AttributeHeader::AttributeHeader(Uint32 anAttributeId, Uint32 aByteSize) 00128 { 00129 m_value = 0; 00130 this->setAttributeId(anAttributeId); 00131 this->setByteSize(aByteSize); 00132 } 00133 00134 inline 00135 AttributeHeader::~AttributeHeader() 00136 {} 00137 00138 inline 00139 Uint32 AttributeHeader::getHeaderSize() const 00140 { 00141 // Should check 'e' bit here 00142 return 1; 00143 } 00144 00145 inline 00146 Uint32 AttributeHeader::getAttributeId() const 00147 { 00148 return (m_value & 0xFFFF0000) >> 16; 00149 } 00150 00151 inline 00152 void AttributeHeader::setAttributeId(Uint32 anAttributeId) 00153 { 00154 m_value &= 0x0000FFFF; // Clear attribute id 00155 m_value |= (anAttributeId << 16); 00156 } 00157 00158 inline 00159 Uint32 AttributeHeader::getByteSize() const 00160 { 00161 return (m_value & 0xFFFF); 00162 } 00163 00164 inline 00165 void AttributeHeader::setByteSize(Uint32 aByteSize) 00166 { 00167 m_value &= (~0xFFFF); 00168 m_value |= aByteSize; 00169 } 00170 00171 inline 00172 Uint32 AttributeHeader::getDataSize() const 00173 { 00174 return (((m_value & 0xFFFF) + 3) >> 2); 00175 } 00176 00177 inline 00178 void AttributeHeader::setDataSize(Uint32 aDataSize) 00179 { 00180 m_value &= (~0xFFFF); 00181 m_value |= (aDataSize << 2); 00182 } 00183 00184 inline 00185 bool AttributeHeader::isNULL() const 00186 { 00187 return (getDataSize() == 0); 00188 } 00189 00190 inline 00191 void AttributeHeader::setNULL() 00192 { 00193 setDataSize(0); 00194 } 00195 00196 inline 00197 Uint32* AttributeHeader::getDataPtr() const 00198 { 00199 return (Uint32*)&m_value + getHeaderSize(); 00200 } 00201 00202 inline 00203 void AttributeHeader::insertHeader(Uint32* target) 00204 { 00205 *target = m_value; 00206 } 00207 00208 inline 00209 AttributeHeader* 00210 AttributeHeader::getNext() const { 00211 return (AttributeHeader*)(getDataPtr() + getDataSize()); 00212 } 00213 00214 inline 00215 void 00216 //AttributeHeader::print(NdbOut& output) { 00217 AttributeHeader::print(FILE* output) { 00218 fprintf(output, "AttributeId: H\'%.8x (D\'%d), DataSize: H\'%.8x (D\'%d), " 00219 "isNULL: %d\n", 00220 getAttributeId(), getAttributeId(), 00221 getDataSize(), getDataSize(), 00222 isNULL()); 00223 } 00224 00225 inline 00226 Uint32 00227 AttributeHeader::getByteSize(Uint32 m_value){ 00228 return (m_value & 0xFFFF); 00229 } 00230 00231 inline 00232 Uint32 00233 AttributeHeader::getDataSize(Uint32 m_value){ 00234 return (((m_value & 0xFFFF) + 3) >> 2); 00235 } 00236 00237 #endif 00238 00239 00240 00241 00242 00243 00244
1.4.7

