#ifndef __IUP_TABLE_BI__ 
#define __IUP_TABLE_BI__

#include once "iup.bi"


' Hash Table
' The hash table can be indexed by strings or pointer address, 
' and each value can contain strings, pointers or function pointers.

' How the table key is interpreted.
enum Itable_IndexTypes
  IUPTABLE_POINTERINDEXED = 10, ' a pointer address is used as key.
  IUPTABLE_STRINGINDEXED        ' a string as key
end enum

' How the value is interpreted.
enum Itable_Types
  IUPTABLE_POINTER,     ' regular pointer for strings and other pointers/
  IUPTABLE_STRING,      ' string duplicated internally
  IUPTABLE_FUNCPOINTER  ' function pointer
end enum 

type Ifunc as sub cdecl ()

type _Itable as any : type Itable as _Itable

extern "c"

' Creates a hash table with an initial default size.
' This function is equivalent to iupTableCreateSized(0)
_DF_ iupTableCreate(index as Itable_IndexTypes) as Itable ptr

' Creates a hash table with the specified initial size.
' Use this function if you expect the table to become very large.
' initialSizeIndex is an array into the (internal) list of possible hash table sizes. 
' Currently only indexes from 0 to 8 are supported.
' If you specify a higher value here, the maximum allowed value will be used.
_DF_ iupTableCreateSized(indexType as Itable_IndexTypes , initialSizeIndex as uinteger) as Itable ptr

' Destroys the Itable.  Calls iupTableClear.
_DS_ iupTableDestroy(it as Itable ptr)

' Removes all items in the table.
' This function does also free the memory of strings contained in the table!!!!
_DS_ iupTableClear(it as Itable ptr)

' Returns the number of keys stored in the table.
_DF_ iupTableCount(it as Itable ptr) as integer

' Store an element in the table.
_DS_ iupTableSet(it as Itable ptr, key as const zstring ptr, value as any ptr, itemType as Itable_Types)

' Store a function pointer in the table.
' Type is set to IUPTABLE_FUNCPOINTER.
_DS_ iupTableSetFunc(it as Itable ptr, key as const zstring ptr, func as Ifunc)

' Retrieves an element from the table.
' Returns NULL if not found.
_DF_ iupTableGet(it as Itable ptr, key as const zstring ptr) as any ptr

' Retrieves a function pointer from the table. 
' If not a function or not found returns NULL.
' value always contains the element pointer.
_DF_ iupTableGetFunc(it as Itable ptr, key as const zstring ptr, value as any ptr ptr) as Ifunc 

' Retrieves an element from the table and its type.
_DF_ iupTableGetTyped(it as Itable ptr, key as const zstring ptr, itemType as Itable_Types ptr) as any ptr

' Removes the entry at the specified key from the hash table 
' and frees the memory used by it if it is a string...
_DS_ iupTableRemove(it as Itable ptr, key as const zstring ptr)

' Key iteration function. Returns a key.
' To iterate over all keys call iupTableFirst at the first and call iupTableNext in a loop until 0 is returned...
' Do NOT change the content of the hash table during iteration.
' During an iteration you can use context with iupTableGetCurr() to access the value of the key very fast.
_DF_ iupTableFirst(it as Itable ptr) as zstring ptr

' Key iteration function. See iupTableNext.
_DF_ iupTableNext(it as Itable ptr) as zstring ptr

' Returns the value at the current position.
' The current context is an iterator that is filled by iupTableNext().
' iupTableGetCur() is faster then iupTableGet(), so when you want to access an item stored
' at a key returned by iupTableNext(), use this function instead of iupTableGet().
_DF_ iupTableGetCurr(it as Itable ptr) as any ptr 

' Removes the current element and returns the next key.
' Use this function to remove an element during an iteration.
_DF_ iupTableRemoveCurr(it as Itable ptr) as zstring ptr

end extern


#endif

