2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.utils;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
37 * オンデマンド割り当てをするオブジェクト配列。
\r
40 public abstract class NyObjectStack
\r
42 private final static int ARRAY_APPEND_STEP = 64;
\r
44 protected final Object[] _items;
\r
46 private int _allocated_size;
\r
48 protected int _length;
\r
51 * 最大ARRAY_MAX個の動的割り当てバッファを準備する。
\r
55 public NyObjectStack(Object[] i_array)
\r
57 // ポインタだけははじめに確保しておく
\r
58 this._items = i_array;
\r
59 // アロケート済サイズと、使用中個数をリセット
\r
60 this._allocated_size = 0;
\r
65 * ポインタを1進めて、その要素を予約し、その要素へのポインタを返します。
\r
66 * 特定型に依存させるときには、継承したクラスでこの関数をオーバーライドしてください。
\r
68 public final Object prePush() throws NyARException
\r
71 if (this._length >= this._allocated_size) {
\r
73 if (this._length >= this._items.length) {
\r
74 throw new NyARException();
\r
77 int range = this._length + ARRAY_APPEND_STEP;
\r
78 if (range >= this._items.length) {
\r
79 range = this._items.length;
\r
82 this.onReservRequest(this._allocated_size, range, this._items);
\r
83 this._allocated_size = range;
\r
85 // 使用領域を+1して、予約した領域を返す。
\r
86 Object ret = this._items[this._length];
\r
91 * 見かけ上の要素数を1減らして、最後尾のアイテムを返します。
\r
94 public final Object pop() throws NyARException
\r
97 throw new NyARException();
\r
100 return this.getItem(this._length);
\r
103 * 0~i_number_of_item-1までの領域を予約します。
\r
104 * 予約すると、見かけ上の要素数は0にリセットされます。
\r
105 * @param i_number_of_reserv
\r
107 final public void reserv(int i_number_of_item) throws NyARException
\r
110 if (i_number_of_item >= this._allocated_size) {
\r
112 if (i_number_of_item >= this._items.length) {
\r
113 throw new NyARException();
\r
116 int range = i_number_of_item+ARRAY_APPEND_STEP;
\r
117 if (range >= this._items.length) {
\r
118 range = this._items.length;
\r
121 this.onReservRequest(this._allocated_size, range, this._items);
\r
122 this._allocated_size = range;
\r
125 this._length=i_number_of_item;
\r
132 * この関数を継承先クラスで実装して下さい。
\r
133 * i_bufferの配列の、i_start番目からi_end-1番目までの要素に、オブジェクトを割り当てて下さい。
\r
139 protected abstract void onReservRequest(int i_start, int i_end, Object[] i_buffer);
\r
145 public final Object[] getArray()
\r
147 return this._items;
\r
149 public final Object getItem(int i_index)
\r
151 return this._items[i_index];
\r
154 * 配列の見かけ上の要素数を返却します。
\r
157 public final int getLength()
\r
159 return this._length;
\r
163 * 見かけ上の要素数をリセットします。
\r
165 public final void clear()
\r