⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbllist.h

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 H
字号:
/*____________________________________________________________________________*\
 *

 Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.

 These sources, libraries and applications are
 FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
 as long as the following conditions are adhered to.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer. 

 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

 3. The name of the author may not be used to endorse or promote products
    derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.

 *____________________________________________________________________________*|
 *
 * $Source: /cvsroot/pi3web/Pi3Web_200/Source/Base/DblList.h,v $
 * $Date: 2003/05/13 18:41:55 $
 *
 Description:
	Definition file for a doubly linked list and iterator classes.
\*____________________________________________________________________________*/
//$HeaderTop:$

#ifndef DBLLIST_H_
#define DBLLIST_H_

#include <assert.h>
#include "PIAlloc.h"

/*____________________________________________________________________________*\
 *
 Declarations:
\*____________________________________________________________________________*/
class DblList;

/*____________________________________________________________________________*\
 *
 Class:
 Description:
\*____________________________________________________________________________*/
class _Node
{
public:
	typedef void *type;

private:
	type lObj;
	_Node *pLast;
	_Node *pNext;
	inline void Detach()
		{ pLast->pNext=pNext; pNext->pLast=pLast; };
	inline _Node(_Node *pL, _Node *pN)
		:   lObj(0), pLast(pL), pNext(pN) {};
	inline _Node(type lO, _Node *pL, _Node *pN)
		:   lObj(lO), pLast(pL), pNext(pN)
		{ pLast->pNext=this; pNext->pLast=this; };
	inline void Delete()
		{ Detach(); PI_DELETE( this ); };	

	/* --- friends --- */
	friend class DblListIterator;
	friend class ConstDblListIterator;
	friend class DblList;
};

/*____________________________________________________________________________*\
 *
 Class:
 Description:
\*____________________________________________________________________________*/
class DblListIterator
{
private:
	_Node *pSentinel;
	_Node *p;
	_Node *ObjectAtIndex( const int i);
	inline DblListIterator( const DblListIterator & )	
		{ /* do not use copy constructor! */ assert( 0 ); };

public:
	inline DblListIterator( DblList &tList );
	inline DblListIterator &operator=( DblList &tList );
	inline int BadIndex()						{ return p==pSentinel; };
	inline DblListIterator &operator++()
		{ p=p->pNext; return *this; };
	inline DblListIterator &operator++(int)
		{ p=p->pNext; return *this; };
	inline _Node::type Current()				{ return p->lObj; };
	inline _Node *Current_Node()				{ return p; };
	inline _Node::type operator[]( const int i)	{ return ObjectAtIndex(i)->lObj; };

	/* --- friends --- */
	friend class DblList;
};

/*____________________________________________________________________________*\
 *
 Class:
 Description:
\*____________________________________________________________________________*/
class ConstDblListIterator
{
private:
	const _Node *pSentinel;
	const _Node *p;
	const _Node *ObjectAtIndex( const int i);
	inline ConstDblListIterator( const ConstDblListIterator & )	
		{ /* do not use copy constructor! */ assert( 0 ); };

public:
	inline ConstDblListIterator( const DblList &tList );
	inline ConstDblListIterator &operator=( const DblList &tList );
	inline int BadIndex() const						{ return p==pSentinel; };
	inline const ConstDblListIterator &operator++()
		{ p=p->pNext; return *this; };
	inline const ConstDblListIterator &operator++(int)
		{ p=p->pNext; return *this; };
	inline const _Node::type Current() const		{ return p->lObj; };
	inline const _Node *Current_Node() const		{ return p; };
	inline const _Node::type operator[]( const int i)
		{ return ObjectAtIndex(i)->lObj; };
};

/*____________________________________________________________________________*\
 *
 Class:
 Description:
\*____________________________________________________________________________*/
class DblList
{
private:
	_Node tSentinel;
	inline _Node &Sentinel()					{ return tSentinel; };
	inline const _Node &Sentinel() const		{ return tSentinel; };
	inline _Node *Begin()						{ return Sentinel().pNext; };
	inline const _Node *Begin() const			{ return Sentinel().pNext; };
	inline _Node *End()							{ return Sentinel().pLast; };
	inline const _Node *End() const				{ return Sentinel().pLast; };
	int iSize;

	DblList( const DblList & )
		: 	tSentinel( 0, 0 ), iSize(0)
		{ /* do not allow copy constructor! */ assert( 0 ); };

public:
	DblList() : 	tSentinel(&Sentinel(), &Sentinel()), iSize(0)
												{};
	~DblList()									{ Clear(); };
	inline void PushBack( _Node::type );
	inline void Append( _Node::type );
	inline _Node::type Cap();
	_Node::type Detach( const int i );
	_Node::type Detach( DblListIterator &i );
	inline const int Size()	const				{ return iSize; };
	inline _Node::type operator[]( const int i );
	inline const _Node::type operator[]( const int i ) const;
	inline _Node::type First()				{ return Sentinel().pNext->lObj; };
	inline const _Node::type First() const	{ return Sentinel().pNext->lObj; };
	inline _Node::type Last()				{ return Sentinel().pLast->lObj; };
	inline const _Node::type Last() const	{ return Sentinel().pLast->lObj; };
	void Clear();

	typedef _Node::type type;
	
	/* --- friends --- */
	friend class DblListIterator;
	friend class ConstDblListIterator;
};

#include "DblList.hpp"

#endif /* DBLLIST_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -