<commit_before>/*************************************************************************
 *
 *  $RCSfile: prevwsh.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-26 18:06:12 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SC_PREVWSH_HXX
#define SC_PREVWSH_HXX

class ScrollBar;

#ifndef _VIEWFAC_HXX //autogen
#include <sfx2/viewfac.hxx>
#endif
#ifndef _SFXVIEWSH_HXX //autogen
#include <sfx2/viewsh.hxx>
#endif
#ifndef _SVX_ZOOMITEM_HXX //autogen
#include <svx/zoomitem.hxx>
#endif

#include "shellids.hxx"

class ScDocument;
class ScDocShell;
class ScPreview;
struct ScHeaderFieldData;
class ScPreviewLocationData;
class CommandEvent;

//==================================================================

class ScPreviewShell: public SfxViewShell
{
    ScDocShell*     pDocShell;

    ScPreview*      pPreview;               // Ausgabe-Fenster
    ScrollBar*      pHorScroll;
    ScrollBar*      pVerScroll;
    Window*         pCorner;

    String          aSourceData;            // ViewData
    BYTE            nSourceDesignMode;      // form design mode from TabView
    SvxZoomType     eZoom;

    SfxBroadcaster* pAccessibilityBroadcaster;

private:
    void            Construct( Window* pParent );
    DECL_LINK(ScrollHandler, ScrollBar* );
    void            DoScroll( USHORT nMode );

protected:
    virtual void    Activate(BOOL bMDI);
    virtual void    Deactivate(BOOL bMDI);

    virtual void    AdjustPosSizePixel( const Point &rPos, const Size &rSize );

    virtual void    InnerResizePixel( const Point &rOfs, const Size &rSize );
    virtual void    OuterResizePixel( const Point &rOfs, const Size &rSize );

    virtual Size    GetOptimalSizePixel() const;

    virtual String  GetDescription() const;

    virtual void    WriteUserData(String &, BOOL bBrowse = FALSE);
    virtual void    ReadUserData(const String &, BOOL bBrowse = FALSE);

    virtual void    WriteUserDataSequence (::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
    virtual void    ReadUserDataSequence (const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );

public:
                    TYPEINFO();

                    SFX_DECL_INTERFACE(SCID_PREVIEW_SHELL);
                    SFX_DECL_VIEWFACTORY(ScPreviewShell);

                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    const ScPreviewShell&   rWin );
                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    Window*                 pParent);
                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    SfxViewShell*           pOldSh );

    virtual         ~ScPreviewShell();

    void            InitStartTable(USHORT nTab);

    void            UpdateScrollBars();
    BOOL            ScrollCommand( const CommandEvent& rCEvt );

    void            Execute( SfxRequest& rReq );
    void            GetState( SfxItemSet& rSet );

    void            FillFieldData( ScHeaderFieldData& rData );

    const String&   GetSourceData() const   { return aSourceData; }
    BYTE            GetSourceDesignMode() const { return nSourceDesignMode; }

    virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
                         const SfxHint& rHint, const TypeId& rHintType );

    virtual SfxPrinter*     GetPrinter( BOOL bCreate = FALSE );
    virtual USHORT          SetPrinter( SfxPrinter* pNewPrinter, USHORT nDiffFlags = SFX_PRINTER_ALL );
    virtual PrintDialog*    CreatePrintDialog( Window* pParent );
    virtual SfxTabPage*     CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions );
    virtual void            PreparePrint( PrintDialog* pPrintDialog = NULL );
    virtual USHORT          Print( SfxProgress& rProgress, PrintDialog* pPrintDialog = NULL );

    void    AddAccessibilityObject( SfxListener& rObject );
    void    RemoveAccessibilityObject( SfxListener& rObject );
    void    BroadcastAccessibility( const SfxHint &rHint );
    BOOL    HasAccessibilityObjects();

    const ScPreviewLocationData& GetLocationData();
    ScDocument*     GetDocument();
    ScPreview*      GetPreview() { return pPreview; }
};

#endif
<commit_msg>INTEGRATION: CWS rowlimit (1.5.202); FILE MERGED 2004/01/13 20:04:33 er 1.5.202.1: #i1967# SCCOL,SCROW,SCTAB replace USHORT; SCsCOL,SCsROW,SCsTAB replace short<commit_after>/*************************************************************************
 *
 *  $RCSfile: prevwsh.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2004-06-04 11:38:48 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SC_PREVWSH_HXX
#define SC_PREVWSH_HXX

class ScrollBar;

#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

#ifndef _VIEWFAC_HXX //autogen
#include <sfx2/viewfac.hxx>
#endif
#ifndef _SFXVIEWSH_HXX //autogen
#include <sfx2/viewsh.hxx>
#endif
#ifndef _SVX_ZOOMITEM_HXX //autogen
#include <svx/zoomitem.hxx>
#endif

#include "shellids.hxx"

class ScDocument;
class ScDocShell;
class ScPreview;
struct ScHeaderFieldData;
class ScPreviewLocationData;
class CommandEvent;

//==================================================================

class ScPreviewShell: public SfxViewShell
{
    ScDocShell*     pDocShell;

    ScPreview*      pPreview;               // Ausgabe-Fenster
    ScrollBar*      pHorScroll;
    ScrollBar*      pVerScroll;
    Window*         pCorner;

    String          aSourceData;            // ViewData
    BYTE            nSourceDesignMode;      // form design mode from TabView
    SvxZoomType     eZoom;

    SfxBroadcaster* pAccessibilityBroadcaster;

private:
    void            Construct( Window* pParent );
    DECL_LINK(ScrollHandler, ScrollBar* );
    void            DoScroll( USHORT nMode );

protected:
    virtual void    Activate(BOOL bMDI);
    virtual void    Deactivate(BOOL bMDI);

    virtual void    AdjustPosSizePixel( const Point &rPos, const Size &rSize );

    virtual void    InnerResizePixel( const Point &rOfs, const Size &rSize );
    virtual void    OuterResizePixel( const Point &rOfs, const Size &rSize );

    virtual Size    GetOptimalSizePixel() const;

    virtual String  GetDescription() const;

    virtual void    WriteUserData(String &, BOOL bBrowse = FALSE);
    virtual void    ReadUserData(const String &, BOOL bBrowse = FALSE);

    virtual void    WriteUserDataSequence (::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
    virtual void    ReadUserDataSequence (const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );

public:
                    TYPEINFO();

                    SFX_DECL_INTERFACE(SCID_PREVIEW_SHELL);
                    SFX_DECL_VIEWFACTORY(ScPreviewShell);

                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    const ScPreviewShell&   rWin );
                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    Window*                 pParent);
                    ScPreviewShell( SfxViewFrame*           pViewFrame,
                                    SfxViewShell*           pOldSh );

    virtual         ~ScPreviewShell();

    void            InitStartTable(SCTAB nTab);

    void            UpdateScrollBars();
    BOOL            ScrollCommand( const CommandEvent& rCEvt );

    void            Execute( SfxRequest& rReq );
    void            GetState( SfxItemSet& rSet );

    void            FillFieldData( ScHeaderFieldData& rData );

    const String&   GetSourceData() const   { return aSourceData; }
    BYTE            GetSourceDesignMode() const { return nSourceDesignMode; }

    virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
                         const SfxHint& rHint, const TypeId& rHintType );

    virtual SfxPrinter*     GetPrinter( BOOL bCreate = FALSE );
    virtual USHORT          SetPrinter( SfxPrinter* pNewPrinter, USHORT nDiffFlags = SFX_PRINTER_ALL );
    virtual PrintDialog*    CreatePrintDialog( Window* pParent );
    virtual SfxTabPage*     CreatePrintOptionsPage( Window *pParent, const SfxItemSet &rOptions );
    virtual void            PreparePrint( PrintDialog* pPrintDialog = NULL );
    virtual USHORT          Print( SfxProgress& rProgress, PrintDialog* pPrintDialog = NULL );

    void    AddAccessibilityObject( SfxListener& rObject );
    void    RemoveAccessibilityObject( SfxListener& rObject );
    void    BroadcastAccessibility( const SfxHint &rHint );
    BOOL    HasAccessibilityObjects();

    const ScPreviewLocationData& GetLocationData();
    ScDocument*     GetDocument();
    ScPreview*      GetPreview() { return pPreview; }
};

#endif
<|endoftext|>


<commit_before>/*
 * Publisher.cpp
 *
 *  Created on: Jul 19, 2016
 *      Author: pschultz
 */

#include "Publisher.hpp"
#include "utils/PVAssert.hpp"
#include "include/pv_common.h"

namespace PV {

Publisher::Publisher(Communicator * comm, int numItems, PVLayerLoc loc, int numLevels, bool isSparse)
{
   //size_t dataSize  = numItems * sizeof(float);
   size_t dataSize  = sizeof(float);

   this->mComm  = comm;

   cube.data = nullptr;
   cube.loc = loc;
   cube.numItems = numItems;

   const int numBuffers = loc.nbatch;

   // not really inplace but ok as is only used to deliver
   // to provide cube information for data from store
   cube.size = numBuffers * numItems * dataSize + sizeof(PVLayerCube);

   store = new DataStore(numBuffers, numItems, dataSize, numLevels, isSparse);

   //DONE: check for memory leak here, method flagged by valgrind
   this->neighborDatatypes = Communicator::newDatatypes(&loc);

   requests.clear();
   requests.reserve((NUM_NEIGHBORHOOD-1) * loc.nbatch);
}

Publisher::~Publisher()
{
   delete store;
   Communicator::freeDatatypes(neighborDatatypes); neighborDatatypes = nullptr;
}

int Publisher::updateAllActiveIndices() {
   if(store->isSparse()) return calcAllActiveIndices(); else return PV_SUCCESS;
}

int Publisher::updateActiveIndices() {
   if(store->isSparse()) return calcActiveIndices(); else return PV_SUCCESS;
}

int Publisher::calcAllActiveIndices() {
   for(int l = 0; l < store->numberOfLevels(); l++){
      for(int b = 0; b < store->numberOfBuffers(); b++){
         //Active indicies stored as local ext values
         int numActive = 0;
         pvdata_t * activity = (pvdata_t*) store->buffer(b, l);;
         unsigned int * activeIndices = store->activeIndicesBuffer(b, l);
         long * numActiveBuf = store->numActiveBuffer(b, l);

         for (int kex = 0; kex < store->getNumItems(); kex++) {
            if (activity[kex] != 0.0) {
               activeIndices[numActive] = kex;
               numActive++;
            }
         }
         *numActiveBuf = numActive;
      }
   }

   return PV_SUCCESS;
}

int Publisher::calcActiveIndices() {
   for(int b = 0; b < store->numberOfBuffers(); b++){
      //Active indicies stored as local ext values
      int numActive = 0;
      pvdata_t * activity = (pvdata_t*) store->buffer(b);;
      unsigned int * activeIndices = store->activeIndicesBuffer(b);
      long * numActiveBuf = store->numActiveBuffer(b);
      for (int kex = 0; kex < store->getNumItems(); kex++) {
         if (activity[kex] != 0.0) {
            activeIndices[numActive] = kex;
            numActive++;
         }
      }
      *numActiveBuf = numActive;
   }

   return PV_SUCCESS;
}

int Publisher::publish(double currentTime, double lastUpdateTime,
                       PVLayerCube* cube)
{
   //
   // Everyone publishes border region to neighbors even if no subscribers.
   // This means that everyone should wait as well.
   //

   size_t dataSize = cube->numItems * sizeof(pvdata_t);
   pvAssert(dataSize == (store->size() * store->numberOfBuffers()));

   pvdata_t * sendBuf = cube->data;
   pvdata_t * recvBuf = recvBuffer(0); //Grab all of the buffer, allocated continuously

   bool isSparse = store->isSparse();

   if (lastUpdateTime >= currentTime) {
      // copy entire layer and let neighbors overwrite
      //Only need to exchange borders if layer was updated this timestep
      memcpy(recvBuf, sendBuf, dataSize);
      exchangeBorders(&cube->loc, 0);
      store->setLastUpdateTime(LOCAL/*bufferId*/, lastUpdateTime);

      //Updating active indices is done after MPI wait in HyPerCol
      //to avoid race condition because exchangeBorders mpi is async
   }
   else if (store->numberOfLevels()>1){
      // If there are delays, copy last level's data to this level.
      // TODO: we could use pointer indirection to cut down on the number of memcpy calls required, if this turns out to be an expensive step
      memcpy(recvBuf, recvBuffer(LOCAL/*bufferId*/,1), dataSize);
      store->setLastUpdateTime(LOCAL/*bufferId*/, lastUpdateTime);
   }

   return PV_SUCCESS;
}

int Publisher::exchangeBorders(const PVLayerLoc * loc, int delay/*default 0*/) {
   PVHalo const * halo = &loc->halo;
   if (halo->lt==0 && halo->rt==0 && halo->dn==0 && halo->up==0) { return PV_SUCCESS; }
   int status = PV_SUCCESS;

#ifdef PV_USE_MPI
   pvAssert(requests.empty());
   //Using local ranks and communicators for border exchange
   int icRank = mComm->commRank();
   MPI_Comm mpiComm = mComm->communicator();

   //Loop through batch.
   //The loop over batch elements probably belongs inside
   //Communicator::exchange(), but for this to happen, exchange() would need
   //to know how its data argument is organized with respect to batching.
   for(int b = 0; b < loc->nbatch; b++){
      // don't send interior
      pvAssert(requests.size() == b * (mComm->numberOfNeighbors()-1));

      pvdata_t * data = recvBuffer(b, delay);
      std::vector<MPI_Request> batchElementMPIRequest{};
      mComm->exchange(data, neighborDatatypes, loc, batchElementMPIRequest);
      pvAssert(batchElementMPIRequest.size()==mComm->numberOfNeighbors()-1);
      requests.insert(requests.end(), batchElementMPIRequest.begin(), batchElementMPIRequest.end());
      pvAssert(requests.size() == (b+1) * (mComm->numberOfNeighbors()-1));
   }
   pvAssert(requests.size() == loc->nbatch * (mComm->numberOfNeighbors()-1));

#endif // PV_USE_MPI

   return status;
}

/**
 * wait until all outstanding published messages have arrived
 */
int Publisher::wait()
{
#ifdef PV_USE_MPI
# ifdef DEBUG_OUTPUT
   pvInfo().printf("[%2d]: waiting for data, num_requests==%d\n", mComm->commRank(), numRemote);
   pvInfo().flush();
# endif // DEBUG_OUTPUT

   if (!requests.empty()) {
      mComm->wait(requests);
   }
#endif // PV_USE_MPI

   return 0;
}

} /* namespace PV */
<commit_msg>Removing unused variable<commit_after>/*
 * Publisher.cpp
 *
 *  Created on: Jul 19, 2016
 *      Author: pschultz
 */

#include "Publisher.hpp"
#include "utils/PVAssert.hpp"
#include "include/pv_common.h"

namespace PV {

Publisher::Publisher(Communicator * comm, int numItems, PVLayerLoc loc, int numLevels, bool isSparse)
{
   //size_t dataSize  = numItems * sizeof(float);
   size_t dataSize  = sizeof(float);

   this->mComm  = comm;

   cube.data = nullptr;
   cube.loc = loc;
   cube.numItems = numItems;

   const int numBuffers = loc.nbatch;

   // not really inplace but ok as is only used to deliver
   // to provide cube information for data from store
   cube.size = numBuffers * numItems * dataSize + sizeof(PVLayerCube);

   store = new DataStore(numBuffers, numItems, dataSize, numLevels, isSparse);

   this->neighborDatatypes = Communicator::newDatatypes(&loc);

   requests.clear();
   requests.reserve((NUM_NEIGHBORHOOD-1) * loc.nbatch);
}

Publisher::~Publisher()
{
   delete store;
   Communicator::freeDatatypes(neighborDatatypes); neighborDatatypes = nullptr;
}

int Publisher::updateAllActiveIndices() {
   if(store->isSparse()) return calcAllActiveIndices(); else return PV_SUCCESS;
}

int Publisher::updateActiveIndices() {
   if(store->isSparse()) return calcActiveIndices(); else return PV_SUCCESS;
}

int Publisher::calcAllActiveIndices() {
   for(int l = 0; l < store->numberOfLevels(); l++){
      for(int b = 0; b < store->numberOfBuffers(); b++){
         //Active indicies stored as local ext values
         int numActive = 0;
         pvdata_t * activity = (pvdata_t*) store->buffer(b, l);;
         unsigned int * activeIndices = store->activeIndicesBuffer(b, l);
         long * numActiveBuf = store->numActiveBuffer(b, l);

         for (int kex = 0; kex < store->getNumItems(); kex++) {
            if (activity[kex] != 0.0) {
               activeIndices[numActive] = kex;
               numActive++;
            }
         }
         *numActiveBuf = numActive;
      }
   }

   return PV_SUCCESS;
}

int Publisher::calcActiveIndices() {
   for(int b = 0; b < store->numberOfBuffers(); b++){
      //Active indicies stored as local ext values
      int numActive = 0;
      pvdata_t * activity = (pvdata_t*) store->buffer(b);;
      unsigned int * activeIndices = store->activeIndicesBuffer(b);
      long * numActiveBuf = store->numActiveBuffer(b);
      for (int kex = 0; kex < store->getNumItems(); kex++) {
         if (activity[kex] != 0.0) {
            activeIndices[numActive] = kex;
            numActive++;
         }
      }
      *numActiveBuf = numActive;
   }

   return PV_SUCCESS;
}

int Publisher::publish(double currentTime, double lastUpdateTime,
                       PVLayerCube* cube)
{
   //
   // Everyone publishes border region to neighbors even if no subscribers.
   // This means that everyone should wait as well.
   //

   size_t dataSize = cube->numItems * sizeof(pvdata_t);
   pvAssert(dataSize == (store->size() * store->numberOfBuffers()));

   pvdata_t * sendBuf = cube->data;
   pvdata_t * recvBuf = recvBuffer(0); //Grab all of the buffer, allocated continuously

   if (lastUpdateTime >= currentTime) {
      // copy entire layer and let neighbors overwrite
      //Only need to exchange borders if layer was updated this timestep
      memcpy(recvBuf, sendBuf, dataSize);
      exchangeBorders(&cube->loc, 0);
      store->setLastUpdateTime(LOCAL/*bufferId*/, lastUpdateTime);

      //Updating active indices is done after MPI wait in HyPerCol
      //to avoid race condition because exchangeBorders mpi is async
   }
   else if (store->numberOfLevels()>1){
      // If there are delays, copy last level's data to this level.
      // TODO: we could use pointer indirection to cut down on the number of memcpy calls required, if this turns out to be an expensive step
      memcpy(recvBuf, recvBuffer(LOCAL/*bufferId*/,1), dataSize);
      store->setLastUpdateTime(LOCAL/*bufferId*/, lastUpdateTime);
   }

   return PV_SUCCESS;
}

int Publisher::exchangeBorders(const PVLayerLoc * loc, int delay/*default 0*/) {
   PVHalo const * halo = &loc->halo;
   if (halo->lt==0 && halo->rt==0 && halo->dn==0 && halo->up==0) { return PV_SUCCESS; }
   int status = PV_SUCCESS;

#ifdef PV_USE_MPI
   pvAssert(requests.empty());
   //Using local ranks and communicators for border exchange
   int icRank = mComm->commRank();
   MPI_Comm mpiComm = mComm->communicator();

   //Loop through batch.
   //The loop over batch elements probably belongs inside
   //Communicator::exchange(), but for this to happen, exchange() would need
   //to know how its data argument is organized with respect to batching.
   for(int b = 0; b < loc->nbatch; b++){
      // don't send interior
      pvAssert(requests.size() == b * (mComm->numberOfNeighbors()-1));

      pvdata_t * data = recvBuffer(b, delay);
      std::vector<MPI_Request> batchElementMPIRequest{};
      mComm->exchange(data, neighborDatatypes, loc, batchElementMPIRequest);
      pvAssert(batchElementMPIRequest.size()==mComm->numberOfNeighbors()-1);
      requests.insert(requests.end(), batchElementMPIRequest.begin(), batchElementMPIRequest.end());
      pvAssert(requests.size() == (b+1) * (mComm->numberOfNeighbors()-1));
   }
   pvAssert(requests.size() == loc->nbatch * (mComm->numberOfNeighbors()-1));

#endif // PV_USE_MPI

   return status;
}

/**
 * wait until all outstanding published messages have arrived
 */
int Publisher::wait()
{
#ifdef PV_USE_MPI
# ifdef DEBUG_OUTPUT
   pvInfo().printf("[%2d]: waiting for data, num_requests==%d\n", mComm->commRank(), numRemote);
   pvInfo().flush();
# endif // DEBUG_OUTPUT

   if (!requests.empty()) {
      mComm->wait(requests);
   }
#endif // PV_USE_MPI

   return 0;
}

} /* namespace PV */
<|endoftext|>


<commit_before>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include <cstring>
#include <iostream>
#include <sstream>
#include <vector>

//Include available regex headers
#ifdef HAVE_PCRE_H
#include <pcre.h>
#endif
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif

#include "regex.hxx"

//Determine support level.
//First check for specific requests from the configuration.
#if defined(FORCE_REGEX_PCRE16)
#  if defined(HAVE_PCRE_H) && defined(PCRE_SUPPORTS_16_BIT)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE16
#  elif !defined(HAVE_PCRE_H)
#    error Configuration forces REGEX_PCRE16, but you do not have PCRE
#  else
#    error Configuration forces REGEX_PCRE16, but 16-bit not supported
#  endif
#elif defined(FORCE_REGEX_PCRE8)
#  if defined(HAVE_PCRE_H)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE8
#  else
#    error Configuration forces REGEX_PCRE8, but you do not have PCRE
#  endif
#elif defined(FORCE_REGEX_POSIX)
#  if defined(HAVE_REGEX_H)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_POSIX
#  else
#    error Configuration forces REGEX_POSIX, but your system does not have it
#  endif
#elif defined(FORCE_REGEX_NONE)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_NONE
//Not forced, determine automatically
#elif defined(HAVE_PCRE_H) && defined(PCRE_SUPPORTS_16_BIT)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE16
#elif defined(HAVE_PCRE_H)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE8
#elif defined(HAVE_REGEX_H)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_POSIX
#else
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_NONE
#endif

using namespace std;

namespace tglng {
  const unsigned regexLevel = TGLNG_REGEX_LEVEL;
#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_NONE
  const wstring regexLevelName(L"NONE");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  const wstring regexLevelName(L"POSIX");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8
  const wstring regexLevelName(L"PCRE8");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
  const wstring regexLevelName(L"PCRE16");
#endif

  //Functions to convert natvie wstrings to the type needed by the backend.
#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
  typedef vector<PCRE_UCHAR16> rstring;
  static void convertString(rstring& dst, const wstring& src) {
    dst.resize(src.size()+1);
    for (unsigned i = 0; i < src.size(); ++i)
      if (src[i] <= 0xFFFF)
        dst[i] = src[i];
      else
        dst[i] = 0x001A;

    dst[src.size()] = 0;
  }
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8 || \
      TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  typedef vector<char> rstring;
  static void convertString(rstring& dst, const wstring& src) {
    dst.resize(src.size()+1);
    for (unsigned i = 0; i < src.size(); ++i)
      if (src[i] <= 0xFF)
        dst[i] = (src[i] & 0xFF);
      else
        dst[i] = 0x1A;
    dst[src.size()] = 0;
  }
#endif

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_NONE
  //Null implementation; always fails at everything
  Regex::Regex(const wstring&, const wstring&)
  : data(*(RegexData*)NULL) {}
  Regex::~Regex() {}
  Regex::operator bool() const { return false; }
  void Regex::showWhy() const {
    wcerr << L"regular expressions not supported in this build." << endl;
  }
  void Regex::input(const wstring&) {}
  bool Regex::match() { return false; }
  unsigned Regex::groupCount() const { return 0; }
  void Regex::group(wstring&, unsigned) const {}
  void Regex::tail(wstring&) const {}
  void Regex::head(wstring&) const {}
  unsigned Regex::where() const { return 0; }
#endif /* NONE */

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  //POSIX.1-2001 implementation
  struct RegexData {
    regex_t rx;
    int status; //0=OK, others=error
    rstring input;
    wstring rawInput;
    unsigned inputOffset, headBegin, headEnd;
    string why;
    regmatch_t matches[10];
  };

  Regex::Regex(const wstring& pattern, const wstring& options)
  : data(*new RegexData)
  {
    rstring rpattern;
    convertString(rpattern, pattern);

    int flags = REG_EXTENDED;
    //Parse options
    for (unsigned i = 0; i < options.size(); ++i)
      switch (options[i]) {
      case L'i':
        flags |= REG_ICASE;
        break;

      case L'l':
        flags |= REG_NEWLINE;
        break;
      }

    data.status = regcomp(&data.rx, &rpattern[0], flags);
    if (data.status) {
      //Save error message
      data.why.resize(regerror(data.status, &data.rx, NULL, 0));
      regerror(data.status, &data.rx, &data.why[0], data.why.size());
    }
  }

  Regex::~Regex() {
    if (data.status == 0)
      regfree(&data.rx);
    delete &data;
  }

  Regex::operator bool() const {
    return !data.status;
  }

  void Regex::showWhy() const {
    wcerr << "POSIX extended regular expression: "
          << &data.why[0] << endl;
  }

  void Regex::input(const std::wstring& str) {
    convertString(data.input, str);
    data.inputOffset = 0;
    data.rawInput = str;
  }

  bool Regex::match() {
    //Manually fail the empty string
    if (data.inputOffset >= data.input.size()) {
      data.status = 0;
      memset(data.matches, -1, sizeof(data.matches));
      return false;
    }

    data.status = regexec(&data.rx, &data.input[data.inputOffset],
                          sizeof(data.matches)/sizeof(data.matches[0]),
                          data.matches, 0);
    if (data.status == REG_NOMATCH) {
      //Transform to a more uniform result
      //(Nothing went wrong, no error should be returned, in theory)
      data.status = 0;
      memset(data.matches, -1, sizeof(data.matches));
    }
    if (data.status) {
      //Failed for some reason
      data.why.resize(regerror(data.status, &data.rx, NULL, 0));
      regerror(data.status, &data.rx, &data.why[0], data.why.size());
      //Free the pattern now, since the destructor won't think it exists
      regfree(&data.rx);
      return false;
    }

    //Matched if the zeroth group is not -1
    if (-1 != data.matches[0].rm_eo) {
      //Update offsets
      data.headBegin = data.inputOffset;
      data.headEnd = data.matches[0].rm_so;
      data.inputOffset = data.matches[0].rm_eo;
    }
    return -1 != data.matches[0].rm_eo;
  }

  unsigned Regex::groupCount() const {
    //Elements in the middle may be unmatched if that particular group was
    //excluded, so search for the last group.
    unsigned last;
    for (unsigned i = 0; i < sizeof(data.matches)/sizeof(data.matches[0]); ++i)
      if (-1 != data.matches[i].rm_so)
        last = i;

    return last+1;
  }

  void Regex::group(wstring& dst, unsigned ix) const {
    //Indices may be negative if this group didn't match
    if (data.matches[ix].rm_so == -1)
      dst.clear();
    else
      dst.assign(data.rawInput, data.matches[ix].rm_so,
                 data.matches[ix].rm_eo - data.matches[ix].rm_so);
  }

  void Regex::tail(wstring& dst) const {
    dst.assign(data.rawInput, data.inputOffset,
               data.rawInput.size() - data.inputOffset);
  }

  void Regex::head(wstring& dst) const {
    dst.assign(data.rawInput, data.headBegin,
               data.headEnd - data.headBegin);
  }

  unsigned Regex::where() const {
    return 0;
  }
#endif /* POSIX */

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8 ||   \
    TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
#  if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8
#    define pcreN pcre
#    define pcreN_compile    pcre_compile
#    define pcreN_exec       pcre_exec
#    define pcreN_free       pcre_free
#    define pcreN_maketables pcre_maketables
#  else
#    define pcreN pcre16
#    define pcreN_compile    pcre16_compile
#    define pcreN_exec       pcre16_exec
#    define pcreN_free       pcre16_free
#    define pcreN_maketables pcre16_maketables
#  endif

  /* By default, PCRE only classifies characters based on ASCII (some builds
   * may instead automatically rebuild the tables according to the "C" locale
   * (why not the system locale?), but we can't count on that.
   *
   * Whenever the current C locale (by setlocale(LC_ALL,NULL)) differs from the
   * lastPcreTableLocale, generate a new table.
   */
  static string lastPcreTableLocale("C");
  static const unsigned char* localPcreTable(NULL);

  struct RegexData {
    pcreN* rx;
    unsigned errorOffset;
    /* We want ten matches. Each match takes two entries. Additionally, PCRE
     * requires that we allocate an extra entry at the end for each match.
     */
#define MAX_MATCHES 10
    signed matches[MAX_MATCHES*3];
    rstring input;
    wstring rawInput;
    unsigned inputOffset, headBegin, headEnd;
    string errorMessage;
  };

  Regex::Regex(const wstring& pattern, const wstring& options)
  : data(*new RegexData)
  {
    rstring rpattern;
    const char* errorMessage = NULL;
    data.errorOffset = 0;
    convertString(rpattern, pattern);

    //Parse the options
    int flags = PCRE_DOTALL | PCRE_DOLLAR_ENDONLY;
    for (unsigned i = 0; i < options.size(); ++i)
      switch (options[i]) {
      case L'i':
        flags |= PCRE_CASELESS;
        break;

      case L'l':
        flags &= ~(PCRE_DOTALL | PCRE_DOLLAR_ENDONLY);
        //Would be nice if there were a constant for this
        //(Then again,
        //  flags &= ~(`[PCRE_NEWLINE_`E{CR LF CRLF ANYCRLF ANY}| |`]);
        flags &= ~(PCRE_NEWLINE_CR | PCRE_NEWLINE_LF | PCRE_NEWLINE_CRLF |
                   PCRE_NEWLINE_ANYCRLF | PCRE_NEWLINE_ANY);
        flags |= PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF;
        break;
      }

    //Generate a table if necessary
    if (lastPcreTableLocale != setlocale(LC_ALL, NULL)) {
      lastPcreTableLocale = setlocale(LC_ALL, NULL);
      if (localPcreTable)
        pcreN_free(const_cast<void*>(static_cast<const void*>(localPcreTable)));
      localPcreTable = pcreN_maketables();
    }

    data.rx = pcreN_compile(&rpattern[0], flags, &errorMessage,
                            (int*)&data.errorOffset, localPcreTable);
    if (!data.rx)
      data.errorMessage = errorMessage;
  }

  Regex::~Regex() {
    if (data.rx)
      pcreN_free(data.rx);
    delete &data;
  }

  Regex::operator bool() const {
    return !!data.rx;
  }

  void Regex::showWhy() const {
    wcerr << L"Perl-Compatible Regular Expression: "
          << data.errorMessage.c_str() << endl;
  }

  void Regex::input(const wstring& str) {
    convertString(data.input, str);
    data.rawInput = str;
    data.inputOffset = 0;
  }

  bool Regex::match() {
    //Set all elements to -1
    memset(data.matches, -1, sizeof(data.matches));
    int status = pcreN_exec(data.rx, NULL,
                            &data.input[0],
                            //Subtract one for term NUL
                            data.input.size() - 1,
                            data.inputOffset,
                            PCRE_NOTEMPTY,
                            data.matches,
                            sizeof(data.matches)/sizeof(data.matches[0]));
    if (status < 0) {
      //Error (there doesn't seem to be any way to get an error message)
      ostringstream msg;
      msg << "Perl-Compatible Regular Expression: error code " << status;
      data.errorMessage = msg.str();
      //Free the rx so that operator bool() returns false
      pcreN_free(data.rx);
      data.rx = NULL;
      return false;
    }

    //PCRE can return 0 even for successful matches (eg, there were more groups
    //than provided), so check for success manually.
    //Any group which was not matched will have entries of -1. If matching is
    //successful, group 0 is defined.
    if (data.matches[0] != -1) {
      //Advance input
      data.headBegin = data.inputOffset;
      data.headEnd = data.matches[0];
      data.inputOffset = data.matches[1];
      return true;
    } else {
      return false;
    }
  }

  unsigned Regex::groupCount() const {
    //PCRE groups are indexed by occurrance within the pattern, so some groups
    //might not match; find the last matched group.
    unsigned last = 0;
    for (unsigned i = 0; i < MAX_MATCHES; ++i)
      if (data.matches[i*2] != -1)
        last = i;

    return last+1;
  }

  void Regex::group(wstring& dst, unsigned ix) const {
    //Some middle groups may be unmatched, so return an empty string if -1
    if (data.matches[ix*2] == -1)
      dst.clear();
    else
      dst.assign(data.rawInput, data.matches[ix*2],
                 data.matches[ix*2+1] - data.matches[ix*2]);
  }

  void Regex::head(wstring& dst) const {
    dst.assign(data.rawInput, data.headBegin,
               data.headEnd - data.headBegin);
  }

  void Regex::tail(wstring& dst) const {
    dst.assign(data.rawInput, data.inputOffset,
               data.rawInput.size() - data.inputOffset);
  }

  unsigned Regex::where() const {
    return data.errorOffset;
  }
#endif /* PCRE* */
}
<commit_msg>Fix problems in POSIX and PCRE regex engine wrappers.<commit_after>#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include <cstring>
#include <iostream>
#include <sstream>
#include <vector>

//Include available regex headers
#ifdef HAVE_PCRE_H
#include <pcre.h>
#endif
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif

#include "regex.hxx"

//Determine support level.
//First check for specific requests from the configuration.
#if defined(FORCE_REGEX_PCRE16)
#  if defined(HAVE_PCRE_H) && defined(PCRE_SUPPORTS_16_BIT)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE16
#  elif !defined(HAVE_PCRE_H)
#    error Configuration forces REGEX_PCRE16, but you do not have PCRE
#  else
#    error Configuration forces REGEX_PCRE16, but 16-bit not supported
#  endif
#elif defined(FORCE_REGEX_PCRE8)
#  if defined(HAVE_PCRE_H)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE8
#  else
#    error Configuration forces REGEX_PCRE8, but you do not have PCRE
#  endif
#elif defined(FORCE_REGEX_POSIX)
#  if defined(HAVE_REGEX_H)
#    define TGLNG_REGEX_LEVEL TGLNG_REGEX_POSIX
#  else
#    error Configuration forces REGEX_POSIX, but your system does not have it
#  endif
#elif defined(FORCE_REGEX_NONE)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_NONE
//Not forced, determine automatically
#elif defined(HAVE_PCRE_H) && defined(PCRE_SUPPORTS_16_BIT)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE16
#elif defined(HAVE_PCRE_H)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_PCRE8
#elif defined(HAVE_REGEX_H)
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_POSIX
#else
#  define TGLNG_REGEX_LEVEL TGLNG_REGEX_NONE
#endif

using namespace std;

namespace tglng {
  const unsigned regexLevel = TGLNG_REGEX_LEVEL;
#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_NONE
  const wstring regexLevelName(L"NONE");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  const wstring regexLevelName(L"POSIX");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8
  const wstring regexLevelName(L"PCRE8");
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
  const wstring regexLevelName(L"PCRE16");
#endif

  //Functions to convert natvie wstrings to the type needed by the backend.
#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
  typedef vector<PCRE_UCHAR16> rstring;
  static void convertString(rstring& dst, const wstring& src) {
    dst.resize(src.size()+1);
    for (unsigned i = 0; i < src.size(); ++i)
      if (src[i] <= 0xFFFF)
        dst[i] = src[i];
      else
        dst[i] = 0x001A;

    dst[src.size()] = 0;
  }
#elif TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8 || \
      TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  typedef vector<char> rstring;
  static void convertString(rstring& dst, const wstring& src) {
    dst.resize(src.size()+1);
    for (unsigned i = 0; i < src.size(); ++i)
      if (src[i] <= 0xFF)
        dst[i] = (src[i] & 0xFF);
      else
        dst[i] = 0x1A;
    dst[src.size()] = 0;
  }
#endif

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_NONE
  //Null implementation; always fails at everything
  Regex::Regex(const wstring&, const wstring&)
  : data(*(RegexData*)NULL) {}
  Regex::~Regex() {}
  Regex::operator bool() const { return false; }
  void Regex::showWhy() const {
    wcerr << L"regular expressions not supported in this build." << endl;
  }
  void Regex::input(const wstring&) {}
  bool Regex::match() { return false; }
  unsigned Regex::groupCount() const { return 0; }
  void Regex::group(wstring&, unsigned) const {}
  void Regex::tail(wstring&) const {}
  void Regex::head(wstring&) const {}
  unsigned Regex::where() const { return 0; }
#endif /* NONE */

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_POSIX
  //POSIX.1-2001 implementation
  struct RegexData {
    regex_t rx;
    int status; //0=OK, others=error
    rstring input;
    wstring rawInput;
    unsigned inputOffset, headBegin, headEnd;
    string why;
    #define MAX_MATCHES 10
    regmatch_t matches[MAX_MATCHES];
  };

  Regex::Regex(const wstring& pattern, const wstring& options)
  : data(*new RegexData)
  {
    rstring rpattern;
    convertString(rpattern, pattern);

    int flags = REG_EXTENDED;
    //Parse options
    for (unsigned i = 0; i < options.size(); ++i)
      switch (options[i]) {
      case L'i':
        flags |= REG_ICASE;
        break;

      case L'l':
        flags |= REG_NEWLINE;
        break;
      }

    data.status = regcomp(&data.rx, &rpattern[0], flags);
    if (data.status) {
      //Save error message
      data.why.resize(regerror(data.status, &data.rx, NULL, 0));
      regerror(data.status, &data.rx, &data.why[0], data.why.size());
    }
  }

  Regex::~Regex() {
    if (data.status == 0)
      regfree(&data.rx);
    delete &data;
  }

  Regex::operator bool() const {
    return !data.status;
  }

  void Regex::showWhy() const {
    wcerr << "POSIX extended regular expression: "
          << &data.why[0] << endl;
  }

  void Regex::input(const std::wstring& str) {
    convertString(data.input, str);
    data.inputOffset = 0;
    data.rawInput = str;
  }

  bool Regex::match() {
    //Manually fail the empty string
    if (data.inputOffset >= data.input.size()) {
      data.status = 0;
      memset(data.matches, -1, sizeof(data.matches));
      return false;
    }

    data.status = regexec(&data.rx, &data.input[data.inputOffset],
                          MAX_MATCHES,
                          data.matches, 0);
    if (data.status == REG_NOMATCH) {
      //Transform to a more uniform result
      //(Nothing went wrong, no error should be returned, in theory)
      data.status = 0;
      memset(data.matches, -1, sizeof(data.matches));
    }
    if (data.status) {
      //Failed for some reason
      data.why.resize(regerror(data.status, &data.rx, NULL, 0));
      regerror(data.status, &data.rx, &data.why[0], data.why.size());
      //Free the pattern now, since the destructor won't think it exists
      regfree(&data.rx);
      return false;
    }

    //Add offset to all matches
    for (unsigned i = 0; i < MAX_MATCHES; ++i) {
      if (data.matches[i].rm_so != -1) {
        data.matches[i].rm_so += data.inputOffset;
        data.matches[i].rm_eo += data.inputOffset;
      }
    }

    //Matched if the zeroth group is not -1
    if (-1 != data.matches[0].rm_eo) {
      //Update offsets
      data.headBegin = data.inputOffset;
      data.headEnd = data.matches[0].rm_so;
      data.inputOffset = data.matches[0].rm_eo;
    }
    return -1 != data.matches[0].rm_eo;
  }

  unsigned Regex::groupCount() const {
    //Elements in the middle may be unmatched if that particular group was
    //excluded, so search for the last group.
    unsigned last;
    for (unsigned i = 0; i < MAX_MATCHES; ++i)
      if (-1 != data.matches[i].rm_so)
        last = i;

    return last+1;
  }

  void Regex::group(wstring& dst, unsigned ix) const {
    //Indices may be negative if this group didn't match
    if (data.matches[ix].rm_so == -1)
      dst.clear();
    else
      dst.assign(data.rawInput, data.matches[ix].rm_so,
                 data.matches[ix].rm_eo - data.matches[ix].rm_so);
  }

  void Regex::tail(wstring& dst) const {
    dst.assign(data.rawInput, data.inputOffset,
               data.rawInput.size() - data.inputOffset);
  }

  void Regex::head(wstring& dst) const {
    dst.assign(data.rawInput, data.headBegin,
               data.headEnd - data.headBegin);
  }

  unsigned Regex::where() const {
    return 0;
  }
#endif /* POSIX */

#if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8 ||   \
    TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE16
#  if TGLNG_REGEX_LEVEL == TGLNG_REGEX_PCRE8
#    define pcreN pcre
#    define pcreN_compile    pcre_compile
#    define pcreN_exec       pcre_exec
#    define pcreN_free       pcre_free
#    define pcreN_maketables pcre_maketables
#  else
#    define pcreN pcre16
#    define pcreN_compile    pcre16_compile
#    define pcreN_exec       pcre16_exec
#    define pcreN_free       pcre16_free
#    define pcreN_maketables pcre16_maketables
#  endif

  /* By default, PCRE only classifies characters based on ASCII (some builds
   * may instead automatically rebuild the tables according to the "C" locale
   * (why not the system locale?), but we can't count on that.
   *
   * Whenever the current C locale (by setlocale(LC_ALL,NULL)) differs from the
   * lastPcreTableLocale, generate a new table.
   */
  static string lastPcreTableLocale("C");
  static const unsigned char* localPcreTable(NULL);

  struct RegexData {
    pcreN* rx;
    unsigned errorOffset;
    /* We want ten matches. Each match takes two entries. Additionally, PCRE
     * requires that we allocate an extra entry at the end for each match.
     */
#define MAX_MATCHES 10
    signed matches[MAX_MATCHES*3];
    rstring input;
    wstring rawInput;
    unsigned inputOffset, headBegin, headEnd;
    string errorMessage;
  };

  Regex::Regex(const wstring& pattern, const wstring& options)
  : data(*new RegexData)
  {
    rstring rpattern;
    const char* errorMessage = NULL;
    data.errorOffset = 0;
    convertString(rpattern, pattern);

    //Parse the options
    int flags = PCRE_DOTALL | PCRE_DOLLAR_ENDONLY;
    for (unsigned i = 0; i < options.size(); ++i)
      switch (options[i]) {
      case L'i':
        flags |= PCRE_CASELESS;
        break;

      case L'l':
        flags &= ~(PCRE_DOTALL | PCRE_DOLLAR_ENDONLY);
        //Would be nice if there were a constant for this
        //(Then again,
        //  flags &= ~(`[PCRE_NEWLINE_`E{CR LF CRLF ANYCRLF ANY}| |`]);
        flags &= ~(PCRE_NEWLINE_CR | PCRE_NEWLINE_LF | PCRE_NEWLINE_CRLF |
                   PCRE_NEWLINE_ANYCRLF | PCRE_NEWLINE_ANY);
        flags |= PCRE_MULTILINE | PCRE_NEWLINE_ANYCRLF;
        break;
      }

    //Generate a table if necessary
    if (lastPcreTableLocale != setlocale(LC_ALL, NULL)) {
      lastPcreTableLocale = setlocale(LC_ALL, NULL);
      if (localPcreTable)
        pcreN_free(const_cast<void*>(static_cast<const void*>(localPcreTable)));
      localPcreTable = pcreN_maketables();
    }

    data.rx = pcreN_compile(&rpattern[0], flags, &errorMessage,
                            (int*)&data.errorOffset, localPcreTable);
    if (!data.rx)
      data.errorMessage = errorMessage;
  }

  Regex::~Regex() {
    if (data.rx)
      pcreN_free(data.rx);
    delete &data;
  }

  Regex::operator bool() const {
    return !!data.rx;
  }

  void Regex::showWhy() const {
    wcerr << L"Perl-Compatible Regular Expression: "
          << data.errorMessage.c_str() << endl;
  }

  void Regex::input(const wstring& str) {
    convertString(data.input, str);
    data.rawInput = str;
    data.inputOffset = 0;
  }

  bool Regex::match() {
    //Set all elements to -1
    memset(data.matches, -1, sizeof(data.matches));
    int status = pcreN_exec(data.rx, NULL,
                            &data.input[0],
                            //Subtract one for term NUL
                            data.input.size() - 1,
                            data.inputOffset,
                            PCRE_NOTEMPTY,
                            data.matches,
                            sizeof(data.matches)/sizeof(data.matches[0]));
    if (status == PCRE_ERROR_NOMATCH) {
      status = 0;
      memset(data.matches, -1, sizeof(data.matches));
    }
    if (status < 0) {
      //Error (there doesn't seem to be any way to get an error message)
      ostringstream msg;
      msg << "Perl-Compatible Regular Expression: error code " << status;
      data.errorMessage = msg.str();
      //Free the rx so that operator bool() returns false
      pcreN_free(data.rx);
      data.rx = NULL;
      return false;
    }

    //PCRE can return 0 even for successful matches (eg, there were more groups
    //than provided), so check for success manually.
    //Any group which was not matched will have entries of -1. If matching is
    //successful, group 0 is defined.
    if (data.matches[0] != -1) {
      //Advance input
      data.headBegin = data.inputOffset;
      data.headEnd = data.matches[0];
      data.inputOffset = data.matches[1];
      return true;
    } else {
      return false;
    }
  }

  unsigned Regex::groupCount() const {
    //PCRE groups are indexed by occurrance within the pattern, so some groups
    //might not match; find the last matched group.
    unsigned last = 0;
    for (unsigned i = 0; i < MAX_MATCHES; ++i)
      if (data.matches[i*2] != -1)
        last = i;

    return last+1;
  }

  void Regex::group(wstring& dst, unsigned ix) const {
    //Some middle groups may be unmatched, so return an empty string if -1
    if (data.matches[ix*2] == -1)
      dst.clear();
    else
      dst.assign(data.rawInput, data.matches[ix*2],
                 data.matches[ix*2+1] - data.matches[ix*2]);
  }

  void Regex::head(wstring& dst) const {
    dst.assign(data.rawInput, data.headBegin,
               data.headEnd - data.headBegin);
  }

  void Regex::tail(wstring& dst) const {
    dst.assign(data.rawInput, data.inputOffset,
               data.rawInput.size() - data.inputOffset);
  }

  unsigned Regex::where() const {
    return data.errorOffset;
  }
#endif /* PCRE* */
}
<|endoftext|>


<commit_before>#include "Player.h"

#include <SFML/Graphics.hpp>

#include <iostream>
#include <sstream>
#include <iomanip>

#include "../World/World.h"

#include "../Renderer/RenderMaster.h"

sf::Font f;

Player::Player()
:   Entity  ({2500, 125, 2500}, {0, 0, 0}, {0.3, 1.0, 0.3})
,   m_itemDown  (sf::Keyboard::Down)
,   m_itemUp    (sf::Keyboard::Up)
,   m_flyKey    (sf::Keyboard::F)
,   m_num1 (sf::Keyboard::Num1)
,   m_num2 (sf::Keyboard::Num2)
,   m_num3 (sf::Keyboard::Num3)
,   m_num4 (sf::Keyboard::Num4)
,   m_num5 (sf::Keyboard::Num5)

{
    f.loadFromFile("Res/Fonts/rs.ttf");

    for (int i = 0; i < 5; i++)
    {
        m_items.emplace_back(Material::NOTHING, 0);
    }

    for (float i = 0; i < 5; i++)
    {
        sf::Text t;
        t.setFont(f);
        t.setOutlineColor(sf::Color::Black);
        t.setCharacterSize(25);
        t.setPosition({20.0f, 20.0f * i + 100.0f});
        m_itemText.push_back(t);
    }
    m_posPrint.setFont(f);
    m_posPrint.setOutlineColor(sf::Color::Black);
    m_posPrint.setCharacterSize(25);
    m_posPrint.setPosition(20.0f, 20.0f * 6.0f + 100.0f);
}

void Player::addItem(const Material& material)
{
    Material::ID id = material.id;

    for (unsigned i = 0; i < m_items.size(); i++)
    {
        if (m_items[i].getMaterial().id == id)
        {
            /*int leftOver =*/ m_items[i].add(1);

            return;
        }
        else if (m_items[i].getMaterial().id == Material::ID::Nothing)
        {
            m_items[i] = {material, 1};
            return;
        }
    }
}

ItemStack& Player::getHeldItems()
{
    return m_items[m_heldItem];
}

void Player::handleInput(const sf::RenderWindow& window)
{
    keyboardInput();
    mouseInput(window);

    if(m_itemDown.isKeyPressed())
    {
        m_heldItem++;
        if (m_heldItem == (int)m_items.size())
        {
            m_heldItem = 0;
        }
    }
    else if (m_itemUp.isKeyPressed())
    {
        m_heldItem--;
        if (m_heldItem == -1)
        {
            m_heldItem = m_items.size() - 1;
        }
    }

    if (m_flyKey.isKeyPressed())
    {
        m_isFlying = !m_isFlying;
    }

    if(m_num1.isKeyPressed()){
        m_heldItem = 0;
    }
    if(m_num2.isKeyPressed()){
        m_heldItem = 1;
    }
    if(m_num3.isKeyPressed()){
        m_heldItem = 2;
    }
    if(m_num4.isKeyPressed()){
        m_heldItem = 3;
    }
    if(m_num5.isKeyPressed()){
        m_heldItem = 4;
    }

}

void Player::update(float dt, World& world)
{
    velocity += m_acceleation;
    m_acceleation = {0, 0, 0};

    if (!m_isFlying)
    {
        if (!m_isOnGround)
        {
            velocity.y -= 40 * dt;
        }
        m_isOnGround = false;
    }

    position.x += velocity.x * dt;
    collide (world, {velocity.x, 0, 0}, dt);

    position.y += velocity.y * dt;
    collide (world, {0, velocity.y, 0}, dt);

    position.z += velocity.z * dt;
    collide (world, {0, 0, velocity.z}, dt);

    box.update(position);
    velocity.x *= 0.95;
    velocity.z *= 0.95;
    if (m_isFlying)
    {
        velocity.y *= 0.95;
    }
}

void Player::collide(World& world, const glm::vec3& vel, float dt)
{
    for (int x = position.x - box.dimensions.x; x < position.x + box.dimensions.x; x++)
    for (int y = position.y - box.dimensions.y; y < position.y + 0.7             ; y++)
    for (int z = position.z - box.dimensions.z; z < position.z + box.dimensions.z; z++)
    {
        auto block = world.getBlock(x, y, z);

        if (block != 0 && block.getData().isCollidable)
        {
            if (vel.y > 0)
            {
                position.y = y - box.dimensions.y;
                velocity.y = 0;
            }
            else if (vel.y < 0)
            {
                m_isOnGround = true;
                position.y = y + box.dimensions.y + 1;
                velocity.y = 0;
            }

            if (vel.x > 0)
            {
                position.x = x - box.dimensions.x;
            }
            else if (vel.x < 0)
            {
                position.x = x + box.dimensions.x + 1;
            }

            if (vel.z > 0)
            {
                position.z = z - box.dimensions.z;
            }
            else if (vel.z < 0)
            {
                position.z = z + box.dimensions.z + 1;
            }
        }
    }
}

///@TODO Move this
float speed = 0.2f;

void Player::keyboardInput()
{
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
    {
        float s = speed;
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) s *= 5;
        m_acceleation.x += -glm::cos(glm::radians(rotation.y + 90)) * s;
        m_acceleation.z += -glm::sin(glm::radians(rotation.y + 90)) * s;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
    {
        m_acceleation.x += glm::cos(glm::radians(rotation.y + 90)) * speed;
        m_acceleation.z += glm::sin(glm::radians(rotation.y + 90)) * speed;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
    {
        m_acceleation.x += -glm::cos(glm::radians(rotation.y)) * speed;
        m_acceleation.z += -glm::sin(glm::radians(rotation.y)) * speed;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
    {
        m_acceleation.x += glm::cos(glm::radians(rotation.y)) * speed;
        m_acceleation.z += glm::sin(glm::radians(rotation.y)) * speed;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
    {
        jump();
    }
    else if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) && m_isFlying)
    {
        m_acceleation.y -= speed * 3;
    }
}

void Player::mouseInput(const sf::RenderWindow& window)
{
    static bool useMouse = true;
    static ToggleKey useMouseKey (sf::Keyboard::L);

    if (useMouseKey.isKeyPressed())
    {
        useMouse = !useMouse;
    }

    if (!useMouse)
    {
        return;
    }

    static auto const BOUND = 89.9999;
    static auto lastMousePosition = sf::Mouse::getPosition(window);
    auto change = sf::Mouse::getPosition() - lastMousePosition;

    rotation.y += change.x * 0.05;
    rotation.x += change.y * 0.05;

    if      (rotation.x >  BOUND) rotation.x =  BOUND;
    else if (rotation.x < -BOUND) rotation.x = -BOUND;

    if      (rotation.y >  360) rotation.y = 0;
    else if (rotation.y <  0)   rotation.y = 360;

    auto cx = static_cast<int>(window.getSize().x / 2);
    auto cy = static_cast<int>(window.getSize().y / 2);

    sf::Mouse::setPosition({cx, cy}, window);

    lastMousePosition = sf::Mouse::getPosition();
}

void Player::draw(RenderMaster& master)
{
    for (unsigned i = 0; i < m_items.size(); i++)
    {
        sf::Text& t = m_itemText[i];
        if (i == (unsigned)m_heldItem)
        {
            t.setFillColor(sf::Color::Red);
        }
        else
        {
            t.setFillColor(sf::Color::White);
        }
        t.setString((m_items[i].getMaterial().name) + " " + std::to_string(m_items[i].getNumInStack()) + " ");
        master.drawSFML(t);
    }
    std::ostringstream stream;
    stream  << " X: " << position.x
            << " Y: " << position.y
            << " Z: " << position.z
            << " Grounded " << std::boolalpha << m_isOnGround;

    m_posPrint.setString(stream.str());

    master.drawSFML(m_posPrint);
}

void Player::jump()
{
    if (!m_isFlying)
    {
        if (m_isOnGround)
        {
            m_isOnGround = false;
            m_acceleation.y += speed * 50;
        }
    }
    else
    {
        m_acceleation.y += speed * 3;
    }
}

<commit_msg>Fixed #61<commit_after>#include "Player.h"

#include <SFML/Graphics.hpp>

#include <iostream>
#include <sstream>
#include <iomanip>

#include "../World/World.h"

#include "../Renderer/RenderMaster.h"

sf::Font f;

Player::Player()
:   Entity  ({2500, 125, 2500}, {0, 0, 0}, {0.3, 1.0, 0.3})
,   m_itemDown  (sf::Keyboard::Down)
,   m_itemUp    (sf::Keyboard::Up)
,   m_flyKey    (sf::Keyboard::F)
,   m_num1 (sf::Keyboard::Num1)
,   m_num2 (sf::Keyboard::Num2)
,   m_num3 (sf::Keyboard::Num3)
,   m_num4 (sf::Keyboard::Num4)
,   m_num5 (sf::Keyboard::Num5)

{
    f.loadFromFile("Res/Fonts/rs.ttf");

    for (int i = 0; i < 5; i++)
    {
        m_items.emplace_back(Material::NOTHING, 0);
    }

    for (float i = 0; i < 5; i++)
    {
        sf::Text t;
        t.setFont(f);
        t.setOutlineColor(sf::Color::Black);
        t.setCharacterSize(25);
        t.setPosition({20.0f, 20.0f * i + 100.0f});
        m_itemText.push_back(t);
    }
    m_posPrint.setFont(f);
    m_posPrint.setOutlineColor(sf::Color::Black);
    m_posPrint.setCharacterSize(25);
    m_posPrint.setPosition(20.0f, 20.0f * 6.0f + 100.0f);
}

void Player::addItem(const Material& material)
{
    Material::ID id = material.id;

    for (unsigned i = 0; i < m_items.size(); i++)
    {
        if (m_items[i].getMaterial().id == id)
        {
            /*int leftOver =*/ m_items[i].add(1);

            return;
        }
        else if (m_items[i].getMaterial().id == Material::ID::Nothing)
        {
            m_items[i] = {material, 1};
            return;
        }
    }
}

ItemStack& Player::getHeldItems()
{
    return m_items[m_heldItem];
}

void Player::handleInput(const sf::RenderWindow& window)
{
    keyboardInput();
    mouseInput(window);

    if(m_itemDown.isKeyPressed())
    {
        m_heldItem++;
        if (m_heldItem == (int)m_items.size())
        {
            m_heldItem = 0;
        }
    }
    else if (m_itemUp.isKeyPressed())
    {
        m_heldItem--;
        if (m_heldItem == -1)
        {
            m_heldItem = m_items.size() - 1;
        }
    }

    if (m_flyKey.isKeyPressed())
    {
        m_isFlying = !m_isFlying;
    }

    if(m_num1.isKeyPressed()){
        m_heldItem = 0;
    }
    if(m_num2.isKeyPressed()){
        m_heldItem = 1;
    }
    if(m_num3.isKeyPressed()){
        m_heldItem = 2;
    }
    if(m_num4.isKeyPressed()){
        m_heldItem = 3;
    }
    if(m_num5.isKeyPressed()){
        m_heldItem = 4;
    }

}

void Player::update(float dt, World& world)
{
    velocity += m_acceleation;
    m_acceleation = {0, 0, 0};

    if (!m_isFlying)
    {
        if (!m_isOnGround)
        {
            velocity.y -= 40 * dt;
        }
        m_isOnGround = false;
    }

    position.x += velocity.x * dt;
    collide (world, {velocity.x, 0, 0}, dt);

    position.y += velocity.y * dt;
    collide (world, {0, velocity.y, 0}, dt);

    position.z += velocity.z * dt;
    collide (world, {0, 0, velocity.z}, dt);

    box.update(position);
    velocity.x *= 0.95;
    velocity.z *= 0.95;
    if (m_isFlying)
    {
        velocity.y *= 0.95;
    }
}

void Player::collide(World& world, const glm::vec3& vel, float dt)
{
    for (int x = position.x - box.dimensions.x; x < position.x + box.dimensions.x; x++)
    for (int y = position.y - box.dimensions.y; y < position.y + 0.7             ; y++)
    for (int z = position.z - box.dimensions.z; z < position.z + box.dimensions.z; z++)
    {
        auto block = world.getBlock(x, y, z);

        if (block != 0 && block.getData().isCollidable)
        {
            if (vel.y > 0)
            {
                position.y = y - box.dimensions.y;
                velocity.y = 0;
            }
            else if (vel.y < 0)
            {
                m_isOnGround = true;
                position.y = y + box.dimensions.y + 1;
                velocity.y = 0;
            }

            if (vel.x > 0)
            {
                position.x = x - box.dimensions.x;
            }
            else if (vel.x < 0)
            {
                position.x = x + box.dimensions.x + 1;
            }

            if (vel.z > 0)
            {
                position.z = z - box.dimensions.z;
            }
            else if (vel.z < 0)
            {
                position.z = z + box.dimensions.z + 1;
            }
        }
    }
}

///@TODO Move this
float speed = 0.2f;

void Player::keyboardInput()
{
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
    {
        float s = speed;
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) s *= 5;
        m_acceleation.x += -glm::cos(glm::radians(rotation.y + 90)) * s;
        m_acceleation.z += -glm::sin(glm::radians(rotation.y + 90)) * s;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
    {
        m_acceleation.x += glm::cos(glm::radians(rotation.y + 90)) * speed;
        m_acceleation.z += glm::sin(glm::radians(rotation.y + 90)) * speed;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
    {
        m_acceleation.x += -glm::cos(glm::radians(rotation.y)) * speed;
        m_acceleation.z += -glm::sin(glm::radians(rotation.y)) * speed;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
    {
        m_acceleation.x += glm::cos(glm::radians(rotation.y)) * speed;
        m_acceleation.z += glm::sin(glm::radians(rotation.y)) * speed;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
    {
        jump();
    }
    else if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) && m_isFlying)
    {
        m_acceleation.y -= speed * 3;
    }
}

void Player::mouseInput(const sf::RenderWindow& window)
{
    static bool useMouse = true;
    static ToggleKey useMouseKey (sf::Keyboard::L);

    if (useMouseKey.isKeyPressed())
    {
        useMouse = !useMouse;
    }

    if (!useMouse)
    {
        return;
    }

	 static sf::Vector2i center = {
		 static_cast<int>(window.getSize().x / 2),
		 static_cast<int>(window.getSize().y / 2)
	 };

    static auto const BOUND = 89.9999;
    static auto lastMousePosition = sf::Mouse::getPosition(window);
    auto change = sf::Mouse::getPosition(window) - lastMousePosition;

    rotation.y += change.x * 0.05;
    rotation.x += change.y * 0.05;

    if      (rotation.x >  BOUND) rotation.x =  BOUND;
    else if (rotation.x < -BOUND) rotation.x = -BOUND;

    if      (rotation.y >  360) rotation.y = 0;
    else if (rotation.y <  0)   rotation.y = 360;

    lastMousePosition = sf::Mouse::getPosition(window);

	 if(lastMousePosition.x < 10 || lastMousePosition.x > window.getSize().x - 10 || lastMousePosition.y < 10 || lastMousePosition.y > window.getSize().y - 10 ) {
		sf::Mouse::setPosition( center );
		lastMousePosition = center;
	 }
}

void Player::draw(RenderMaster& master)
{
    for (unsigned i = 0; i < m_items.size(); i++)
    {
        sf::Text& t = m_itemText[i];
        if (i == (unsigned)m_heldItem)
        {
            t.setFillColor(sf::Color::Red);
        }
        else
        {
            t.setFillColor(sf::Color::White);
        }
        t.setString((m_items[i].getMaterial().name) + " " + std::to_string(m_items[i].getNumInStack()) + " ");
        master.drawSFML(t);
    }
    std::ostringstream stream;
    stream  << " X: " << position.x
            << " Y: " << position.y
            << " Z: " << position.z
            << " Grounded " << std::boolalpha << m_isOnGround;

    m_posPrint.setString(stream.str());

    master.drawSFML(m_posPrint);
}

void Player::jump()
{
    if (!m_isFlying)
    {
        if (m_isOnGround)
        {
            m_isOnGround = false;
            m_acceleation.y += speed * 50;
        }
    }
    else
    {
        m_acceleation.y += speed * 3;
    }
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: plctrl.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: ihi $ $Date: 2007-06-05 14:43:47 $
 *
 *  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
 *
 ************************************************************************/
#ifndef __PLCTRL_HXX
#define __PLCTRL_HXX

#include <tools/debug.hxx>

#include <cppuhelper/weak.hxx>
#include <plugin/multiplx.hxx>

#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUES_HPP_
#include <com/sun/star/beans/PropertyValues.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_
#include <com/sun/star/beans/PropertyState.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XFASTPROPERTYSET_HPP_
#include <com/sun/star/beans/XFastPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XVETOABLECHANGELISTENER_HPP_
#include <com/sun/star/beans/XVetoableChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_
#include <com/sun/star/beans/XPropertyState.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATECHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_
#include <com/sun/star/beans/XPropertyAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
#include <com/sun/star/beans/XPropertyContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATECHANGEEVENT_HPP_
#include <com/sun/star/beans/PropertyStateChangeEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLCONTAINERPEER_HPP_
#include <com/sun/star/awt/XVclContainerPeer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLWINDOWPEER_HPP_
#include <com/sun/star/awt/XVclWindowPeer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROLMODEL_HPP_
#include <com/sun/star/awt/XControlModel.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XUNOCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XUnoControlContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XControlContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_VCLWINDOWPEERATTRIBUTE_HPP_
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLCONTAINER_HPP_
#include <com/sun/star/awt/XVclContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROL_HPP_
#include <com/sun/star/awt/XControl.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
#include <com/sun/star/awt/XTopWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
#include <com/sun/star/awt/PosSize.hpp>
#endif

#include <cppuhelper/implbase4.hxx>

#include <list>

class SystemChildWindow;

//==================================================================================================
class PluginControl_Impl : public ::cppu::WeakAggImplHelper4<
      ::com::sun::star::awt::XControl,
      ::com::sun::star::awt::XWindow,
      ::com::sun::star::awt::XFocusListener,
      ::com::sun::star::awt::XView >
{
public:
    // ::com::sun::star::awt::XControl
    virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & xContext ) throw( ::com::sun::star::uno::RuntimeException )
    { _xContext = xContext; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getContext() throw( ::com::sun::star::uno::RuntimeException )
    { return _xContext; }

    virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & Model ) throw( ::com::sun::star::uno::RuntimeException ) = 0;
//  { DBG_ERROR( "### setModel() illegal on plugincontrol!" ); return sal_False; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > SAL_CALL getModel() throw( ::com::sun::star::uno::RuntimeException ) = 0;

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XView > SAL_CALL getView() throw( ::com::sun::star::uno::RuntimeException )
    { return (::com::sun::star::awt::XView*)this; }

    virtual sal_Bool SAL_CALL isTransparent() throw( ::com::sun::star::uno::RuntimeException )
    { return sal_False; }

    virtual void SAL_CALL setDesignMode( sal_Bool bOn ) throw( ::com::sun::star::uno::RuntimeException );
    virtual sal_Bool SAL_CALL isDesignMode() throw( ::com::sun::star::uno::RuntimeException )
    { return _bInDesignMode; }

    virtual void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > & xToolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > & Parent) throw( ::com::sun::star::uno::RuntimeException );
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > SAL_CALL getPeer() throw( ::com::sun::star::uno::RuntimeException )
    { return _xPeer; }

    // ::com::sun::star::awt::XWindow
    virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setEnable( sal_Bool bEnable ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setFocus(void) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) throw( ::com::sun::star::uno::RuntimeException );
    virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize(void) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( RuntimeException );
    virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::lang::XEventListener
    virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject & rSource ) throw( ::com::sun::star::uno::RuntimeException );
    // ::com::sun::star::awt::XFocusListener
    virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::lang::XComponent
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::awt::XView
    virtual sal_Bool SAL_CALL setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > & aDevice ) throw( ::com::sun::star::uno::RuntimeException )
    { return sal_False; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > SAL_CALL getGraphics(void) throw( ::com::sun::star::uno::RuntimeException )
    { return ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > (); }

    virtual ::com::sun::star::awt::Size SAL_CALL getSize(void) throw( ::com::sun::star::uno::RuntimeException )
    { return ::com::sun::star::awt::Size(_nWidth, _nHeight); }

    virtual void SAL_CALL draw( sal_Int32 x, sal_Int32 y ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setZoom( float ZoomX, float ZoomY ) throw( ::com::sun::star::uno::RuntimeException );

public:
                                PluginControl_Impl();
    virtual                     ~PluginControl_Impl();

    MRCListenerMultiplexerHelper* getMultiplexer();

protected:
    void                        releasePeer();

protected:
    ::std::list< Reference< ::com::sun::star::lang::XEventListener > >  _aDisposeListeners;
    MRCListenerMultiplexerHelper*       _pMultiplexer;

    Reference< XInterface >                         _xContext;

    sal_Int32                               _nX;
    sal_Int32                               _nY;
    sal_Int32                               _nWidth;
    sal_Int32                               _nHeight;
    sal_Int16                               _nFlags;

    sal_Bool                                _bVisible;
    sal_Bool                                _bInDesignMode;
    sal_Bool                                _bEnable;

    SystemChildWindow*                  _pSysChild;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >                      _xPeer;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >                          _xPeerWindow;

    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >                          _xParentWindow;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >                      _xParentPeer;
};

#endif

<commit_msg>INTEGRATION: CWS wae4extensions (1.5.68); FILE MERGED 2007/09/27 10:20:01 fs 1.5.68.1: #i81612# warning-free code<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: plctrl.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: ihi $ $Date: 2008-01-14 14:52: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
 *
 ************************************************************************/
#ifndef __PLCTRL_HXX
#define __PLCTRL_HXX

#include <tools/debug.hxx>

#include <cppuhelper/weak.hxx>
#include <plugin/multiplx.hxx>

#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUES_HPP_
#include <com/sun/star/beans/PropertyValues.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_
#include <com/sun/star/beans/PropertyState.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_
#include <com/sun/star/beans/XMultiPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XFASTPROPERTYSET_HPP_
#include <com/sun/star/beans/XFastPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XVETOABLECHANGELISTENER_HPP_
#include <com/sun/star/beans/XVetoableChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATE_HPP_
#include <com/sun/star/beans/XPropertyState.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSTATECHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyStateChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTIESCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_
#include <com/sun/star/beans/XPropertyAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
#include <com/sun/star/beans/XPropertyContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATECHANGEEVENT_HPP_
#include <com/sun/star/beans/PropertyStateChangeEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLCONTAINERPEER_HPP_
#include <com/sun/star/awt/XVclContainerPeer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLWINDOWPEER_HPP_
#include <com/sun/star/awt/XVclWindowPeer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROLMODEL_HPP_
#include <com/sun/star/awt/XControlModel.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XUNOCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XUnoControlContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XControlContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_VCLWINDOWPEERATTRIBUTE_HPP_
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XVCLCONTAINER_HPP_
#include <com/sun/star/awt/XVclContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XCONTROL_HPP_
#include <com/sun/star/awt/XControl.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XTOPWINDOW_HPP_
#include <com/sun/star/awt/XTopWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
#include <com/sun/star/awt/PosSize.hpp>
#endif

#include <cppuhelper/implbase4.hxx>

#include <list>

class SystemChildWindow;

//==================================================================================================
class PluginControl_Impl : public ::cppu::WeakAggImplHelper4<
      ::com::sun::star::awt::XControl,
      ::com::sun::star::awt::XWindow,
      ::com::sun::star::awt::XFocusListener,
      ::com::sun::star::awt::XView >
{
public:
    // ::com::sun::star::awt::XControl
    virtual void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & xContext ) throw( ::com::sun::star::uno::RuntimeException )
    { _xContext = xContext; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getContext() throw( ::com::sun::star::uno::RuntimeException )
    { return _xContext; }

    virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & Model ) throw( ::com::sun::star::uno::RuntimeException ) = 0;
//  { DBG_ERROR( "### setModel() illegal on plugincontrol!" ); return sal_False; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > SAL_CALL getModel() throw( ::com::sun::star::uno::RuntimeException ) = 0;

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XView > SAL_CALL getView() throw( ::com::sun::star::uno::RuntimeException )
    { return (::com::sun::star::awt::XView*)this; }

    virtual sal_Bool SAL_CALL isTransparent() throw( ::com::sun::star::uno::RuntimeException )
    { return sal_False; }

    virtual void SAL_CALL setDesignMode( sal_Bool bOn ) throw( ::com::sun::star::uno::RuntimeException );
    virtual sal_Bool SAL_CALL isDesignMode() throw( ::com::sun::star::uno::RuntimeException )
    { return _bInDesignMode; }

    virtual void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > & xToolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > & Parent) throw( ::com::sun::star::uno::RuntimeException );
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > SAL_CALL getPeer() throw( ::com::sun::star::uno::RuntimeException )
    { return _xPeer; }

    // ::com::sun::star::awt::XWindow
    virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setEnable( sal_Bool bEnable ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setFocus(void) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) throw( ::com::sun::star::uno::RuntimeException );
    virtual ::com::sun::star::awt::Rectangle SAL_CALL getPosSize(void) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addMouseMotionListener( const Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( RuntimeException );
    virtual void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener > & l ) throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::lang::XEventListener
    virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject & rSource ) throw( ::com::sun::star::uno::RuntimeException );
    // ::com::sun::star::awt::XFocusListener
    virtual void SAL_CALL focusGained( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL focusLost( const ::com::sun::star::awt::FocusEvent & rEvt ) throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::lang::XComponent
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & l ) throw( ::com::sun::star::uno::RuntimeException );

    virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );

    // ::com::sun::star::awt::XView
    virtual sal_Bool SAL_CALL setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > & /*aDevice*/ ) throw( ::com::sun::star::uno::RuntimeException )
    { return sal_False; }
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > SAL_CALL getGraphics(void) throw( ::com::sun::star::uno::RuntimeException )
    { return ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > (); }

    virtual ::com::sun::star::awt::Size SAL_CALL getSize(void) throw( ::com::sun::star::uno::RuntimeException )
    { return ::com::sun::star::awt::Size(_nWidth, _nHeight); }

    virtual void SAL_CALL draw( sal_Int32 x, sal_Int32 y ) throw( ::com::sun::star::uno::RuntimeException );
    virtual void SAL_CALL setZoom( float ZoomX, float ZoomY ) throw( ::com::sun::star::uno::RuntimeException );

public:
                                PluginControl_Impl();
    virtual                     ~PluginControl_Impl();

    MRCListenerMultiplexerHelper* getMultiplexer();

protected:
    void                        releasePeer();

protected:
    ::std::list< Reference< ::com::sun::star::lang::XEventListener > >  _aDisposeListeners;
    MRCListenerMultiplexerHelper*       _pMultiplexer;

    Reference< XInterface >                         _xContext;

    sal_Int32                               _nX;
    sal_Int32                               _nY;
    sal_Int32                               _nWidth;
    sal_Int32                               _nHeight;
    sal_Int16                               _nFlags;

    sal_Bool                                _bVisible;
    sal_Bool                                _bInDesignMode;
    sal_Bool                                _bEnable;

    SystemChildWindow*                  _pSysChild;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >                      _xPeer;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >                          _xPeerWindow;

    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >                          _xParentWindow;
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >                      _xParentPeer;
};

#endif

<|endoftext|>


<commit_before>/* bzflag
 * Copyright (c) 1993 - 2003 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"
#include "ShotUpdate.h"

//
// ShotUpdate
//

void*			ShotUpdate::pack(void* buf) const
{
  buf = nboPackUByte(buf, player);
  buf = flagnboPackUShort(buf, id);
  buf = nboPackVector(buf, pos);
  buf = nboPackVector(buf, vel);
  buf = nboPackFloat(buf, dt);
  return buf;
}

void*			ShotUpdate::unpack(void* buf)
{
  buf = nboUnpackUByte(buf, player);
  buf = nboUnpackUShort(buf, id);
  buf = nboUnpackVector(buf, pos);
  buf = nboUnpackVector(buf, vel);
  buf = nboUnpackFloat(buf, dt);
  return buf;
}

//
// FiringInfo
//

FiringInfo::FiringInfo()
{
  // do nothing -- must be prepared before use by unpack() or assignment
}

void*			FiringInfo::pack(void* buf) const
{
  buf = shot.pack(buf);
  buf = nboPackUShort(buf, uint16_t(flag));
  buf = nboPackFloat(buf, lifetime);
  return buf;
}

void*			FiringInfo::unpack(void* buf)
{
  uint16_t _flag;
  buf = shot.unpack(buf);
  buf = nboUnpackUShort(buf, _flag);
  flag = FlagId(_flag);
  buf = nboUnpackFloat(buf, lifetime);
  return buf;
}

<commit_msg>FiringInfo packs and unpacks FlagDescs now<commit_after>/* bzflag
 * Copyright (c) 1993 - 2003 Tim Riker
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"
#include "ShotUpdate.h"

//
// ShotUpdate
//

void*			ShotUpdate::pack(void* buf) const
{
  buf = nboPackUByte(buf, player);
  buf = nboPackUShort(buf, id);
  buf = nboPackVector(buf, pos);
  buf = nboPackVector(buf, vel);
  buf = nboPackFloat(buf, dt);
  return buf;
}

void*			ShotUpdate::unpack(void* buf)
{
  buf = nboUnpackUByte(buf, player);
  buf = nboUnpackUShort(buf, id);
  buf = nboUnpackVector(buf, pos);
  buf = nboUnpackVector(buf, vel);
  buf = nboUnpackFloat(buf, dt);
  return buf;
}

//
// FiringInfo
//

FiringInfo::FiringInfo()
{
  // do nothing -- must be prepared before use by unpack() or assignment
}

void*			FiringInfo::pack(void* buf) const
{
  buf = shot.pack(buf);
  buf = flag->pack(buf);
  buf = nboPackFloat(buf, lifetime);
  return buf;
}

void*			FiringInfo::unpack(void* buf)
{
  buf = shot.unpack(buf);
  buf = FlagDesc::unpack(buf, flag);
  buf = nboUnpackFloat(buf, lifetime);
  return buf;
}

<|endoftext|>