Xbase64 Class Library  3.1.2
xbntx.h
Go to the documentation of this file.
1 /* xbntx.h
2 
3  Xbase64 project source code
4 
5  This file contains a header file for the xbNdx object, which is used
6  for handling xbNdx type indices.
7 
8  Copyright (C) 1997,2003 Bob Cotton
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 
24 
25  Contact:
26 
27  Email:
28 
29  xdb-devel@lists.sourceforge.net
30  xdb-users@lists.sourceforge.net
31 
32 
33  Regular Mail:
34 
35  XBase Support
36  149C South Main St
37  Keller Texas, 76248
38  USA
39 
40 */
41 
42 #ifndef __XB_NTX_H__
43 #define __XB_NTX_H__
44 
45 #ifdef __GNU_LesserG__
46 #pragma interface
47 #endif
48 
49 #include <xbase64/xbase64.h>
50 #include <string.h>
51 
55 #define XB_NTX_NODE_SIZE 1024
56 
58 
61 struct NtxHeadNode { /* ntx header on disk */
62  xbUShort Signature; /* Clipper 5.x or Clipper 87 */
63  xbUShort Version; /* Compiler Version */
64  /* Also turns out to be a last modified counter */
65  xbLong StartNode; /* Offset in file for first index */
66  xbULong UnusedOffset; /* First free page offset */
67  xbUShort KeySize; /* Size of items (KeyLen + 8) */
68  xbUShort KeyLen; /* Size of the Key */
69  xbUShort DecimalCount; /* Number of decimal positions */
70  xbUShort KeysPerNode; /* Max number of keys per page */
71  xbUShort HalfKeysPerNode; /* Min number of keys per page */
72  char KeyExpression[256]; /* Null terminated key expression */
73  unsigned Unique; /* Unique Flag */
74  char NotUsed[745];
75 };
76 
78 
81 struct NtxLeafNode { /* ndx node on disk */
84 };
85 
86 
88 
91 struct NtxItem
92 {
95  char Key[256];
96 };
97 
99 
102 struct xbNodeLink { /* ndx node memory */
105  xbUShort CurKeyNo; /* 0 - KeysPerNode-1 */
107  struct NtxLeafNode Leaf;
109 };
110 
112 
115 class XBDLLEXPORT xbNtx : public xbIndex
116 {
117 protected:
122  char Node[XB_NTX_NODE_SIZE];
123  xbNodeLink * NodeChain; /* pointer to node chain of index nodes */
124  xbNodeLink * FreeNodeChain; /* pointer to chain of free index nodes */
125  xbNodeLink * CurNode; /* pointer to current node */
126  xbNodeLink * DeleteChain; /* pointer to chain to delete */
127 // xbNodeLink * CloneChain; /* pointer to node chain copy (add dup) */
129 
130 /* private functions */
132  xbShort CompareKey( const char *, const char *, xbShort );
133  xbShort CompareKey( const char *, const char * );
139  virtual xbShort GetHeadNode();
143  void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree = false);
161  xbShort FindKey( const char *, xbShort, xbShort );
169  xbShort FindKey( const char *, xbLong ); /* for a specific dbf no */
170 
171 public:
172  xbNtx();
174  virtual ~xbNtx();
175 
176 /* note to gak - don't uncomment next line - it causes seg faults */
177 // ~NTX() { if( NtxStatus ) CloseIndex(); }
178 
179  void DumpHdrNode ( xbShort Option );
180  void DumpNodeRec ( xbLong );
181  xbShort CreateIndex( const char *, const char *, xbShort, xbShort );
186  xbShort GetCurrentKey(char *key);
188  xbShort UniqueIndex() { return HeadNode.Unique; }
191  xbShort FindKey( const char * );
194  xbShort GetNextKey() { return GetNextKey( 1 ); }
195  xbShort GetLastKey() { return GetLastKey( 0, 1 ); }
196  xbShort GetFirstKey() { return GetFirstKey( 1 ); }
197  xbShort GetPrevKey() { return GetPrevKey( 1 ); }
198  xbShort ReIndex(void (*statusFunc)(xbLong itemNum, xbLong numItems) = 0) ;
199  xbShort KeyExists( char * Key ) { return FindKey( Key, strlen( Key ), 0 ); }
201  virtual void GetExpression(char *buf, int len);
202 #ifdef XBASE_DEBUG
203  xbShort CheckIndexIntegrity( xbShort Option );
204 #endif
205 
206  virtual const char* GetExtWithDot(bool lower);
207 
208  protected:
209  virtual xbUShort GetKeyLen();
210  virtual const char* GetKeyExpression();
211  virtual void FreeNodesMemory();
212 };
213 #endif /* __XB_NTX_H__ */
xbMH struct
Definition: xbdbf.h:190
xbIndex class
Definition: xbindex.h:63
virtual xbShort FindKey()=0
xbULong CurDbfRec
Definition: xbindex.h:126
xbNtx class
Definition: xbntx.h:116
xbShort PutLeafNode(xbLong, xbNodeLink *)
void DumpNodeRec(xbLong)
xbShort SplitINode(xbNodeLink *, xbNodeLink *, xbLong)
xbShort FindKey(const char *, xbLong)
xbShort GetLeafNode(xbLong, xbShort)
xbLong ReusedNodeLinks
Definition: xbntx.h:121
xbShort TouchIndex()
xbShort FindKey(const char *, xbShort, xbShort)
xbUShort DeleteKeyOffset(xbShort, xbNodeLink *)
virtual void FreeNodesMemory()
xbNodeLink * DeleteChain
Definition: xbntx.h:126
xbShort FindKey(const char *)
xbShort KeyExists(xbDouble)
xbLong GetLeftNodeNo(xbShort, xbNodeLink *)
xbShort FindKey()
xbShort UniqueIndex()
Definition: xbntx.h:188
xbNodeLink * NodeChain
Definition: xbntx.h:123
xbShort GetCurrentKey(char *key)
xbShort DeleteKey(xbLong DbfRec)
void DumpHdrNode(xbShort Option)
xbShort CreateIndex(const char *, const char *, xbShort, xbShort)
xbShort GetLastKey()
Definition: xbntx.h:195
xbShort DeleteKeyFromNode(xbShort, xbNodeLink *)
xbShort GetLastKey(xbLong, xbShort)
NtxHeadNode HeadNode
Definition: xbntx.h:118
xbShort ReIndex(void(*statusFunc)(xbLong itemNum, xbLong numItems)=0)
NtxItem PushItem
Definition: xbntx.h:128
virtual const char * GetKeyExpression()
xbShort PutHeadNode(NtxHeadNode *, FILE *, xbShort)
xbShort UpdateParentKey(xbNodeLink *)
xbShort CompareKey(const char *, const char *, xbShort)
virtual const char * GetExtWithDot(bool lower)
xbLong GetTotalNodes()
xbShort CompareKey(const char *, const char *)
xbShort AddToIxList()
xbNodeLink * FreeNodeChain
Definition: xbntx.h:124
void ReleaseNodeMemory(xbNodeLink *n, xbBool doFree=false)
xbUShort InsertKeyOffset(xbShort, xbNodeLink *)
xbNtx(xbDbf *)
xbNodeLink * CurNode
Definition: xbntx.h:125
xbLong GetNextNodeNo()
xbShort KeyWasChanged()
xbShort KeyExists(char *Key)
Definition: xbntx.h:199
xbLong GetDbfNo(xbShort, xbNodeLink *)
void DumpNodeChain()
xbShort PutLeftNodeNo(xbShort, xbNodeLink *, xbLong)
xbShort GetNextKey(xbShort)
virtual xbShort GetHeadNode()
xbShort FindKey(xbDouble)
xbLong NodeLinkCtr
Definition: xbntx.h:120
virtual xbUShort GetKeyLen()
xbULong GetLeafFromInteriorNode(const char *, xbShort)
xbShort PutKeyData(xbShort, xbNodeLink *)
xbShort AddKey(xbLong)
xbShort GetPrevKey()
Definition: xbntx.h:197
xbShort GetFirstKey()
Definition: xbntx.h:196
xbShort GetPrevKey(xbShort)
void ProcessDeleteList()
NtxLeafNode LeafNode
Definition: xbntx.h:119
xbULong GetCurDbfRec()
Definition: xbntx.h:183
char * GetKeyData(xbShort, xbNodeLink *)
xbShort CreateKey(xbShort, xbShort)
xbNodeLink * GetNodeMemory()
xbShort SplitLeafNode(xbNodeLink *, xbNodeLink *, xbShort, xbLong)
xbShort PutDbfNo(xbShort, xbNodeLink *, xbLong)
xbShort GetFirstKey(xbShort)
virtual ~xbNtx()
xbShort PutKeyInNode(xbNodeLink *, xbShort, xbLong, xbLong, xbShort)
xbShort GetNextKey()
Definition: xbntx.h:194
xbShort JoinSiblings(xbNodeLink *, xbShort, xbNodeLink *, xbNodeLink *)
void UpdateDeleteList(xbNodeLink *)
xbUShort GetItemOffset(xbShort, xbNodeLink *, xbShort)
xbUShort GetKeysPerNode()
xbShort RemoveFromIxList()
xbShort RemoveKeyFromNode(xbShort, xbNodeLink *)
virtual void GetExpression(char *buf, int len)
xbShort CalcKeyLen()
xbNtxHeadNode struct
Definition: xbntx.h:61
xbUShort Version
Definition: xbntx.h:63
unsigned Unique
Definition: xbntx.h:73
char NotUsed[745]
Definition: xbntx.h:74
xbUShort KeysPerNode
Definition: xbntx.h:70
xbUShort KeySize
Definition: xbntx.h:67
xbLong StartNode
Definition: xbntx.h:65
xbUShort DecimalCount
Definition: xbntx.h:69
xbUShort Signature
Definition: xbntx.h:62
xbULong UnusedOffset
Definition: xbntx.h:66
xbUShort HalfKeysPerNode
Definition: xbntx.h:71
char KeyExpression[256]
Definition: xbntx.h:72
xbUShort KeyLen
Definition: xbntx.h:68
xbNtxItem struct
Definition: xbntx.h:92
xbULong RecordNumber
Definition: xbntx.h:94
char Key[256]
Definition: xbntx.h:95
xbULong Node
Definition: xbntx.h:93
xbNtxLeafNode struct
Definition: xbntx.h:81
xbUShort NoOfKeysThisNode
Definition: xbntx.h:82
char KeyRecs[XB_NTX_NODE_SIZE]
Definition: xbntx.h:83
#define XBDLLEXPORT
Definition: xbase64.h:86
#define XB_NTX_NODE_SIZE
Definition: xbntx.h:55
long xbLong
Definition: xbtypes.h:61
short int xbBool
xbBool type
Definition: xbtypes.h:78
short int xbShort
xbShort type
Definition: xbtypes.h:60
unsigned short int xbUShort
xbUShort type
Definition: xbtypes.h:55
double xbDouble
xbDouble type
Definition: xbtypes.h:73
unsigned long int xbULong
xbULong type
Definition: xbtypes.h:50