#ifndef __SAFE_LIST__
#define __SAFE_LIST__

#include <list>
#include <locale.h>
#include "CritSection.h"

class CDatabase;
using namespace std;

template <class _Ty,class _Ax = allocator<_Ty>>
class SafeList: public std::list<_Ty, _Ax>
{
public:
	ThreadSection _critSection;
	void _push_back(const _Ty& _Val)
	{
		AutoThreadSection aSection(&_critSection);
		push_back(_Val);
	}

	void _push_front(const _Ty& _Val)
	{
		AutoThreadSection aSection(&_critSection);
		push_front(_Val);
	}

	void _pop_front()
	{
		AutoThreadSection aSection(&_critSection);
		pop_front();
	}

	_Ty _pop_front_()
	{
		AutoThreadSection aSection(&_critSection);
		if (size())
		{
			_Ty it = front();
			pop_front();
			return it;
		}

		return NULL;
	}

	void _pop_back()
	{
		AutoThreadSection aSection(&_critSection);
		pop_back();
	}

	void _remove(const _Ty& _Val_arg)
	{
		AutoThreadSection aSection(&_critSection);
		remove(_Val_arg);
	}

	reference _front()
	{
		AutoThreadSection aSection(&_critSection);
		return (*begin());
	}

	const_reference _front() const
	{	
		AutoThreadSection aSection(&_critSection);
		return (*begin());
	}

	reference _back()
	{	
		AutoThreadSection aSection(&_critSection);
		return (*(--end()));
	}

	const_reference _back() const
	{	
		AutoThreadSection aSection(&_critSection);
		return (*(--end()));
	}

	size_type _size()
	{	
		//AutoThreadSection aSection(&_critSection);
		return size();
	}
};

typedef SafeList<CDatabase*> ODBCConnectList;

#endif // __SAFE_LIST__