<commit_before>/*************************************************************************
 *
 *  $RCSfile: frmpage.hxx,v $
 *
 *  $Revision: 1.17 $
 *
 *  last change: $Author: kz $ $Date: 2004-08-02 14:24:07 $
 *
 *  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 _FRMPAGE_HXX
#define _FRMPAGE_HXX

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif
#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif
#ifndef _LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif
#ifndef _FIELD_HXX //autogen
#include <vcl/field.hxx>
#endif
#ifndef _SFXTABDLG_HXX //autogen
#include <sfx2/tabdlg.hxx>
#endif
#ifndef _SVXSWFRAMEPOSSTRINGS_HXX
#include <svx/swframeposstrings.hxx>
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _BMPWIN_HXX
#include <bmpwin.hxx>
#endif
#ifndef _SVXSWFRAMEEXAMPLE_HXX
#include <svx/swframeexample.hxx>
#endif
#ifndef _PRCNTFLD_HXX
#include <prcntfld.hxx>
#endif
#ifndef _GLOBALS_HRC
#include <globals.hrc>
#endif

namespace sfx2{class FileDialogHelper;}
class SwWrtShell;
struct FrmMap;
// OD 12.11.2003 #i22341#
struct SwPosition;

/*--------------------------------------------------------------------
     Beschreibung:  Rahmendialog
 --------------------------------------------------------------------*/

class SwFrmPage: public SfxTabPage
{
    // Size
    FixedText       aWidthFT;
    FixedText       aWidthAutoFT;
    PercentField    aWidthED;
    CheckBox        aRelWidthCB;
    CheckBox        aAutoWidthCB;
    FixedText       aHeightFT;
    FixedText       aHeightAutoFT;
    PercentField    aHeightED;
    CheckBox        aRelHeightCB;
    CheckBox        aAutoHeightCB;
    CheckBox        aFixedRatioCB;
    PushButton      aRealSizeBT;
    FixedLine       aSizeFL;

    // Anker
    FixedLine       aTypeFL;
    FixedLine       aTypeSepFL;
    RadioButton     aAnchorAtPageRB;
    RadioButton     aAnchorAtParaRB;
    RadioButton     aAnchorAtCharRB;
    RadioButton     aAnchorAsCharRB;
    RadioButton     aAnchorAtFrameRB;

    // Position
    FixedText       aHorizontalFT;
    ListBox         aHorizontalDLB;
    FixedText       aAtHorzPosFT;
    MetricField     aAtHorzPosED;
    FixedText       aHoriRelationFT;
    ListBox         aHoriRelationLB;
    CheckBox        aMirrorPagesCB;
    FixedText       aVerticalFT;
    ListBox         aVerticalDLB;
    FixedText       aAtVertPosFT;
    MetricField     aAtVertPosED;
    FixedText       aVertRelationFT;
    ListBox         aVertRelationLB;
    // OD 02.10.2003 #i18732# - check box for new option 'FollowTextFlow'
    CheckBox        aFollowTextFlowCB;
    FixedLine       aPositionFL;
    BOOL            bAtHorzPosModified;
    BOOL            bAtVertPosModified;

    // Example
    SvxSwFrameExample   aExampleWN;

    //'string provider'
    SvxSwFramePosString aFramePosString;

    BOOL            bFormat;
    BOOL            bNew;
    BOOL            bHtmlMode;
    BOOL            bNoModifyHdl;
    BOOL            bVerticalChanged;  //check done whether frame is in vertical environment
    BOOL            bIsVerticalFrame;  //current frame is in vertical environment - strings are exchanged
    BOOL            bIsInRightToLeft; // current frame is in right-to-left environment - strings are exchanged
    USHORT          nHtmlMode;
    USHORT          nDlgType;
    Size            aGrfSize;
    Size            aWrap;
    SwTwips         nUpperBorder;
    SwTwips         nLowerBorder;
    double          fWidthHeightRatio; //width-to-height ratio to support the KeepRatio button

    // OD 12.11.2003 #i22341# - keep content position of character for
    // to character anchored objects.
    const SwPosition* mpToCharCntntPos;

    // Die alten Ausrichtungen
    USHORT          nOldH;
    USHORT          nOldHRel;
    USHORT          nOldV;
    USHORT          nOldVRel;

    FrmMap* pVMap;
    FrmMap* pHMap;

    virtual void    ActivatePage(const SfxItemSet& rSet);
    virtual int     DeactivatePage(SfxItemSet *pSet);

    DECL_LINK( RangeModifyHdl, Edit * );
    DECL_LINK( AnchorTypeHdl, RadioButton * );
    DECL_LINK( PosHdl, ListBox * );
    DECL_LINK( RelHdl, ListBox * );
    void            InitPos(USHORT nId, USHORT nH, USHORT nHRel,
                            USHORT nV,  USHORT nVRel,
                            long   nX,  long   nY);

    DECL_LINK( RealSizeHdl, Button * );
    DECL_LINK( RelSizeClickHdl, CheckBox * );
    DECL_LINK( MirrorHdl, CheckBox * );

    DECL_LINK( AutoWidthClickHdl, void* );
    DECL_LINK( AutoHeightClickHdl, void* );

    // Beispiel aktualisieren
    void            UpdateExample();
    DECL_LINK( ModifyHdl, Edit * );

    void            Init(const SfxItemSet& rSet, BOOL bReset = FALSE);
    // OD 12.11.2003 #i22341# - adjustment to handle maps, that are ambigous
    //                          in the alignment.
    USHORT          FillPosLB( const FrmMap* _pMap,
                               const USHORT _nAlign,
                               const USHORT _nRel,
                               ListBox& _rLB );
    // OD 14.11.2003 #i22341# - adjustment to handle maps, that are ambigous
    //                          in their string entries.
    ULONG           FillRelLB( const FrmMap* _pMap,
                               const USHORT _nLBSelPos,
                               const USHORT _nAlign,
                               USHORT _nRel,
                               ListBox& _rLB,
                               FixedText& _rFT );
    USHORT          GetMapPos( const FrmMap *pMap, ListBox &rAlignLB );
    short           GetAlignment(FrmMap *pMap, USHORT nMapPos, ListBox &rAlignLB, ListBox &rRelationLB);
    short           GetRelation(FrmMap *pMap, ListBox &rRelationLB);
    short           GetAnchor();

    void            EnableGraficMode( void );   // hides auto check boxes and re-org controls for "Real Size" button

    SwFrmPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmPage();

public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);
    static USHORT* GetRanges();

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);

    void            SetNewFrame(BOOL bNewFrame) { bNew      = bNewFrame; }
    void            SetFormatUsed(BOOL bFmt);
    void            SetFrmType(USHORT nType)    { nDlgType  = nType;     }
    inline BOOL     IsInGraficMode( void )      { return nDlgType == DLG_FRM_GRF || nDlgType == DLG_FRM_OLE; }
};

class SwGrfExtPage: public SfxTabPage
{
    // Spiegeln
    FixedLine       aMirrorFL;
    CheckBox        aMirrorVertBox;
    CheckBox        aMirrorHorzBox;
    RadioButton     aAllPagesRB;
    RadioButton     aLeftPagesRB;
    RadioButton     aRightPagesRB;
    BmpWindow       aBmpWin;

    FixedLine       aConnectFL;
    FixedText       aConnectFT;
    Edit            aConnectED;
    PushButton      aBrowseBT;

    String          aFilterName;
    String          aGrfName, aNewGrfName;

    ::sfx2::FileDialogHelper*     pGrfDlg;

    BOOL            bHtmlMode;

    // Handler fuer Spiegeln
    DECL_LINK( MirrorHdl, CheckBox * );
    DECL_LINK( BrowseHdl, Button * );

    virtual void    ActivatePage(const SfxItemSet& rSet);
    SwGrfExtPage(Window *pParent, const SfxItemSet &rSet);
    ~SwGrfExtPage();

public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);
    virtual int  DeactivatePage(SfxItemSet *pSet);
};

class SwFrmURLPage : public SfxTabPage
{
    //Hyperlink
    FixedLine       aHyperLinkFL;
    FixedText       aURLFT;
    Edit            aURLED;
    PushButton      aSearchPB;
    FixedText       aNameFT;
    Edit            aNameED;
    FixedText       aFrameFT;
    ComboBox        aFrameCB;

    //Image map
    FixedLine       aImageFL;
    CheckBox        aServerCB;
    CheckBox        aClientCB;

    DECL_LINK( InsertFileHdl, PushButton * );

    SwFrmURLPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmURLPage();
public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);
};

/*-----------------13.11.96 12.59-------------------

--------------------------------------------------*/

class SwFrmAddPage : public SfxTabPage
{
    FixedText   aNameFT;
    Edit        aNameED;
    FixedText   aAltNameFT;
    Edit        aAltNameED;
    FixedText   aPrevFT;
    ListBox     aPrevLB;
    FixedText   aNextFT;
    ListBox     aNextLB;
    FixedLine   aNamesFL;

    CheckBox    aProtectContentCB;
    CheckBox    aProtectFrameCB;
    CheckBox    aProtectSizeCB;
    FixedLine   aProtectFL;

    CheckBox    aEditInReadonlyCB;
    CheckBox    aPrintFrameCB;
    FixedText   aTextFlowFT;
    ListBox     aTextFlowLB;

    FixedLine   aExtFL;

    SwWrtShell* pWrtSh;

    USHORT      nDlgType;
    BOOL        bHtmlMode;
    BOOL        bFormat;
    BOOL        bNew;

    DECL_LINK(EditModifyHdl, Edit*);
    DECL_LINK(ChainModifyHdl, ListBox*);

    SwFrmAddPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmAddPage();

public:

    static SfxTabPage*  Create(Window *pParent, const SfxItemSet &rSet);
    static USHORT*      GetRanges();

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);

    void            SetFormatUsed(BOOL bFmt);
    void            SetFrmType(USHORT nType) { nDlgType = nType; }
    void            SetNewFrame(BOOL bNewFrame) { bNew  = bNewFrame; }
    void            SetShell(SwWrtShell* pSh) { pWrtSh  = pSh; }

};

#endif // _FRMPAGE_HXX
<commit_msg>INTEGRATION: CWS ooo19126 (1.17.630); FILE MERGED 2005/09/05 13:45:13 rt 1.17.630.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: frmpage.hxx,v $
 *
 *  $Revision: 1.18 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 09:16:02 $
 *
 *  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 _FRMPAGE_HXX
#define _FRMPAGE_HXX

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif
#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif
#ifndef _LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif
#ifndef _FIELD_HXX //autogen
#include <vcl/field.hxx>
#endif
#ifndef _SFXTABDLG_HXX //autogen
#include <sfx2/tabdlg.hxx>
#endif
#ifndef _SVXSWFRAMEPOSSTRINGS_HXX
#include <svx/swframeposstrings.hxx>
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _BMPWIN_HXX
#include <bmpwin.hxx>
#endif
#ifndef _SVXSWFRAMEEXAMPLE_HXX
#include <svx/swframeexample.hxx>
#endif
#ifndef _PRCNTFLD_HXX
#include <prcntfld.hxx>
#endif
#ifndef _GLOBALS_HRC
#include <globals.hrc>
#endif

namespace sfx2{class FileDialogHelper;}
class SwWrtShell;
struct FrmMap;
// OD 12.11.2003 #i22341#
struct SwPosition;

/*--------------------------------------------------------------------
     Beschreibung:  Rahmendialog
 --------------------------------------------------------------------*/

class SwFrmPage: public SfxTabPage
{
    // Size
    FixedText       aWidthFT;
    FixedText       aWidthAutoFT;
    PercentField    aWidthED;
    CheckBox        aRelWidthCB;
    CheckBox        aAutoWidthCB;
    FixedText       aHeightFT;
    FixedText       aHeightAutoFT;
    PercentField    aHeightED;
    CheckBox        aRelHeightCB;
    CheckBox        aAutoHeightCB;
    CheckBox        aFixedRatioCB;
    PushButton      aRealSizeBT;
    FixedLine       aSizeFL;

    // Anker
    FixedLine       aTypeFL;
    FixedLine       aTypeSepFL;
    RadioButton     aAnchorAtPageRB;
    RadioButton     aAnchorAtParaRB;
    RadioButton     aAnchorAtCharRB;
    RadioButton     aAnchorAsCharRB;
    RadioButton     aAnchorAtFrameRB;

    // Position
    FixedText       aHorizontalFT;
    ListBox         aHorizontalDLB;
    FixedText       aAtHorzPosFT;
    MetricField     aAtHorzPosED;
    FixedText       aHoriRelationFT;
    ListBox         aHoriRelationLB;
    CheckBox        aMirrorPagesCB;
    FixedText       aVerticalFT;
    ListBox         aVerticalDLB;
    FixedText       aAtVertPosFT;
    MetricField     aAtVertPosED;
    FixedText       aVertRelationFT;
    ListBox         aVertRelationLB;
    // OD 02.10.2003 #i18732# - check box for new option 'FollowTextFlow'
    CheckBox        aFollowTextFlowCB;
    FixedLine       aPositionFL;
    BOOL            bAtHorzPosModified;
    BOOL            bAtVertPosModified;

    // Example
    SvxSwFrameExample   aExampleWN;

    //'string provider'
    SvxSwFramePosString aFramePosString;

    BOOL            bFormat;
    BOOL            bNew;
    BOOL            bHtmlMode;
    BOOL            bNoModifyHdl;
    BOOL            bVerticalChanged;  //check done whether frame is in vertical environment
    BOOL            bIsVerticalFrame;  //current frame is in vertical environment - strings are exchanged
    BOOL            bIsInRightToLeft; // current frame is in right-to-left environment - strings are exchanged
    USHORT          nHtmlMode;
    USHORT          nDlgType;
    Size            aGrfSize;
    Size            aWrap;
    SwTwips         nUpperBorder;
    SwTwips         nLowerBorder;
    double          fWidthHeightRatio; //width-to-height ratio to support the KeepRatio button

    // OD 12.11.2003 #i22341# - keep content position of character for
    // to character anchored objects.
    const SwPosition* mpToCharCntntPos;

    // Die alten Ausrichtungen
    USHORT          nOldH;
    USHORT          nOldHRel;
    USHORT          nOldV;
    USHORT          nOldVRel;

    FrmMap* pVMap;
    FrmMap* pHMap;

    virtual void    ActivatePage(const SfxItemSet& rSet);
    virtual int     DeactivatePage(SfxItemSet *pSet);

    DECL_LINK( RangeModifyHdl, Edit * );
    DECL_LINK( AnchorTypeHdl, RadioButton * );
    DECL_LINK( PosHdl, ListBox * );
    DECL_LINK( RelHdl, ListBox * );
    void            InitPos(USHORT nId, USHORT nH, USHORT nHRel,
                            USHORT nV,  USHORT nVRel,
                            long   nX,  long   nY);

    DECL_LINK( RealSizeHdl, Button * );
    DECL_LINK( RelSizeClickHdl, CheckBox * );
    DECL_LINK( MirrorHdl, CheckBox * );

    DECL_LINK( AutoWidthClickHdl, void* );
    DECL_LINK( AutoHeightClickHdl, void* );

    // Beispiel aktualisieren
    void            UpdateExample();
    DECL_LINK( ModifyHdl, Edit * );

    void            Init(const SfxItemSet& rSet, BOOL bReset = FALSE);
    // OD 12.11.2003 #i22341# - adjustment to handle maps, that are ambigous
    //                          in the alignment.
    USHORT          FillPosLB( const FrmMap* _pMap,
                               const USHORT _nAlign,
                               const USHORT _nRel,
                               ListBox& _rLB );
    // OD 14.11.2003 #i22341# - adjustment to handle maps, that are ambigous
    //                          in their string entries.
    ULONG           FillRelLB( const FrmMap* _pMap,
                               const USHORT _nLBSelPos,
                               const USHORT _nAlign,
                               USHORT _nRel,
                               ListBox& _rLB,
                               FixedText& _rFT );
    USHORT          GetMapPos( const FrmMap *pMap, ListBox &rAlignLB );
    short           GetAlignment(FrmMap *pMap, USHORT nMapPos, ListBox &rAlignLB, ListBox &rRelationLB);
    short           GetRelation(FrmMap *pMap, ListBox &rRelationLB);
    short           GetAnchor();

    void            EnableGraficMode( void );   // hides auto check boxes and re-org controls for "Real Size" button

    SwFrmPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmPage();

public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);
    static USHORT* GetRanges();

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);

    void            SetNewFrame(BOOL bNewFrame) { bNew      = bNewFrame; }
    void            SetFormatUsed(BOOL bFmt);
    void            SetFrmType(USHORT nType)    { nDlgType  = nType;     }
    inline BOOL     IsInGraficMode( void )      { return nDlgType == DLG_FRM_GRF || nDlgType == DLG_FRM_OLE; }
};

class SwGrfExtPage: public SfxTabPage
{
    // Spiegeln
    FixedLine       aMirrorFL;
    CheckBox        aMirrorVertBox;
    CheckBox        aMirrorHorzBox;
    RadioButton     aAllPagesRB;
    RadioButton     aLeftPagesRB;
    RadioButton     aRightPagesRB;
    BmpWindow       aBmpWin;

    FixedLine       aConnectFL;
    FixedText       aConnectFT;
    Edit            aConnectED;
    PushButton      aBrowseBT;

    String          aFilterName;
    String          aGrfName, aNewGrfName;

    ::sfx2::FileDialogHelper*     pGrfDlg;

    BOOL            bHtmlMode;

    // Handler fuer Spiegeln
    DECL_LINK( MirrorHdl, CheckBox * );
    DECL_LINK( BrowseHdl, Button * );

    virtual void    ActivatePage(const SfxItemSet& rSet);
    SwGrfExtPage(Window *pParent, const SfxItemSet &rSet);
    ~SwGrfExtPage();

public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);
    virtual int  DeactivatePage(SfxItemSet *pSet);
};

class SwFrmURLPage : public SfxTabPage
{
    //Hyperlink
    FixedLine       aHyperLinkFL;
    FixedText       aURLFT;
    Edit            aURLED;
    PushButton      aSearchPB;
    FixedText       aNameFT;
    Edit            aNameED;
    FixedText       aFrameFT;
    ComboBox        aFrameCB;

    //Image map
    FixedLine       aImageFL;
    CheckBox        aServerCB;
    CheckBox        aClientCB;

    DECL_LINK( InsertFileHdl, PushButton * );

    SwFrmURLPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmURLPage();
public:
    static SfxTabPage *Create(Window *pParent, const SfxItemSet &rSet);

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);
};

/*-----------------13.11.96 12.59-------------------

--------------------------------------------------*/

class SwFrmAddPage : public SfxTabPage
{
    FixedText   aNameFT;
    Edit        aNameED;
    FixedText   aAltNameFT;
    Edit        aAltNameED;
    FixedText   aPrevFT;
    ListBox     aPrevLB;
    FixedText   aNextFT;
    ListBox     aNextLB;
    FixedLine   aNamesFL;

    CheckBox    aProtectContentCB;
    CheckBox    aProtectFrameCB;
    CheckBox    aProtectSizeCB;
    FixedLine   aProtectFL;

    CheckBox    aEditInReadonlyCB;
    CheckBox    aPrintFrameCB;
    FixedText   aTextFlowFT;
    ListBox     aTextFlowLB;

    FixedLine   aExtFL;

    SwWrtShell* pWrtSh;

    USHORT      nDlgType;
    BOOL        bHtmlMode;
    BOOL        bFormat;
    BOOL        bNew;

    DECL_LINK(EditModifyHdl, Edit*);
    DECL_LINK(ChainModifyHdl, ListBox*);

    SwFrmAddPage(Window *pParent, const SfxItemSet &rSet);
    ~SwFrmAddPage();

public:

    static SfxTabPage*  Create(Window *pParent, const SfxItemSet &rSet);
    static USHORT*      GetRanges();

    virtual BOOL FillItemSet(SfxItemSet &rSet);
    virtual void Reset(const SfxItemSet &rSet);

    void            SetFormatUsed(BOOL bFmt);
    void            SetFrmType(USHORT nType) { nDlgType = nType; }
    void            SetNewFrame(BOOL bNewFrame) { bNew  = bNewFrame; }
    void            SetShell(SwWrtShell* pSh) { pWrtSh  = pSh; }

};

#endif // _FRMPAGE_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: mediash.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2007-09-27 12:05:13 $
 *
 *  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 _SWMEDIASH_HXX
#define _SWMEDIASH_HXX

#include "frmsh.hxx"

class SwMediaShell: public SwBaseShell
{
public:
    SFX_DECL_INTERFACE(SW_MEDIASHELL)

    void    ExecMedia(SfxRequest &);
    void    GetMediaState(SfxItemSet &);

            SwMediaShell(SwView &rView);
};

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.4.242); FILE MERGED 2008/03/31 16:58:36 rt 1.4.242.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: mediash.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef _SWMEDIASH_HXX
#define _SWMEDIASH_HXX

#include "frmsh.hxx"

class SwMediaShell: public SwBaseShell
{
public:
    SFX_DECL_INTERFACE(SW_MEDIASHELL)

    void    ExecMedia(SfxRequest &);
    void    GetMediaState(SfxItemSet &);

            SwMediaShell(SwView &rView);
};

#endif
<|endoftext|>


<commit_before>////////////////////////////////////////////////////////////////////////////////
/// @brief json result generator
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Achim Brandt
/// @author Copyright 2008-2011, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#include "JsonResultGenerator.h"

#include <math.h>

#include <Logger/Logger.h>
#include <Basics/StringBuffer.h>
#include <Basics/StringUtils.h>
#include <Variant/VariantArray.h>
#include <Variant/VariantBlob.h>
#include <Variant/VariantBoolean.h>
#include <Variant/VariantDate.h>
#include <Variant/VariantDatetime.h>
#include <Variant/VariantDouble.h>
#include <Variant/VariantFloat.h>
#include <Variant/VariantInt16.h>
#include <Variant/VariantInt32.h>
#include <Variant/VariantInt64.h>
#include <Variant/VariantMatrix2.h>
#include <Variant/VariantNull.h>
#include <Variant/VariantString.h>
#include <Variant/VariantUInt16.h>
#include <Variant/VariantUInt32.h>
#include <Variant/VariantUInt64.h>
#include <Variant/VariantVector.h>

using namespace triagens::basics;

namespace triagens {
  namespace rest {

    // -----------------------------------------------------------------------------
    // output methods
    // -----------------------------------------------------------------------------

    namespace {
      void generateVariantArray (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantArray* array = dynamic_cast<VariantArray*>(object);
        vector<string> const& attributes = array->getAttributes();
        vector<VariantObject*> const& values = array->getValues();

        // generate array header
        output.appendText("{");
        char const * sep = "";

        // generate attributes
        vector<string>::const_iterator ai = attributes.begin();
        vector<VariantObject*>::const_iterator vi = values.begin();

        for (;  ai != attributes.end() && vi != values.end();  ++ai, ++vi) {
          output.appendText(sep);

          generator->generateAtom(output, *ai);
          output.appendText(":");
          generator->generateVariant(output, *vi);

          sep = ",";
        }

        // generate array trailer
        output.appendText("}");
      }

      void generateVariantBoolean (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantBoolean*>(object)->getValue());
      }

      void generateVariantBlob (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantBlob* blob = dynamic_cast<VariantBlob*>(object);

        generator->generateAtom(output, blob->getValue(), blob->getLength(), false);
      }

      void generateVariantDate (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDate*>(object)->getValue());
      }

      void generateVariantDatetime (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDatetime*>(object)->getValue());
      }

      void generateVariantDouble (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDouble*>(object)->getValue());
      }

      void generateVariantFloat (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantFloat*>(object)->getValue());
      }

      void generateVariantInt16 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt16*>(object)->getValue());
      }

      void generateVariantInt32 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt32*>(object)->getValue());
      }

      void generateVariantInt64 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt64*>(object)->getValue());
      }

      void generateVariantMatrix2 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantMatrix2* matrix2 = dynamic_cast<VariantMatrix2*>(object);
        vector<string> ds[2];

        ds[0] = matrix2->getDimension(0);
        ds[1] = matrix2->getDimension(1);

        // generate array header
        output.appendText("{");

        // generate dimensions
        generator->generateAtom(output, "dimensions");
        output.appendText(":[");

        char const * sep1 = "";

        for (size_t n = 0;  n < 2;  ++n) {
          output.appendText(sep1);
          output.appendText("[");

          char const * sep2 = "";

          for (vector<string>::const_iterator j = ds[n].begin();  j != ds[n].end();  ++j) {
            output.appendText(sep2);
            generator->generateAtom(output, *j);
            sep2 = ", ";
          }

          output.appendText("]");

          sep1 = ", ";
        }

        output.appendText("], ");

        // generate matrix
        generator->generateAtom(output, "matrix");
        output.appendText(":[");

        sep1 = "";

        for (size_t x = 0;  x < ds[0].size();  ++x) {
          output.appendText(sep1);
          output.appendText("[");

          char const * sep2 = "";

          for (size_t y = 0;  y < ds[1].size();  ++y) {
            output.appendText(sep2);

            VariantObject* obj = matrix2->getValue(x, y);

            if (obj != 0) {
              generator->generateVariant(output, obj);
            }

            sep2 = ",";
          }

          output.appendText("]");

          sep1 = ", ";
        }

        output.appendText("]");

        // generate array trailer
        output.appendText("}");
      }

      void generateVariantNull (ResultGenerator const*, StringBuffer& output, VariantObject*) {
        output.appendText("null");
      }

      void generateVariantString (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantString*>(object)->getValue());
      }

      void generateVariantUInt16 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt16*>(object)->getValue());
      }

      void generateVariantUInt32 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt32*>(object)->getValue());
      }

      void generateVariantUInt64 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt64*>(object)->getValue());
      }

      void generateVariantVector (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantVector* vec = dynamic_cast<VariantVector*>(object);
        output.appendText("[");

        vector<VariantObject*> const& values = vec->getValues();
        string sep = "";

        for (vector<VariantObject*>::const_iterator i = values.begin();  i != values.end();  ++i) {
          output.appendText(sep);
          generator->generateVariant(output, *i);
          sep = ", ";
        }

        output.appendText("]");
      }
    }

    // -----------------------------------------------------------------------------
    // static public methods
    // -----------------------------------------------------------------------------

    void JsonResultGenerator::initialise (ResultGeneratorType type) {
      registerObject(VariantObject::VARIANT_ARRAY, type, generateVariantArray);
      registerObject(VariantObject::VARIANT_BLOB, type, generateVariantBlob);
      registerObject(VariantObject::VARIANT_BOOLEAN, type, generateVariantBoolean);
      registerObject(VariantObject::VARIANT_DATE, type, generateVariantDate);
      registerObject(VariantObject::VARIANT_DATETIME, type, generateVariantDatetime);
      registerObject(VariantObject::VARIANT_DOUBLE, type, generateVariantDouble);
      registerObject(VariantObject::VARIANT_FLOAT, type, generateVariantFloat);
      registerObject(VariantObject::VARIANT_INT16, type, generateVariantInt16);
      registerObject(VariantObject::VARIANT_INT32, type, generateVariantInt32);
      registerObject(VariantObject::VARIANT_INT64, type, generateVariantInt64);
      registerObject(VariantObject::VARIANT_MATRIX2, type, generateVariantMatrix2);
      registerObject(VariantObject::VARIANT_NULL, type, generateVariantNull);
      registerObject(VariantObject::VARIANT_STRING, type, generateVariantString);
      registerObject(VariantObject::VARIANT_UINT16, type, generateVariantUInt16);
      registerObject(VariantObject::VARIANT_UINT32, type, generateVariantUInt32);
      registerObject(VariantObject::VARIANT_UINT64, type, generateVariantUInt64);
      registerObject(VariantObject::VARIANT_VECTOR, type, generateVariantVector);
    }

    // -----------------------------------------------------------------------------
    // ResultGenerator methods
    // -----------------------------------------------------------------------------

    void JsonResultGenerator::generateAtom (StringBuffer& output, string const& value) const {
      output.appendText("\"");
      output.appendText(StringUtils::escapeUnicode(value));
      output.appendText("\"");
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value) const {
      if (value == 0) {
        output.appendText("null");
      }
      else {
        output.appendText("\"");
        output.appendText(StringUtils::escapeUnicode(value));
        output.appendText("\"");
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value, size_t length, bool quote) const {
      if (value == 0) {
        if (quote) {
          output.appendText("null");
        }
      }
      else {
        string v(value, length);

        if (quote) {
          output.appendText("\"");
          output.appendText(StringUtils::escapeUnicode(v));
          output.appendText("\"");
        }
        else {
          output.appendText(v);
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, bool value) const {
      output.appendText(value ? "true" : "false");
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, double value) const {
      if (value == 0.0) {
        output.appendText("0.0", 3);
      }
      else if (isnormal(value)) {
        output.appendDecimal(value);
      }
      else {
        int a = isinf(value);

        if (a == -1) {
          generateAtom(output, "-INF");
        }
        else if (a == 1) {
          generateAtom(output, "INF");
        }
        else /* if (isnan(value)) */ {
          generateAtom(output, "NAN");
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, float value) const {
      if (value == 0.0) {
        output.appendText("0.0", 3);
      }
      else if (isnormal(value)) {
        output.appendDecimal(value);
      }
      else {
        int a = isinf(value);

        if (a == -1) {
          generateAtom(output, "-INF");
        }
        else if (a == 1) {
          generateAtom(output, "INF");
        }
        else /* if (isnan(value)) */ {
          generateAtom(output, "NAN");
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int16_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int32_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int64_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint16_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint32_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint64_t value) const {
      output.appendInteger(value);
    }
  }
}
<commit_msg>removed some strlens<commit_after>////////////////////////////////////////////////////////////////////////////////
/// @brief json result generator
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2011 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Achim Brandt
/// @author Copyright 2008-2011, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#include "JsonResultGenerator.h"

#include <math.h>

#include <Logger/Logger.h>
#include <Basics/StringBuffer.h>
#include <Basics/StringUtils.h>
#include <Variant/VariantArray.h>
#include <Variant/VariantBlob.h>
#include <Variant/VariantBoolean.h>
#include <Variant/VariantDate.h>
#include <Variant/VariantDatetime.h>
#include <Variant/VariantDouble.h>
#include <Variant/VariantFloat.h>
#include <Variant/VariantInt16.h>
#include <Variant/VariantInt32.h>
#include <Variant/VariantInt64.h>
#include <Variant/VariantMatrix2.h>
#include <Variant/VariantNull.h>
#include <Variant/VariantString.h>
#include <Variant/VariantUInt16.h>
#include <Variant/VariantUInt32.h>
#include <Variant/VariantUInt64.h>
#include <Variant/VariantVector.h>

using namespace triagens::basics;

namespace triagens {
  namespace rest {

    // -----------------------------------------------------------------------------
    // output methods
    // -----------------------------------------------------------------------------

    namespace {
      void generateVariantArray (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantArray* array = dynamic_cast<VariantArray*>(object);
        vector<string> const& attributes = array->getAttributes();
        vector<VariantObject*> const& values = array->getValues();

        // generate array header
        output.appendChar('{');
        char const * sep = "";

        // generate attributes
        vector<string>::const_iterator ai = attributes.begin();
        vector<VariantObject*>::const_iterator vi = values.begin();

        for (;  ai != attributes.end() && vi != values.end();  ++ai, ++vi) {
          output.appendText(sep);

          generator->generateAtom(output, *ai);
          output.appendChar(':');
          generator->generateVariant(output, *vi);

          sep = ",";
        }

        // generate array trailer
        output.appendChar('}');
      }

      void generateVariantBoolean (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantBoolean*>(object)->getValue());
      }

      void generateVariantBlob (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantBlob* blob = dynamic_cast<VariantBlob*>(object);

        generator->generateAtom(output, blob->getValue(), blob->getLength(), false);
      }

      void generateVariantDate (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDate*>(object)->getValue());
      }

      void generateVariantDatetime (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDatetime*>(object)->getValue());
      }

      void generateVariantDouble (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantDouble*>(object)->getValue());
      }

      void generateVariantFloat (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantFloat*>(object)->getValue());
      }

      void generateVariantInt16 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt16*>(object)->getValue());
      }

      void generateVariantInt32 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt32*>(object)->getValue());
      }

      void generateVariantInt64 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantInt64*>(object)->getValue());
      }

      void generateVariantMatrix2 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantMatrix2* matrix2 = dynamic_cast<VariantMatrix2*>(object);
        vector<string> ds[2];

        ds[0] = matrix2->getDimension(0);
        ds[1] = matrix2->getDimension(1);

        // generate array header
        output.appendChar('{');

        // generate dimensions
        generator->generateAtom(output, "dimensions");
        output.appendText(":[", 2);

        char const * sep1 = "";

        for (size_t n = 0;  n < 2;  ++n) {
          output.appendText(sep1);
          output.appendChar('[');

          char const * sep2 = "";

          for (vector<string>::const_iterator j = ds[n].begin();  j != ds[n].end();  ++j) {
            output.appendText(sep2);
            generator->generateAtom(output, *j);
            sep2 = ", ";
          }

          output.appendChar(']');

          sep1 = ", ";
        }

        output.appendText("], ", 3);

        // generate matrix
        generator->generateAtom(output, "matrix");
        output.appendText(":[", 2);

        sep1 = "";

        for (size_t x = 0;  x < ds[0].size();  ++x) {
          output.appendText(sep1);
          output.appendChar('[');

          char const * sep2 = "";

          for (size_t y = 0;  y < ds[1].size();  ++y) {
            output.appendText(sep2);

            VariantObject* obj = matrix2->getValue(x, y);

            if (obj != 0) {
              generator->generateVariant(output, obj);
            }

            sep2 = ",";
          }

          output.appendChar(']');

          sep1 = ", ";
        }

        output.appendChar(']');

        // generate array trailer
        output.appendChar('}');
      }

      void generateVariantNull (ResultGenerator const*, StringBuffer& output, VariantObject*) {
        output.appendText("null", 4);
      }

      void generateVariantString (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantString*>(object)->getValue());
      }

      void generateVariantUInt16 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt16*>(object)->getValue());
      }

      void generateVariantUInt32 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt32*>(object)->getValue());
      }

      void generateVariantUInt64 (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        generator->generateAtom(output, dynamic_cast<VariantUInt64*>(object)->getValue());
      }

      void generateVariantVector (ResultGenerator const* generator, StringBuffer& output, VariantObject* object) {
        VariantVector* vec = dynamic_cast<VariantVector*>(object);
        output.appendChar('[');

        vector<VariantObject*> const& values = vec->getValues();
        string sep = "";

        for (vector<VariantObject*>::const_iterator i = values.begin();  i != values.end();  ++i) {
          output.appendText(sep);
          generator->generateVariant(output, *i);
          sep = ", ";
        }

        output.appendChar(']');
      }
    }

    // -----------------------------------------------------------------------------
    // static public methods
    // -----------------------------------------------------------------------------

    void JsonResultGenerator::initialise (ResultGeneratorType type) {
      registerObject(VariantObject::VARIANT_ARRAY, type, generateVariantArray);
      registerObject(VariantObject::VARIANT_BLOB, type, generateVariantBlob);
      registerObject(VariantObject::VARIANT_BOOLEAN, type, generateVariantBoolean);
      registerObject(VariantObject::VARIANT_DATE, type, generateVariantDate);
      registerObject(VariantObject::VARIANT_DATETIME, type, generateVariantDatetime);
      registerObject(VariantObject::VARIANT_DOUBLE, type, generateVariantDouble);
      registerObject(VariantObject::VARIANT_FLOAT, type, generateVariantFloat);
      registerObject(VariantObject::VARIANT_INT16, type, generateVariantInt16);
      registerObject(VariantObject::VARIANT_INT32, type, generateVariantInt32);
      registerObject(VariantObject::VARIANT_INT64, type, generateVariantInt64);
      registerObject(VariantObject::VARIANT_MATRIX2, type, generateVariantMatrix2);
      registerObject(VariantObject::VARIANT_NULL, type, generateVariantNull);
      registerObject(VariantObject::VARIANT_STRING, type, generateVariantString);
      registerObject(VariantObject::VARIANT_UINT16, type, generateVariantUInt16);
      registerObject(VariantObject::VARIANT_UINT32, type, generateVariantUInt32);
      registerObject(VariantObject::VARIANT_UINT64, type, generateVariantUInt64);
      registerObject(VariantObject::VARIANT_VECTOR, type, generateVariantVector);
    }

    // -----------------------------------------------------------------------------
    // ResultGenerator methods
    // -----------------------------------------------------------------------------

    void JsonResultGenerator::generateAtom (StringBuffer& output, string const& value) const {
      output.appendChar('\"');
      output.appendText(StringUtils::escapeUnicode(value));
      output.appendChar('\"');
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value) const {
      if (value == 0) {
        output.appendText("null", 4);
      }
      else {
        output.appendChar('\"');
        output.appendText(StringUtils::escapeUnicode(value));
        output.appendChar('\"');
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, char const* value, size_t length, bool quote) const {
      if (value == 0) {
        if (quote) {
          output.appendText("null", 4);
        }
      }
      else {
        string v(value, length);

        if (quote) {
          output.appendChar('\"');
          output.appendText(StringUtils::escapeUnicode(v));
          output.appendChar('\"');
        }
        else {
          output.appendText(v);
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, bool value) const {
      if (value) {
        output.appendText("true", 4);
      }
      else {
        output.appendText("false", 5);
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, double value) const {
      if (value == 0.0) {
        output.appendText("0.0", 3);
      }
      else if (isnormal(value)) {
        output.appendDecimal(value);
      }
      else {
        int a = isinf(value);

        if (a == -1) {
          generateAtom(output, "-INF");
        }
        else if (a == 1) {
          generateAtom(output, "INF");
        }
        else /* if (isnan(value)) */ {
          generateAtom(output, "NAN");
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, float value) const {
      if (value == 0.0) {
        output.appendText("0.0", 3);
      }
      else if (isnormal(value)) {
        output.appendDecimal(value);
      }
      else {
        int a = isinf(value);

        if (a == -1) {
          generateAtom(output, "-INF");
        }
        else if (a == 1) {
          generateAtom(output, "INF");
        }
        else /* if (isnan(value)) */ {
          generateAtom(output, "NAN");
        }
      }
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int16_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int32_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, int64_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint16_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint32_t value) const {
      output.appendInteger(value);
    }

    void JsonResultGenerator::generateAtom (StringBuffer& output, uint64_t value) const {
      output.appendInteger(value);
    }
  }
}
<|endoftext|>


<commit_before>//===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
//
// This file contains the code for the Sparc Target that does not fit in any of
// the other files in this directory.
//
//===----------------------------------------------------------------------===//

#include "SparcInternals.h"
#include "llvm/Target/TargetMachineImpls.h"
#include "llvm/Function.h"
#include "llvm/PassManager.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionInfo.h"
#include "llvm/CodeGen/PreSelection.h"
#include "llvm/CodeGen/StackSlots.h"
#include "llvm/CodeGen/PeepholeOpts.h"
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/CodeGen/InstrScheduling.h"
#include "llvm/CodeGen/RegisterAllocation.h"
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/Reoptimizer/Mapping/MappingInfo.h"
#include "llvm/Reoptimizer/Mapping/FInfo.h"
#include "Support/CommandLine.h"
using std::cerr;

static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
// Build the MachineInstruction Description Array...
const TargetInstrDescriptor SparcMachineInstrDesc[] = {
#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
          NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS)             \
  { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE,             \
          NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS, 0,          \
          ImplicitRegUseList, ImplicitRegUseList },
#include "SparcInstr.def"
};

//---------------------------------------------------------------------------
// Command line options to control choice of code generation passes.
//---------------------------------------------------------------------------

static cl::opt<bool> DisablePreSelect("nopreselect",
                                      cl::desc("Disable preselection pass"));

static cl::opt<bool> DisableSched("nosched",
                                  cl::desc("Disable local scheduling pass"));

static cl::opt<bool> DisablePeephole("nopeephole",
                                cl::desc("Disable peephole optimization pass"));

//----------------------------------------------------------------------------
// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
//----------------------------------------------------------------------------

TargetMachine *allocateSparcTargetMachine(unsigned Configuration) {
  return new UltraSparc();
}

//---------------------------------------------------------------------------
// class UltraSparcFrameInfo
//
//   Interface to stack frame layout info for the UltraSPARC.
//   Starting offsets for each area of the stack frame are aligned at
//   a multiple of getStackFrameSizeAlignment().
//---------------------------------------------------------------------------

int
UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& ,
                                                bool& pos) const
{
  pos = false;                          // static stack area grows downwards
  return StaticAreaOffsetFromFP;
}

int
UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo,
                                           bool& pos) const
{
  // ensure no more auto vars are added
  mcInfo.getInfo()->freezeAutomaticVarsArea();

  pos = false;                          // static stack area grows downwards
  unsigned autoVarsSize = mcInfo.getInfo()->getAutomaticVarsSize();
  return StaticAreaOffsetFromFP - autoVarsSize;
}

int
UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo,
                                      bool& pos) const
{
  MachineFunctionInfo *MFI = mcInfo.getInfo();
  MFI->freezeAutomaticVarsArea();     // ensure no more auto vars are added
  MFI->freezeSpillsArea();            // ensure no more spill slots are added

  pos = false;                          // static stack area grows downwards
  unsigned autoVarsSize = MFI->getAutomaticVarsSize();
  unsigned spillAreaSize = MFI->getRegSpillsSize();
  int offset = autoVarsSize + spillAreaSize;
  return StaticAreaOffsetFromFP - offset;
}

int
UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
                                          bool& pos) const
{
  // Dynamic stack area grows downwards starting at top of opt-args area.
  // The opt-args, required-args, and register-save areas are empty except
  // during calls and traps, so they are shifted downwards on each
  // dynamic-size alloca.
  pos = false;
  unsigned optArgsSize = mcInfo.getInfo()->getMaxOptionalArgsSize();
  if (int extra = optArgsSize % getStackFrameSizeAlignment())
    optArgsSize += (getStackFrameSizeAlignment() - extra);
  int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
  assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
  return offset;
}

//---------------------------------------------------------------------------
// class UltraSparcMachine
//
// Purpose:
//   Primary interface to machine description for the UltraSPARC.
//   Primarily just initializes machine-dependent parameters in
//   class TargetMachine, and creates machine-dependent subclasses
//   for classes such as TargetInstrInfo.
//
//---------------------------------------------------------------------------

UltraSparc::UltraSparc()
  : TargetMachine("UltraSparc-Native", false),
    schedInfo(*this),
    regInfo(*this),
    frameInfo(*this),
    cacheInfo(*this),
    optInfo(*this) {
}

// addPassesToEmitAssembly - This method controls the entire code generation
// process for the ultra sparc.
//
bool UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
{
  // FIXME: implement the switch instruction in the instruction selector.
  PM.add(createLowerSwitchPass());

  // Construct and initialize the MachineFunction object for this fn.
  PM.add(createMachineCodeConstructionPass(*this));

  //Insert empty stackslots in the stack frame of each function
  //so %fp+offset-8 and %fp+offset-16 are empty slots now!
  PM.add(createStackSlotsPass(*this));

  // Specialize LLVM code for this target machine and then
  // run basic dataflow optimizations on LLVM code.
  if (!DisablePreSelect) {
    PM.add(createPreSelectionPass(*this));
    PM.add(createReassociatePass());
    PM.add(createLICMPass());
    PM.add(createGCSEPass());
  }

  PM.add(createInstructionSelectionPass(*this));

  if (!DisableSched)
    PM.add(createInstructionSchedulingWithSSAPass(*this));

  PM.add(getRegisterAllocator(*this));

  PM.add(getPrologEpilogInsertionPass());

  if (!DisablePeephole)
    PM.add(createPeepholeOptsPass(*this));

  PM.add(MappingInfoForFunction(Out));

  // Output assembly language to the .s file.  Assembly emission is split into
  // two parts: Function output and Global value output.  This is because
  // function output is pipelined with all of the rest of code generation stuff,
  // allowing machine code representations for functions to be free'd after the
  // function has been emitted.
  //
  PM.add(getFunctionAsmPrinterPass(Out));
  PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed

  // Emit Module level assembly after all of the functions have been processed.
  PM.add(getModuleAsmPrinterPass(Out));

  // Emit bytecode to the assembly file into its special section next
  PM.add(getEmitBytecodeToAsmPass(Out));
  PM.add(getFunctionInfo(Out));
  return false;
}

// addPassesToJITCompile - This method controls the JIT method of code
// generation for the UltraSparc.
//
bool UltraSparc::addPassesToJITCompile(PassManager &PM) {
  // FIXME: implement the switch instruction in the instruction selector.
  PM.add(createLowerSwitchPass());

  // Construct and initialize the MachineFunction object for this fn.
  PM.add(createMachineCodeConstructionPass(*this));

  //Insert empty stackslots in the stack frame of each function
  //so %fp+offset-8 and %fp+offset-16 are empty slots now!
  PM.add(createStackSlotsPass(*this));

  PM.add(createInstructionSelectionPass(*this));

  // new pass: convert Value* in MachineOperand to an unsigned register
  // this brings it in line with what the X86 JIT's RegisterAllocator expects
  //PM.add(createAddRegNumToValuesPass());

  PM.add(getRegisterAllocator(*this));
  PM.add(getPrologEpilogInsertionPass());

  return false; // success!
}
<commit_msg>Make LLI behave just like LLC with regard to the compile passes it uses.<commit_after>//===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
//
// This file contains the code for the Sparc Target that does not fit in any of
// the other files in this directory.
//
//===----------------------------------------------------------------------===//

#include "SparcInternals.h"
#include "llvm/Target/TargetMachineImpls.h"
#include "llvm/Function.h"
#include "llvm/PassManager.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionInfo.h"
#include "llvm/CodeGen/PreSelection.h"
#include "llvm/CodeGen/StackSlots.h"
#include "llvm/CodeGen/PeepholeOpts.h"
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/CodeGen/InstrScheduling.h"
#include "llvm/CodeGen/RegisterAllocation.h"
#include "llvm/CodeGen/MachineCodeForInstruction.h"
#include "llvm/Reoptimizer/Mapping/MappingInfo.h"
#include "llvm/Reoptimizer/Mapping/FInfo.h"
#include "Support/CommandLine.h"
using std::cerr;

static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
// Build the MachineInstruction Description Array...
const TargetInstrDescriptor SparcMachineInstrDesc[] = {
#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
          NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS)             \
  { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE,             \
          NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS, 0,          \
          ImplicitRegUseList, ImplicitRegUseList },
#include "SparcInstr.def"
};

//---------------------------------------------------------------------------
// Command line options to control choice of code generation passes.
//---------------------------------------------------------------------------

static cl::opt<bool> DisablePreSelect("nopreselect",
                                      cl::desc("Disable preselection pass"));

static cl::opt<bool> DisableSched("nosched",
                                  cl::desc("Disable local scheduling pass"));

static cl::opt<bool> DisablePeephole("nopeephole",
                                cl::desc("Disable peephole optimization pass"));

//----------------------------------------------------------------------------
// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
//----------------------------------------------------------------------------

TargetMachine *allocateSparcTargetMachine(unsigned Configuration) {
  return new UltraSparc();
}

//---------------------------------------------------------------------------
// class UltraSparcFrameInfo
//
//   Interface to stack frame layout info for the UltraSPARC.
//   Starting offsets for each area of the stack frame are aligned at
//   a multiple of getStackFrameSizeAlignment().
//---------------------------------------------------------------------------

int
UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& ,
                                                bool& pos) const
{
  pos = false;                          // static stack area grows downwards
  return StaticAreaOffsetFromFP;
}

int
UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo,
                                           bool& pos) const
{
  // ensure no more auto vars are added
  mcInfo.getInfo()->freezeAutomaticVarsArea();

  pos = false;                          // static stack area grows downwards
  unsigned autoVarsSize = mcInfo.getInfo()->getAutomaticVarsSize();
  return StaticAreaOffsetFromFP - autoVarsSize;
}

int
UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo,
                                      bool& pos) const
{
  MachineFunctionInfo *MFI = mcInfo.getInfo();
  MFI->freezeAutomaticVarsArea();     // ensure no more auto vars are added
  MFI->freezeSpillsArea();            // ensure no more spill slots are added

  pos = false;                          // static stack area grows downwards
  unsigned autoVarsSize = MFI->getAutomaticVarsSize();
  unsigned spillAreaSize = MFI->getRegSpillsSize();
  int offset = autoVarsSize + spillAreaSize;
  return StaticAreaOffsetFromFP - offset;
}

int
UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
                                          bool& pos) const
{
  // Dynamic stack area grows downwards starting at top of opt-args area.
  // The opt-args, required-args, and register-save areas are empty except
  // during calls and traps, so they are shifted downwards on each
  // dynamic-size alloca.
  pos = false;
  unsigned optArgsSize = mcInfo.getInfo()->getMaxOptionalArgsSize();
  if (int extra = optArgsSize % getStackFrameSizeAlignment())
    optArgsSize += (getStackFrameSizeAlignment() - extra);
  int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
  assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
  return offset;
}

//---------------------------------------------------------------------------
// class UltraSparcMachine
//
// Purpose:
//   Primary interface to machine description for the UltraSPARC.
//   Primarily just initializes machine-dependent parameters in
//   class TargetMachine, and creates machine-dependent subclasses
//   for classes such as TargetInstrInfo.
//
//---------------------------------------------------------------------------

UltraSparc::UltraSparc()
  : TargetMachine("UltraSparc-Native", false),
    schedInfo(*this),
    regInfo(*this),
    frameInfo(*this),
    cacheInfo(*this),
    optInfo(*this) {
}

// addPassesToEmitAssembly - This method controls the entire code generation
// process for the ultra sparc.
//
bool UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
{
  // FIXME: implement the switch instruction in the instruction selector.
  PM.add(createLowerSwitchPass());

  // Construct and initialize the MachineFunction object for this fn.
  PM.add(createMachineCodeConstructionPass(*this));

  //Insert empty stackslots in the stack frame of each function
  //so %fp+offset-8 and %fp+offset-16 are empty slots now!
  PM.add(createStackSlotsPass(*this));

  // Specialize LLVM code for this target machine and then
  // run basic dataflow optimizations on LLVM code.
  if (!DisablePreSelect) {
    PM.add(createPreSelectionPass(*this));
    PM.add(createReassociatePass());
    PM.add(createLICMPass());
    PM.add(createGCSEPass());
  }

  PM.add(createInstructionSelectionPass(*this));

  if (!DisableSched)
    PM.add(createInstructionSchedulingWithSSAPass(*this));

  PM.add(getRegisterAllocator(*this));

  PM.add(getPrologEpilogInsertionPass());

  if (!DisablePeephole)
    PM.add(createPeepholeOptsPass(*this));

  PM.add(MappingInfoForFunction(Out));

  // Output assembly language to the .s file.  Assembly emission is split into
  // two parts: Function output and Global value output.  This is because
  // function output is pipelined with all of the rest of code generation stuff,
  // allowing machine code representations for functions to be free'd after the
  // function has been emitted.
  //
  PM.add(getFunctionAsmPrinterPass(Out));
  PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed

  // Emit Module level assembly after all of the functions have been processed.
  PM.add(getModuleAsmPrinterPass(Out));

  // Emit bytecode to the assembly file into its special section next
  PM.add(getEmitBytecodeToAsmPass(Out));
  PM.add(getFunctionInfo(Out));
  return false;
}

// addPassesToJITCompile - This method controls the JIT method of code
// generation for the UltraSparc.
//
bool UltraSparc::addPassesToJITCompile(PassManager &PM) {
  // FIXME: implement the switch instruction in the instruction selector.
  PM.add(createLowerSwitchPass());

  // Construct and initialize the MachineFunction object for this fn.
  PM.add(createMachineCodeConstructionPass(*this));

  //Insert empty stackslots in the stack frame of each function
  //so %fp+offset-8 and %fp+offset-16 are empty slots now!
  PM.add(createStackSlotsPass(*this));

  // Specialize LLVM code for this target machine and then
  // run basic dataflow optimizations on LLVM code.
  if (!DisablePreSelect) {
    PM.add(createPreSelectionPass(*this));
    PM.add(createReassociatePass());
    PM.add(createLICMPass());
    PM.add(createGCSEPass());
  }

  PM.add(createInstructionSelectionPass(*this));

  if (!DisableSched)
    PM.add(createInstructionSchedulingWithSSAPass(*this));

  // new pass: convert Value* in MachineOperand to an unsigned register
  // this brings it in line with what the X86 JIT's RegisterAllocator expects
  //PM.add(createAddRegNumToValuesPass());

  PM.add(getRegisterAllocator(*this));
  PM.add(getPrologEpilogInsertionPass());

  if (!DisablePeephole)
    PM.add(createPeepholeOptsPass(*this));

  return false; // success!
}
<|endoftext|>


<commit_before>/**************************************************************************
 *
 * Copyright 2012 Jose Fonseca
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 **************************************************************************/

#include <string.h>

#include "pickle.hpp"

#include "os_binary.hpp"

#include "cli.hpp"
#include "cli_pager.hpp"

#include "trace_parser.hpp"
#include "trace_model.hpp"
#include "trace_callset.hpp"

using namespace trace;

class PickleVisitor : public trace::Visitor
{
protected:
    PickleWriter &writer;

public:
    PickleVisitor(PickleWriter &_writer) :
        writer(_writer) {
    }

    void visit(Null *node) {
        writer.writeInt(0);
    }

    void visit(Bool *node) {
        writer.writeBool(node->value);
    }

    void visit(SInt *node) {
        writer.writeInt(node->value);
    }

    void visit(UInt *node) {
        writer.writeInt(node->value);
    }

    void visit(Float *node) {
        writer.writeFloat(node->value);
    }

    void visit(Double *node) {
        writer.writeFloat(node->value);
    }

    void visit(String *node) {
        writer.writeString(node->value);
    }

    void visit(Enum *node) {
        // TODO: keep symbolic name
        writer.writeInt(node->value);
    }

    void visit(Bitmask *node) {
        // TODO: keep symbolic name
        writer.writeInt(node->value);
    }

    void visit(Struct *node) {
        writer.beginDict();
        for (unsigned i = 0; i < node->sig->num_members; ++i) {
            writer.beginItem(node->sig->member_names[i]);
            _visit(node->members[i]);
            writer.endItem();
        }
        writer.endDict();
    }

    void visit(Array *node) {
        writer.beginList();
        for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
            _visit(*it);
        }
        writer.endList();
    }

    void visit(Blob *node) {
        writer.writeString((const char *)node->buf, node->size);
    }

    void visit(Pointer *node) {
        writer.writeInt(node->value);
    }

    void visit(Call *call) {
        writer.beginTuple();

        writer.writeInt(call->no);

        writer.writeString(call->name());

        writer.beginList();
        for (unsigned i = 0; i < call->args.size(); ++i) {
            if (call->args[i].value) {
                _visit(call->args[i].value);
            } else {
                writer.writeNone();
            }
        }
        writer.endList();

        if (call->ret) {
            _visit(call->ret);
        } else {
            writer.writeNone();
        }

        writer.endTuple();
    }
};

static trace::CallSet calls(trace::FREQUENCY_ALL);

static const char *synopsis = "Pickle given trace(s) to standard output.";

static void
usage(void)
{
    std::cout
        << "usage: apitrace pickle [OPTIONS] <trace-file>...\n"
        << synopsis << "\n"
        "\n"
        "    --calls <CALLSET>   Only pickle specified calls\n"
    ;
}

static int
command(int argc, char *argv[])
{
    int i;

    for (i = 1; i < argc;) {
        const char *arg = argv[i];

        if (arg[0] != '-') {
            break;
        }

        ++i;

        if (!strcmp(arg, "--")) {
            break;
        } else if (!strcmp(arg, "--help")) {
            usage();
            return 0;
        } else if (!strcmp(arg, "--calls")) {
            calls = trace::CallSet(argv[i++]);
        } else {
            std::cerr << "error: unknown option " << arg << "\n";
            usage();
            return 1;
        }
    }

    os::setBinaryMode(stdout);

    for (; i < argc; ++i) {
        trace::Parser parser;

        if (!parser.open(argv[i])) {
            std::cerr << "error: failed to open " << argv[i] << "\n";
            return 1;
        }

        trace::Call *call;
        while ((call = parser.parse_call())) {
            if (calls.contains(*call)) {
                PickleWriter writer(std::cout);
                PickleVisitor visitor(writer);

                visitor.visit(call);
            }
            delete call;
        }
    }

    return 0;
}

const Command pickle_command = {
    "pickle",
    synopsis,
    usage,
    command
};
<commit_msg>Use getopt on apitrace pickle.<commit_after>/**************************************************************************
 *
 * Copyright 2012 Jose Fonseca
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 **************************************************************************/

#include <string.h>
#include <limits.h> // for CHAR_MAX
#include <getopt.h>

#include "pickle.hpp"

#include "os_binary.hpp"

#include "cli.hpp"
#include "cli_pager.hpp"

#include "trace_parser.hpp"
#include "trace_model.hpp"
#include "trace_callset.hpp"

using namespace trace;

class PickleVisitor : public trace::Visitor
{
protected:
    PickleWriter &writer;

public:
    PickleVisitor(PickleWriter &_writer) :
        writer(_writer) {
    }

    void visit(Null *node) {
        writer.writeInt(0);
    }

    void visit(Bool *node) {
        writer.writeBool(node->value);
    }

    void visit(SInt *node) {
        writer.writeInt(node->value);
    }

    void visit(UInt *node) {
        writer.writeInt(node->value);
    }

    void visit(Float *node) {
        writer.writeFloat(node->value);
    }

    void visit(Double *node) {
        writer.writeFloat(node->value);
    }

    void visit(String *node) {
        writer.writeString(node->value);
    }

    void visit(Enum *node) {
        // TODO: keep symbolic name
        writer.writeInt(node->value);
    }

    void visit(Bitmask *node) {
        // TODO: keep symbolic name
        writer.writeInt(node->value);
    }

    void visit(Struct *node) {
        writer.beginDict();
        for (unsigned i = 0; i < node->sig->num_members; ++i) {
            writer.beginItem(node->sig->member_names[i]);
            _visit(node->members[i]);
            writer.endItem();
        }
        writer.endDict();
    }

    void visit(Array *node) {
        writer.beginList();
        for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
            _visit(*it);
        }
        writer.endList();
    }

    void visit(Blob *node) {
        writer.writeString((const char *)node->buf, node->size);
    }

    void visit(Pointer *node) {
        writer.writeInt(node->value);
    }

    void visit(Call *call) {
        writer.beginTuple();

        writer.writeInt(call->no);

        writer.writeString(call->name());

        writer.beginList();
        for (unsigned i = 0; i < call->args.size(); ++i) {
            if (call->args[i].value) {
                _visit(call->args[i].value);
            } else {
                writer.writeNone();
            }
        }
        writer.endList();

        if (call->ret) {
            _visit(call->ret);
        } else {
            writer.writeNone();
        }

        writer.endTuple();
    }
};

static trace::CallSet calls(trace::FREQUENCY_ALL);

static const char *synopsis = "Pickle given trace(s) to standard output.";

static void
usage(void)
{
    std::cout
        << "usage: apitrace pickle [OPTIONS] TRACE_FILE...\n"
        << synopsis << "\n"
        "\n"
        "    -h, --help           show this help message and exit\n"
        "    --calls=CALLSET      only dump specified calls\n"
    ;
}

enum {
	CALLS_OPT = CHAR_MAX + 1,
};

const static char *
shortOptions = "h";

const static struct option
longOptions[] = {
    {"help", no_argument, 0, 'h'},
    {"calls", required_argument, 0, CALLS_OPT},
    {0, 0, 0, 0}
};

static int
command(int argc, char *argv[])
{
    int opt;
    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
        switch (opt) {
        case 'h':
            usage();
            return 0;
        case CALLS_OPT:
            calls = trace::CallSet(optarg);
            break;
        default:
            std::cerr << "error: unexpected option `" << opt << "`\n";
            usage();
            return 1;
        }
    }

    os::setBinaryMode(stdout);

    for (int i = optind; i < argc; ++i) {
        trace::Parser parser;

        if (!parser.open(argv[i])) {
            std::cerr << "error: failed to open " << argv[i] << "\n";
            return 1;
        }

        trace::Call *call;
        while ((call = parser.parse_call())) {
            if (calls.contains(*call)) {
                PickleWriter writer(std::cout);
                PickleVisitor visitor(writer);

                visitor.visit(call);
            }
            delete call;
        }
    }

    return 0;
}

const Command pickle_command = {
    "pickle",
    synopsis,
    usage,
    command
};
<|endoftext|>


<commit_before>/*
 * Fiahil
 * 12.05.2012
 */

#include <iostream>
#include <vector>
#include "APlayer.hpp"

APlayer::APlayer(Map & map)
  : _map(map),
    _pv(100),
    _id(0),
    _teamId(0),
    _color(0),
    _attack(false),
    _timers(5, -1.0),
    _weapon(BombType::NORMAL),
    _skin(Skin::NORMAL),
    _state(State::STATIC),
    _dir(Dir::SOUTH),
    _indic(0.5f, 0.5f, 0.8f, _color),
    _rotFuncMap(Dir::LAST, 0)
{
  this->_rotFuncMap[Dir::NORTH] = &APlayer::NORTHFunction;
  this->_rotFuncMap[Dir::SOUTH] = &APlayer::SOUTHFunction;
  this->_rotFuncMap[Dir::WEST] = &APlayer::WESTFunction;
  this->_rotFuncMap[Dir::EAST] = &APlayer::EASTFunction;
  this->_bombEffect[BombType::NORMAL] = &APlayer::normalBombEffect;
  this->_bombEffect[BombType::MEGABOMB] = &APlayer::megaBombEffect;
  this->_pos._scale = 2.0f;
  this->setPos(1, 1);
  this->_indic.setScale(2.0f);
  this->_indic.setPos(1, 1);
}

APlayer::~APlayer()
{
}

void		APlayer::initialize(void)
{
  std::vector<std::string>	refModel(Skin::LAST, "");

  refModel[Skin::NORMAL] = "models/Man.fbx";
  this->_model = gdl::Model::load(refModel[this->_skin]);
  this->_model.infos();
}

void		APlayer::draw(void)
{
  glPushMatrix();
  glTranslatef(this->_pos._pos.x, this->_pos._pos.y - 1.0f, this->_pos._pos.z);
  (this->*_rotFuncMap[this->_dir])();
  glScalef(0.05f, 0.05f, 0.05f);
  this->_model.draw();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0f, 3.0f, 0.0f);
  this->_indic.draw();
  glPopMatrix();
}

void		APlayer::update(gdl::GameClock const& clock, gdl::Input& input)
{
  this->play(clock, input);
  this->_model.update(clock);
  this->_indic.setPos(this->_pos._x, this->_pos._y);
}

void		APlayer::normalBombEffect()
{
  this->_pv -= 10;
  if (this->_pv < 0)
    this->_pv = 0;
}

void		APlayer::megaBombEffect()
{
  this->_pv -= 30;
  if (this->_pv < 0)
    this->_pv = 0;
}

void		APlayer::takeDamage(Pattern const& pattern, BombType::eBomb type)
{
  if (this->_pos._x >= (pattern._x - pattern._coefW) &&
      this->_pos._x <= (pattern._x + pattern._coefE) &&
      this->_pos._y >= (pattern._y - pattern._coefN) &&
      this->_pos._y <= (pattern._y + pattern._coefS))
    (this->*_bombEffect[type])();
}

void		APlayer::setPv(int pv)
{
  this->_pv = pv;
}

int		APlayer::getPv() const
{
  return this->_pv;
}

void		APlayer::setWeapon(BombType::eBomb weapon)
{
  this->_weapon = weapon;
}

BombType::eBomb	APlayer::getWeapon() const
{
  return this->_weapon;
}

void		APlayer::setTeamId(size_t team)
{
  this->_teamId = team;
}

size_t		APlayer::getTeamId() const
{
  return this->_teamId;
}

void		APlayer::setId(size_t id)
{
  this->_id = id;
}

size_t		APlayer::getId() const
{
  return this->_id;
}

size_t		APlayer::getColor() const
{
  return this->_color;
}

void		APlayer::setColor(size_t val)
{
  this->_color = val;
  this->_indic.setColor(val);
}

void		APlayer::setState(State::eState state)
{
  this->_state = state;
}

State::eState	APlayer::getState() const
{
  return this->_state;
}

void		APlayer::setSkin(Skin::eSkin skin)
{
  this->_skin = skin;
}

Skin::eSkin	APlayer::getSkin(void) const
{
  return this->_skin;
}

void		APlayer::setDir(Dir::eDir dir)
{
  this->_dir = dir;
}

Dir::eDir	APlayer::getDir() const
{
  return this->_dir;
}

size_t		APlayer::getType() const
{
  return this->_type;
}

void		APlayer::setType(size_t t)
{
  this->_type = t;
}

void		APlayer::setName(std::string const& name)
{
  this->_name = name;
}

void		APlayer::setTeamName(std::string const& name)
{
  this->_teamName = name;
}

std::string const&	APlayer::getName() const
{
  return this->_name;
}

std::string const&	APlayer::getTeamName() const
{
  return this->_teamName;
}

void		APlayer::UPFunction(gdl::GameClock const& clock)
{
  double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::UP])
    {
      this->_timers[HumGame::UP] = current + 0.1;
      this->_dir = Dir::NORTH;
      if (this->_map.canMoveAt(this->_pos._x, this->_pos._y - 1))
	this->_pos.setPos(this->_pos._x, this->_pos._y - 1);
    }
}

void		APlayer::LEFTFunction(gdl::GameClock const& clock)
{
  double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::LEFT])
    {
      this->_timers[HumGame::LEFT] = current + 0.1;
      this->_dir = Dir::WEST;
      if (this->_map.canMoveAt(this->_pos._x - 1, this->_pos._y))
	this->_pos.setPos(this->_pos._x - 1, this->_pos._y);
    }
}

void		APlayer::RIGHTFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::RIGHT])
    {
      this->_timers[HumGame::RIGHT] = current + 0.1;
      this->_dir = Dir::EAST;
      if (this->_map.canMoveAt(this->_pos._x + 1, this->_pos._y))
	this->_pos.setPos(this->_pos._x + 1, this->_pos._y);
    }
}

void		APlayer::DOWNFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::DOWN])
    {
      this->_timers[HumGame::DOWN] = current + 0.1;
      this->_dir = Dir::SOUTH;
      if (this->_map.canMoveAt(this->_pos._x, this->_pos._y + 1))
	this->_pos.setPos(this->_pos._x, this->_pos._y + 1);
    }
}

void		APlayer::ATTACKFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::ATTACK])
    {
      this->_timers[HumGame::ATTACK] = current + 1.5;
      this->_attack = true;
    }
}

Bomb*		APlayer::isAttack()
{
  if (!this->_attack)
    return 0;
  Bomb	*ret = new Bomb(this->_weapon, this->_pos, this->_id);
  ret->initialize();
  this->_attack = false;
  return ret;
}

void		APlayer::NORTHFunction()
{
  glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
}

void		APlayer::SOUTHFunction()
{
 glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);

}

void		APlayer::WESTFunction()
{
  glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
 }

void		APlayer::EASTFunction()
{
}
<commit_msg>rendu cool (possage bombe + destruction caisse + degat joueur)<commit_after>/*
 * Fiahil
 * 12.05.2012
 */

#include <iostream>
#include <vector>
#include "APlayer.hpp"

APlayer::APlayer(Map & map)
  : _map(map),
    _pv(100),
    _id(0),
    _teamId(0),
    _color(0),
    _attack(false),
    _timers(5, -1.0),
    _weapon(BombType::NORMAL),
    _skin(Skin::NORMAL),
    _state(State::STATIC),
    _dir(Dir::SOUTH),
    _indic(0.5f, 0.5f, 0.8f, _color),
    _rotFuncMap(Dir::LAST, 0)
{
  this->_rotFuncMap[Dir::NORTH] = &APlayer::NORTHFunction;
  this->_rotFuncMap[Dir::SOUTH] = &APlayer::SOUTHFunction;
  this->_rotFuncMap[Dir::WEST] = &APlayer::WESTFunction;
  this->_rotFuncMap[Dir::EAST] = &APlayer::EASTFunction;
  this->_bombEffect[BombType::NORMAL] = &APlayer::normalBombEffect;
  this->_bombEffect[BombType::MEGABOMB] = &APlayer::megaBombEffect;
  this->_pos._scale = 2.0f;
  this->setPos(1, 1);
  this->_indic.setScale(2.0f);
  this->_indic.setPos(1, 1);
}

APlayer::~APlayer()
{
}

void		APlayer::initialize(void)
{
  std::vector<std::string>	refModel(Skin::LAST, "");

  refModel[Skin::NORMAL] = "models/Man.fbx";
  this->_model = gdl::Model::load(refModel[this->_skin]);
  this->_model.infos();
}

void		APlayer::draw(void)
{
  glPushMatrix();
  glTranslatef(this->_pos._pos.x, this->_pos._pos.y - 1.0f, this->_pos._pos.z);
  (this->*_rotFuncMap[this->_dir])();
  glScalef(0.05f, 0.05f, 0.05f);
  this->_model.draw();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0f, 3.0f, 0.0f);
  this->_indic.draw();
  glPopMatrix();
}

void		APlayer::update(gdl::GameClock const& clock, gdl::Input& input)
{
  this->play(clock, input);
  this->_model.update(clock);
  this->_indic.setPos(this->_pos._x, this->_pos._y);
}

void		APlayer::normalBombEffect()
{
  this->_pv -= 10;
  if (this->_pv < 0)
    this->_pv = 0;
}

void		APlayer::megaBombEffect()
{
  this->_pv -= 30;
  if (this->_pv < 0)
    this->_pv = 0;
}

void		APlayer::takeDamage(Pattern const& pattern, BombType::eBomb type)
{
  if (this->_pos._x >= (pattern._x - pattern._coefW) &&
      this->_pos._x <= (pattern._x + pattern._coefE) &&
      this->_pos._y >= (pattern._y - pattern._coefN) &&
      this->_pos._y <= (pattern._y + pattern._coefS))
    (this->*_bombEffect[type])();
}

void		APlayer::setPv(int pv)
{
  this->_pv = pv;
}

int		APlayer::getPv() const
{
  return this->_pv;
}

void		APlayer::setWeapon(BombType::eBomb weapon)
{
  this->_weapon = weapon;
}

BombType::eBomb	APlayer::getWeapon() const
{
  return this->_weapon;
}

void		APlayer::setTeamId(size_t team)
{
  this->_teamId = team;
}

size_t		APlayer::getTeamId() const
{
  return this->_teamId;
}

void		APlayer::setId(size_t id)
{
  this->_id = id;
}

size_t		APlayer::getId() const
{
  return this->_id;
}

size_t		APlayer::getColor() const
{
  return this->_color;
}

void		APlayer::setColor(size_t val)
{
  this->_color = val;
  this->_indic.setColor(val);
}

void		APlayer::setState(State::eState state)
{
  this->_state = state;
}

State::eState	APlayer::getState() const
{
  return this->_state;
}

void		APlayer::setSkin(Skin::eSkin skin)
{
  this->_skin = skin;
}

Skin::eSkin	APlayer::getSkin(void) const
{
  return this->_skin;
}

void		APlayer::setDir(Dir::eDir dir)
{
  this->_dir = dir;
}

Dir::eDir	APlayer::getDir() const
{
  return this->_dir;
}

size_t		APlayer::getType() const
{
  return this->_type;
}

void		APlayer::setType(size_t t)
{
  this->_type = t;
}

void		APlayer::setName(std::string const& name)
{
  this->_name = name;
}

void		APlayer::setTeamName(std::string const& name)
{
  this->_teamName = name;
}

std::string const&	APlayer::getName() const
{
  return this->_name;
}

std::string const&	APlayer::getTeamName() const
{
  return this->_teamName;
}

void		APlayer::UPFunction(gdl::GameClock const& clock)
{
  double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::UP])
    {
      this->_timers[HumGame::UP] = current + 0.15;
      this->_dir = Dir::NORTH;
      if (this->_map.canMoveAt(this->_pos._x, this->_pos._y - 1))
	this->_pos.setPos(this->_pos._x, this->_pos._y - 1);
      this->_model.play("Take 001");
    }
}

void		APlayer::LEFTFunction(gdl::GameClock const& clock)
{
  double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::LEFT])
    {
      this->_timers[HumGame::LEFT] = current + 0.15;
      this->_dir = Dir::WEST;
      if (this->_map.canMoveAt(this->_pos._x - 1, this->_pos._y))
	this->_pos.setPos(this->_pos._x - 1, this->_pos._y);
      this->_model.play("Take 001");
    }
}

void		APlayer::RIGHTFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::RIGHT])
    {
      this->_timers[HumGame::RIGHT] = current + 0.15;
      this->_dir = Dir::EAST;
      if (this->_map.canMoveAt(this->_pos._x + 1, this->_pos._y))
	this->_pos.setPos(this->_pos._x + 1, this->_pos._y);
      this->_model.play("Take 001");
    }
}

void		APlayer::DOWNFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::DOWN])
    {
      this->_timers[HumGame::DOWN] = current + 0.15;
      this->_dir = Dir::SOUTH;
      if (this->_map.canMoveAt(this->_pos._x, this->_pos._y + 1))
	this->_pos.setPos(this->_pos._x, this->_pos._y + 1);
      this->_model.play("Take 001");
    }
}

void		APlayer::ATTACKFunction(gdl::GameClock const& clock)
{
   double	current;

  if ((current = static_cast<double>(clock.getTotalGameTime())) >=
      this->_timers[HumGame::ATTACK])
    {
      this->_timers[HumGame::ATTACK] = current + 1.5;
      this->_attack = true;
    }
}

Bomb*		APlayer::isAttack()
{
  if (!this->_attack)
    return 0;
  Bomb	*ret = new Bomb(this->_weapon, this->_pos, this->_id);
  ret->initialize();
  this->_attack = false;
  return ret;
}

void		APlayer::NORTHFunction()
{
  glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
}

void		APlayer::SOUTHFunction()
{
 glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);

}

void		APlayer::WESTFunction()
{
  glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
 }

void		APlayer::EASTFunction()
{
}
<|endoftext|>