Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
xbindex.h
Go to the documentation of this file.
1/* xbindex.h
2
3XBase64 Software Library
4
5Copyright (c) 1997,2003,2014, 2018, 2022 Gary A Kunkel
6
7The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.
8
9Email Contact:
10
11 XDB-devel@lists.sourceforge.net
12 XDB-users@lists.sourceforge.net
13
14*/
15
16
17#ifndef __XB_INDEX_H__
18#define __XB_INDEX_H__
19
20#ifdef XB_INDEX_SUPPORT
21
22
23#define XB_ADD_KEY 1
24#define XB_UPD_KEY 2
25#define XB_DEL_KEY 3
26
27namespace xb{
28
29
30
32// structure for index nodes, each node contains information regarding one block
33struct XBDLLEXPORT xbIxNode {
34 xbIxNode *npPrev; // pointer to previous node in chain
35 xbIxNode *npNext; // pointer to next node in chain
36 xbUInt32 iCurKeyNo; // current key number in the node, 0 offset
37 xbUInt32 ulBlockNo; // this block number
38 xbUInt32 ulBufSize; // size of cpBlockData
39 char *cpBlockData; // pointer to memory version of block data stored in file
40};
42
43
45
120class XBDLLEXPORT xbIx : public xbFile {
121 public:
122 xbIx( xbDbf * d );
123 virtual ~xbIx();
124
125 virtual xbInt16 CheckTagIntegrity( void *vpTag, xbInt16 iOpt ) = 0;
126 virtual xbInt16 Close();
127 virtual xbInt16 CreateTag( const xbString &sName, const xbString &sKey, const xbString &sFilter, xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverlay, void **vpTag ) = 0;
128 virtual xbInt16 FindKey( void *vpTag, const xbString &sKey, xbInt16 iRetrieveSw );
129 virtual xbInt16 FindKey( void *vpTag, const char * cKey, xbInt32 lKeyLen, xbInt16 iRetrieveSw );
130 virtual xbInt16 FindKey( void *vpTag, const xbBcd &bcd, xbInt16 iRetrieveSw );
131 virtual xbInt16 FindKey( void *vpTag, const xbDate &dtKey, xbInt16 iRetrieveSw );
132 virtual xbInt16 FindKey( void *vpTag, xbDouble dKey, xbInt16 iRetrieveSw );
133 virtual xbInt16 FindKey( void *vpTag, const void *vKey, xbInt32 lKeyLen, xbInt16 iRetrieveSw ) = 0;
134 virtual void *GetCurTag() const;
135 virtual xbDbf *GetDbf() const;
136
137 virtual xbString &GetKeyExpression( const void *vpTag ) const = 0;
138 virtual xbString &GetKeyFilter( const void *vpTag ) const = 0;
139 virtual char GetKeyType( const void *vpTag ) const = 0;
140 virtual xbBool GetLocked() const;
141
142 virtual xbInt16 GetFirstKey( void *vpTag, xbInt16 iRetrieveSw ) = 0;
143 virtual xbInt16 GetFirstKey( void *vpTag );
144 virtual xbInt16 GetFirstKey();
145
146 virtual xbInt16 GetLastKey( void *vpTag, xbInt16 lRetrieveSw ) = 0;
147 virtual xbInt16 GetLastKey( void *vpTag );
148 virtual xbInt16 GetLastKey();
149
150 virtual xbInt16 GetNextKey( void *vpTag, xbInt16 iRetrieveSw ) = 0;
151 virtual xbInt16 GetNextKey( void *vpTag );
152 virtual xbInt16 GetNextKey();
153
154 virtual xbInt16 GetPrevKey( void *vpTag, xbInt16 iRetrieveSw ) = 0;
155 virtual xbInt16 GetPrevKey( void *vpTag );
156 virtual xbInt16 GetPrevKey();
157
158 virtual void *GetTag( xbInt16 iTagNo ) const = 0;
159 virtual void *GetTag( xbString &sTagName ) const = 0;
160 virtual xbInt16 GetTagCount() const = 0;
161
162 virtual xbString &GetTagName( void *vpTag ) const = 0;
163 virtual const char * GetTagName( void *vpTag, xbInt16 iOpt ) const = 0;
164 virtual void GetTagName( void *vpTag, xbString &sTagName ) {};
165
166 virtual xbBool GetUnique( void *vpTag ) const = 0;
167 virtual xbBool GetSortOrder( void *vpTag ) const = 0;
168
169 virtual xbInt16 Open( const xbString &sFileName );
170 virtual xbInt16 SetCurTag( xbInt16 iTagNo ) = 0;
171 virtual xbInt16 SetCurTag( xbString &sTagName ) = 0;
172 virtual void SetCurTag( void * vpCurTag );
173 virtual void SetLocked( xbBool bLocked );
174
175 virtual void TestStub( char *s, void *vpTag ) {};
176
177
178
179 virtual xbInt16 Reindex( void **vpTag ) = 0;
180
181
182 #ifdef XB_DEBUG_SUPPORT
183 virtual xbInt16 DumpFreeBlocks( xbInt16 iOpt = 0 ) { return XB_NO_ERROR; }
184 virtual xbInt16 DumpHeader( xbInt16 iDestOpt = 0, xbInt16 iFmtOpt = 0 ) = 0;
185 virtual xbInt16 DumpIxForTag( void *vpTag, xbInt16 iOutputOpt ) = 0;
186 virtual void DumpIxNodeChain( void *vpTag, xbInt16 iOutputOpt ) const = 0;
187 virtual xbInt16 DumpNode( void * vpTag, xbIxNode * pNode, xbInt16 iOption ) const;
188 virtual xbInt16 DumpTagBlocks( xbInt16 iOpt = 1, void *vpTag = NULL ) = 0;
189
190 #endif
191
192 protected:
193 friend class xbDbf;
194
195 virtual xbInt16 AddKey( void *vpTag, xbUInt32 ulRecNo ) = 0;
196 virtual xbInt16 AddKeys( xbUInt32 ulRecNo );
197 virtual xbIxNode *AllocateIxNode( xbUInt32 ulBufSize = 0, xbInt16 iOption = 0 );
198 virtual xbInt16 BSearchBlock( char cKeyType, xbIxNode *npNode, xbInt32 lKeyLen, const void *vpKey, xbInt32 lSearchKeyLen, xbInt16 &iCompRc, xbBool bDescending = xbFalse ) const;
199 virtual xbInt16 CheckForDupKeys();
200 virtual xbInt16 CheckForDupKey( void *vpTag ) = 0;
201 virtual xbInt16 CompareKey( char cKeyType, const void *v1, const void *v2, size_t lKeyLen ) const;
202 virtual xbInt16 CreateKeys( xbInt16 iOpt );
203 virtual xbInt16 CreateKey( void * vpTag, xbInt16 iOpt ) = 0;
204 virtual xbInt16 DeleteFromNode( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo ) = 0;
205 virtual xbInt16 DeleteKeys();
206 virtual xbInt16 DeleteKey( void *vpTag ) = 0;
207 virtual xbInt16 DeleteTag( void *vpTag ) = 0;
208
209 virtual xbInt16 FindKeyForCurRec( void *vpTag ) = 0;
210 virtual xbIxNode *FreeNodeChain( xbIxNode *np );
211 virtual xbInt16 GetBlock( void *vpTag, xbUInt32 ulBlockNo, xbInt16 iOpt, xbUInt32 ulAddlBuf = 0 );
212 virtual xbInt32 GetKeyCount( xbIxNode *npNode ) const;
213 virtual char *GetKeyData( xbIxNode *npNode, xbInt16 iKeyNo, xbInt16 iKeyItemLen ) const;
214 virtual xbInt16 GetKeySts( void *vpTag ) const = 0;
215 virtual xbInt16 GetLastKey( xbUInt32 ulNodeNo, void *vpTag, xbInt16 lRetrieveSw ) = 0;
216 virtual xbInt16 InsertNodeL( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo, char * cpKeyBuf, xbUInt32 uiPtr ) = 0;
217 virtual xbInt16 InsertNodeI( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo, xbUInt32 uiPtr ) = 0;
218 virtual xbInt16 KeyExists( void * ) = 0;
219 virtual void NodeFree( xbIxNode * ixNode );
220 virtual xbInt16 ReadHeadBlock( xbInt16 iOpt = 0 ) = 0;
221 // virtual xbInt16 Reindex( void **vpTag ) = 0;
222 virtual void SetDbf( xbDbf *dbf );
223 virtual xbInt16 SplitNodeL( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, char *cpKeyBuf, xbUInt32 uiPtr ) = 0;
224 virtual xbInt16 SplitNodeI( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, xbUInt32 uiPtr ) = 0;
225 virtual xbInt16 UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo = 0 ) = 0;
226 virtual xbInt16 WriteHeadBlock( xbInt16 iOption ) = 0;
227
228 xbDbf *dbf;
229 char *cNodeBuf; // pointer to memory for processing in a block of index data
230 void *vpCurTag; // pointer to active tag. Single index files have only one tag
231
232 private:
233 virtual void AppendNodeChain( void *vpTag, xbIxNode *npNode ) = 0;
234 virtual xbInt16 GetKeyPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *npNode, xbUInt32 &ulKeyPtr ) const = 0;
235 virtual xbBool IsLeaf( void *vpTag, xbIxNode *npNode ) const = 0;
236 // virtual void SetCurNode( void *vpTag, xbIxNode *npNode ) = 0;
237
238 xbBool bLocked; // index file locked?
239};
240
241#ifdef XB_NDX_SUPPORT
242
243#define XB_NDX_BLOCK_SIZE 512
244
245
247struct XBDLLEXPORT xbNdxTag {
248
249 // NDX File Header Fields
250 xbUInt32 ulRootBlock; // header node is 0
251 xbUInt32 ulTotalBlocks; // includes header node
252 char cKeyType; // C = Char, F = Numeric, D = Date
253 xbInt16 iKeyLen; // length of key data
254 xbInt16 iKeysPerBlock; // max number keys per block <=100
255 xbInt16 iKeyType; // 00 = Char, 01 = Numeric
256 xbInt16 iKeyItemLen; // KeyLen + 8 bytes
257 char cSerNo; // rolling incrementing serial number +1 on each index update
258 xbInt16 iUnique; // True if unique
259 xbString sKeyExpression; // index expression
260 // end of NDX Header field
261
262 xbExp *exp; // pointer to expression for expression keys
263 time_t tNodeChainTs; // node chain time stamp
264 xbIxNode *npNodeChain;
265 xbIxNode *npCurNode;
266 char *cpKeyBuf; // key buffer, for searches and adds
267 char *cpKeyBuf2; // key buffer, for deletes
268 xbString sTagName; // tag name - is the file name without the extension
269 xbBool bFoundSts; // key found? used to determine if new key should be added in XB_EMULATE_DBASE mode in AddKey
270
271
272 xbInt16 iKeySts; // key updated? set in method CreateKey, checked in AddKey and DeleteKey routines
273 // old key filtered new key filtered iKeySts
274 // Y Y XB_UPD_KEY 2 - update key if changed (delete and add)
275 // Y N XB_DEL_KEY 3 - delete key
276 // N Y XB_ADD_KEY 1 - add key
277 // N N 0 - no update
278
279};
281
283
302class XBDLLEXPORT xbIxNdx : public xbIx {
303 public:
304 xbIxNdx( xbDbf * d );
305 ~xbIxNdx();
306 xbInt16 CheckTagIntegrity( void *vpTag, xbInt16 iOpt );
307 xbInt16 CreateTag( const xbString &sName, const xbString &sKey, const xbString &sFilter, xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverlay, void **vpTag );
308 xbInt16 FindKey( void *vpTag, const void *vpKey, xbInt32 lKeyLen, xbInt16 iRetrieveSw );
309 xbInt16 GetFirstKey( void *vpTag, xbInt16 iRetrieveSw );
310
311 xbInt16 GetLastKey( void *vpTag, xbInt16 iRetrieveSw = 1 );
312 xbInt16 GetNextKey( void *vpTag, xbInt16 iRetrieveSw = 1 );
313 xbInt16 GetPrevKey( void *vpTag, xbInt16 iRetrieveSw = 1 );
314 xbInt32 GetKeyLen ( const void *vpTag ) const;
315 char GetKeyType ( const void *vpTag ) const;
316 xbString &GetKeyExpression( const void *vpTag ) const;
317 xbString &GetKeyFilter( const void *vpTag ) const;
318 void *GetTag( xbInt16 iTagNo ) const;
319 void *GetTag( xbString &sTagName ) const;
320 xbString &GetTagName( void *vpTag ) const;
321 const char * GetTagName( void *vpTag, xbInt16 iOpt ) const;
322
323 xbInt16 GetTagCount() const;
324 xbBool GetUnique( void *vpTag = NULL ) const;
325 xbBool GetSortOrder( void *vpTag ) const;
326 xbInt16 SetCurTag( xbInt16 iTagNo );
327 xbInt16 SetCurTag( xbString &sTagName );
328
329 #ifdef XB_DEBUG_SUPPORT
330 xbInt16 DumpTagBlocks( xbInt16 iOpt = 1, void *vpTag = NULL );
331 xbInt16 DumpHeader( xbInt16 iOpt = 0, xbInt16 iFmt = 0 );
332 xbInt16 DumpIxForTag( void *vpTag, xbInt16 iOutputOpt );
333 void DumpIxNodeChain( void *vpTag, xbInt16 iOutputOpt ) const;
334 xbInt16 DumpNode( void * vpTag, xbIxNode * pNode, xbInt16 iOption ) const;
335 #endif
336
337 xbInt16 Reindex( void **vpTag );
338
339
340 protected:
341 friend class xbDbf;
342 xbInt16 AddKey( void *vpTag, xbUInt32 ulRecNo );
343 xbIxNode *AllocateIxNode( xbUInt32 ulBufSize = 0, xbInt16 iOption = 0 );
344 xbInt16 CheckForDupKey( void *vpTag );
345 xbIxNode *CreateIxNode( xbUInt32 ulBufSize );
346 xbInt16 CreateKey( void * vpTag, xbInt16 iOpt );
347 xbInt16 DeleteFromNode( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo );
348 xbInt16 DeleteKey( void *vpTag );
349 xbInt16 DeleteTag( void *vpTag );
350 xbInt16 FindKeyForCurRec( void *vpTag );
351 xbInt16 GetKeyTypeN( const void *vpTag ) const;
352 xbInt16 GetKeySts( void *vpTag ) const;
353 xbInt16 GetLastKey( xbUInt32 ulNodeNo, void *vpTag, xbInt16 iRetrieveSw = 1 );
354 xbInt16 InsertNodeI( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo, xbUInt32 uiPtr );
355 xbInt16 InsertNodeL( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo, char * cpKeyBuf, xbUInt32 uiPtr );
356 xbInt16 KeyExists( void *vpTag = NULL );
357 xbInt16 ReadHeadBlock(xbInt16 iOpt); // read the header node of the disk NDX file
358// xbInt16 Reindex( void **vpTag );
359 xbInt16 SplitNodeI( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, xbUInt32 uiPtr );
360 xbInt16 SplitNodeL( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, char *cpKeyBuf, xbUInt32 uiPtr );
361 xbInt16 UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo = 0 );
362 xbInt16 WriteHeadBlock( xbInt16 iOption );
363
364 private:
365 xbInt16 AddKeyNewRoot( xbNdxTag *npTag, xbIxNode *npLeft, xbIxNode *npRight );
366 void AppendNodeChain( void *vpTag, xbIxNode *npNode );
367 xbInt16 GetDbfPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *npNode, xbUInt32 &ulDbfPtr ) const;
368 xbInt16 GetKeyPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *npNode, xbUInt32 &ulKeyPtr ) const;
369 xbInt16 GetLastKeyForBlockNo( void *vpTag, xbUInt32 ulBlockNo, char *cpKeyBuf );
370 xbBool IsLeaf( void *vpTag, xbIxNode *npNode ) const;
371 xbInt16 KeySetPosAdd( xbNdxTag *npTag, xbUInt32 ulAddKeyRecNo );
372 xbInt16 KeySetPosDel( xbNdxTag *npTag );
373 xbNdxTag *ndxTag;
374};
375
376#endif /* XB_NDX_SUPPORT */
377
378
379#ifdef XB_MDX_SUPPORT
380//#define XB_MDX_BLOCK_SIZE 1024
381
382struct XBDLLEXPORT xbMdxTag {
383
384 // next 7 fields comprise the tag table entry
385 xbUInt32 ulTagHdrPageNo; // 512 byte page number, NOT block number
386 char cTagName[11];
387 char cKeyFmt; // always 0x10 w/ DBase V7
388 char cLeftChild; // cFwdTagThread
389 char cRightChild; // cFwdTagThread2
390 char cParent; // cBwdTagThread
391 char c2;
392 char cKeyType; // C,D,N
393
394 xbUInt32 ulRootPage; // 512 byte page number, NOT block number
395 xbUInt32 ulTagSize; // Number of 512 byte pages allocated to the tag. Tag size of two is a single 1024 block
396
397 char cKeyFmt2; // 0x10 - base
398 // 0x08 - descending
399 // 0x40 - unique
400 char cKeyType2;
401 // one unused byte fits here
402
403 char cTag11; // dbase sets to 0x1B
404 xbInt16 iKeyLen;
405 xbInt16 iKeysPerBlock;
406 xbInt16 iSecKeyType;
407 xbInt16 iKeyItemLen; // iKeyLen + 4
408
409 char cSerialNo; // Increments +1 for each tag update
410 char cUnique;
411 xbString *sKeyExp; // Key expression
412 char cHasFilter; // 0x00 or 0x01
413 char cHasKeys; // 0x00 or 0x01
414 xbUInt32 ulLeftChild; // dbase 7 sets this to the root page on tag creation
415 xbUInt32 ulRightChild; // dbase 7 sets this to the root page on tag creation
416
417 char cTagYY;
418 char cTagMM;
419 char cTagDD;
420
421 char cKeyFmt3; // dbase 7 sets this 0x01 if discreet field or 0x00 if calculated or combination field key expression on tag creation
422
423 xbString *sFiltExp; // Filter expression
424
425 time_t tNodeChainTs;
426 xbIxNode *npNodeChain;
427 xbIxNode *npCurNode;
428 xbExp *exp; // pointer to expression for expression based tags
429 xbExp *filter; // pointer to expression for index filter
430
431 char *cpKeyBuf; // key buffer
432 char *cpKeyBuf2; // key buffer
433 xbString *sTagName; // string tag name
434
435
436 xbMdxTag *next;
437 xbBool bFoundSts; // key found? used to determine if new key should be added in XB_EMULATE_DBASE mode in AddKey
438
439
440 xbInt16 iKeySts; // key updated? set in method CreateKey, checked in AddKey and DeleteKey routines
441 // old key filtered new key filtered iKeySts
442 // Y Y XB_UPD_KEY 2 - update key if changed (delete and add)
443 // Y N XB_DEL_KEY 3 - delete key
444 // N Y XB_ADD_KEY 1 - add key
445 // N N 0 - no update
446
447
448};
449
450
451class XBDLLEXPORT xbIxMdx : public xbIx {
452 public:
453 xbIxMdx( xbDbf * d );
454 ~xbIxMdx();
455 virtual xbInt16 CheckTagIntegrity( void *vpTag, xbInt16 iOpt );
456 virtual xbInt16 CreateTag( const xbString &sName, const xbString &sKey, const xbString &sFilter, xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverlay, void **vpTag );
457 virtual xbInt16 FindKey( void *vpTag, const void *vKey, xbInt32 lKeyLen, xbInt16 iRetrieveSw );
458 virtual xbInt16 FindKey( void *vpTag, xbDouble dKey, xbInt16 iRetrieveSw );
459 virtual xbInt16 GetFirstKey( void *vpTag, xbInt16 lRetrieveSw );
460 virtual xbString &GetKeyExpression( const void *vpTag ) const;
461 virtual xbString &GetKeyFilter( const void *vpTag ) const;
462 virtual char GetKeyType( const void *vpTag ) const;
463 virtual xbInt16 GetLastKey( void *vpTag, xbInt16 lRetrieveSw );
464 virtual xbInt16 GetNextKey( void *vpTag, xbInt16 lRetrieveSw );
465 virtual xbInt16 GetPrevKey( void *vpTag, xbInt16 lRetrieveSw );
466 virtual xbBool GetReuseEmptyNodesSw() const;
467 virtual xbBool GetSortOrder( void *vpTag ) const;
468 virtual void *GetTag( xbInt16 iTagNo ) const;
469 virtual void *GetTag( xbString &sTagName ) const;
470 virtual xbInt16 GetTagCount() const;
471
472 virtual xbString &GetTagName( void *vpTag ) const;
473 virtual const char * GetTagName( void *vpTag, xbInt16 iOpt ) const;
474 virtual void GetTagName( void *vpTag, xbString &sTagName );
475
476 virtual xbInt16 GetUnique( void *vpTag ) const;
477 virtual xbInt16 SetCurTag( xbInt16 iTagNo );
478 virtual xbInt16 SetCurTag( xbString &sTagName );
479 void SetReuseEmptyNodesSw( xbBool bReuse );
480
481 void TestStub( char *s, void *vpTag );
482
483
484 virtual xbInt16 Reindex( void **vpTag );
485
486
487 protected:
488 friend class xbDbf;
489
490 xbInt16 AddKey( void *vpTag, xbUInt32 ulRecNo );
491 xbIxNode *AllocateIxNode( xbMdxTag * mpTag, xbUInt32 ulBufSize, xbUInt32 ulBlock2 );
492 void CalcBtreePointers();
493 char CalcTagKeyFmt( xbExp &exp );
494
495 xbInt16 CheckForDupKey( void *vpTag );
496 virtual xbInt16 Close();
497 xbInt16 CreateKey( void * vpTag, xbInt16 iOpt );
498 xbInt16 DeleteFromNode( void *vpTag, xbIxNode * npNode, xbInt16 iSlotNo );
499 xbInt16 DeleteKey( void *vpTag );
500
501 virtual xbInt16 DeleteTag( void *vpTag );
502
503 xbInt16 FindKeyForCurRec( void *vpTag );
504 xbInt16 GetKeySts( void *vpTag ) const;
505 xbInt16 GetLastKey( xbUInt32 ulBlockNo, void *vpTag, xbInt16 lRetrieveSw );
506 void *GetTagTblPtr() const;
507
508 xbInt16 HarvestTagNodes( xbMdxTag *mpTag, xbBool bRecycleRoot = xbFalse );
509 void Init( xbInt16 iOpt = 0 );
510 xbInt16 InsertNodeI( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, xbUInt32 uiPtr );
511 xbInt16 InsertNodeL( void *vpTag, xbIxNode *npNode, xbInt16 iSlotNo, char *cpKeyBuf, xbUInt32 uiPtr );
512 xbInt16 KeyExists( void * );
513 xbInt16 LoadTagTable();
514 xbInt16 ReadHeadBlock(xbInt16 iOpt); // read the header node of the disk file
515 //virtual xbInt16 Reindex( void **vpTag );
516 xbInt16 SplitNodeI( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, xbUInt32 uiPtr );
517 xbInt16 SplitNodeL( void *vpTag, xbIxNode * npLeft, xbIxNode *npRight, xbInt16 iSlotNo, char *cpKeyBuf, xbUInt32 uiPtr );
518 xbInt16 UpdateTagKey( char cAction, void *vpTag, xbUInt32 ulRecNo = 0 );
519 xbInt16 WriteHeadBlock( xbInt16 iOption );
520
521 #ifdef XB_DEBUG_SUPPORT
522 xbInt16 DumpTagBlocks( xbInt16 iOpt = 1, void *vpTag = NULL );
523 xbInt16 DumpFreeBlocks( xbInt16 iOpt = 0 );
524 xbInt16 DumpHeader( xbInt16 iOpt = 0, xbInt16 iFmtOpt = 0 );
525 xbInt16 DumpIxForTag( void *vpTag, xbInt16 iOutputOpt );
526 void DumpIxNodeChain( void *vpTag, xbInt16 iOutputOpt ) const;
527 #endif
528
529
530 xbMdxTag *mdxTagTbl;
531
532// MDX File Header Fields
533 char cVersion;
534 char cCreateYY;
535 char cCreateMM;
536 char cCreateDD;
537 xbString sFileName;
538 xbInt16 iBlockFactor; // 1-32 #of 512 byte segments in a block
539
540 // use file version
541 // xbInt16 iBlockSize; // Stored at the xbFile level
542
543 char cProdIxFlag;
544 char cTagEntryCnt;
545 xbInt16 iTagLen;
546 xbInt16 iTagUseCnt;
547 char cNextTag; // byte 28 +1
548 char c1B; // always 0x1B
549 xbUInt32 ulPageCnt; // number of 512 byte pages in the mdx file
550 xbUInt32 ulFirstFreePage; // page number corresponding to the next free block
551 xbUInt32 ulNoOfBlockAvail; // might be improperly named?? not sure how it is used
552 char cUpdateYY;
553 char cUpdateMM;
554 char cUpdateDD;
555 // end of MDX Header fields
556
557
558 xbBool bReuseEmptyNodes; // Reuese empty MDX nodes when all keys deleted?
559 // DBase 7.x and MS ODBC drivers do not reuse empty nodes, leaves them stranded in the file
560 // Codebase 6.x reuses empty nodes.
561 // Setting this to True will reuse empty nodes in the same manner Codebase 6.x reuses them.
562
563
564 private:
565 xbInt16 AddKeyNewRoot( xbMdxTag *npTag, xbIxNode *npLeft, xbIxNode *npRight );
566 void AppendNodeChain( void *vpTag, xbIxNode *npNode );
567 xbUInt32 BlockToPage( xbUInt32 ulBlockNo );
568 xbMdxTag *ClearTagTable();
569 xbInt16 DumpBlock( xbInt16 iOpt, xbUInt32 ulBlockNo, xbMdxTag * mpTag );
570 xbInt16 GetDbfPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *npNode, xbUInt32 &ulDbfPtr ) const;
571 xbInt16 GetKeyPtr( void *vpTag, xbInt16 iKeyNo, xbIxNode *npNode, xbUInt32 &ulKeyPtr ) const;
572 xbInt16 GetLastKeyForBlockNo( void *vpTag, xbUInt32 ulBlockNo, char *cpKeyBuf );
573 xbInt16 HarvestEmptyNode( xbMdxTag *mpTag, xbIxNode *npNode, xbInt16 iOpt, xbBool bHarvestRoot = xbFalse );
574 xbBool IsLeaf( void *vpTag, xbIxNode *npNode ) const;
575 xbInt16 KeySetPosAdd( xbMdxTag *mpTag, xbUInt32 ulAddKeyRecNo );
576 xbInt16 KeySetPosDel( xbMdxTag *mpTag );
577 xbInt16 LoadTagDetail( xbInt16 iOption, xbMdxTag *tte );
578 xbUInt32 PageToBlock( xbUInt32 ulPageNo );
579 xbInt16 TagSerialNo( xbInt16 iOption, xbMdxTag *mpTag );
580 xbInt16 UpdateTagSize( xbMdxTag *mpTag, xbUInt32 ulTagSz );
581
582 #ifdef XB_DEBUG_SUPPORT
583 xbInt16 PrintKey( void *vpTag, xbIxNode *npNode, xbInt16 iKeyNo, xbInt16 iDepth, char cType, xbInt16 iOutputOpt );
584 #endif
585
586
587 };
588 #endif /* XB_MDX_SUPPORT */
589
590
591#ifdef XB_TDX_SUPPORT
592
593class XBDLLEXPORT xbIxTdx : public xbIxMdx {
594 public:
595 xbIxTdx( xbDbf * d );
596 ~xbIxTdx();
597
598 xbInt16 CreateTag( const xbString &sName, const xbString &sKey, const xbString &sFilter, xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverlay, void **vpTag );
599
600 protected:
601 friend class xbDbf;
602 xbInt16 Close();
603 xbInt16 DeleteTag( void *vpTag );
604
605 private:
606};
607
608#endif /* XB_TDX_SUPPORT */
609
610
611 } /* namespace xb */
612 #endif /* XB_INDEX_SUPPORT */
613#endif /* __XB_INDEX_H__ */
Definition: xbdate.cpp:19
double xbDouble
Definition: xbtypes.h:23
short int xbBool
Definition: xbtypes.h:24
class XBDLLEXPORT xbDbf
Definition: xbtblmgr.h:28
#define XB_NO_ERROR
Definition: xbretcod.h:24
#define xbFalse
Definition: xbtypes.h:29