21#ifndef __XB_XBLNKLSTORD_H__
22#define __XB_XBLNKLSTORD_H__
24#ifdef XB_LINKLIST_SUPPORT
30template<
class xbNodeType>
31class XBDLLEXPORT xbLinkListOrd {
37 xbLinkListNode<xbNodeType> *GetHeadNode()
const;
38 xbLinkListNode<xbNodeType> *GetEndNode()
const;
39 xbLinkListNode<xbNodeType> *GetNodeForKey(
const xbString &sKey )
const;
41 xbInt16 GetDataForKey (
const xbNodeType &ntKey, xbString &sData );
45 xbUInt32 GetNodeCnt ()
const;
46 xbUInt32 GetNodeCnt (
const xbString &sNodeKey )
const;
47 xbInt16 InsertKey (
const xbNodeType &ntKey );
48 xbInt16 InsertKey (
const xbNodeType &ntKey,
const xbString &sData );
49 xbInt16 InsertKey (
const xbNodeType &ntKey, xbUInt32 ulData );
51 xbBool KeyExists (
const xbNodeType &ntKey )
const;
52 xbInt16 RemoveKey (
const xbNodeType &ntKey );
53 xbInt16 RemoveFromEnd ( xbNodeType &ntKey );
54 xbInt16 RemoveFromFront( xbNodeType &ntKey );
55 xbInt16 RemoveFromFront();
56 void SetDupKeys (
xbBool bAllowDupKeys );
57 xbInt16 UpdateForKey (
const xbNodeType &ntKey,
const xbString &sData );
63 xbLinkListNode<xbNodeType> *llStartPtr;
64 xbLinkListNode<xbNodeType> *llEndPtr;
69template<
class xbNodeType>
70xbLinkListOrd<xbNodeType>::xbLinkListOrd(){
77template<
class xbNodeType>
78xbLinkListOrd<xbNodeType>::~xbLinkListOrd(){
82template<
class xbNodeType>
83void xbLinkListOrd<xbNodeType>::Clear(){
84 xbLinkListNode<xbNodeType> *cPtr = llStartPtr, *tPtr;
85 for( xbUInt32 i = 0; i < ulNodeCnt; i++ ){
87 cPtr = cPtr->GetNextNode();
99template<
class xbNodeType>
100xbLinkListNode<xbNodeType> * xbLinkListOrd<xbNodeType>::GetHeadNode()
const{
104template<
class xbNodeType>
105xbLinkListNode<xbNodeType> * xbLinkListOrd<xbNodeType>::GetEndNode()
const{
109template<
class xbNodeType>
110xbUInt32 xbLinkListOrd<xbNodeType>::GetNodeCnt()
const{
114template<
class xbNodeType>
115xbUInt32 xbLinkListOrd<xbNodeType>::GetNodeCnt(
const xbString &sNodeKey )
const{
118 xbLinkListNode<xbNodeType> *currPtr = llStartPtr;
120 while( currPtr && ( sNodeKey > currPtr->GetKey())) {
121 currPtr = currPtr->GetNextNode();
125 while( currPtr && ( sNodeKey == currPtr->GetKey())) {
127 currPtr = currPtr->GetNextNode();
133template<
class xbNodeType>
134xbInt16 xbLinkListOrd<xbNodeType>::InsertKey(
const xbNodeType &ntKey ){
136 return InsertKey( ntKey, s );
142template<
class xbNodeType>
143xbInt16 xbLinkListOrd<xbNodeType>::InsertKey(
const xbNodeType &ntKey, xbUInt32 ul ){
146 s.Sprintf(
"%ld", ul );
147 return InsertKey( ntKey, s );
151template<
class xbNodeType>
152xbInt16 xbLinkListOrd<xbNodeType>::InsertKey(
const xbNodeType &ntKey,
const xbString &sData ){
154 xbLinkListNode<xbNodeType> *p =
new xbLinkListNode<xbNodeType>( ntKey, sData );
159 xbLinkListNode<xbNodeType> *currPtr = llStartPtr;
160 xbLinkListNode<xbNodeType> *prevPtr = NULL;
163 while( currPtr && ntKey > currPtr->GetKey() ){
165 currPtr = currPtr->GetNextNode();
167 if( currPtr && ntKey == currPtr->GetKey() && bAllowDupKeys == 0 ){
172 if( currPtr == NULL ){
175 prevPtr->SetNextNode( p );
176 p->SetPrevNode( prevPtr );
178 }
else if( currPtr->GetPrevNode() == NULL ){
180 p->SetNextNode( llStartPtr );
181 llStartPtr->SetPrevNode( p );
186 p->SetNextNode( currPtr );
187 p->SetPrevNode( currPtr->GetPrevNode());
188 currPtr->SetPrevNode( p );
189 prevPtr->SetNextNode( p );
200template<
class xbNodeType>
201xbInt16 xbLinkListOrd<xbNodeType>::RemoveKey(
const xbNodeType &ntKey ){
203 xbLinkListNode<xbNodeType> *currPtr = llStartPtr;
204 xbLinkListNode<xbNodeType> *prevPtr = NULL;
206 while( currPtr && ntKey > currPtr->GetKey() ){
208 currPtr = currPtr->GetNextNode();
211 if( currPtr && ntKey == currPtr->GetKey()){
213 if( prevPtr == NULL ){
214 llStartPtr = currPtr->GetNextNode();
217 llStartPtr->SetPrevNode( NULL );
222 }
else if( currPtr->GetNextNode() == NULL ){
224 prevPtr->SetNextNode( NULL );
230 prevPtr->SetNextNode( currPtr->GetNextNode());
231 currPtr->GetNextNode()->SetPrevNode( prevPtr );
241template<
class xbNodeType>
242xbInt16 xbLinkListOrd<xbNodeType>::RemoveFromFront( xbNodeType &ntKey ){
246 xbLinkListNode<xbNodeType> *p = llStartPtr;
247 llStartPtr = p->GetNextNode();
249 llStartPtr->SetPrevNode( NULL );
256template<
class xbNodeType>
257xbInt16 xbLinkListOrd<xbNodeType>::RemoveFromFront(){
261 xbLinkListNode<xbNodeType> *p = llStartPtr;
262 llStartPtr = p->GetNextNode();
264 llStartPtr->SetPrevNode( NULL );
276template<
class xbNodeType>
277xbInt16 xbLinkListOrd<xbNodeType>::RemoveFromEnd( xbNodeType &ntKey ){
281 xbLinkListNode<xbNodeType> *p = llEndPtr;
282 llEndPtr = p->GetPrevNode();
283 llEndPtr->SetNextNode( NULL );
290template<
class xbNodeType>
291xbBool xbLinkListOrd<xbNodeType>::GetDupKeys(){
292 return bAllowDupKeys;
295template<
class xbNodeType>
296void xbLinkListOrd<xbNodeType>::SetDupKeys(
xbBool bAllowDupKeys ){
297 this->bAllowDupKeys = bAllowDupKeys;
301template<
class xbNodeType>
302xbBool xbLinkListOrd<xbNodeType>::KeyExists(
const xbNodeType &ntKey )
const {
304 xbLinkListNode<xbNodeType> *currPtr = llStartPtr;
305 while( currPtr && ntKey > currPtr->GetKey() ){
306 currPtr = currPtr->GetNextNode();
308 if( currPtr && ntKey == currPtr->GetKey()){
316template<
class xbNodeType>
317xbInt16 xbLinkListOrd<xbNodeType>::GetDataForKey(
const xbNodeType &ntKey, xbString &sData ){
319 xbLinkListNode<xbNodeType> *currPtr = llStartPtr;
320 while( currPtr && ntKey > currPtr->GetKey() ){
321 currPtr = currPtr->GetNextNode();
324 if( currPtr && ntKey == currPtr->GetKey()){
325 sData = currPtr->GetData();
333template<
class xbNodeType>
334xbInt16 xbLinkListOrd<xbNodeType>::UpdateForKey(
const xbNodeType &ntKey,
const xbString &sData ){
337 return InsertKey( ntKey, sData );
338 xbLinkListNode<xbNodeType> * currPtr = llStartPtr;
339 xbLinkListNode<xbNodeType> * prevPtr = NULL;
340 while( currPtr && ntKey > currPtr->GetKey() ) {
342 currPtr = currPtr->GetNextNode();
345 if( currPtr && ntKey == currPtr->GetKey() ) {
346 xbLinkListNode<xbNodeType> *p =
new xbLinkListNode<xbNodeType>( ntKey, sData );
348 prevPtr->SetNextNode( p );
351 p->SetNextNode( currPtr->GetNextNode() );
352 p->SetPrevNode( currPtr->GetPrevNode() );
357 return InsertKey( ntKey, sData );
Definition: xbdate.cpp:19
short int xbBool
Definition: xbtypes.h:24
#define XB_INVALID_NODELINK
Definition: xbretcod.h:28
#define XB_NOT_FOUND
Definition: xbretcod.h:39
#define XB_NO_ERROR
Definition: xbretcod.h:24
#define XB_KEY_NOT_UNIQUE
Definition: xbretcod.h:29
#define XB_NO_MEMORY
Definition: xbretcod.h:25
#define xbTrue
Definition: xbtypes.h:28
#define xbFalse
Definition: xbtypes.h:29