PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/lldepthstack.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 99 lines | 61 code | 12 blank | 26 comment | 2 complexity | ef27ddac0a06e9853568279ac229f842 MD5 | raw file
 1/** 
 2 * @file lldepthstack.h
 3 * @brief Declaration of the LLDepthStack 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
27#ifndef LL_LLDEPTHSTACK_H
28#define LL_LLDEPTHSTACK_H
29
30#include "linked_lists.h"
31
32template <class DATA_TYPE> class LLDepthStack
33{
34private:
35	LLLinkedList<DATA_TYPE> mStack;
36	U32						mCurrentDepth;
37	U32						mMaxDepth;
38
39public:
40	LLDepthStack() : mCurrentDepth(0), mMaxDepth(0) {}
41	~LLDepthStack()	{}
42
43	void setDepth(U32 depth)
44	{
45		mMaxDepth = depth;
46	}
47
48	U32 getDepth(void) const
49	{
50		return mCurrentDepth;
51	}
52
53	void push(DATA_TYPE *data)
54	{ 
55		if (mCurrentDepth < mMaxDepth)
56		{
57			mStack.addData(data); 
58			mCurrentDepth++;
59		}
60		else
61		{
62			// the last item falls off stack and is deleted
63			mStack.getLastData();
64			mStack.deleteCurrentData();	
65			mStack.addData(data);
66		}
67	}
68	
69	DATA_TYPE *pop()
70	{ 
71		DATA_TYPE *tempp = mStack.getFirstData(); 
72		if (tempp)
73		{
74			mStack.removeCurrentData(); 
75			mCurrentDepth--;
76		}
77		return tempp; 
78	}
79	
80	DATA_TYPE *check()
81	{ 
82		DATA_TYPE *tempp = mStack.getFirstData(); 
83		return tempp; 
84	}
85	
86	void deleteAllData()
87	{ 
88		mCurrentDepth = 0;
89		mStack.deleteAllData(); 
90	}
91	
92	void removeAllNodes()
93	{ 
94		mCurrentDepth = 0;
95		mStack.removeAllNodes(); 
96	}
97};
98
99#endif