PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/lldlinked.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 93 lines | 57 code | 11 blank | 25 comment | 4 complexity | 0021c8b1a19bef39fda025a4743ee18a MD5 | raw file
 1/** 
 2 * @file lldlinked.h
 3 * @brief Declaration of the LLDLinked class.
 4 *
 5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26#ifndef LL_LLDLINKED_H
27#define LL_LLDLINKED_H
28
29template <class Type> class LLDLinked
30{
31	LLDLinked* mNextp;
32	LLDLinked* mPrevp;
33public:
34
35	Type*   getNext()  { return (Type*)mNextp; }
36	Type*   getPrev()  { return (Type*)mPrevp; }
37	Type*   getFirst() { return (Type*)mNextp; }
38
39	void    init()
40	{
41		mNextp = mPrevp = NULL;
42	}
43
44	void    unlink()
45	{
46		if (mPrevp) mPrevp->mNextp = mNextp;
47		if (mNextp) mNextp->mPrevp = mPrevp;
48	}
49
50	 LLDLinked() { mNextp = mPrevp = NULL; }
51	virtual ~LLDLinked() { unlink(); }
52
53	virtual void    deleteAll()
54	{
55		Type *curp = getFirst();
56		while(curp)
57		{
58			Type *nextp = curp->getNext();
59			curp->unlink();
60			delete curp;
61			curp = nextp;
62		}
63	}
64
65	void relink(Type &after)
66	{
67		LLDLinked *afterp = (LLDLinked*)&after;
68		afterp->mPrevp = this;
69		mNextp = afterp;
70	}
71
72	virtual void    append(Type& after)
73	{
74		LLDLinked *afterp = (LLDLinked*)&after;
75		afterp->mPrevp    = this;
76		afterp->mNextp    = mNextp;
77		if (mNextp) mNextp->mPrevp = afterp;
78		mNextp            = afterp;
79	}
80
81	virtual void    insert(Type& before)
82	{
83		LLDLinked *beforep = (LLDLinked*)&before;
84		beforep->mNextp    = this;
85		beforep->mPrevp    = mPrevp;
86		if (mPrevp) mPrevp->mNextp = beforep;
87		mPrevp             = beforep;
88	}
89
90	virtual void    put(Type& obj) { append(obj); }
91};
92
93#endif