OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fast_back_stack.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 
14 #ifndef OSG_FAST_BACK_STACK
15 #define OSG_FAST_BACK_STACK 1
16 
17 #include <vector>
18 
19 namespace osg {
20 
29 template<class T>
31 {
32  public:
33 
34  inline fast_back_stack():_value(),_stack(),_size(0) {}
35 
36  inline fast_back_stack(const fast_back_stack& fbs):_value(fbs._value),_stack(fbs._stack),_size(fbs._size) {}
37 
38  inline fast_back_stack(const T& value):_value(value),_stack(),_size(1) {}
39 
41  {
42  _value = fbs._value;
43  _stack = fbs._stack;
44  _size = fbs._size;
45  return *this;
46  }
47 
48  inline void clear() { _stack.clear(); _size = 0; }
49 
50  inline bool empty() const { return _size==0; }
51 
52  inline unsigned int size() const { return _size; }
53 
54  inline T& back() { return _value; }
55 
56  inline const T& back() const { return _value; }
57 
58  inline void push_back()
59  {
60  if (_size>0)
61  {
62  _stack.push_back(_value);
63  }
64  ++_size;
65  }
66 
67  inline void push_back(const T& value)
68  {
69  if (_size>0)
70  {
71  _stack.push_back(_value);
72  }
73  _value = value;
74  ++_size;
75  }
76 
77  inline void pop_back()
78  {
79  if (_size>0)
80  {
81  if (!_stack.empty())
82  {
83  _value = _stack.back();
84  _stack.pop_back();
85  }
86  --_size;
87  } // else error condition.
88  }
89 
90  T _value;
91  std::vector<T> _stack;
92  unsigned int _size;
93 };
94 
95 }
96 
97 #endif
const T & back() const
fast_back_stack(const fast_back_stack &fbs)
void push_back(const T &value)
std::vector< T > _stack
fast_back_stack(const T &value)
Definition: AlphaFunc.h:19
unsigned int size() const
fast_back_stack & operator=(const fast_back_stack &fbs)