📄 mxdblist.cpp
字号:
/* ------------------------------------------------------------------------*/
/* MX Resource Version 1.01 */
/* */
/* Copyright(c) MX-Groups 1993 */
/* all right reserved */
/* ------------------------------------------------------------------------*/
/* ------------------------------------------------------------------------*/
/* */
/* MXDBLIST.CPP */
/* */
/* Copyright (c) MX Groups */
/* All Rights Reserved. */
/* Writen by MHW 1993 */
/* */
/* Member functions of class MXCFG */
/* */
/* ------------------------------------------------------------------------*/
#include "mxdblist.h"
DBList::DBList()
{
total = curpos = 0;
firstobject = currobject = tailobject = 0L;
}
dataobj *DBList::add( dataobj *obj )
// insert after curobj
{
if ( !obj ) return (dataobj *)0;
if ( !total )
{
firstobject = currobject = tailobject = obj;
firstobject->prevobj = tailobject->nextobj = 0;
}
else
{
obj->nextobj = currobject->nextobj;
if ( currobject->nextobj )
(currobject->nextobj)->prevobj = obj;
obj->prevobj = currobject;
currobject->nextobj = obj;
}
total++;
return currobject;
}
dataobj *DBList::addAtHead( dataobj *obj )
{
if ( !obj ) return (dataobj *)0;
if ( !total )
{
firstobject = currobject = tailobject = obj;
firstobject->prevobj = tailobject->nextobj = 0;
}
else
{
obj->prevobj = 0;
obj->nextobj = firstobject;
firstobject->prevobj = obj;
}
total++;
return firstobject = obj;
}
dataobj *DBList::addAtTail( dataobj *obj )
{
if ( !obj ) return (dataobj *)0;
if ( !total )
{
firstobject = currobject = tailobject = obj;
firstobject->prevobj = tailobject->nextobj = 0;
}
else
{
obj->nextobj = 0;
obj->prevobj = tailobject;
tailobject->nextobj = obj;
}
total++;
return tailobject = obj;
}
void DBList::deleteAll()
{
dataobj *obj;
int i;
for( i=0; i<total; i++ ) {
obj = firstobject;
firstobject = obj->nextobj;
//if ( obj ) delete obj;
if ( obj ) {
obj->safeDelNode( obj );
//delete obj;
}
}
curpos = total = 0;
firstobject = currobject = tailobject = NULL;
}
bool DBList::deleteNode( int index )
{
dataobj *next;
if ( total == 0 ) return false;
if ( !peekAt(index) ) return false;
next = currobject->nextobj;
if ( next == NULL )
{
next = currobject->prevobj;
if ( currobject == tailobject ) tailobject = next;
if ( curpos ) curpos--;
}
if ( currobject == firstobject ) firstobject = next;
if ( currobject->prevobj )
( currobject->prevobj )->nextobj = currobject->nextobj;
if ( currobject->nextobj )
( currobject->nextobj )->prevobj = currobject->prevobj;
currobject->safeDelNode(currobject);
//delete currobject;
total--;
currobject = next;
return true;
}
dataobj *DBList::peekAt( int index )
{
int distance = curpos - index;
if ( distance > 0 ) return forward( distance );
if ( distance < 0 ) return nextward( -distance );
return currobject;
}
dataobj *DBList::forward( int steps )
{
if ( steps > curpos ) return NULL;
while ( steps-- > 0 )
{
curpos--;
currobject = currobject->prevobj;
}
return currobject;
}
dataobj *DBList::nextward( int steps )
{
if ( steps >= (total- curpos) ) return NULL;
while ( steps-- > 0 )
{
curpos++;
currobject = currobject->nextobj;
}
return currobject;
}
dataobj *DBList::operator[](int order)
{
if ( order <0 || order >=total ) return NULL;
return peekAt(order);
}
dataobj *DBList::findMember( dataobj * tofind )
{
int i =0, pos = tellAt();
dataobj *obj = peekAt(0);
do {
if ( obj == NULL ) break;
if ( obj->isEqual(tofind) ) break;
obj = nextward();
} while( ++i<total );
peekAt(pos);
return (i<total)? obj:NULL;
}
bool DBList::hasMember( dataobj * member )
{
int i =0, pos = tellAt();
dataobj *obj = peekAt(0);
do {
if ( obj == NULL ) break;
if ( obj->isEqual(member) ) break;
obj = nextward();
} while( ++i<total );
peekAt(pos);
return (i<total)? true:false;
}
void DBList::forEach( void (*func)( dataobj &, int &), int ¶)
{
int i =0, pos = tellAt();
dataobj *obj;
obj = peekAt(0);
do {
if ( obj == NULL ) break;
func( *obj, para );
obj = nextward();
} while( ++i<total );
peekAt(pos);
}
/*=============================================
MXDBLIST Version 1.00
CopyRight(c) Mx Groups 1993
All right reserved
===============================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -