1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef YY_CY_STACK_HH_INCLUDED
23 #define YY_CY_STACK_HH_INCLUDED
27 template <class Type_>
30 typedef std::reverse_iterator<Type_ *> const_iterator;
38 for (Type_ *i(begin_); i != end_; ++i)
43 size_t capacity(capacity_ - begin_);
49 Type_ *data(static_cast<Type_ *>(::operator new(sizeof(Type_) * capacity)));
51 size_t size(end_ - begin_);
52 for (size_t i(0); i != size; ++i) {
53 Type_ &old(begin_[i]);
54 new (data + i) Type_(old);
58 ::operator delete(begin_);
62 capacity_ = data + capacity;
76 ::operator delete(begin_);
79 _finline Type_ &operator [](size_t i) {
83 _finline const Type_ &operator [](size_t i) const {
87 _finline void push(Type_ &t) {
88 if (end_ == capacity_)
90 new (end_++) Type_(t);
97 _finline void pop(unsigned int size) {
98 for (; size != 0; --size)
107 _finline size_t size() const {
108 return end_ - begin_;
111 _finline const_iterator begin() const {
112 return const_iterator(end_);
115 _finline const_iterator end() const {
116 return const_iterator(begin_);
120 stack(const stack &);
121 stack &operator =(const stack &);
124 template <class Type_, class Stack_ = stack<Type_> >
127 slice(const Stack_ &stack, unsigned int range) :
133 _finline const Type_ &operator [](unsigned int i) const {
134 return stack_[range_ - i];
138 const Stack_ &stack_;
144 #endif/*YY_CY_STACK_HH_INCLUDED*/