CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
OdStack.h
Go to the documentation of this file.
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24
25
26
27#ifndef _ODSTACK_H_
28#define _ODSTACK_H_
29
30#include "TD_PackPush.h"
31
32template <class T> class OdStackItem;
33template <class T> class OdStack;
34
39template <class T>
40class OdStackItem : public T
41{
42 friend class OdStack<T>;
43protected:
45 inline OdStackItem(OdStackItem* pUnder, const T& val)
46 : T(val), m_pUnder(pUnder) { }
47 inline OdStackItem(OdStackItem* pUnder) : m_pUnder(pUnder) { }
48};
49
54template <class T>
56{
57 typedef OdStackItem<T> TItem;
58public:
60 inline OdStack() : m_pTop(0) { }
61 inline void push(const T& inVal)
62 {
63 m_pTop = new TItem(m_pTop, inVal);
64 }
65 inline T* push()
66 {
67 m_pTop = new TItem(m_pTop);
68 return top();
69 }
70 inline void pop(T& outVal)
71 {
72 ODA_ASSERT(m_pTop); // pop from empty stack
73 outVal = *m_pTop;
74 pop();
75 }
76
77 inline const T* top() const { return m_pTop; }
78 inline T* top() { return m_pTop; }
79
80 inline void pop()
81 {
82 TItem* pTop = m_pTop;
83 ODA_ASSERT(pTop); // pop from empty stack
84 m_pTop = pTop->m_pUnder;
85 delete pTop;
86 }
87
88 inline ~OdStack()
89 {
90 while(m_pTop)
91 {
92 pop();
93 }
94 }
95
96 inline T* beforeTop() const
97 {
99 return m_pTop->m_pUnder;
100 }
101
102 bool empty()const { return m_pTop == 0; }
103
104 size_t size() const
105 {
106 size_t n = 0;
107 for ( TItem* p = m_pTop; p; p = p->m_pUnder)
108 ++n;
109 return n;
110 }
111};
112
113#include "TD_PackPop.h"
114
115#endif //#ifndef _ODSTACK_H_
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
bool empty() const
Definition: OdStack.h:102
const T * top() const
Definition: OdStack.h:77
void push(const T &inVal)
Definition: OdStack.h:61
T * top()
Definition: OdStack.h:78
~OdStack()
Definition: OdStack.h:88
T * beforeTop() const
Definition: OdStack.h:96
size_t size() const
Definition: OdStack.h:104
TItem * m_pTop
Definition: OdStack.h:59
void pop(T &outVal)
Definition: OdStack.h:70
T * push()
Definition: OdStack.h:65
OdStack()
Definition: OdStack.h:60
void pop()
Definition: OdStack.h:80
OdStackItem * m_pUnder
Definition: OdStack.h:44
OdStackItem(OdStackItem *pUnder)
Definition: OdStack.h:47
OdStackItem(OdStackItem *pUnder, const T &val)
Definition: OdStack.h:45