/*
 * $Id: uty.h,v 1.1 2003/02/07 18:15:44 wheeler Exp $
 *
 * $Log: uty.h,v $
 * Revision 1.1  2003/02/07 18:15:44  wheeler
 * Fox's version of libultra and friends.
 *
 * Revision 1.7  1997/01/29  12:08:47  hayakawa
 * NEW,DELETEのいろいろなバージョン追加
 *
 * Revision 1.6  1996/10/20  09:19:33  hayakawa
 * _LANGUAGE_C_PLUS_PLUS を __cplusplus に変更
 *
 */

#ifndef __UTY_H_
#define __UTY_H_

#ifdef __cplusplus
extern "C" {
#endif

    /*
     * ２つのポインタを持つ非構造型リスト
     */
    typedef struct ptr2_s {
	void *p1;
	void *p2;
    } ptr2_t;
    
    int AddList_original(void **pp, const int mpp, void *const p);
    int DelList(void **pp, const int mpp, void *const p);
    int AddListx(ptr2_t * pp, const int mpp, void *const p1, void *const p2);
    int DelListx(ptr2_t * pp, const int mpp, void *const p1, void *const p2);

#define ADD_LIST1q(pp, p) AddList_original((void **)(pp), number(pp), p)
#define DEL_LIST1q(pp, p) DelList((void **)(pp), number(pp), p)
#define ADD_LIST1(pp, p) ADD_LIST1x(pp, p, NULL)
#define DEL_LIST1(pp, p) DEL_LIST1x(pp, p, NULL)
#define ADD_LIST1x(pp, p1, p2) AddListx((pp), number(pp), p1, p2)
#define DEL_LIST1x(pp, p1, p2) DelListx((pp), number(pp), p1, p2)
#define DEL_LIST2(name, ptr) DelList((void **)name##Ptr, name##Max, ptr)
#define ADD_LIST2(name, ptr) AddList_original((void **)name##Ptr, name##Max, ptr)

    /*
     * Log2を整数型で返す限定関数
     */
    int log2(int n);

/*
 * NEW/New:コンストラクタを呼び出さない new
 * DELETE/Delete:デストラクタを呼び出さない delete
 * NEWA/NewA:NEW/New の配列対応バージョン
 * DELETEA/DeleteA:DELETE/Delete の配列対応バージョン
 */
#define NEWA(type, array) ((type(*)array)malloc(sizeof(type array)))
#define DELETEA(ptr) 	free(ptr)
#define NEW(type) 	NEWA(type,)
#define DELETE(ptr) 	DELETEA(ptr)
#define NewA(type, array) NEWA(type)
#define DeleteA(ptr) 	DELETEA(ptr)
#define New(type) 	NEW(type)
#define Delete(ptr) 	DELETE(ptr)

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* __UTY_H_ */
