SSTACK.H
[目次 | 型・クラス・構造体 | マクロ]
1|/**************************************************************************
2|* 1. <<< 固定長スタック (SStack) >>>
3|***************************************************************************/
4|
5|#ifndef __SSTACK_H
6|#define __SSTACK_H
7|
8|/*----------------------------------------------------------------------
9|[Module Property]
10|name = SStack
11|title = 固定長スタック
12|category = コンテナ
13|src = sstack.c
14|depend =
15|priority =
16|accord =
17|----------------------------------------------------------------------*/
18|
19|#ifndef USES_PRIORITY_HEADER
20|/*[START_OF_PRIORITY_HEADER]*/
21|
22|#define USES_SSTACK
23|typedef struct _SStack SStack;
24|
25|/*[END_OF_PRIORITY_HEADER]*/
26|#endif /* USES_PRIORITY_HEADER */
27|
28|
29|/*------------------------------------------------------------------------*/
30|/* 2. <<< Interface Area ----------------------------------------------- >>> */
31|/*------------------------------------------------------------------------*/
32|
33|/**************************************************************************
34|* 3. <<< 固定長スタック [SStack] >>>
35|***************************************************************************/
36|struct _SStack {
37| char* array;
38| int size;
39| int n;
40| int max;
41|};
42|
43|void SStack_initX( SStack*, void*, int size, int max );
44|void SStack_pushX( SStack* this, void* item );
45|void* SStack_popX( SStack* this );
46|
47|
48|/*------------------------------------------------------------------------*/
49|/* 4. <<< Mapping Area ------------------------------------------------- >>> */
50|/*------------------------------------------------------------------------*/
51|
52|/**************************************************************************
53|* 5. <<< 初期化 [SStack_init()] >>>
54|* ・array : データを格納する配列領域
55|* サイズは sizeof(type) * max 必要
56|* ・type : 要素の型
57|* ・max : スタックに入れることができる最大の要素数
58|* void SStack_init( SStack* this, void* array, type, int max );
59|***************************************************************************/
60|#define SStack_init( this, array, type, max ) \
61| SStack_initX( this, array, sizeof(type), max )
62|
63|
64|/**************************************************************************
65|* 6. <<< プッシュする [SStack_push()] >>>
66|* this->n < this->max とスタックに空きがあるか確認すること
67|* ・item : プッシュする値の入った要素
68|* ・type : 要素の型
69|* void SStack_push( SStack* this, type item, type );
70|***************************************************************************/
71|#define SStack_push( this, item, type ) \
72| SStack_pushX( this, &(item) )
73|
74|
75|/**************************************************************************
76|* 7. <<< ポップする [SStack_pop()] >>>
77|* this->n > 0 とスタックに要素があるか確認すること
78|* ・type : 要素の型、要素のポインタ型にしないこと。
79|* ・返り値 : ポップした要素
80|* &SStack_pop() として参照した場合は、
81|* 次にポップされるまで値は有効
82|* type SStack_pop( SStack* this, type );
83|***************************************************************************/
84|#define SStack_pop( this, type ) \
85| (*((type*)SStack_popX( this )))
86|
87|
88|/**************************************************************************
89|* 8. <<< スタックの要素を参照する [SStack_peek()] >>>
90|* &SStack_peek() として参照することも可能
91|* ・i : インデックス
92|* 0, 正 = スタックに入っていない要素
93|* 負 = スタックに入っている要素
94|* type SStack_peek( SStack* this, int i, type );
95|***************************************************************************/
96|#define SStack_peek( this, i, type ) \
97| (*((type*)( &(this)->array[ (this)->size*((this)->n + (i)) ] )))
98|
99|
100|#endif /* __SSTACK_H */
101|
102|
103|