/******************************************************************************

    MODULE
	HL.h

    DESCRIPTION
	Header File for ``Hierarchic Lists''

	That module may be used in connection with
	some XDME structures like EDs, Keytables,
	and Menustrips, Refpaths, since these use HLs
	themselfes ...

	HL is a Subclass of ExecNode which is itself
	a Subclass of DNode. A HNode can itself
	contain a couple of Subs, all DLL actions might
	be performed on such a list _after_ successfully
	locking it

    HISTORY
	22-11-94 b_noll created

******************************************************************************/

#ifndef HL_H
#define HL_H 1

/**************************************
	    Includes
**************************************/

#ifndef   EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef   SLL_H
#include "SLL.h"
#endif

#ifndef   DLL_H
#include "DLL.h"
#endif

#ifndef   AVL_H
#include "AVL.h"
#endif

/**************************************
	    Defines & Structures
**************************************/

struct HClass {
    ULONG (*Dispatcher)();
    ULONG	   Size;
    LONG	   Offset;
    struct HClass *Superclass;
}; /* struct HClass */

struct HNode {
    struct DNode   Node;
    UBYTE	   BlockCnt;
    UBYTE	   Pad1;
    UBYTE	  *Name;
    WORD	   Flags;
    struct HClass *Class;
    struct SList   Locks;
    struct HNode  *Parent;
}; /* struct HNode */

/* following structures _might_ be appended to a struct HNode - depends on Flags */

struct HLAValue {
    UBYTE	  *Value;
}; /* struct HLAValue */

struct HLASubs {
    struct DList   Subs;
    UBYTE	 **Array;
}; /* struct HLASubs */

struct HLATree {
    struct TreeNode *Subs;
}; /* struct HLATree */

/* ---- Possible Returnvalues: */
#define HL_OK	    0	  /* anything was OK in a HL_* operation */
/* there are others ... 8) */

/* ---- Possible Flags: */
#define HLF_SYSNODE	1
#define HLF_VALUE	2
#define HLF_SUBCARRIER	4
#define HLF_TREE	8 /* Please note, TREE and LIST are mutually exclusive */

#define HLF_PRIVATESET 16 /* internal use ... */

/* ---- Possible Attributes: */
#define HLA_Ignore	0 /* System Private use */
#define HLA_Name	1 /* a node's name */
#define HLA_Labels	2 /* a node's subs list */
#define HLA_LabelArray	3 /* an array built from a node's subs */
#define HLA_Value	4 /* a node's value */

/**************************************
	    Prototypes
**************************************/

/* ---- Init & Uninit, if another function is allocation the full structure */
ULONG	      HL_Init	    (struct HNode *n, const UBYTE *name, struct HNode *parent, UWORD flags);
ULONG	      HL_Uninit     (struct HNode *n);

/* ---- Connections between HNodes */
ULONG	      HL_Connect    (struct HNode *n, struct HNode *m, ULONG attr);
ULONG	      HL_Disconnect (struct HNode *n, struct HNode *m);

/* ---- get access to the Subnodes - MAY FAIL! */
struct DList *HL_LockSubs   (struct HNode *n);
ULONG	      HL_UnlockSubs (struct HNode *n);

/* ---- Init/Uninit + malloc/free only if the HNode structure is big enough */
ULONG	      HL_Dispose    (struct HNode *n);
struct HNode *HL_New	    (const UBYTE *name, struct HNode *parent, UWORD flags);

/* ---- output a HL_* error code ... */
void	      HL_Error	    (ULONG code, UBYTE **av);

/* ---- shortcuts */
struct HNode *HL_SystemList (const UBYTE *name);
void	      HL_Scan	    (struct HNode *n, void (*scan)(struct HNode *, void *, int), void *userdata);
struct HNode *HL_Find	    (struct HNode *n, int  (*find)(struct HNode *, void *, int), void *userdata);

#endif /* !HL_H */

/******************************************************************************
*****  END HL.h
******************************************************************************/
