#ifndef _COM_SUN_STAR_BEANS_OPTIONAL_HPP_
#define _COM_SUN_STAR_BEANS_OPTIONAL_HPP_

#ifndef _SAL_CONFIG_H_
#include "sal/config.h"
#endif

#ifndef _COM_SUN_STAR_BEANS_OPTIONAL_HDL_
#include "com/sun/star/beans/Optional.hdl"
#endif

#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_
#include "com/sun/star/uno/Type.hxx"
#endif
#ifndef INCLUDED_CPPU_UNOTYPE_HXX
#include "cppu/unotype.hxx"
#endif
#ifndef _RTL_STRBUF_HXX_
#include "rtl/strbuf.hxx"
#endif
#ifndef _RTL_TEXTENC_H
#include "rtl/textenc.h"
#endif
#ifndef _RTL_USTRING_HXX_
#include "rtl/ustring.hxx"
#endif
#ifndef _SAL_TYPES_H_
#include "sal/types.h"
#endif
#ifndef _TYPELIB_TYPECLASS_H_
#include "typelib/typeclass.h"
#endif
#ifndef _TYPELIB_TYPEDESCRIPTION_H_
#include "typelib/typedescription.h"
#endif

namespace com { namespace sun { namespace star { namespace beans {

template< typename typeparam_T > inline Optional< typeparam_T >::Optional() SAL_THROW( () )
    : IsPresent(false)
    , Value()
{
}

template< typename typeparam_T > inline Optional< typeparam_T >::Optional(const ::sal_Bool& IsPresent_, typeparam_T const & Value_) SAL_THROW( () )
    : IsPresent(IsPresent_)
    , Value(Value_)
{
}

} } } }

namespace cppu {

template< typename typeparam_T > class UnoType< ::com::sun::star::beans::Optional< typeparam_T > > {
public:
    static inline ::com::sun::star::uno::Type const & get() {
        //TODO: On certain platforms with weak memory models, the following code can result in some threads observing that the_type points to garbage
        static ::typelib_TypeDescriptionReference * the_type = 0;
        if (the_type == 0) {
            ::rtl::OStringBuffer the_buffer("com.sun.star.beans.Optional<");
            the_buffer.append(::rtl::OUStringToOString(::cppu::getTypeFavourChar(static_cast< typeparam_T * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));
            the_buffer.append('>');
            ::typelib_static_type_init(&the_type, typelib_TypeClass_STRUCT, the_buffer.getStr());
        }
        return *reinterpret_cast< ::com::sun::star::uno::Type * >(&the_type);
    }

private:
    UnoType(UnoType &); // not defined
    ~UnoType(); // not defined
    void operator =(UnoType); // not defined
};

}

template< typename typeparam_T > inline ::com::sun::star::uno::Type const & SAL_CALL getCppuType(::com::sun::star::beans::Optional< typeparam_T > const *) SAL_THROW(()) {
        return ::cppu::UnoType< ::com::sun::star::beans::Optional< typeparam_T > >::get();
    }

#endif // _COM_SUN_STAR_BEANS_OPTIONAL_HPP_
