//----------------------------------------------------
/**
	\file		ctk/inc/list.h
	\ingroup	general
	\ingroup	all

	\brief		Knihovna seznamu
				<<< ALL >>>
			
	\author		ConTeK s.r.o., Ing. Pavel Bazika
	\version	01.01
	\date		4.8.2008
*/
//----------------------------------------------------

#ifndef _LIST_H_
#define _LIST_H_		//!< Definice pritomnosti knihovny

#include <ctktypes.h>

typedef struct _HEAD1 {
	struct _HEAD1	* next;
} HEAD1;


static inline void _List1Initialize(HEAD1 * list)
{
	list->next = NULL;
}

void _List1Insert(HEAD1 * prev, HEAD1 * item);

static inline HEAD1 * _List1Next(HEAD1 * list)
{
	return list->next;
}

static inline void _List1Remove(HEAD1 * prev)
{
	if (prev->next != NULL)
	{
		prev->next = prev->next->next;
	}
	else
	{
		prev->next = NULL;
	}
}

// makra zajistujici praci nad seznamem libovolneho typu
// rusi vsak typovou kontrolu

#define List1Initialize(list) \
	_List1Initialize((HEAD1 *)(list))

#define List1Insert(prev, item) \
	_List1Insert((HEAD1 *)(prev), (HEAD1 *)(item))

#define List1Remove(prev) \
	_List1Remove(prev)

#define List1First(head) \
	((head)->next)

#ifdef MSVC
template< typename LIST_TYPE >
static inline LIST_TYPE List1Next(LIST_TYPE list)
{
	return (LIST_TYPE)_List1Next((HEAD1 *)(list));
}
#else

#define List1Next(list) \
	(typeof(list))(_List1Next((HEAD1 *)(list)))

#endif // MSVC

#endif // _LIST_H_
