blob: b0e81ff4f9256a148a4da0384dff2aa83b52074c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// file : xsde/cxx/stack.ixx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
namespace xsde
{
namespace cxx
{
inline stack::
~stack ()
{
delete[] data_;
}
inline stack::
stack (size_t el_size, void* first_el)
: el_size_ (el_size),
first_ (first_el),
data_ (0),
size_ (0),
capacity_ (0)
{
}
inline void stack::
pop ()
{
--size_;
}
#ifdef XSDE_EXCEPTIONS
inline void stack::
#else
inline stack::error stack::
#endif
push ()
{
if (size_ > capacity_)
{
#ifdef XSDE_EXCEPTIONS
grow ();
#else
if (error e = grow ())
return e;
#endif
}
++size_;
#ifndef XSDE_EXCEPTIONS
return error_none;
#endif
}
inline void* stack::
top ()
{
return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_;
}
inline void stack::
clear ()
{
size_ = 0;
}
inline bool stack::
empty () const
{
return size_ == 0;
}
inline size_t stack::
size () const
{
return size_;
}
inline size_t stack::
element_size () const
{
return el_size_;
}
}
}
|