ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change
on this file since be03945 was
860f19f,
checked in by Aaron Moss <a3moss@…>, 7 years ago
|
Clean up code edits
|
-
Property mode set to
100644
|
File size:
979 bytes
|
Line | |
---|
1 | #include "cpp-vstack.hpp" |
---|
2 | #include <utility> |
---|
3 | |
---|
4 | stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {} |
---|
5 | |
---|
6 | void stack::clear() { |
---|
7 | for ( node * next = head; next; ) { |
---|
8 | node * crnt = next; |
---|
9 | next = crnt->next; |
---|
10 | delete crnt; |
---|
11 | } |
---|
12 | head = nullptr; |
---|
13 | } |
---|
14 | |
---|
15 | void stack::copy( const stack & o ) { |
---|
16 | node ** crnt = &head; |
---|
17 | for ( node * next = o.head; next; next = next->next ) { |
---|
18 | *crnt = new node{ *next->value }; /***/ |
---|
19 | crnt = &(*crnt)->next; |
---|
20 | } |
---|
21 | *crnt = nullptr; |
---|
22 | } |
---|
23 | |
---|
24 | stack::stack() : head( nullptr ) {} |
---|
25 | stack::stack( const stack & o ) { copy( o ); } |
---|
26 | stack::~stack() { clear(); } |
---|
27 | |
---|
28 | stack & stack::operator=( const stack & o ) { |
---|
29 | if ( this == &o ) return *this; |
---|
30 | clear(); |
---|
31 | copy( o ); |
---|
32 | return *this; |
---|
33 | } |
---|
34 | |
---|
35 | bool stack::empty() const { return head == nullptr; } |
---|
36 | |
---|
37 | void stack::push( const object & value ) { head = new node{ value, head }; /***/ } |
---|
38 | |
---|
39 | ptr<object> stack::pop() { |
---|
40 | node * n = head; |
---|
41 | head = n->next; |
---|
42 | ptr<object> v = std::move( n->value ); |
---|
43 | delete n; |
---|
44 | return v; |
---|
45 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.