<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: HtmlOptionsDialog.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 18:21:54 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _VOS_MODULE_HXX_
#include <vos/module.hxx>
#endif

#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XVIEWDATASUPPLIER_HPP_
#include <com/sun/star/document/XViewDataSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
#include <com/sun/star/container/XIndexAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_
#include <com/sun/star/uno/Sequence.h>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_H_
#include <com/sun/star/uno/Any.h>
#endif
#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
#include <com/sun/star/lang/XInitialization.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_
#include <com/sun/star/beans/XPropertyAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XEXPORTER_HPP_
#include <com/sun/star/document/XExporter.hpp>
#endif

#ifndef _CPPUHELPER_IMPLBASE5_HXX_
#include <cppuhelper/implbase5.hxx>
#endif

#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif

using namespace rtl;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::document;
using namespace com::sun::star::beans;
using namespace com::sun::star::container;
using namespace com::sun::star::frame;
using namespace com::sun::star::ui::dialogs;

#include "pres.hxx"
//CHINA001 #include "pubdlg.hxx"
#include "sdabstdlg.hxx" //CHINA001
#include "pubdlg.hrc" //CHINA001
#include "tools/debug.hxx" //CHINA001
class SdHtmlOptionsDialog : public cppu::WeakImplHelper5
<
    XExporter,
    XExecutableDialog,
    XPropertyAccess,
    XInitialization,
    XServiceInfo
>
{
    const Reference< XMultiServiceFactory > &mrxMgr;
    Sequence< PropertyValue > maMediaDescriptor;
    Sequence< PropertyValue > maFilterDataSequence;
    OUString aDialogTitle;
    DocumentType meDocType;

public:

    SdHtmlOptionsDialog( const Reference< XMultiServiceFactory >& _rxORB );
    ~SdHtmlOptionsDialog();

    // XInterface
    virtual void SAL_CALL acquire() throw();
    virtual void SAL_CALL release() throw();

    // XInitialization
    virtual void SAL_CALL initialize( const Sequence< Any > & aArguments ) throw ( Exception, RuntimeException );

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() throw ( RuntimeException );
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw ( RuntimeException );
    virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( RuntimeException );

    // XPropertyAccess
    virtual Sequence< PropertyValue > SAL_CALL getPropertyValues() throw ( RuntimeException );
    virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps )
        throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException,
                ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException,
                ::com::sun::star::uno::RuntimeException );

    // XExecuteDialog
    virtual sal_Int16 SAL_CALL execute()
        throw ( com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
        throw ( ::com::sun::star::uno::RuntimeException );

    // XExporter
    virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
        throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

};

// -------------------------
// - SdHtmlOptionsDialog -
// -------------------------

Reference< XInterface >
    SAL_CALL SdHtmlOptionsDialog_CreateInstance(
        const Reference< XMultiServiceFactory > & _rxFactory )
{
    return static_cast< ::cppu::OWeakObject* > ( new SdHtmlOptionsDialog( _rxFactory ) );
}

OUString SdHtmlOptionsDialog_getImplementationName()
    throw( RuntimeException )
{
    return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.draw.SdHtmlOptionsDialog" ) );
}
#define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
sal_Bool SAL_CALL SdHtmlOptionsDialog_supportsService( const OUString& ServiceName )
    throw( RuntimeException )
{
    return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
}

Sequence< OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames()
    throw( RuntimeException )
{
    Sequence< OUString > aRet(1);
    OUString* pArray = aRet.getArray();
    pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
    return aRet;
}
#undef SERVICE_NAME

// -----------------------------------------------------------------------------

SdHtmlOptionsDialog::SdHtmlOptionsDialog( const Reference< XMultiServiceFactory > & xMgr ) :
    mrxMgr      ( xMgr ),
    meDocType   ( DOCUMENT_TYPE_DRAW )
{
}

// -----------------------------------------------------------------------------

SdHtmlOptionsDialog::~SdHtmlOptionsDialog()
{
}

// -----------------------------------------------------------------------------

void SAL_CALL SdHtmlOptionsDialog::acquire() throw()
{
    OWeakObject::acquire();
}

// -----------------------------------------------------------------------------

void SAL_CALL SdHtmlOptionsDialog::release() throw()
{
    OWeakObject::release();
}

// XInitialization
void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & aArguments )
    throw ( Exception, RuntimeException )
{
}

// XServiceInfo
OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
    throw( RuntimeException )
{
    return SdHtmlOptionsDialog_getImplementationName();
}
sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const OUString& rServiceName )
    throw( RuntimeException )
{
    return SdHtmlOptionsDialog_supportsService( rServiceName );
}
Sequence< OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
    throw ( RuntimeException )
{
    return SdHtmlOptionsDialog_getSupportedServiceNames();
}

// XPropertyAccess
Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
        throw ( RuntimeException )
{
    sal_Int32 i, nCount;
    for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
    {
        if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
            break;
    }
    if ( i == nCount )
        maMediaDescriptor.realloc( ++nCount );

    // the "FilterData" Property is an Any that will contain our PropertySequence of Values
    maMediaDescriptor[ i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
    maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
    return maMediaDescriptor;
}

void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
        throw ( UnknownPropertyException, PropertyVetoException,
                IllegalArgumentException, WrappedTargetException,
                RuntimeException )
{
    maMediaDescriptor = aProps;

    sal_Int32 i, nCount;
    for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
    {
        if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
        {
            maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
            break;
        }
    }
}

// XExecutableDialog
void SdHtmlOptionsDialog::setTitle( const OUString& aTitle )
    throw ( RuntimeException )
{
    aDialogTitle = aTitle;
}

sal_Int16 SdHtmlOptionsDialog::execute()
    throw ( RuntimeException )
{
    //CHINA001 SdPublishingDlg aDlg( Application::GetDefDialogParent(), meDocType );
    SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();//CHINA001
    DBG_ASSERT(pFact, "SdAbstractDialogFactory fail!");//CHINA001
    AbstractSdPublishingDlg* pDlg = pFact->CreateSdPublishingDlg(ResId( DLG_PUBLISHING ), Application::GetDefDialogParent(), meDocType );
    DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
    if( pDlg->Execute() ) //CHINA001 if( aDlg.Execute() )
    {
        pDlg->GetParameterSequence( maFilterDataSequence ); //CHINA001 aDlg.GetParameterSequence( maFilterDataSequence );
        return ExecutableDialogResults::OK;
    }
    else
    {
        return ExecutableDialogResults::CANCEL;
    }
    delete pDlg; //add by CHINA001

}

// XEmporter
void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
        throw ( IllegalArgumentException, RuntimeException )
{
    // try to set the corresponding metric unit
    String aConfigPath;
    Reference< XServiceInfo > xServiceInfo
            ( xDoc, UNO_QUERY );
    if ( xServiceInfo.is() )
    {
        if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
        {
            meDocType = DOCUMENT_TYPE_IMPRESS;
            return;
        }
        else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
        {
            meDocType = DOCUMENT_TYPE_DRAW;
            return;
        }
    }
    throw IllegalArgumentException();
}

<commit_msg>INTEGRATION: CWS sdwarningsbegone (1.3.38); FILE MERGED 2006/11/22 12:41:37 cl 1.3.38.1: #i69285# warning free code changes for unxlngi6.pro<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: HtmlOptionsDialog.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 16:42:10 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _VOS_MODULE_HXX_
#include <vos/module.hxx>
#endif

#ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
#include <com/sun/star/frame/XModel.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XVIEWDATASUPPLIER_HPP_
#include <com/sun/star/document/XViewDataSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
#include <com/sun/star/container/XIndexAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_
#include <com/sun/star/uno/Sequence.h>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_H_
#include <com/sun/star/uno/Any.h>
#endif
#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
#include <com/sun/star/lang/XInitialization.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_
#include <com/sun/star/beans/XPropertyAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#endif
#ifndef _COM_SUN_STAR_DOCUMENT_XEXPORTER_HPP_
#include <com/sun/star/document/XExporter.hpp>
#endif

#ifndef _CPPUHELPER_IMPLBASE5_HXX_
#include <cppuhelper/implbase5.hxx>
#endif

#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif

using namespace rtl;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::document;
using namespace com::sun::star::beans;
using namespace com::sun::star::container;
using namespace com::sun::star::frame;
using namespace com::sun::star::ui::dialogs;

#include "pres.hxx"
#include "sdabstdlg.hxx"
#include "tools/debug.hxx"
class SdHtmlOptionsDialog : public cppu::WeakImplHelper5
<
    XExporter,
    XExecutableDialog,
    XPropertyAccess,
    XInitialization,
    XServiceInfo
>
{
    const Reference< XMultiServiceFactory > &mrxMgr;
    Sequence< PropertyValue > maMediaDescriptor;
    Sequence< PropertyValue > maFilterDataSequence;
    OUString aDialogTitle;
    DocumentType meDocType;

public:

    SdHtmlOptionsDialog( const Reference< XMultiServiceFactory >& _rxORB );
    ~SdHtmlOptionsDialog();

    // XInterface
    virtual void SAL_CALL acquire() throw();
    virtual void SAL_CALL release() throw();

    // XInitialization
    virtual void SAL_CALL initialize( const Sequence< Any > & aArguments ) throw ( Exception, RuntimeException );

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() throw ( RuntimeException );
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw ( RuntimeException );
    virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( RuntimeException );

    // XPropertyAccess
    virtual Sequence< PropertyValue > SAL_CALL getPropertyValues() throw ( RuntimeException );
    virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps )
        throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException,
                ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException,
                ::com::sun::star::uno::RuntimeException );

    // XExecuteDialog
    virtual sal_Int16 SAL_CALL execute()
        throw ( com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
        throw ( ::com::sun::star::uno::RuntimeException );

    // XExporter
    virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
        throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );

};

// -------------------------
// - SdHtmlOptionsDialog -
// -------------------------

Reference< XInterface >
    SAL_CALL SdHtmlOptionsDialog_CreateInstance(
        const Reference< XMultiServiceFactory > & _rxFactory )
{
    return static_cast< ::cppu::OWeakObject* > ( new SdHtmlOptionsDialog( _rxFactory ) );
}

OUString SdHtmlOptionsDialog_getImplementationName()
    throw( RuntimeException )
{
    return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.draw.SdHtmlOptionsDialog" ) );
}
#define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
sal_Bool SAL_CALL SdHtmlOptionsDialog_supportsService( const OUString& ServiceName )
    throw( RuntimeException )
{
    return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
}

Sequence< OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames()
    throw( RuntimeException )
{
    Sequence< OUString > aRet(1);
    OUString* pArray = aRet.getArray();
    pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
    return aRet;
}
#undef SERVICE_NAME

// -----------------------------------------------------------------------------

SdHtmlOptionsDialog::SdHtmlOptionsDialog( const Reference< XMultiServiceFactory > & xMgr ) :
    mrxMgr      ( xMgr ),
    meDocType   ( DOCUMENT_TYPE_DRAW )
{
}

// -----------------------------------------------------------------------------

SdHtmlOptionsDialog::~SdHtmlOptionsDialog()
{
}

// -----------------------------------------------------------------------------

void SAL_CALL SdHtmlOptionsDialog::acquire() throw()
{
    OWeakObject::acquire();
}

// -----------------------------------------------------------------------------

void SAL_CALL SdHtmlOptionsDialog::release() throw()
{
    OWeakObject::release();
}

// XInitialization
void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & )
    throw ( Exception, RuntimeException )
{
}

// XServiceInfo
OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
    throw( RuntimeException )
{
    return SdHtmlOptionsDialog_getImplementationName();
}
sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const OUString& rServiceName )
    throw( RuntimeException )
{
    return SdHtmlOptionsDialog_supportsService( rServiceName );
}
Sequence< OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
    throw ( RuntimeException )
{
    return SdHtmlOptionsDialog_getSupportedServiceNames();
}

// XPropertyAccess
Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
        throw ( RuntimeException )
{
    sal_Int32 i, nCount;
    for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
    {
        if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
            break;
    }
    if ( i == nCount )
        maMediaDescriptor.realloc( ++nCount );

    // the "FilterData" Property is an Any that will contain our PropertySequence of Values
    maMediaDescriptor[ i ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
    maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
    return maMediaDescriptor;
}

void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
        throw ( UnknownPropertyException, PropertyVetoException,
                IllegalArgumentException, WrappedTargetException,
                RuntimeException )
{
    maMediaDescriptor = aProps;

    sal_Int32 i, nCount;
    for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
    {
        if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
        {
            maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
            break;
        }
    }
}

// XExecutableDialog
void SdHtmlOptionsDialog::setTitle( const OUString& aTitle )
    throw ( RuntimeException )
{
    aDialogTitle = aTitle;
}

sal_Int16 SdHtmlOptionsDialog::execute()
    throw ( RuntimeException )
{
    sal_Int16 nRet = ExecutableDialogResults::CANCEL;

    SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
    if( pFact )
    {
        AbstractSdPublishingDlg* pDlg = pFact->CreateSdPublishingDlg( Application::GetDefDialogParent(), meDocType );
        if( pDlg )
        {
            if( pDlg->Execute() )
            {
                pDlg->GetParameterSequence( maFilterDataSequence );
                nRet = ExecutableDialogResults::OK;
            }
            else
            {
                nRet = ExecutableDialogResults::CANCEL;
            }
            delete pDlg;
        }
    }
    return nRet;
}

// XEmporter
void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
        throw ( IllegalArgumentException, RuntimeException )
{
    // try to set the corresponding metric unit
    String aConfigPath;
    Reference< XServiceInfo > xServiceInfo
            ( xDoc, UNO_QUERY );
    if ( xServiceInfo.is() )
    {
        if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
        {
            meDocType = DOCUMENT_TYPE_IMPRESS;
            return;
        }
        else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
        {
            meDocType = DOCUMENT_TYPE_DRAW;
            return;
        }
    }
    throw IllegalArgumentException();
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: SdShapeTypes.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 03:30:06 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include "SdShapeTypes.hxx"
#include "AccessiblePresentationShape.hxx"
#include "AccessiblePresentationGraphicShape.hxx"
#include "AccessiblePresentationOLEShape.hxx"

#ifndef _RTL_USTRING_H_
#include <rtl/ustring.h>
#endif

namespace accessibility {

AccessibleShape*
    CreateSdAccessibleShape (
        const AccessibleShapeInfo& rShapeInfo,
        const AccessibleShapeTreeInfo& rShapeTreeInfo,
        ShapeTypeId nId)
{
    switch (nId)
    {
        case PRESENTATION_TITLE:
        case PRESENTATION_OUTLINER:
        case PRESENTATION_SUBTITLE:
        case PRESENTATION_PAGE:
        case PRESENTATION_NOTES:
        case PRESENTATION_HANDOUT:
        case PRESENTATION_HEADER:
        case PRESENTATION_FOOTER:
        case PRESENTATION_DATETIME:
        case PRESENTATION_PAGENUMBER:
            return new AccessiblePresentationShape (rShapeInfo, rShapeTreeInfo);

        case PRESENTATION_GRAPHIC_OBJECT:
            return new AccessiblePresentationGraphicShape (rShapeInfo, rShapeTreeInfo);

        case PRESENTATION_OLE:
        case PRESENTATION_CHART:
        case PRESENTATION_TABLE:
            return new AccessiblePresentationOLEShape (rShapeInfo, rShapeTreeInfo);

        default:
            return new AccessibleShape (rShapeInfo, rShapeTreeInfo);
    }
}

ShapeTypeDescriptor aSdShapeTypeList[] = {
    ShapeTypeDescriptor (
        PRESENTATION_OUTLINER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.OutlinerShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_SUBTITLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.SubtitleShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_GRAPHIC_OBJECT,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.GraphicObjectShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_PAGE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.PageShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_OLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.OLE2Shape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_CHART,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.ChartShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_TABLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.TableShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_NOTES,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.NotesShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_TITLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.TitleTextShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_HANDOUT,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.HandoutShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_HEADER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.HeaderShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_FOOTER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.FooterShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_DATETIME,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.DateTimeShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_PAGENUMBER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.SlideNumberShape"),
        CreateSdAccessibleShape )
};

void RegisterImpressShapeTypes (void)
{
    ShapeTypeHandler::Instance().AddShapeTypeList (
        PRESENTATION_PAGENUMBER - PRESENTATION_OUTLINER + 1,
        aSdShapeTypeList);
}

} // end of namespace accessibility
<commit_msg>INTEGRATION: CWS pchfix02 (1.10.282); FILE MERGED 2006/09/01 17:36:52 kaib 1.10.282.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: SdShapeTypes.cxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-16 18:27:52 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "SdShapeTypes.hxx"
#include "AccessiblePresentationShape.hxx"
#include "AccessiblePresentationGraphicShape.hxx"
#include "AccessiblePresentationOLEShape.hxx"

#ifndef _RTL_USTRING_H_
#include <rtl/ustring.h>
#endif

namespace accessibility {

AccessibleShape*
    CreateSdAccessibleShape (
        const AccessibleShapeInfo& rShapeInfo,
        const AccessibleShapeTreeInfo& rShapeTreeInfo,
        ShapeTypeId nId)
{
    switch (nId)
    {
        case PRESENTATION_TITLE:
        case PRESENTATION_OUTLINER:
        case PRESENTATION_SUBTITLE:
        case PRESENTATION_PAGE:
        case PRESENTATION_NOTES:
        case PRESENTATION_HANDOUT:
        case PRESENTATION_HEADER:
        case PRESENTATION_FOOTER:
        case PRESENTATION_DATETIME:
        case PRESENTATION_PAGENUMBER:
            return new AccessiblePresentationShape (rShapeInfo, rShapeTreeInfo);

        case PRESENTATION_GRAPHIC_OBJECT:
            return new AccessiblePresentationGraphicShape (rShapeInfo, rShapeTreeInfo);

        case PRESENTATION_OLE:
        case PRESENTATION_CHART:
        case PRESENTATION_TABLE:
            return new AccessiblePresentationOLEShape (rShapeInfo, rShapeTreeInfo);

        default:
            return new AccessibleShape (rShapeInfo, rShapeTreeInfo);
    }
}

ShapeTypeDescriptor aSdShapeTypeList[] = {
    ShapeTypeDescriptor (
        PRESENTATION_OUTLINER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.OutlinerShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_SUBTITLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.SubtitleShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_GRAPHIC_OBJECT,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.GraphicObjectShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_PAGE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.PageShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_OLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.OLE2Shape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_CHART,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.ChartShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_TABLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.TableShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_NOTES,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.NotesShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_TITLE,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.TitleTextShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_HANDOUT,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.HandoutShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_HEADER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.HeaderShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_FOOTER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.FooterShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_DATETIME,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.DateTimeShape"),
        CreateSdAccessibleShape ),
    ShapeTypeDescriptor (
        PRESENTATION_PAGENUMBER,
        ::rtl::OUString::createFromAscii ("com.sun.star.presentation.SlideNumberShape"),
        CreateSdAccessibleShape )
};

void RegisterImpressShapeTypes (void)
{
    ShapeTypeHandler::Instance().AddShapeTypeList (
        PRESENTATION_PAGENUMBER - PRESENTATION_OUTLINER + 1,
        aSdShapeTypeList);
}

} // end of namespace accessibility
<|endoftext|>


<commit_before>#include <cerrno>
#include <cstring>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ros/ros.h>
#include <sensor_msgs/JoyFeedbackArray.h>

class RumbleEventNode {
public:
  RumbleEventNode() :
      rumble_fd(-1),
      device("/usr/input/gamepads/event_dft"),
      duration_sec(5.0),
      active(false),
      reconnect(false),
      local_handle("~") {
    // Initialize internal structures
    memset(&rumble_effect, 0, sizeof(rumble_effect));
    rumble_effect.type = FF_RUMBLE;
    rumble_effect.id = -1; // Will get populated by ioctl
    memset(&rumble_event, 0, sizeof(rumble_event));
    rumble_event.type = EV_FF;
    rumble_event.code = -1;

    // Update ROS parameters
    local_handle.param<std::string>("device", device, device);
    local_handle.param<double>("duration_sec", duration_sec, duration_sec);

    // Setup subscribers
    set_rumble_sub = local_handle.subscribe("set_rumble", 10,
      &RumbleEventNode::setRumbleCB, this);
  };

  ~RumbleEventNode() {
    termRumbleDevice();
  };

  bool initRumbleDevice() {
    rumble_fd = open(device.c_str(), O_RDWR);
    if (rumble_fd == -1) {
      if (!reconnect) {
        ROS_ERROR_STREAM("Failed to open " << device);
      }
      active = false;
    } else {
      active = true;
      reconnect = false;
      ROS_INFO_STREAM("Opened " << device);
    }
    return active;
  };

  void setRumbleCB(const sensor_msgs::JoyFeedbackArray::ConstPtr& msg) {
    if (!active) return;

    double strongMagnPct = 0, weakMagnPct = 0;
    bool update = false;
    for (const sensor_msgs::JoyFeedback& f: msg->array) {
      if (f.type == sensor_msgs::JoyFeedback::TYPE_RUMBLE) {
        if (f.id == 0) { strongMagnPct = f.intensity; update = true; }
        else if (f.id == 1) { weakMagnPct = f.intensity; update = true; }
      }
    }

    if (update) {
      setRumble(strongMagnPct, weakMagnPct, duration_sec);
    }
  };

  void spin() {
    ros::Rate hz(10);
    while (ros::ok()) {
      if (reconnect) {
        ROS_INFO_STREAM("attempt reconnect");
        initRumbleDevice();
      }
      ros::spinOnce();
      hz.sleep();
    }
  };

protected:
  void termRumbleDevice(bool forced=false) {
    if (rumble_fd >= 0) {
      if (!forced) {
        issueRumbleEvent(false); // Stop previous rumble effect
      }
      close(rumble_fd);
      rumble_effect.id = -1;
      rumble_event.code = -1;
      rumble_fd = -1;
      ROS_INFO_STREAM("Closed " << device);
    }
    active = false;
    if (forced) {
      reconnect = true;
    }
  };

  void issueRumbleEvent(bool active) {
    if (rumble_fd < 0 || rumble_effect.id < 0) return;

    rumble_event.code = rumble_effect.id;
    rumble_event.value = active;
    if (write(rumble_fd, (const void*) &rumble_event, sizeof(rumble_event)) == -1) {
      ROS_ERROR_STREAM("Failed to issue rumble event: " << strerror(errno));
      termRumbleDevice(true);
      return;
    }
  };

  void setRumble(double strongMagnPct, double weakMagnPct,
      double durationSec, double delaySec=0) {
    if (rumble_fd < 0) return;

    // Cap and convert arguments
    strongMagnPct = std::min(std::max(strongMagnPct, 0.0), 1.0);
    weakMagnPct = std::min(std::max(weakMagnPct, 0.0), 1.0);
    durationSec = std::min(std::max(durationSec, 0.0), 65.535);
    delaySec = std::min(std::max(delaySec, 0.0), 65.535);
    unsigned short strong_magnitude = 65535*strongMagnPct;
    unsigned short weak_magnitude = 65535*weakMagnPct;
    unsigned short length = durationSec*1000;
    unsigned short delay = delaySec*1000;

    // Option A: stop existing event
    if (strong_magnitude == 0 && weak_magnitude == 0) {
      if (rumble_event.value) {
        issueRumbleEvent(false);
      } // else already stopped event, so ignore request
      return;
    }

    // Option B: re-issue existing event
    if (rumble_effect.id >= 0 &&
        strong_magnitude == rumble_effect.u.rumble.strong_magnitude &&
        weak_magnitude == rumble_effect.u.rumble.weak_magnitude &&
        length == rumble_effect.replay.length &&
        delay == rumble_effect.replay.delay) {
      issueRumbleEvent(false);
      issueRumbleEvent(true);
      return;
    }

    // Option C: stop and clear previous rumble effect ...
    if (rumble_effect.id >= 0) {
      issueRumbleEvent(false);

      if (ioctl(rumble_fd, EVIOCRMFF, rumble_effect.id) == -1) {
        ROS_ERROR_STREAM("Failed to clear rumble effect: " << strerror(errno));
        termRumbleDevice(true);
        return;
      }
      rumble_effect.id = -1;
    }

    // ... then upload new rumble effect...
    rumble_effect.u.rumble.strong_magnitude = strong_magnitude;
    rumble_effect.u.rumble.weak_magnitude = weak_magnitude;
    rumble_effect.replay.length = length;
    rumble_effect.replay.delay = delay;
    if (ioctl(rumble_fd, EVIOCSFF, &rumble_effect) == -1) {
      ROS_ERROR_STREAM("Failed to upload rumble effect: " << strerror(errno));
      termRumbleDevice(true);
      return;
    }

    // ... and start rumble
    issueRumbleEvent(true);
  };

  int rumble_fd;
  struct ff_effect rumble_effect;
  struct input_event rumble_event;
  std::string device;
  double duration_sec;
  bool active; // Used to disconnect on failure
  bool reconnect;

  ros::NodeHandle local_handle;
  ros::Subscriber set_rumble_sub;
};

int main(int argc, char** argv) {
  ros::init(argc, argv, "rumble_event_node");
  RumbleEventNode* n = new RumbleEventNode();
  if (n->initRumbleDevice()) {
    n->spin();
  }
  delete n;

  return EXIT_SUCCESS;
};
<commit_msg>fixed typo<commit_after>#include <cerrno>
#include <cstring>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ros/ros.h>
#include <sensor_msgs/JoyFeedbackArray.h>

class RumbleEventNode {
public:
  RumbleEventNode() :
      rumble_fd(-1),
      device("/dev/input/gamepads/event_dft"),
      duration_sec(5.0),
      active(false),
      reconnect(false),
      local_handle("~") {
    // Initialize internal structures
    memset(&rumble_effect, 0, sizeof(rumble_effect));
    rumble_effect.type = FF_RUMBLE;
    rumble_effect.id = -1; // Will get populated by ioctl
    memset(&rumble_event, 0, sizeof(rumble_event));
    rumble_event.type = EV_FF;
    rumble_event.code = -1;

    // Update ROS parameters
    local_handle.param<std::string>("device", device, device);
    local_handle.param<double>("duration_sec", duration_sec, duration_sec);

    // Setup subscribers
    set_rumble_sub = local_handle.subscribe("set_rumble", 10,
      &RumbleEventNode::setRumbleCB, this);
  };

  ~RumbleEventNode() {
    termRumbleDevice();
  };

  bool initRumbleDevice() {
    rumble_fd = open(device.c_str(), O_RDWR);
    if (rumble_fd == -1) {
      if (!reconnect) {
        ROS_ERROR_STREAM("Failed to open " << device);
      }
      active = false;
    } else {
      active = true;
      reconnect = false;
      ROS_INFO_STREAM("Opened " << device);
    }
    return active;
  };

  void setRumbleCB(const sensor_msgs::JoyFeedbackArray::ConstPtr& msg) {
    if (!active) return;

    double strongMagnPct = 0, weakMagnPct = 0;
    bool update = false;
    for (const sensor_msgs::JoyFeedback& f: msg->array) {
      if (f.type == sensor_msgs::JoyFeedback::TYPE_RUMBLE) {
        if (f.id == 0) { strongMagnPct = f.intensity; update = true; }
        else if (f.id == 1) { weakMagnPct = f.intensity; update = true; }
      }
    }

    if (update) {
      setRumble(strongMagnPct, weakMagnPct, duration_sec);
    }
  };

  void spin() {
    ros::Rate hz(10);
    while (ros::ok()) {
      if (reconnect) {
        ROS_INFO_STREAM("attempt reconnect");
        initRumbleDevice();
      }
      ros::spinOnce();
      hz.sleep();
    }
  };

protected:
  void termRumbleDevice(bool forced=false) {
    if (rumble_fd >= 0) {
      if (!forced) {
        issueRumbleEvent(false); // Stop previous rumble effect
      }
      close(rumble_fd);
      rumble_effect.id = -1;
      rumble_event.code = -1;
      rumble_fd = -1;
      ROS_INFO_STREAM("Closed " << device);
    }
    active = false;
    if (forced) {
      reconnect = true;
    }
  };

  void issueRumbleEvent(bool active) {
    if (rumble_fd < 0 || rumble_effect.id < 0) return;

    rumble_event.code = rumble_effect.id;
    rumble_event.value = active;
    if (write(rumble_fd, (const void*) &rumble_event, sizeof(rumble_event)) == -1) {
      ROS_ERROR_STREAM("Failed to issue rumble event: " << strerror(errno));
      termRumbleDevice(true);
      return;
    }
  };

  void setRumble(double strongMagnPct, double weakMagnPct,
      double durationSec, double delaySec=0) {
    if (rumble_fd < 0) return;

    // Cap and convert arguments
    strongMagnPct = std::min(std::max(strongMagnPct, 0.0), 1.0);
    weakMagnPct = std::min(std::max(weakMagnPct, 0.0), 1.0);
    durationSec = std::min(std::max(durationSec, 0.0), 65.535);
    delaySec = std::min(std::max(delaySec, 0.0), 65.535);
    unsigned short strong_magnitude = 65535*strongMagnPct;
    unsigned short weak_magnitude = 65535*weakMagnPct;
    unsigned short length = durationSec*1000;
    unsigned short delay = delaySec*1000;

    // Option A: stop existing event
    if (strong_magnitude == 0 && weak_magnitude == 0) {
      if (rumble_event.value) {
        issueRumbleEvent(false);
      } // else already stopped event, so ignore request
      return;
    }

    // Option B: re-issue existing event
    if (rumble_effect.id >= 0 &&
        strong_magnitude == rumble_effect.u.rumble.strong_magnitude &&
        weak_magnitude == rumble_effect.u.rumble.weak_magnitude &&
        length == rumble_effect.replay.length &&
        delay == rumble_effect.replay.delay) {
      issueRumbleEvent(false);
      issueRumbleEvent(true);
      return;
    }

    // Option C: stop and clear previous rumble effect ...
    if (rumble_effect.id >= 0) {
      issueRumbleEvent(false);

      if (ioctl(rumble_fd, EVIOCRMFF, rumble_effect.id) == -1) {
        ROS_ERROR_STREAM("Failed to clear rumble effect: " << strerror(errno));
        termRumbleDevice(true);
        return;
      }
      rumble_effect.id = -1;
    }

    // ... then upload new rumble effect...
    rumble_effect.u.rumble.strong_magnitude = strong_magnitude;
    rumble_effect.u.rumble.weak_magnitude = weak_magnitude;
    rumble_effect.replay.length = length;
    rumble_effect.replay.delay = delay;
    if (ioctl(rumble_fd, EVIOCSFF, &rumble_effect) == -1) {
      ROS_ERROR_STREAM("Failed to upload rumble effect: " << strerror(errno));
      termRumbleDevice(true);
      return;
    }

    // ... and start rumble
    issueRumbleEvent(true);
  };

  int rumble_fd;
  struct ff_effect rumble_effect;
  struct input_event rumble_event;
  std::string device;
  double duration_sec;
  bool active; // Used to disconnect on failure
  bool reconnect;

  ros::NodeHandle local_handle;
  ros::Subscriber set_rumble_sub;
};

int main(int argc, char** argv) {
  ros::init(argc, argv, "rumble_event_node");
  RumbleEventNode* n = new RumbleEventNode();
  if (n->initRumbleDevice()) {
    n->spin();
  }
  delete n;

  return EXIT_SUCCESS;
};
<|endoftext|>


<commit_before>#include "Test.h"
#include "System/Common.h"

typedef struct human_bytes_pair {
    uint64_t    value;
    char        text[5];
} human_bytes_pair_t;

TEST_DEFINE(TestCommonHumanBytes)
{
    char                buf[5];
    unsigned            i;
    human_bytes_pair_t  human_byte_pairs[] = {
        {1,             "1"},
        {10,            "10"},
        {100,           "100"},
        {1000,          "1.0k"},
        {10000,         "10k"},
        {100000,        "100k"},
        {1000000,       "1.0M"},
        {10000000,      "10M"},
        {100000000,     "100M"},
        {1000000000,    "1.0G"},
        {10000000000,   "10G"},
        {100000000000,  "100G"},
        {1000000000000, "1.0T"},
        {1234567890123, "1.2T"},
        {999,           "999"},
        {1000,          "1.0k"},
        {1449,          "1.4k"},
        {1450,          "1.5k"},
        {1499,          "1.5k"},
        {1599,          "1.6k"},
        {1999,          "2.0k"},
    };

    for (i = 0; i < SIZE(human_byte_pairs); i++)
    {
        HumanBytes(human_byte_pairs[i].value, buf);
        TEST_ASSERT(strncmp(buf, human_byte_pairs[i].text, 5) == 0);
        //TEST_LOG("%" PRIu64 " => %s", human_byte_pairs[i].value, buf);
    }

    return TEST_SUCCESS;
}

TEST_DEFINE(TestCommonRandomDistribution)
{
    unsigned    num;
    unsigned    i;
    unsigned    count[3];
    unsigned    min;
    unsigned    max;
    unsigned    maxdev;
    int         rnd;

    SeedRandom();
    num = 10 * 1000 * 1000;

    for (i = 0; i < SIZE(count); i++)
        count[i] = 0;

    for (i = 0; i < num; i++)
    {
        rnd = RandomInt(0, SIZE(count) - 1);
        TEST_ASSERT(rnd >= 0 && rnd < SIZE(count));
        count[rnd % SIZE(count)]++;
    }

    min = (unsigned) -1;
    max = 0;
    maxdev = 0;

    for (i = 0; i < SIZE(count); i++)
    {
        if (count[i] < min)
            min = count[i];
        if (count[i] > max)
            max = count[i];
        if (count[i] * SIZE(count) > num)
        {
            if (count[i] - (float)num / SIZE(count) > maxdev)
                maxdev = count[i] - (float)num / SIZE(count);
        }
        else
        {
            if ((float)num / SIZE(count) - count[i] > maxdev)
                maxdev = (float)num / SIZE(count) - count[i];
        }
    }

    // more than 10% error considered bad discrete uniform distribution
    // the C library random()/rand() is such bad random generator
    if (maxdev > (float)num / SIZE(count) * 0.10)
    {
        TEST_LOG("Error: %2.1f%%", maxdev / ((float)num / SIZE(count) / 100.0));
        TEST_FAIL();
    }

    return TEST_SUCCESS;
}
<commit_msg>Fixed CommonTest warning.<commit_after>#include "Test.h"
#include "System/Common.h"

typedef struct human_bytes_pair {
    uint64_t    value;
    char        text[5];
} human_bytes_pair_t;

TEST_DEFINE(TestCommonHumanBytes)
{
    char                buf[5];
    unsigned            i;
    human_bytes_pair_t  human_byte_pairs[] = {
        {1,             "1"},
        {10,            "10"},
        {100,           "100"},
        {1000,          "1.0k"},
        {10000,         "10k"},
        {100000,        "100k"},
        {1000000,       "1.0M"},
        {10000000,      "10M"},
        {100000000,     "100M"},
        {1000000000,    "1.0G"},
        {10000000000,   "10G"},
        {100000000000,  "100G"},
        {1000000000000, "1.0T"},
        {1234567890123, "1.2T"},
        {999,           "999"},
        {1000,          "1.0k"},
        {1449,          "1.4k"},
        {1450,          "1.5k"},
        {1499,          "1.5k"},
        {1599,          "1.6k"},
        {1999,          "2.0k"},
    };

    for (i = 0; i < SIZE(human_byte_pairs); i++)
    {
        HumanBytes(human_byte_pairs[i].value, buf);
        TEST_ASSERT(strncmp(buf, human_byte_pairs[i].text, 5) == 0);
        //TEST_LOG("%" PRIu64 " => %s", human_byte_pairs[i].value, buf);
    }

    return TEST_SUCCESS;
}

TEST_DEFINE(TestCommonRandomDistribution)
{
    unsigned    num;
    unsigned    i;
    unsigned    count[3];
    unsigned    min;
    unsigned    max;
    unsigned    maxdev;
    int         rnd;

    SeedRandom();
    num = 10 * 1000 * 1000;

    for (i = 0; i < SIZE(count); i++)
        count[i] = 0;

    for (i = 0; i < num; i++)
    {
        rnd = RandomInt(0, SIZE(count) - 1);
        TEST_ASSERT(rnd >= 0 && (unsigned) rnd < SIZE(count));
        count[rnd % SIZE(count)]++;
    }

    min = (unsigned) -1;
    max = 0;
    maxdev = 0;

    for (i = 0; i < SIZE(count); i++)
    {
        if (count[i] < min)
            min = count[i];
        if (count[i] > max)
            max = count[i];
        if (count[i] * SIZE(count) > num)
        {
            if (count[i] - (float)num / SIZE(count) > maxdev)
                maxdev = count[i] - (float)num / SIZE(count);
        }
        else
        {
            if ((float)num / SIZE(count) - count[i] > maxdev)
                maxdev = (float)num / SIZE(count) - count[i];
        }
    }

    // more than 10% error considered bad discrete uniform distribution
    // the C library random()/rand() is such bad random generator
    if (maxdev > (float)num / SIZE(count) * 0.10)
    {
        TEST_LOG("Error: %2.1f%%", maxdev / ((float)num / SIZE(count) / 100.0));
        TEST_FAIL();
    }

    return TEST_SUCCESS;
}
<|endoftext|>


<commit_before>//=======================================================================
// Copyright Baptiste Wicht 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <algorithm>

#include <memory>
#include <boost/variant/variant.hpp>

#include "VariableChecker.hpp"

#include "ast/Program.hpp"

#include "IsConstantVisitor.hpp"
#include "GetTypeVisitor.hpp"
#include "SemanticalException.hpp"
#include "Context.hpp"
#include "FunctionContext.hpp"
#include "Types.hpp"
#include "Variable.hpp"

#include "Compiler.hpp"
#include "Options.hpp"

#include "VisitorUtils.hpp"
#include "ASTVisitor.hpp"

using namespace eddic;

struct CheckerVisitor : public boost::static_visitor<> {
    AUTO_RECURSE_PROGRAM()
    AUTO_RECURSE_FUNCTION_CALLS()
    AUTO_RECURSE_SIMPLE_LOOPS()
    AUTO_RECURSE_BRANCHES()
    AUTO_RECURSE_BINARY_CONDITION()

    void operator()(ast::FunctionDeclaration& declaration){
        //Add all the parameters to the function context
        for(auto& parameter : declaration.Content->parameters){
            Type type = stringToType(parameter.parameterType);

            declaration.Content->context->addParameter(parameter.parameterName, type);
        }

        visit_each(*this, declaration.Content->instructions);
    }

    void operator()(ast::GlobalVariableDeclaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->variableName)) {
            throw SemanticalException("The global Variable " + declaration.Content->variableName + " has already been declared");
        }

        if(!boost::apply_visitor(IsConstantVisitor(), *declaration.Content->value)){
            throw SemanticalException("The value must be constant");
        }

        Type type = stringToType(declaration.Content->variableType);

        declaration.Content->context->addVariable(declaration.Content->variableName, type, *declaration.Content->value);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), *declaration.Content->value);
        if (valueType != type) {
            throw SemanticalException("Incompatible type for global variable " + declaration.Content->variableName);
        }
    }

    void operator()(ast::GlobalArrayDeclaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->arrayName)) {
            throw SemanticalException("The global Variable " + declaration.Content->arrayName + " has already been declared");
        }

        BaseType baseType = stringToBaseType(declaration.Content->arrayType);
        Type type(baseType, declaration.Content->arraySize);

        declaration.Content->context->addVariable(declaration.Content->arrayName, type);
    }

    void operator()(ast::Foreach& foreach){
        if(foreach.Content->context->exists(foreach.Content->variableName)){
            throw SemanticalException("The foreach variable " + foreach.Content->variableName  + " has already been declared");
        }

        foreach.Content->context->addVariable(foreach.Content->variableName, stringToType(foreach.Content->variableType));

        visit_each(*this, foreach.Content->instructions);
    }

    void operator()(ast::Assignment& assignment){
        if (!assignment.Content->context->exists(assignment.Content->variableName)) {
            throw SemanticalException("Variable " + assignment.Content->variableName + " has not  been declared");
        }

        visit(*this, assignment.Content->value);

        auto var = assignment.Content->context->getVariable(assignment.Content->variableName);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), assignment.Content->value);
        if (valueType != var->type()) {
            throw SemanticalException("Incompatible type in assignment of variable " + assignment.Content->variableName);
        }

        var->addReference();
    }

    void operator()(ast::ArrayAssignment& assignment){
        //TODO
    }

    void operator()(ast::Declaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->variableName)) {
            throw SemanticalException("Variable " + declaration.Content->variableName + " has already been declared");
        }

        Type variableType = stringToType(declaration.Content->variableType);
        declaration.Content->context->addVariable(declaration.Content->variableName, variableType);

        visit(*this, *declaration.Content->value);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), *declaration.Content->value);
        if (valueType != variableType) {
            throw SemanticalException("Incompatible type in declaration of variable " + declaration.Content->variableName);
        }
    }

    void operator()(ast::Swap& swap){
        if (swap.Content->lhs == swap.Content->rhs) {
            throw SemanticalException("Cannot swap a variable with itself");
        }

        if (!swap.Content->context->exists(swap.Content->lhs) || !swap.Content->context->exists(swap.Content->rhs)) {
            throw SemanticalException("Variable has not been declared in the swap");
        }

        swap.Content->lhs_var = swap.Content->context->getVariable(swap.Content->lhs);
        swap.Content->rhs_var = swap.Content->context->getVariable(swap.Content->rhs);

        if (swap.Content->lhs_var->type() != swap.Content->rhs_var->type()) {
            throw SemanticalException("Swap of variables of incompatible type");
        }

        //Reference both variables
        swap.Content->lhs_var->addReference();
        swap.Content->rhs_var->addReference();
    }

    void operator()(ast::VariableValue& variable){
        if (!variable.Content->context->exists(variable.Content->variableName)) {
            throw SemanticalException("Variable " + variable.Content->variableName + " has not been declared");
        }

        variable.Content->var = variable.Content->context->getVariable(variable.Content->variableName);

        //Reference the variable
        variable.Content->var->addReference();
    }

    void operator()(ast::ArrayValue& array){
        if (!array.Content->context->exists(array.Content->arrayName)) {
            throw SemanticalException("Array " + array.Content->arrayName + " has not been declared");
        }

        array.Content->var = array.Content->context->getVariable(array.Content->arrayName);

        //Reference the variable
        array.Content->var->addReference();

        visit(*this, array.Content->indexValue);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), array.Content->indexValue);
        if (valueType.base() != BaseType::INT || valueType.isArray()) {
            throw SemanticalException("Invalid index for the array " + array.Content->arrayName);
        }
    }

    void operator()(ast::ComposedValue& value){
        visit(*this, value.Content->first);

        for_each(value.Content->operations.begin(), value.Content->operations.end(),
            [&](boost::tuple<char, ast::Value>& operation){ visit(*this, operation.get<1>()); });

        GetTypeVisitor visitor;

        Type type = boost::apply_visitor(visitor, value.Content->first);

        for(auto& operation : value.Content->operations){
            Type operationType = boost::apply_visitor(visitor, operation.get<1>());

            if(type != operationType){
                throw SemanticalException("Incompatible type");
            }
        }
    }

    void operator()(ast::TerminalNode&){
        //Terminal nodes have no need for variable checking
    }
};

struct UnusedInspector : public boost::static_visitor<> {
    void check(std::shared_ptr<Context> context){
        auto iter = context->begin();
        auto end = context->end();

        for(; iter != end; iter++){
            auto var = iter->second;

            if(var->referenceCount() == 0){
                if(var->position().isStack()){
                    warn("unused variable '" + var->name() + "'");
                } else if(var->position().isGlobal()){
                    warn("unused global variable '" + var->name() + "'");
                } else if(var->position().isParameter()){
                    warn("unused parameter '" + var->name() + "'");
                }
            }
        }
    }

    void operator()(ast::Program& program){
        check(program.Content->context);

        visit_each(*this, program.Content->blocks);
    }

    void operator()(ast::FunctionDeclaration& function){
        check(function.Content->context);
    }

    void operator()(ast::GlobalVariableDeclaration&){
        //Nothing to check there
    }

    void operator()(ast::GlobalArrayDeclaration&){
        //Nothing to check there
    }
};

void VariableChecker::check(ast::Program& program){
    CheckerVisitor visitor;
    visit_non_variant(visitor, program);

    if(WarningUnused){
        UnusedInspector inspector;
        visit_non_variant(inspector, program);
    }
}
<commit_msg>Check variables for array assignments<commit_after>//=======================================================================
// Copyright Baptiste Wicht 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================

#include <algorithm>

#include <memory>
#include <boost/variant/variant.hpp>

#include "VariableChecker.hpp"

#include "ast/Program.hpp"

#include "IsConstantVisitor.hpp"
#include "GetTypeVisitor.hpp"
#include "SemanticalException.hpp"
#include "Context.hpp"
#include "FunctionContext.hpp"
#include "Types.hpp"
#include "Variable.hpp"

#include "Compiler.hpp"
#include "Options.hpp"

#include "VisitorUtils.hpp"
#include "ASTVisitor.hpp"

using namespace eddic;

struct CheckerVisitor : public boost::static_visitor<> {
    AUTO_RECURSE_PROGRAM()
    AUTO_RECURSE_FUNCTION_CALLS()
    AUTO_RECURSE_SIMPLE_LOOPS()
    AUTO_RECURSE_BRANCHES()
    AUTO_RECURSE_BINARY_CONDITION()

    void operator()(ast::FunctionDeclaration& declaration){
        //Add all the parameters to the function context
        for(auto& parameter : declaration.Content->parameters){
            Type type = stringToType(parameter.parameterType);

            declaration.Content->context->addParameter(parameter.parameterName, type);
        }

        visit_each(*this, declaration.Content->instructions);
    }

    void operator()(ast::GlobalVariableDeclaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->variableName)) {
            throw SemanticalException("The global Variable " + declaration.Content->variableName + " has already been declared");
        }

        if(!boost::apply_visitor(IsConstantVisitor(), *declaration.Content->value)){
            throw SemanticalException("The value must be constant");
        }

        Type type = stringToType(declaration.Content->variableType);

        declaration.Content->context->addVariable(declaration.Content->variableName, type, *declaration.Content->value);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), *declaration.Content->value);
        if (valueType != type) {
            throw SemanticalException("Incompatible type for global variable " + declaration.Content->variableName);
        }
    }

    void operator()(ast::GlobalArrayDeclaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->arrayName)) {
            throw SemanticalException("The global Variable " + declaration.Content->arrayName + " has already been declared");
        }

        BaseType baseType = stringToBaseType(declaration.Content->arrayType);
        Type type(baseType, declaration.Content->arraySize);

        declaration.Content->context->addVariable(declaration.Content->arrayName, type);
    }

    void operator()(ast::Foreach& foreach){
        if(foreach.Content->context->exists(foreach.Content->variableName)){
            throw SemanticalException("The foreach variable " + foreach.Content->variableName  + " has already been declared");
        }

        foreach.Content->context->addVariable(foreach.Content->variableName, stringToType(foreach.Content->variableType));

        visit_each(*this, foreach.Content->instructions);
    }

    void operator()(ast::Assignment& assignment){
        if (!assignment.Content->context->exists(assignment.Content->variableName)) {
            throw SemanticalException("Variable " + assignment.Content->variableName + " has not  been declared");
        }

        visit(*this, assignment.Content->value);

        auto var = assignment.Content->context->getVariable(assignment.Content->variableName);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), assignment.Content->value);
        if (valueType != var->type()) {
            throw SemanticalException("Incompatible type in assignment of variable " + assignment.Content->variableName);
        }

        var->addReference();
    }

    void operator()(ast::ArrayAssignment& assignment){
        if (!assignment.Content->context->exists(assignment.Content->variableName)) {
            throw SemanticalException("Array " + assignment.Content->variableName + " has not  been declared");
        }

        visit(*this, assignment.Content->indexValue);
        visit(*this, assignment.Content->value);

        auto var = assignment.Content->context->getVariable(assignment.Content->variableName);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), assignment.Content->value);
        if (valueType.base() != var->type().base()) {
            throw SemanticalException("Incompatible type in assignment of array " + assignment.Content->variableName);
        }

        Type indexType = boost::apply_visitor(GetTypeVisitor(), assignment.Content->indexValue);
        if (indexType.base() != BaseType::INT) {
            throw SemanticalException("Invalid index value type in assignment of array " + assignment.Content->variableName);
        }

        var->addReference();
    }

    void operator()(ast::Declaration& declaration){
        if (declaration.Content->context->exists(declaration.Content->variableName)) {
            throw SemanticalException("Variable " + declaration.Content->variableName + " has already been declared");
        }

        Type variableType = stringToType(declaration.Content->variableType);
        declaration.Content->context->addVariable(declaration.Content->variableName, variableType);

        visit(*this, *declaration.Content->value);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), *declaration.Content->value);
        if (valueType != variableType) {
            throw SemanticalException("Incompatible type in declaration of variable " + declaration.Content->variableName);
        }
    }

    void operator()(ast::Swap& swap){
        if (swap.Content->lhs == swap.Content->rhs) {
            throw SemanticalException("Cannot swap a variable with itself");
        }

        if (!swap.Content->context->exists(swap.Content->lhs) || !swap.Content->context->exists(swap.Content->rhs)) {
            throw SemanticalException("Variable has not been declared in the swap");
        }

        swap.Content->lhs_var = swap.Content->context->getVariable(swap.Content->lhs);
        swap.Content->rhs_var = swap.Content->context->getVariable(swap.Content->rhs);

        if (swap.Content->lhs_var->type() != swap.Content->rhs_var->type()) {
            throw SemanticalException("Swap of variables of incompatible type");
        }

        //Reference both variables
        swap.Content->lhs_var->addReference();
        swap.Content->rhs_var->addReference();
    }

    void operator()(ast::VariableValue& variable){
        if (!variable.Content->context->exists(variable.Content->variableName)) {
            throw SemanticalException("Variable " + variable.Content->variableName + " has not been declared");
        }

        variable.Content->var = variable.Content->context->getVariable(variable.Content->variableName);

        //Reference the variable
        variable.Content->var->addReference();
    }

    void operator()(ast::ArrayValue& array){
        if (!array.Content->context->exists(array.Content->arrayName)) {
            throw SemanticalException("Array " + array.Content->arrayName + " has not been declared");
        }

        array.Content->var = array.Content->context->getVariable(array.Content->arrayName);

        //Reference the variable
        array.Content->var->addReference();

        visit(*this, array.Content->indexValue);

        Type valueType = boost::apply_visitor(GetTypeVisitor(), array.Content->indexValue);
        if (valueType.base() != BaseType::INT || valueType.isArray()) {
            throw SemanticalException("Invalid index for the array " + array.Content->arrayName);
        }
    }

    void operator()(ast::ComposedValue& value){
        visit(*this, value.Content->first);

        for_each(value.Content->operations.begin(), value.Content->operations.end(),
            [&](boost::tuple<char, ast::Value>& operation){ visit(*this, operation.get<1>()); });

        GetTypeVisitor visitor;

        Type type = boost::apply_visitor(visitor, value.Content->first);

        for(auto& operation : value.Content->operations){
            Type operationType = boost::apply_visitor(visitor, operation.get<1>());

            if(type != operationType){
                throw SemanticalException("Incompatible type");
            }
        }
    }

    void operator()(ast::TerminalNode&){
        //Terminal nodes have no need for variable checking
    }
};

struct UnusedInspector : public boost::static_visitor<> {
    void check(std::shared_ptr<Context> context){
        auto iter = context->begin();
        auto end = context->end();

        for(; iter != end; iter++){
            auto var = iter->second;

            if(var->referenceCount() == 0){
                if(var->position().isStack()){
                    warn("unused variable '" + var->name() + "'");
                } else if(var->position().isGlobal()){
                    warn("unused global variable '" + var->name() + "'");
                } else if(var->position().isParameter()){
                    warn("unused parameter '" + var->name() + "'");
                }
            }
        }
    }

    void operator()(ast::Program& program){
        check(program.Content->context);

        visit_each(*this, program.Content->blocks);
    }

    void operator()(ast::FunctionDeclaration& function){
        check(function.Content->context);
    }

    void operator()(ast::GlobalVariableDeclaration&){
        //Nothing to check there
    }

    void operator()(ast::GlobalArrayDeclaration&){
        //Nothing to check there
    }
};

void VariableChecker::check(ast::Program& program){
    CheckerVisitor visitor;
    visit_non_variant(visitor, program);

    if(WarningUnused){
        UnusedInspector inspector;
        visit_non_variant(inspector, program);
    }
}
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(XALAN_NODESORTER_HEADER_GUARD)
#define XALAN_NODESORTER_HEADER_GUARD

/**
 * @author Scott Boag (scott_boag@lotus.com)
 * @author David N. Bertoni (david_n_bertoni@lotus.com)
 */

// Base include file.  Must be first.
#include "XSLTDefinitions.hpp"

#include <functional>
#include <vector>

#include <XPath/XObject.hpp>

#include <XSLT/NodeSortKey.hpp>

class MutableNodeRefList;
class StylesheetExecutionContext;
class XalanNode;
class XPath;

/**
 * This class can sort vectors of nodes according to a select pattern.
 */
class NodeSorter
{
public:

	struct VectorEntry
	{
	public:

		VectorEntry(
			XalanNode*		theNode,
			unsigned int	thePosition) :
			m_node(theNode),
			m_position(thePosition)
		{
		}

		XalanNode*		m_node;
		unsigned int	m_position;
	};

#if defined(XALAN_NO_NAMESPACES)
	typedef vector<VectorEntry>			NodeVectorType;
	typedef vector<NodeSortKey>			NodeSortKeyVectorType;
#else
	typedef std::vector<VectorEntry>	NodeVectorType;
	typedef std::vector<NodeSortKey>	NodeSortKeyVectorType;
#endif

	explicit
	NodeSorter();

	~NodeSorter();

	NodeSortKeyVectorType&
	getSortKeys()
	{
		return m_keys;
	}

	/**
	 * Given a list of nodes, sort each node according to the criteria in the
	 * keys.  The list is assumed to be in document order.
	 *
	 * @param executionContext current execution context
	 * @param v    list of Nodes
	 */
	void
	sort(
			StylesheetExecutionContext&		executionContext,
			MutableNodeRefList&				theList);

	/**
	 * Return the results of a compare of two nodes.
	 */
#if defined(XALAN_NO_NAMESPACES)
	struct NodeSortKeyCompare : public binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
#else
	struct NodeSortKeyCompare : public std::binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
#endif
	{
	public:

	/**
	 * Construct a NodeSortKeyCompare object, to perform the sort
	 *
	 * @param executionContext current execution context
	 * @param theNodes        vector or nodes to be sorted
	 * @param theNodeSortKeys vector of keys upon which to sort
	 */
		NodeSortKeyCompare(
				StylesheetExecutionContext&		executionContext,
				NodeSorter&						theSorter,
				const NodeVectorType&			theNodes,
				const NodeSortKeyVectorType&	theNodeSortKeys) :
			m_executionContext(executionContext),
			m_sorter(theSorter),
			m_nodes(theNodes),
			m_nodeSortKeys(theNodeSortKeys)
		{
		}

		/**
		 * Compare two nodes, returning a value to indicate the
		 * result
		 *
		 * @param theLHS the first node to compare
		 * @param theRHS the second node to compare
		 * @param theKeyIndex the index of the key to use
		 * @result < 0 if theLHS is less than theRHS, 0 if they are equal, and > 0 if theLHS is greater than theRHS
		 */
		int
		compare(
				first_argument_type		theLHS,
				second_argument_type	theRHS,
				unsigned int			theKeyIndex = 0) const;

		/**
		 * Compare two nodes as a less predicate.
		 *
		 * @param theLHS the first node to compare
		 * @param theRHS the second node to compare
		 * @param theKeyIndex the index of the key to use
		 * @return true if theLHS is less than theRHS
		 */
		result_type
		operator()(
				first_argument_type		theLHS,
				second_argument_type	theRHS,
				unsigned int			theKeyIndex = 0) const
		{
			return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false;
		}

	protected:

		double
		getNumberResult(
				const NodeSortKey&		theKey,
				unsigned int			theKeyIndex,
				first_argument_type		theEntry) const;

		const XObjectPtr&
		getStringResult(
				const NodeSortKey&		theKey,
				unsigned int			theKeyIndex,
				first_argument_type		theEntry) const;

	private:

		StylesheetExecutionContext&		m_executionContext;
		NodeSorter&						m_sorter;
		const NodeVectorType&			m_nodes;
		const NodeSortKeyVectorType&	m_nodeSortKeys;
	};

	friend struct NodeSortKeyCompare;

#if defined(XALAN_NO_NAMESPACES)
	typedef	vector<double>		NumberResultsCacheVectorType;

	typedef	vector<XObjectPtr>	StringResultsCacheVectorType;

	typedef vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
	typedef vector<StringResultsCacheVectorType>	StringResultsCacheType;
#else
	typedef	std::vector<double>			NumberResultsCacheVectorType;
	typedef	std::vector<XObjectPtr>		StringResultsCacheVectorType;

	typedef std::vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
	typedef std::vector<StringResultsCacheVectorType>	StringResultsCacheType;
#endif

private:

	/**
	 * Given a vector of nodes, sort each node according to the criteria in the
	 * keys.
	 *
	 * @param executionContext current execution context
	 */
	void
	sort(StylesheetExecutionContext&	executionContext);

	// Data members...
	NumberResultsCacheType	m_numberResultsCache;

	StringResultsCacheType	m_stringResultsCache;

	NodeSortKeyVectorType	m_keys;

	NodeVectorType			m_scratchVector;
};

#endif	// XALAN_NODESORTER_HEADER_GUARD
<commit_msg>Added default parameters to constructor.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#if !defined(XALAN_NODESORTER_HEADER_GUARD)
#define XALAN_NODESORTER_HEADER_GUARD

/**
 * @author Scott Boag (scott_boag@lotus.com)
 * @author David N. Bertoni (david_n_bertoni@lotus.com)
 */

// Base include file.  Must be first.
#include "XSLTDefinitions.hpp"

#include <functional>
#include <vector>

#include <XPath/XObject.hpp>

#include <XSLT/NodeSortKey.hpp>

class MutableNodeRefList;
class StylesheetExecutionContext;
class XalanNode;
class XPath;

/**
 * This class can sort vectors of nodes according to a select pattern.
 */
class NodeSorter
{
public:

	struct VectorEntry
	{
	public:

		VectorEntry(
			XalanNode*		theNode = 0,
			unsigned int	thePosition = 0) :
			m_node(theNode),
			m_position(thePosition)
		{
		}

		XalanNode*		m_node;
		unsigned int	m_position;
	};

#if defined(XALAN_NO_NAMESPACES)
	typedef vector<VectorEntry>			NodeVectorType;
	typedef vector<NodeSortKey>			NodeSortKeyVectorType;
#else
	typedef std::vector<VectorEntry>	NodeVectorType;
	typedef std::vector<NodeSortKey>	NodeSortKeyVectorType;
#endif

	explicit
	NodeSorter();

	~NodeSorter();

	NodeSortKeyVectorType&
	getSortKeys()
	{
		return m_keys;
	}

	/**
	 * Given a list of nodes, sort each node according to the criteria in the
	 * keys.  The list is assumed to be in document order.
	 *
	 * @param executionContext current execution context
	 * @param v    list of Nodes
	 */
	void
	sort(
			StylesheetExecutionContext&		executionContext,
			MutableNodeRefList&				theList);

	/**
	 * Return the results of a compare of two nodes.
	 */
#if defined(XALAN_NO_NAMESPACES)
	struct NodeSortKeyCompare : public binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
#else
	struct NodeSortKeyCompare : public std::binary_function<const NodeVectorType::value_type&, const NodeVectorType::value_type&, bool>
#endif
	{
	public:

	/**
	 * Construct a NodeSortKeyCompare object, to perform the sort
	 *
	 * @param executionContext current execution context
	 * @param theNodes        vector or nodes to be sorted
	 * @param theNodeSortKeys vector of keys upon which to sort
	 */
		NodeSortKeyCompare(
				StylesheetExecutionContext&		executionContext,
				NodeSorter&						theSorter,
				const NodeVectorType&			theNodes,
				const NodeSortKeyVectorType&	theNodeSortKeys) :
			m_executionContext(executionContext),
			m_sorter(theSorter),
			m_nodes(theNodes),
			m_nodeSortKeys(theNodeSortKeys)
		{
		}

		/**
		 * Compare two nodes, returning a value to indicate the
		 * result
		 *
		 * @param theLHS the first node to compare
		 * @param theRHS the second node to compare
		 * @param theKeyIndex the index of the key to use
		 * @result < 0 if theLHS is less than theRHS, 0 if they are equal, and > 0 if theLHS is greater than theRHS
		 */
		int
		compare(
				first_argument_type		theLHS,
				second_argument_type	theRHS,
				unsigned int			theKeyIndex = 0) const;

		/**
		 * Compare two nodes as a less predicate.
		 *
		 * @param theLHS the first node to compare
		 * @param theRHS the second node to compare
		 * @param theKeyIndex the index of the key to use
		 * @return true if theLHS is less than theRHS
		 */
		result_type
		operator()(
				first_argument_type		theLHS,
				second_argument_type	theRHS,
				unsigned int			theKeyIndex = 0) const
		{
			return compare(theLHS, theRHS, theKeyIndex) < 0 ? true : false;
		}

	protected:

		double
		getNumberResult(
				const NodeSortKey&		theKey,
				unsigned int			theKeyIndex,
				first_argument_type		theEntry) const;

		const XObjectPtr&
		getStringResult(
				const NodeSortKey&		theKey,
				unsigned int			theKeyIndex,
				first_argument_type		theEntry) const;

	private:

		StylesheetExecutionContext&		m_executionContext;
		NodeSorter&						m_sorter;
		const NodeVectorType&			m_nodes;
		const NodeSortKeyVectorType&	m_nodeSortKeys;
	};

	friend struct NodeSortKeyCompare;

#if defined(XALAN_NO_NAMESPACES)
	typedef	vector<double>		NumberResultsCacheVectorType;

	typedef	vector<XObjectPtr>	StringResultsCacheVectorType;

	typedef vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
	typedef vector<StringResultsCacheVectorType>	StringResultsCacheType;
#else
	typedef	std::vector<double>			NumberResultsCacheVectorType;
	typedef	std::vector<XObjectPtr>		StringResultsCacheVectorType;

	typedef std::vector<NumberResultsCacheVectorType>	NumberResultsCacheType;
	typedef std::vector<StringResultsCacheVectorType>	StringResultsCacheType;
#endif

private:

	/**
	 * Given a vector of nodes, sort each node according to the criteria in the
	 * keys.
	 *
	 * @param executionContext current execution context
	 */
	void
	sort(StylesheetExecutionContext&	executionContext);

	// Data members...
	NumberResultsCacheType	m_numberResultsCache;

	StringResultsCacheType	m_stringResultsCache;

	NodeSortKeyVectorType	m_keys;

	NodeVectorType			m_scratchVector;
};

#endif	// XALAN_NODESORTER_HEADER_GUARD
<|endoftext|>


<commit_before>/**
 * \file XmlDocument.cpp
 * \brief XML Document
 * \author tcantenot
 * \version 0.1
 * \date 18 mars 2014
 */

#include <algorithm>
#include <fstream>
#include <iosfwd>
#include <iostream>

#include "../AppDebug.hpp"
#include "XmlComment.hpp"
#include "XmlDocument.hpp"
#include "XmlDocumentNode.hpp"
#include "XmlElement.hpp"
#include "XmlProcessingInstruction.hpp"

#ifdef APP_DEBUG
#include <cassert>
#endif

namespace Xml
{
    Document::Document(Element * root):
        mRoot(root),
        mChildren()
    {
        if(root != nullptr)
        {
            mChildren.push_back(root);
        }
    }

    Document::~Document()
    {
        for (auto node : mChildren)
        {
            node->mParent = nullptr;
            delete node;
        }

        mChildren.clear();
    }

    Document const *
    Document::document() const
    {
        return this;
    }

    Object const *
    Document::parent() const
    {
        return nullptr;
    }

    void
    Document::appendComment(std::string const & comment)
    {
        this->appendNode(new Comment(comment));
    }

    Document::NodesList const &
    Document::children() const
    {
        return mChildren;
    }

    void
    Document::setRoot(Element * root)
    {
        if(root == mRoot)
        {
            return;
        }

        if(root != nullptr)
        {
            // If there is already a root node...
            if(mRoot != nullptr)
            {
                auto it = std::find(std::begin(mChildren), std::end(mChildren), mRoot);

                #ifdef APP_DEBUG
                assert(it != std::end(mChildren));
                #endif

                // ...we delete it
                delete mRoot;

                // and replaces it by the new one
                *it = root;
                root->mParent = this;
            }
            else
            {
                this->appendNode(root);
            }
        }
        else
        {
            auto it = std::find(std::begin(mChildren), std::end(mChildren), mRoot);
            mChildren.erase(it);
            delete mRoot;
        }

        mRoot = root;
    }

    bool
    Document::saveToFile(std::string const & path) const
    {
        std::ofstream file(path);

        if(!file.good())
        {
            std::cerr << "Failed to open file: \"" << path << "\"" << std::endl;
            return false;
        }

        file << *this;

        return true;
    }

    void
    Document::exportToStream(std::ostream & stream, std::size_t level, std::string const & indent) const
    {
        for(auto i = 0u; i < mChildren.size(); ++i)
        {
            auto const & c = mChildren[i];

            app_assert(c != nullptr);

            c->exportToStream(stream, level, indent);

            stream << (i == mChildren.size() - 1 ? "" : "\n");
        }
    }

    void
    Document::appendNode(DocumentNode * documentNode)
    {
        #ifdef APP_DEBUG
        assert(documentNode != nullptr);

        assert(
            std::find(std::begin(mChildren), std::end(mChildren), documentNode)
            == std::end(mChildren)
        );

        if(mRoot != nullptr)
        {
            assert(!mRoot->hasChild(documentNode));
        }
        #endif

        // A document has only one Xml::Element
        if(documentNode->isElement() && mRoot != nullptr)
        {
            delete mRoot;
        }

        mChildren.push_back(documentNode);
        documentNode->mParent = this;
    }

}
<commit_msg>Fixed Xml::Document::appendNode<commit_after>/**
 * \file XmlDocument.cpp
 * \brief XML Document
 * \author tcantenot
 * \version 0.1
 * \date 18 mars 2014
 */

#include <algorithm>
#include <fstream>
#include <iosfwd>
#include <iostream>

#include "../AppDebug.hpp"
#include "XmlComment.hpp"
#include "XmlDocument.hpp"
#include "XmlDocumentNode.hpp"
#include "XmlElement.hpp"
#include "XmlProcessingInstruction.hpp"

#ifdef APP_DEBUG
#include <cassert>
#endif

namespace Xml
{
    Document::Document(Element * root):
        mRoot(root),
        mChildren()
    {
        if(root != nullptr)
        {
            mChildren.push_back(root);
        }
    }

    Document::~Document()
    {
        for (auto node : mChildren)
        {
            node->mParent = nullptr;
            delete node;
        }

        mChildren.clear();
    }

    Document const *
    Document::document() const
    {
        return this;
    }

    Object const *
    Document::parent() const
    {
        return nullptr;
    }

    void
    Document::appendComment(std::string const & comment)
    {
        this->appendNode(new Comment(comment));
    }

    Document::NodesList const &
    Document::children() const
    {
        return mChildren;
    }

    void
    Document::setRoot(Element * root)
    {
        if(root == mRoot)
        {
            return;
        }

        if(root != nullptr)
        {
            // If there is already a root node...
            if(mRoot != nullptr)
            {
                auto it = std::find(std::begin(mChildren), std::end(mChildren), mRoot);

                #ifdef APP_DEBUG
                assert(it != std::end(mChildren));
                #endif

                // ...we delete it
                delete mRoot;

                // and replaces it by the new one
                *it = root;
                root->mParent = this;
            }
            else
            {
                this->appendNode(root);
            }
        }
        else
        {
            auto it = std::find(std::begin(mChildren), std::end(mChildren), mRoot);
            mChildren.erase(it);
            delete mRoot;
        }

        mRoot = root;
    }

    bool
    Document::saveToFile(std::string const & path) const
    {
        std::ofstream file(path);

        if(!file.good())
        {
            std::cerr << "Failed to open file: \"" << path << "\"" << std::endl;
            return false;
        }

        file << *this;

        return true;
    }

    void
    Document::exportToStream(std::ostream & stream, std::size_t level, std::string const & indent) const
    {
        for(auto i = 0u; i < mChildren.size(); ++i)
        {
            auto const & c = mChildren[i];

            app_assert(c != nullptr);

            c->exportToStream(stream, level, indent);

            stream << (i == mChildren.size() - 1 ? "" : "\n");
        }
    }

    void
    Document::appendNode(DocumentNode * documentNode)
    {
        #ifdef APP_DEBUG
        assert(documentNode != nullptr);

        assert(
            std::find(std::begin(mChildren), std::end(mChildren), documentNode)
            == std::end(mChildren)
        );

        if(mRoot != nullptr)
        {
            assert(!mRoot->hasChild(documentNode));
        }
        #endif

        // A document has only one Xml::Element
        if(documentNode->isElement() && mRoot != nullptr)
        {
            auto it = std::find(std::begin(mChildren), std::end(mChildren), mRoot);
            mChildren.erase(it);
            delete mRoot;
        }

        mChildren.push_back(documentNode);
        documentNode->mParent = this;
    }

}
<|endoftext|>


<commit_before>#pragma once
//=====================================================================//
/*!	@file
	@brief	RL78/G13 DMA コントローラー定義
    @author 平松邦仁 (hira@rvf-rc45.net)
	@copyright	Copyright (C) 2016 Kunihito Hiramatsu @n
				Released under the MIT license @n
				https://github.com/hirakuni45/RL78/blob/master/LICENSE
*/
//=====================================================================//
#include "common/io_utils.hpp"

namespace device {

	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
	/*!
		@brief  DMA コントローラー・テンプレート
		@param[in]	BASE	ベース
		@param[in]	OFS		オフセット
	*/
	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
	template <uint32_t BASE, uint32_t OFS>
	struct dma_t {

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		/*!
			@brief  SFR アドレス・レジスタ（DSA）
		*/
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		static rw8_t<BASE + OFS> DSA;

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		/*!
			@brief  RAM アドレス・レジスタ（DRA）
		*/
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		static rw16_t<BASE + 0x2 + (OFS * 2)> DRA;

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		/*!
			@brief	バイト・カウント・レジスタ（DBC）
		*/
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		static rw16_t<BASE + 0x6 + (OFS * 2)> DBC;

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		/*!
			@brief  DMAモード・コントロール・レジスタ（DMC）
			@param[in]	T	アクセス・クラス
		*/
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		template <class T>
		struct dmc_t : public T {
			using T::operator =;
			using T::operator ();
			using T::operator |=;
			using T::operator &=;

			bit_rw_t<T, bitpos::B7>	    STG;    ///< DMA転送開始ソフトウエア・トリガ
			bit_rw_t<T, bitpos::B6>	    DRS;    ///< DMA転送方向の選択
			bit_rw_t<T, bitpos::B5>	    DS;     ///< DMA転送での転送データ・サイズの指定
			bit_rw_t<T, bitpos::B4>	    DWAIT;  ///< DMA転送の保留
			bits_rw_t<T, bitpos::B0, 4>	IFC;    ///< DMA起動要因の選択
		};
		static dmc_t< rw8_t<BASE + 0xa + OFS> > DMC;

		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		/*!
			@brief  DMA動作コントロール・レジスタ（DRC）
			@param[in]	T	アクセス・クラス
		*/
		//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
		template <class T>
		struct drc_t : public T {
			using T::operator =;
			using T::operator ();
			using T::operator |=;
			using T::operator &=;

			bit_rw_t<T, bitpos::B7>	DEN;  ///< DMA動作許可フラグ
			bit_rw_t<T, bitpos::B0>	DST;  ///< DMA転送モード・フラグ
		};
		static drc_t< rw8_t<BASE + 0xc + OFS> > DRC;
	};

	typedef dma_t<0xFFFB0, 0> DMA0;
	typedef dma_t<0xFFFB0, 1> DMA1;
	typedef dma_t<0xF0200, 0> DMA2;
	typedef dma_t<0xF0200, 1> DMA3;
}
<commit_msg>remove a file<commit_after><|endoftext|>