/************************************************************************
 *
 * Licensed Materials - Property of IBM.
 * (C) Copyright IBM Corporation 2003, 2012.  All Rights Reserved.
 * U.S. Government Users Restricted Rights:
 * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 ************************************************************************/

#ifndef __INTERNAL_SUN_STAR_INTERFACE_IMPL_H_INCLUDE___
#define __INTERNAL_SUN_STAR_INTERFACE_IMPL_H_INCLUDE___

#include "com/sun/star/lang/XUnoTunnel.hpp"
#include "internal/sun/star/uuid/uuid.h"

namespace internal
{
	namespace sun
	{
		namespace star
		{
			namespace interface
			{
#define INTERNAL_SUN_STAR_INTERFACE_IMPL_COUNT	BOOST_PP_DEC( STLEXT_DERIVE_HELPER_MAX_BASE_COUNT )
#define INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_PARAM(z_, n_, unused_)	/*BOOST_PP_COMMA_IF( n_ )*/ BOOST_PP_CAT(typename TInternalInterface, n_) = void  
#define INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_ARG(z_, n_, unused_)	/*BOOST_PP_COMMA_IF( n_ )*/ BOOST_PP_CAT( TInternalInterface, n_)
				template< BOOST_PP_ENUM( INTERNAL_SUN_STAR_INTERFACE_IMPL_COUNT, INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_PARAM,  ) >
				struct InternalInterfaceImpl: stlext::base_chooser< ::com::sun::star::lang::XUnoTunnel, stlext::derive_helper< BOOST_PP_ENUM( INTERNAL_SUN_STAR_INTERFACE_IMPL_COUNT, INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_ARG,  ) > >::type
				{
					sal_Int64 SAL_CALL getSomething(
						const ::com::sun::star::uno::Sequence<sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException)
					{
						if( rId.getLength() == issu::UUID_LEN )
						{
							{
								const issu::UUID & ID = issu::uuidof<com::sun::star::lang::XUnoTunnel>::ID;
								
								if( std::equal( ID, ID + issu::UUID_LEN, rId.getConstArray() ) )
									return reinterpret_cast<sal_Int64>( static_cast< com::sun::star::lang::XUnoTunnel* >( this ) );
							}

#define INTERNAL_SUN_STAR_INTERFACE_IMPL_QUERYINTERFACE( z_, n_, __macro_data )	\
							{\
								const issu::UUID & ID = issu::uuidof<BOOST_PP_CAT( TInternalInterface, n_ )>::ID;\
\
								if( std::equal( ID, ID + issu::UUID_LEN, rId.getConstArray() ) )\
									return reinterpret_cast<sal_Int64>( static_cast< BOOST_PP_CAT( TInternalInterface, n_ )* >( this ) );\
							}

							BOOST_PP_REPEAT( INTERNAL_SUN_STAR_INTERFACE_IMPL_COUNT, INTERNAL_SUN_STAR_INTERFACE_IMPL_QUERYINTERFACE, )
#undef INTERNAL_SUN_STAR_INTERFACE_IMPL_QUERYINTERFACE
						}

						return 0;
					}
				};
#undef INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_ARG
#undef INTERNAL_SUN_STAR_INTERFACE_IMPL_TEMPLATE_PARAM
#undef INTERNAL_SUN_STAR_INTERFACE_IMPL_COUNT
			}
		}
	}
}

namespace issi = ::internal::sun::star::interface;

#endif // __INTERNAL_SUN_STAR_UUID_UUID_H_INCLUDE___