2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * The NyARToolkit is Java edition ARToolKit class library.
\r
5 * Copyright (C)2008-2009 Ryo Iizuka
\r
7 * This program is free software: you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation, either version 3 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
20 * For further information please contact.
\r
21 * http://nyatla.jp/nyatoolkit/
\r
22 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 package jp.nyatla.nyartoolkit.core.types.stack;
\r
26 import java.lang.reflect.*;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
36 public abstract class NyObjectStack<T>
\r
38 protected final T[] _items;
\r
39 protected int _length;
\r
42 * 最大ARRAY_MAX個の動的割り当てバッファを準備する。
\r
45 * @param i_element_type
\r
46 * JavaのGenedicsの制限突破
\r
48 @SuppressWarnings("unchecked")
\r
49 protected NyObjectStack(int i_length,Class<T> i_element_type) throws NyARException
\r
52 this._items = (T[])Array.newInstance(i_element_type, i_length);
\r
53 for (int i =0; i < i_length; i++){
\r
54 this._items[i] =createElement();
\r
60 protected abstract T createElement();
\r
66 * @throws NyARException
\r
68 public final T prePush()
\r
71 if (this._length >= this._items.length){
\r
74 // 使用領域を+1して、予約した領域を返す。
\r
75 T ret = this._items[this._length];
\r
81 * @param i_reserv_length
\r
85 public final void init(int i_reserv_length) throws NyARException
\r
88 if (i_reserv_length >= this._items.length){
\r
89 throw new NyARException();
\r
91 this._length=i_reserv_length;
\r
95 * 見かけ上の要素数を1減らして、そのオブジェクトを返します。
\r
96 * 返却したオブジェクトの内容は、次回のpushまで有効です。
\r
99 public final T pop()
\r
101 assert(this._length>=1);
\r
103 return this._items[this._length];
\r
106 * 見かけ上の要素数をi_count個減らします。
\r
110 public final void pops(int i_count)
\r
112 assert(this._length>=i_count);
\r
113 this._length-=i_count;
\r
121 public final T[] getArray()
\r
123 return this._items;
\r
125 public final T getItem(int i_index)
\r
127 return this._items[i_index];
\r
130 * 配列の見かけ上の要素数を返却します。
\r
133 public final int getLength()
\r
135 return this._length;
\r
138 * 見かけ上の要素数をリセットします。
\r
140 public final void clear()
\r