1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_FAST_BACK_STACK
15#define OSG_FAST_BACK_STACK 1
21/** Simple stack implementation that keeps the back() cached locally for fast access
22 * rather than at the back of the vector which is the traditional stack implementation.
23 * A conventional std::vector<> stores the rest of the stack. Although fast_back_stack
24 * contains a stl container it only implements the back push_back(),pop_back()
25 * and back() methods so is not as general purpose as stl stack implementation.
26 * The focus of the fast_back_stack is purely to maximize the speed at which the
27 * back can be accessed.*/
34 inline fast_back_stack():_value(),_stack(),_size(0) {}
36 inline fast_back_stack(const fast_back_stack& fbs):_value(fbs._value),_stack(fbs._stack),_size(fbs._size) {}
38 inline fast_back_stack(const T& value):_value(value),_stack(),_size(1) {}
40 fast_back_stack& operator = (const fast_back_stack& fbs)
48 inline void clear() { _stack.clear(); _size = 0; }
50 inline bool empty() const { return _size==0; }
52 inline unsigned int size() const { return _size; }
54 inline T& back() { return _value; }
56 inline const T& back() const { return _value; }
58 inline void push_back()
62 _stack.push_back(_value);
67 inline void push_back(const T& value)
71 _stack.push_back(_value);
77 inline void pop_back()
83 _value = _stack.back();
87 } // else error condition.
91 std::vector<T> _stack;