<commit_before>/*************************************************************************
 *
 *  $RCSfile: xecontent.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2003-09-16 08:18:58 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

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

#ifndef SC_XECONTENT_HXX
#define SC_XECONTENT_HXX

#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif

#ifndef SC_XLCONTENT_HXX
#include "xlcontent.hxx"
#endif
#ifndef SC_XERECORD_HXX
#include "xerecord.hxx"
#endif
#ifndef SC_XEHELPER_HXX
#include "xehelper.hxx"
#endif

/* ============================================================================
Classes to export the big Excel document contents (related to several cells or
globals for the document).
- Shared string table
- Background bitmap
- Hyperlinks
- Label ranges
- Conditional formatting
- Data validation
- Web Queries
============================================================================ */

// Shared string table ========================================================

/** Provides export of the SST (shared string table) record.
    @descr  Contains all strings in the document and writes the SST. */
class XclExpSst : public XclExpRecordBase
{
private:
    ScfDelList< XclExpString >  maStringList; /// List with formatted and unformatted strings.

public:
    inline explicit             XclExpSst() {}
    virtual                     ~XclExpSst();

    /** Inserts a new string into the table.
        @return  The index of the string in the SST. */
    sal_uInt32                  Insert( XclExpString* pString );

    /** Writes the complete SST and EXTSST records. */
    virtual void                Save( XclExpStream& rStrm );
};

// Background bitmap ==========================================================

class Graphic;

/** Provides export of a background bitmap of a sheet. */
class XclExpBitmap : public XclExpRecord
{
private:
    const Graphic*              mpGraphic;      /// Pointer to the bitmap in a brush item.

public:
    explicit                    XclExpBitmap( const XclExpRoot& rRoot );

    /** Writes the BITMAP record, if mpGraphic points to a bitmap. */
    virtual void                Save( XclExpStream& rStrm );
};

// Hyperlinks =================================================================

class SvxURLField;
class INetURLObject;

/** Provides export of hyperlink data. */
class XclExpHyperlink : public XclExpRecord
{
private:
    typedef ::std::auto_ptr< String >   StringPtr;
    typedef ::std::auto_ptr< SvStream > SvStreamPtr;

private:
    ScAddress                   maPos;              /// Position of the hyperlink.
    sal_uInt32                  mnFlags;            /// Option flags.
    StringPtr                   mpRepr;             /// Cell representation text.
    SvStreamPtr                 mpVarData;          /// Buffer stream with variable data.

public:
    /** Constructs the HLINK record from an URL text field. */
    explicit                    XclExpHyperlink( const XclExpRoot& rRoot, const SvxURLField& rUrlField );
    virtual                     ~XclExpHyperlink();

    /** Sets the cell position of the hyperlink. */
    inline void                 SetPosition( const ScAddress& rPos ) { maPos = rPos; }

    /** Returns the cell representation text or NULL, if not available. */
    inline const String*        GetRepr() const { return mpRepr.get(); }

private:
    /** Builds path and file name from the passed URL object.
        @param rName  (out) The path + file name for export.
        @param rnLevel  (out) The parent directory level.
        @param rbRel  (out) true = path is relative. */
    void                        BuildFileName(
                                    String& rName, sal_uInt16& rnLevel, bool& rbRel,
                                    const INetURLObject& rUrlObj, const XclExpRoot& rRoot ) const;

    /** Writes the body of the HLINK record. */
    virtual void                WriteBody( XclExpStream& rStrm );
};

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

typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;

// Label ranges ===============================================================

/** Provides export of the row/column label range list of a sheet. */
class XclExpLabelranges : public XclExpRecord
{
public:
    /** Fills the cell range lists with all ranges of the current sheet. */
    explicit                    XclExpLabelranges( const XclExpRoot& rRoot );

    /** Writes the LABELRANGES record if it contains at least one range. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Fills the specified range list with all label headers of the current sheet.
        @param rRanges  The cell range list to fill.
        @param xLabelRangesRef  The core range list with all ranges.
        @param nTab  The current sheet index. */
    void                        FillRangeList( ScRangeList& rRanges, ScRangePairListRef xLabelRangesRef, sal_uInt16 nTab );

    /** Writes the body of the LABELRANGES record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    ScRangeList                 maRowRanges;    /// Cell range list for row labels.
    ScRangeList                 maColRanges;    /// Cell range list for column labels.
};

// Conditional formatting =====================================================

class ScCondFormatEntry;
class XclExpCF_Impl;

/** Represents a CF record that contains one condition of a conditional format. */
class XclExpCF : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry );
    virtual                     ~XclExpCF();

private:
    /** Writes the body of the CF record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef ::std::auto_ptr< XclExpCF_Impl > XclExpCF_ImplPtr;
    XclExpCF_ImplPtr            mpImpl;
};

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

class ScConditionalFormat;

/** Represents a CONDFMT record that contains all conditions of a conditional format.
    @descr  Contains the conditions which are stored in CF records. */
class XclExpCondfmt : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat );
    virtual                     ~XclExpCondfmt();

    /** Returns true, if this conditional format contains at least one cell range and CF record. */
    bool                        IsValid() const;

    /** Writes the CONDFMT record with following CF records, if there is valid data. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Writes the body of the CONDFMT record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpCF > XclExpCFList;

    XclExpCFList                maCFList;       /// List of CF records.
    ScRangeList                 maRanges;       /// Cell ranges for this conditional format.
};

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

/** Contains all conditional formats of a specific sheet. */
class XclExpCondFormatBuffer : public XclExpRecordBase
{
public:
    /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
    explicit                    XclExpCondFormatBuffer( const XclExpRoot& rRoot );

    /** Writes all contained CONDFMT records with their CF records. */
    virtual void                Save( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpCondfmt > XclExpCondfmtList;
    XclExpCondfmtList           maCondfmtList;  /// List of CONDFMT records.
};

// Data Validation ============================================================

class ScValidationData;

/** Provides export of the data of a DV record.
    @descr  This record contains the settings for a data validation. In detail
    this is a pointer to the core validation data and a cell range list with all
    affected cells. The handle index is used to optimize list search algorithm. */
class XclExpDV : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpDV( const XclExpRoot& rRoot, sal_uInt32 nHandle );

    /** Returns the core handle of the validation data. */
    inline sal_uInt32           GetHandle() const { return mnHandle; }

    /** Inserts a new cell range into the cell range list. */
    void                        InsertCellRange( const ScRange& rPos );
    /** Checks the record contents and crops the range list.
        @return  false = Do not write this record. */
    bool                        CheckWriteRecord();

private:
    /** Writes the body of the DV record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    ScRangeList                 maRanges;       /// A list with all affected cells.
    const ScValidationData*     mpValData;      /// Pointer to the core data (no ownership).
    sal_uInt32                  mnHandle;       /// The core handle for quick list search.
};

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

/** This class contains the DV record list following the DVAL record. */
class XclExpDval : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpDval( const XclExpRoot& rRoot );

    /** Inserts the specified cell range into the range list of the DV record with
        the specified handle. */
    void                        InsertCellRange( const ScRange& rRange, sal_uInt32 nHandle );

    /** Writes the DVAL record and the DV record list. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Searches for or creates a XclExpDV record object with the specified handle. */
    XclExpDV&                   SearchOrCreateDv( sal_uInt32 nHandle );

    /** Writes the body of the DVAL record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpDV > XclExpDVList;

    XclExpDVList                maDVList;       /// List of DV records
    XclExpDV*                   mpLastFoundDV;  /// For search optimization.
};

// Web Queries ================================================================

/** Contains all records for a web query (linked tables in an HTML document).
    @descr  mode 1 (entire document): mpQryTables==NULL, mbEntireDoc==true;
    mode 2 (all tables): mpQryTables==NULL, mbEntireDoc==false;
    mode 3 (custom range list): mpQryTables!=NULL, mbEntireDoc==false. */
class XclExpWebQuery : public XclExpRecordBase
{
public:
    /** Constructs a web query record container with settings from Calc. */
    explicit                    XclExpWebQuery(
                                    const String& rRangeName,
                                    const String& rUrl,
                                    const String& rSource,
                                    sal_Int32 nRefrSecs );
    virtual                     ~XclExpWebQuery();

    /** Writes all needed records for this web query. */
    virtual void                Save( XclExpStream& rStrm );

private:
    XclExpString                maDestRange;    /// Destination range.
    XclExpString                maUrl;          /// Source document URL.
    XclExpString*               mpQryTables;    /// List of source range names.
    sal_Int16                   mnRefresh;      /// Refresh time in minutes.
    bool                        mbEntireDoc;    /// true = entire document.
};

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

/** Contains all web query records for this document. */
class XclExpWebQueryBuffer : public XclExpRecordList< XclExpWebQuery >
{
public:
    explicit                    XclExpWebQueryBuffer( const XclExpRoot& rRoot );
};

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

#endif

<commit_msg>INTEGRATION: CWS calc17 (1.2.124); FILE MERGED 2003/09/22 16:54:41 dr 1.2.124.4: #100887# reduce SST with hash table 2003/09/19 07:43:15 dr 1.2.124.3: #100887# preparations for SST optimisation 2003/09/18 06:57:33 dr 1.2.124.2: RESYNC: (1.2-1.3); FILE MERGED 2003/08/18 14:14:35 dr 1.2.124.1: #111865# page settings reimplemented<commit_after>/*************************************************************************
 *
 *  $RCSfile: xecontent.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2003-11-05 13:39:52 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

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

#ifndef SC_XECONTENT_HXX
#define SC_XECONTENT_HXX

#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif

#ifndef SC_XLCONTENT_HXX
#include "xlcontent.hxx"
#endif
#ifndef SC_XEROOT_HXX
#include "xeroot.hxx"
#endif
#ifndef SC_XERECORD_HXX
#include "xerecord.hxx"
#endif
#ifndef SC_XESTRING_HXX
#include "xestring.hxx"
#endif

/* ============================================================================
Classes to export the big Excel document contents (related to several cells or
globals for the document).
- Shared string table
- Hyperlinks
- Label ranges
- Conditional formatting
- Data validation
- Web Queries
============================================================================ */

// Shared string table ========================================================

class XclExpSst_Impl;

/** Provides export of the SST (shared string table) record.
    @descr  Contains all strings in the document and writes the SST. */
class XclExpSst : public XclExpRecordBase
{
public:
    explicit                    XclExpSst();
    virtual                     ~XclExpSst();

    /** Inserts a new string into the table.
        @return  The index of the string in the SST, used in other records. */
    sal_uInt32                  Insert( XclExpStringPtr pString );

    /** Writes the complete SST and EXTSST records. */
    virtual void                Save( XclExpStream& rStrm );

private:
    typedef ::std::auto_ptr< XclExpSst_Impl > XclExpSst_ImplPtr;
    XclExpSst_ImplPtr           mpImpl;
};

// Hyperlinks =================================================================

class SvxURLField;
class INetURLObject;

/** Provides export of hyperlink data. */
class XclExpHyperlink : public XclExpRecord
{
public:
    /** Constructs the HLINK record from an URL text field. */
    explicit                    XclExpHyperlink( const XclExpRoot& rRoot, const SvxURLField& rUrlField );
    virtual                     ~XclExpHyperlink();

    /** Sets the cell position of the hyperlink. */
    inline void                 SetPosition( const ScAddress& rPos ) { maPos = rPos; }

    /** Returns the cell representation text or NULL, if not available. */
    inline const String*        GetRepr() const { return mpRepr.get(); }

private:
    /** Builds path and file name from the passed URL object.
        @param rName  (out) The path + file name for export.
        @param rnLevel  (out) The parent directory level.
        @param rbRel  (out) true = path is relative. */
    void                        BuildFileName(
                                    String& rName, sal_uInt16& rnLevel, bool& rbRel,
                                    const INetURLObject& rUrlObj, const XclExpRoot& rRoot ) const;

    /** Writes the body of the HLINK record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef ::std::auto_ptr< String >   StringPtr;
    typedef ::std::auto_ptr< SvStream > SvStreamPtr;

    ScAddress                   maPos;              /// Position of the hyperlink.
    StringPtr                   mpRepr;             /// Cell representation text.
    SvStreamPtr                 mpVarData;          /// Buffer stream with variable data.
    sal_uInt32                  mnFlags;            /// Option flags.
};

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

typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;

// Label ranges ===============================================================

/** Provides export of the row/column label range list of a sheet. */
class XclExpLabelranges : public XclExpRecord
{
public:
    /** Fills the cell range lists with all ranges of the current sheet. */
    explicit                    XclExpLabelranges( const XclExpRoot& rRoot );

    /** Writes the LABELRANGES record if it contains at least one range. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Fills the specified range list with all label headers of the current sheet.
        @param rRanges  The cell range list to fill.
        @param xLabelRangesRef  The core range list with all ranges.
        @param nTab  The current sheet index. */
    void                        FillRangeList( ScRangeList& rRanges, ScRangePairListRef xLabelRangesRef, sal_uInt16 nTab );

    /** Writes the body of the LABELRANGES record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    ScRangeList                 maRowRanges;    /// Cell range list for row labels.
    ScRangeList                 maColRanges;    /// Cell range list for column labels.
};

// Conditional formatting =====================================================

class ScCondFormatEntry;
class XclExpCF_Impl;

/** Represents a CF record that contains one condition of a conditional format. */
class XclExpCF : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry );
    virtual                     ~XclExpCF();

private:
    /** Writes the body of the CF record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef ::std::auto_ptr< XclExpCF_Impl > XclExpCF_ImplPtr;
    XclExpCF_ImplPtr            mpImpl;
};

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

class ScConditionalFormat;

/** Represents a CONDFMT record that contains all conditions of a conditional format.
    @descr  Contains the conditions which are stored in CF records. */
class XclExpCondfmt : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat );
    virtual                     ~XclExpCondfmt();

    /** Returns true, if this conditional format contains at least one cell range and CF record. */
    bool                        IsValid() const;

    /** Writes the CONDFMT record with following CF records, if there is valid data. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Writes the body of the CONDFMT record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpCF > XclExpCFList;

    XclExpCFList                maCFList;       /// List of CF records.
    ScRangeList                 maRanges;       /// Cell ranges for this conditional format.
};

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

/** Contains all conditional formats of a specific sheet. */
class XclExpCondFormatBuffer : public XclExpRecordBase
{
public:
    /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
    explicit                    XclExpCondFormatBuffer( const XclExpRoot& rRoot );

    /** Writes all contained CONDFMT records with their CF records. */
    virtual void                Save( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpCondfmt > XclExpCondfmtList;
    XclExpCondfmtList           maCondfmtList;  /// List of CONDFMT records.
};

// Data Validation ============================================================

class ScValidationData;

/** Provides export of the data of a DV record.
    @descr  This record contains the settings for a data validation. In detail
    this is a pointer to the core validation data and a cell range list with all
    affected cells. The handle index is used to optimize list search algorithm. */
class XclExpDV : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpDV( const XclExpRoot& rRoot, sal_uInt32 nHandle );

    /** Returns the core handle of the validation data. */
    inline sal_uInt32           GetHandle() const { return mnHandle; }

    /** Inserts a new cell range into the cell range list. */
    void                        InsertCellRange( const ScRange& rPos );
    /** Checks the record contents and crops the range list.
        @return  false = Do not write this record. */
    bool                        CheckWriteRecord();

private:
    /** Writes the body of the DV record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    ScRangeList                 maRanges;       /// A list with all affected cells.
    const ScValidationData*     mpValData;      /// Pointer to the core data (no ownership).
    sal_uInt32                  mnHandle;       /// The core handle for quick list search.
};

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

/** This class contains the DV record list following the DVAL record. */
class XclExpDval : public XclExpRecord, protected XclExpRoot
{
public:
    explicit                    XclExpDval( const XclExpRoot& rRoot );

    /** Inserts the specified cell range into the range list of the DV record with
        the specified handle. */
    void                        InsertCellRange( const ScRange& rRange, sal_uInt32 nHandle );

    /** Writes the DVAL record and the DV record list. */
    virtual void                Save( XclExpStream& rStrm );

private:
    /** Searches for or creates a XclExpDV record object with the specified handle. */
    XclExpDV&                   SearchOrCreateDv( sal_uInt32 nHandle );

    /** Writes the body of the DVAL record. */
    virtual void                WriteBody( XclExpStream& rStrm );

private:
    typedef XclExpRecordList< XclExpDV > XclExpDVList;

    XclExpDVList                maDVList;       /// List of DV records
    XclExpDV*                   mpLastFoundDV;  /// For search optimization.
};

// Web Queries ================================================================

/** Contains all records for a web query (linked tables in an HTML document).
    @descr  mode 1 (entire document): mpQryTables==NULL, mbEntireDoc==true;
    mode 2 (all tables): mpQryTables==NULL, mbEntireDoc==false;
    mode 3 (custom range list): mpQryTables!=NULL, mbEntireDoc==false. */
class XclExpWebQuery : public XclExpRecordBase
{
public:
    /** Constructs a web query record container with settings from Calc. */
    explicit                    XclExpWebQuery(
                                    const String& rRangeName,
                                    const String& rUrl,
                                    const String& rSource,
                                    sal_Int32 nRefrSecs );
    virtual                     ~XclExpWebQuery();

    /** Writes all needed records for this web query. */
    virtual void                Save( XclExpStream& rStrm );

private:
    XclExpString                maDestRange;    /// Destination range.
    XclExpString                maUrl;          /// Source document URL.
    XclExpStringPtr             mpQryTables;    /// List of source range names.
    sal_Int16                   mnRefresh;      /// Refresh time in minutes.
    bool                        mbEntireDoc;    /// true = entire document.
};

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

/** Contains all web query records for this document. */
class XclExpWebQueryBuffer : public XclExpRecordList< XclExpWebQuery >
{
public:
    explicit                    XclExpWebQueryBuffer( const XclExpRoot& rRoot );
};

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

#endif

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: xladdress.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: vg $ $Date: 2005-02-21 13:46:20 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef SC_XLADDRESS_HXX
#define SC_XLADDRESS_HXX

#include <vector>

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

class ScRangeList;
class XclImpStream;
class XclExpStream;

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

/** A 2D cell address struct with Excel column and row indexes. */
struct XclAddress
{
    sal_uInt16          mnCol;
    sal_uInt16          mnRow;

    inline explicit     XclAddress( ScAddress::Uninitialized ) {}
    inline explicit     XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
    inline explicit     XclAddress( sal_uInt16 nCol, sal_uInt16 nRow ) : mnCol( nCol ), mnRow( nRow ) {}

    inline void         Set( sal_uInt16 nCol, sal_uInt16 nRow ) { mnCol = nCol; mnRow = nRow; }

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
};

inline bool operator==( const XclAddress& rL, const XclAddress& rR )
{
    return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
}

inline XclImpStream& operator>>( XclImpStream& rStrm, XclAddress& rXclPos )
{
    rXclPos.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclAddress& rXclPos )
{
    rXclPos.Write( rStrm );
    return rStrm;
}

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

/** A 2D cell range address struct with Excel column and row indexes. */
struct XclRange
{
    XclAddress          maFirst;
    XclAddress          maLast;

    inline explicit     XclRange( ScAddress::Uninitialized e ) : maFirst( e ), maLast( e ) {}
    inline explicit     XclRange() {}
    inline explicit     XclRange( const XclAddress& rPos ) : maFirst( rPos ), maLast( rPos ) {}
    inline explicit     XclRange( const XclAddress& rFirst, const XclAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
    inline explicit     XclRange( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 ) :
                            maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}

    inline void         Set( const XclAddress& rFirst, const XclAddress& rLast )
                            { maFirst = rFirst; maLast = rLast; }
    inline void         Set( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 )
                            { maFirst.Set( nCol1, nRow1 ); maLast.Set( nCol2, nRow2 ); }

    inline sal_uInt16   GetColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
    inline sal_uInt16   GetRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
    bool                Contains( const XclAddress& rPos ) const;

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
};

inline bool operator==( const XclRange& rL, const XclRange& rR )
{
    return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
}

inline XclImpStream& operator>>( XclImpStream& rStrm, XclRange& rXclRange )
{
    rXclRange.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRange& rXclRange )
{
    rXclRange.Write( rStrm );
    return rStrm;
}

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

/** A 2D cell range address list with Excel column and row indexes. */
class XclRangeList : public ::std::vector< XclRange >
{
public:
    inline explicit     XclRangeList() {}

    XclRange            GetEnclosingRange() const;

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
    void                WriteSubList( XclExpStream& rStrm,
                            size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
};

inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
{
    rXclRanges.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRangeList& rXclRanges )
{
    rXclRanges.Write( rStrm );
    return rStrm;
}

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

class XclTracer;

/** Base class for import/export address converters. */
class XclAddressConverterBase
{
public:
    explicit            XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos );
    virtual             ~XclAddressConverterBase();

    /** Returns whether the "some columns have been cut" warning box should be shown. */
    inline bool         IsColTruncated() const { return mbColTrunc; }
    /** Returns whether the "some rows have been cut" warning box should be shown. */
    inline bool         IsRowTruncated() const { return mbRowTrunc; }
    /** Returns whether the "some sheets have been cut" warning box should be shown. */
    inline bool         IsTabTruncated() const { return mbTabTrunc; }

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

    /** Checks if the passed sheet index is valid.
        @param nScTab  The sheet index to check.
        @param bWarn  true = Sets the internal flag that produces a warning box
            after loading/saving the file, if the sheet index is not valid.
        @return  true = Sheet index in nScTab is valid. */
    bool                CheckScTab( SCTAB nScTab, bool bWarn );

    // ------------------------------------------------------------------------
protected:
    XclTracer&          mrTracer;       /// Tracer for invalid addresses.
    ScAddress           maMaxPos;       /// Default maximum position.
    sal_uInt16          mnMaxCol;       /// Maximum column index, as 16-bit value.
    sal_uInt16          mnMaxRow;       /// Maximum row index, as 16-bit value.
    bool                mbColTrunc;     /// Flag for "columns truncated" warning box.
    bool                mbRowTrunc;     /// Flag for "rows truncated" warning box.
    bool                mbTabTrunc;     /// Flag for "tables truncated" warning box.
};

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

#endif

<commit_msg>INTEGRATION: CWS calc31 (1.2.34); FILE MERGED 2005/03/22 10:49:32 dr 1.2.34.1: #110921# import/export of formatted hyperlinks<commit_after>/*************************************************************************
 *
 *  $RCSfile: xladdress.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-03-29 11:49:34 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef SC_XLADDRESS_HXX
#define SC_XLADDRESS_HXX

#include <vector>

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

class ScRangeList;
class XclImpStream;
class XclExpStream;

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

/** A 2D cell address struct with Excel column and row indexes. */
struct XclAddress
{
    sal_uInt16          mnCol;
    sal_uInt16          mnRow;

    inline explicit     XclAddress( ScAddress::Uninitialized ) {}
    inline explicit     XclAddress() : mnCol( 0 ), mnRow( 0 ) {}
    inline explicit     XclAddress( sal_uInt16 nCol, sal_uInt16 nRow ) : mnCol( nCol ), mnRow( nRow ) {}

    inline void         Set( sal_uInt16 nCol, sal_uInt16 nRow ) { mnCol = nCol; mnRow = nRow; }

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
};

inline bool operator==( const XclAddress& rL, const XclAddress& rR )
{
    return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
}

inline bool operator<( const XclAddress& rL, const XclAddress& rR )
{
    return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
}

inline XclImpStream& operator>>( XclImpStream& rStrm, XclAddress& rXclPos )
{
    rXclPos.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclAddress& rXclPos )
{
    rXclPos.Write( rStrm );
    return rStrm;
}

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

/** A 2D cell range address struct with Excel column and row indexes. */
struct XclRange
{
    XclAddress          maFirst;
    XclAddress          maLast;

    inline explicit     XclRange( ScAddress::Uninitialized e ) : maFirst( e ), maLast( e ) {}
    inline explicit     XclRange() {}
    inline explicit     XclRange( const XclAddress& rPos ) : maFirst( rPos ), maLast( rPos ) {}
    inline explicit     XclRange( const XclAddress& rFirst, const XclAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
    inline explicit     XclRange( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 ) :
                            maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}

    inline void         Set( const XclAddress& rFirst, const XclAddress& rLast )
                            { maFirst = rFirst; maLast = rLast; }
    inline void         Set( sal_uInt16 nCol1, sal_uInt16 nRow1, sal_uInt16 nCol2, sal_uInt16 nRow2 )
                            { maFirst.Set( nCol1, nRow1 ); maLast.Set( nCol2, nRow2 ); }

    inline sal_uInt16   GetColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
    inline sal_uInt16   GetRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
    bool                Contains( const XclAddress& rPos ) const;

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
};

inline bool operator==( const XclRange& rL, const XclRange& rR )
{
    return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
}

inline bool operator<( const XclRange& rL, const XclRange& rR )
{
    return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast));
}

inline XclImpStream& operator>>( XclImpStream& rStrm, XclRange& rXclRange )
{
    rXclRange.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRange& rXclRange )
{
    rXclRange.Write( rStrm );
    return rStrm;
}

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

/** A 2D cell range address list with Excel column and row indexes. */
class XclRangeList : public ::std::vector< XclRange >
{
public:
    inline explicit     XclRangeList() {}

    XclRange            GetEnclosingRange() const;

    void                Read( XclImpStream& rStrm, bool bCol16Bit = true );
    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
    void                WriteSubList( XclExpStream& rStrm,
                            size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
};

inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
{
    rXclRanges.Read( rStrm );
    return rStrm;
}

inline XclExpStream& operator<<( XclExpStream& rStrm, const XclRangeList& rXclRanges )
{
    rXclRanges.Write( rStrm );
    return rStrm;
}

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

class XclTracer;

/** Base class for import/export address converters. */
class XclAddressConverterBase
{
public:
    explicit            XclAddressConverterBase( XclTracer& rTracer, const ScAddress& rMaxPos );
    virtual             ~XclAddressConverterBase();

    /** Returns whether the "some columns have been cut" warning box should be shown. */
    inline bool         IsColTruncated() const { return mbColTrunc; }
    /** Returns whether the "some rows have been cut" warning box should be shown. */
    inline bool         IsRowTruncated() const { return mbRowTrunc; }
    /** Returns whether the "some sheets have been cut" warning box should be shown. */
    inline bool         IsTabTruncated() const { return mbTabTrunc; }

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

    /** Checks if the passed sheet index is valid.
        @param nScTab  The sheet index to check.
        @param bWarn  true = Sets the internal flag that produces a warning box
            after loading/saving the file, if the sheet index is not valid.
        @return  true = Sheet index in nScTab is valid. */
    bool                CheckScTab( SCTAB nScTab, bool bWarn );

    // ------------------------------------------------------------------------
protected:
    XclTracer&          mrTracer;       /// Tracer for invalid addresses.
    ScAddress           maMaxPos;       /// Default maximum position.
    sal_uInt16          mnMaxCol;       /// Maximum column index, as 16-bit value.
    sal_uInt16          mnMaxRow;       /// Maximum row index, as 16-bit value.
    bool                mbColTrunc;     /// Flag for "columns truncated" warning box.
    bool                mbRowTrunc;     /// Flag for "rows truncated" warning box.
    bool                mbTabTrunc;     /// Flag for "tables truncated" warning box.
};

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

#endif

<|endoftext|>


<commit_before>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// properties.cpp
//
// Identification: src/optimizer/properties.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "optimizer/properties.h"

#include "optimizer/property.h"
#include "optimizer/property_visitor.h"

namespace peloton {
namespace optimizer {

/*************** PropertyColumns *****************/

PropertyColumns::PropertyColumns(
    std::vector<std::shared_ptr<expression::AbstractExpression>> column_exprs)
    : column_exprs_(std::move(column_exprs)) {}

PropertyType PropertyColumns::Type() const { return PropertyType::COLUMNS; }

bool PropertyColumns::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::COLUMNS) {
    return false;
  }
  const PropertyColumns &r_columns =
      *reinterpret_cast<const PropertyColumns *>(&r);
  // lhs is less than rhs if size is smaller
  if (column_exprs_.size() < r_columns.column_exprs_.size()) {
    return false;
  }
  // check that every column in the right hand side property exists in the left
  // hand side property
  for (auto r_column : r_columns.column_exprs_) {
    bool has_column = false;
    for (auto column : column_exprs_) {
      if (column->Equals(r_column.get())) {
        has_column = true;
        break;
      }
    }
    if (has_column == false) return false;
  }

  return true;
}

bool PropertyColumns::HasStarExpression() const {
  for (auto expr : column_exprs_) {
    if (expr->GetExpressionType() == ExpressionType::STAR) return true;
  }
  return false;
}

hash_t PropertyColumns::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();
  for (auto expr : column_exprs_) {
    hash = HashUtil::SumHashes(hash, expr->Hash());
  }
  return hash;
}

void PropertyColumns::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyColumns *)this);
}

std::string PropertyColumns::ToString() const {
  std::string str = PropertyTypeToString(Type()) + ": ";
  for (auto column_expr : column_exprs_) {
    if (column_expr->GetExpressionType() == ExpressionType::VALUE_TUPLE) {
      str += ((expression::TupleValueExpression *)column_expr.get())
                 ->GetColumnName();
      str += " ";
    } else {
      column_expr->DeduceExpressionName();
      str += column_expr->GetExpressionName();
      str += " ";
    }
  }
  return str + "\n";
}

/*************** PropertyDistinct *****************/

PropertyDistinct::PropertyDistinct(
    std::vector<std::shared_ptr<expression::AbstractExpression>>
        distinct_column_exprs)
    : distinct_column_exprs_(std::move(distinct_column_exprs)) {
  LOG_TRACE("Size of column property: %ld", distinct_column_exprs_.size());
}

PropertyType PropertyDistinct::Type() const { return PropertyType::DISTINCT; }

bool PropertyDistinct::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::DISTINCT) return false;
  const PropertyDistinct &r_columns =
      *reinterpret_cast<const PropertyDistinct *>(&r);

  // check that every column in the left hand side property exists in the right
  // hand side property. which is the opposite to
  // the condition of propertyColumns
  // e.g. distinct(col_a) >= distinct(col_a, col_b)
  for (auto r_column : r_columns.distinct_column_exprs_) {
    bool has_column = false;
    for (auto column : distinct_column_exprs_) {
      if (column->Equals(r_column.get())) {
        has_column = true;
        break;
      }
    }
    if (has_column == false) return false;
  }

  return true;
}

hash_t PropertyDistinct::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();
  for (auto expr : distinct_column_exprs_) {
    hash = HashUtil::CombineHashes(hash, expr->Hash());
  }
  return hash;
}

void PropertyDistinct::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyDistinct *)this);
}

std::string PropertyDistinct::ToString() const {
  std::string str = PropertyTypeToString(Type()) + ": ";
  for (auto column_expr : distinct_column_exprs_) {
    if (column_expr->GetExpressionType() == ExpressionType::VALUE_TUPLE) {
      str += ((expression::TupleValueExpression *)column_expr.get())
                 ->GetColumnName();
      str += " ";
    } else {
      // TODO: Add support for other expression
      str += "expr ";
    }
  }
  return str + "\n";
}

/*************** PropertyLimit *****************/

PropertyType PropertyLimit::Type() const { return PropertyType::LIMIT; }

bool PropertyLimit::operator>=(const Property &r) const {
  if (r.Type() != PropertyType::LIMIT) return false;
  const PropertyLimit &r_limit = *reinterpret_cast<const PropertyLimit *>(&r);
  return offset_ == r_limit.offset_ && limit_ == r_limit.limit_;
}

hash_t PropertyLimit::Hash() const {
  hash_t hash = Property::Hash();
  HashUtil::CombineHashes(hash, offset_);
  HashUtil::CombineHashes(hash, limit_);
  return hash;
}

void PropertyLimit::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyLimit *)this);
}

std::string PropertyLimit::ToString() const {
  std::string res = PropertyTypeToString(Type());
  res += std::to_string(offset_) + " " + std::to_string(limit_) + "\n";
  return res;
}

/*************** PropertySort *****************/

PropertySort::PropertySort(
    std::vector<std::shared_ptr<expression::AbstractExpression>> sort_columns,
    std::vector<bool> sort_ascending)
    : sort_columns_(std::move(sort_columns)),
      sort_ascending_(std::move(sort_ascending)) {}

PropertyType PropertySort::Type() const { return PropertyType::SORT; }

bool PropertySort::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::SORT) return false;
  const PropertySort &r_sort = *reinterpret_cast<const PropertySort *>(&r);

  // All the sorting orders in r must be satisfied
  size_t num_sort_columns = r_sort.sort_columns_.size();
  PL_ASSERT(num_sort_columns == r_sort.sort_ascending_.size());
  for (size_t i = 0; i < num_sort_columns; ++i) {
    if (!sort_columns_[i]->Equals(r_sort.sort_columns_[i].get())) return false;
    if (sort_ascending_[i] != r_sort.sort_ascending_[i]) return false;
  }
  return true;
}

hash_t PropertySort::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();

  // hash sorting columns
  size_t num_sort_columns = sort_columns_.size();
  for (size_t i = 0; i < num_sort_columns; ++i) {
    hash = HashUtil::CombineHashes(hash, sort_columns_[i]->Hash());
    hash = HashUtil::CombineHashes(hash, sort_ascending_[i]);
  }
  return hash;
}

void PropertySort::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertySort *)this);
}

std::string PropertySort::ToString() const {
  return PropertyTypeToString(Type()) + "\n";
}

}  // namespace optimizer
}  // namespace peloton
<commit_msg>Modify logic for PropertySort::operator>=<commit_after>//===----------------------------------------------------------------------===//
//
//                         Peloton
//
// properties.cpp
//
// Identification: src/optimizer/properties.cpp
//
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "optimizer/properties.h"

#include "optimizer/property.h"
#include "optimizer/property_visitor.h"

namespace peloton {
namespace optimizer {

/*************** PropertyColumns *****************/

PropertyColumns::PropertyColumns(
    std::vector<std::shared_ptr<expression::AbstractExpression>> column_exprs)
    : column_exprs_(std::move(column_exprs)) {}

PropertyType PropertyColumns::Type() const { return PropertyType::COLUMNS; }

bool PropertyColumns::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::COLUMNS) {
    return false;
  }
  const PropertyColumns &r_columns =
      *reinterpret_cast<const PropertyColumns *>(&r);
  // lhs is less than rhs if size is smaller
  if (column_exprs_.size() < r_columns.column_exprs_.size()) {
    return false;
  }
  // check that every column in the right hand side property exists in the left
  // hand side property
  for (auto r_column : r_columns.column_exprs_) {
    bool has_column = false;
    for (auto column : column_exprs_) {
      if (column->Equals(r_column.get())) {
        has_column = true;
        break;
      }
    }
    if (has_column == false) return false;
  }

  return true;
}

bool PropertyColumns::HasStarExpression() const {
  for (auto expr : column_exprs_) {
    if (expr->GetExpressionType() == ExpressionType::STAR) return true;
  }
  return false;
}

hash_t PropertyColumns::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();
  for (auto expr : column_exprs_) {
    hash = HashUtil::SumHashes(hash, expr->Hash());
  }
  return hash;
}

void PropertyColumns::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyColumns *)this);
}

std::string PropertyColumns::ToString() const {
  std::string str = PropertyTypeToString(Type()) + ": ";
  for (auto column_expr : column_exprs_) {
    if (column_expr->GetExpressionType() == ExpressionType::VALUE_TUPLE) {
      str += ((expression::TupleValueExpression *)column_expr.get())
                 ->GetColumnName();
      str += " ";
    } else {
      column_expr->DeduceExpressionName();
      str += column_expr->GetExpressionName();
      str += " ";
    }
  }
  return str + "\n";
}

/*************** PropertyDistinct *****************/

PropertyDistinct::PropertyDistinct(std::vector<
    std::shared_ptr<expression::AbstractExpression>> distinct_column_exprs)
    : distinct_column_exprs_(std::move(distinct_column_exprs)) {
  LOG_TRACE("Size of column property: %ld", distinct_column_exprs_.size());
}

PropertyType PropertyDistinct::Type() const { return PropertyType::DISTINCT; }

bool PropertyDistinct::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::DISTINCT) return false;
  const PropertyDistinct &r_columns =
      *reinterpret_cast<const PropertyDistinct *>(&r);

  // check that every column in the left hand side property exists in the right
  // hand side property. which is the opposite to
  // the condition of propertyColumns
  // e.g. distinct(col_a) >= distinct(col_a, col_b)
  for (auto r_column : r_columns.distinct_column_exprs_) {
    bool has_column = false;
    for (auto column : distinct_column_exprs_) {
      if (column->Equals(r_column.get())) {
        has_column = true;
        break;
      }
    }
    if (has_column == false) return false;
  }

  return true;
}

hash_t PropertyDistinct::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();
  for (auto expr : distinct_column_exprs_) {
    hash = HashUtil::CombineHashes(hash, expr->Hash());
  }
  return hash;
}

void PropertyDistinct::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyDistinct *)this);
}

std::string PropertyDistinct::ToString() const {
  std::string str = PropertyTypeToString(Type()) + ": ";
  for (auto column_expr : distinct_column_exprs_) {
    if (column_expr->GetExpressionType() == ExpressionType::VALUE_TUPLE) {
      str += ((expression::TupleValueExpression *)column_expr.get())
                 ->GetColumnName();
      str += " ";
    } else {
      // TODO: Add support for other expression
      str += "expr ";
    }
  }
  return str + "\n";
}

/*************** PropertyLimit *****************/

PropertyType PropertyLimit::Type() const { return PropertyType::LIMIT; }

bool PropertyLimit::operator>=(const Property &r) const {
  if (r.Type() != PropertyType::LIMIT) return false;
  const PropertyLimit &r_limit = *reinterpret_cast<const PropertyLimit *>(&r);
  return offset_ == r_limit.offset_ && limit_ == r_limit.limit_;
}

hash_t PropertyLimit::Hash() const {
  hash_t hash = Property::Hash();
  HashUtil::CombineHashes(hash, offset_);
  HashUtil::CombineHashes(hash, limit_);
  return hash;
}

void PropertyLimit::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertyLimit *)this);
}

std::string PropertyLimit::ToString() const {
  std::string res = PropertyTypeToString(Type());
  res += std::to_string(offset_) + " " + std::to_string(limit_) + "\n";
  return res;
}

/*************** PropertySort *****************/

PropertySort::PropertySort(
    std::vector<std::shared_ptr<expression::AbstractExpression>> sort_columns,
    std::vector<bool> sort_ascending)
    : sort_columns_(std::move(sort_columns)),
      sort_ascending_(std::move(sort_ascending)) {}

PropertyType PropertySort::Type() const { return PropertyType::SORT; }

bool PropertySort::operator>=(const Property &r) const {
  // check the type
  if (r.Type() != PropertyType::SORT) return false;
  const PropertySort &r_sort = *reinterpret_cast<const PropertySort *>(&r);

  // All the sorting orders in r must be satisfied
  size_t l_num_sort_columns = sort_columns_.size();
  size_t r_num_sort_columns = r_sort.sort_columns_.size();
  PL_ASSERT(num_sort_columns == r_sort.sort_ascending_.size());
  size_t l_sort_col_idx = 0;
  // We want to ensure that Sort(a, b, c, d, e) >= Sort(a, c, e)
  for (size_t r_sort_col_idx = 0; r_sort_col_idx < r_num_sort_columns;
       ++r_sort_col_idx) {
    while (l_sort_col_idx < l_num_sort_columns &&
           !sort_columns_[l_sort_col_idx]->Equals(
               r_sort.sort_columns_[r_sort_col_idx].get())) {
      ++l_sort_col_idx;
    }
    if (l_sort_col_idx == l_num_sort_columns ||
        sort_ascending_[l_sort_col_idx] !=
            r_sort.sort_ascending_[r_sort_col_idx]) {
      return false;
    }
    ++l_sort_col_idx;
  }
  return true;
}

hash_t PropertySort::Hash() const {
  // hash the type
  hash_t hash = Property::Hash();

  // hash sorting columns
  size_t num_sort_columns = sort_columns_.size();
  for (size_t i = 0; i < num_sort_columns; ++i) {
    hash = HashUtil::CombineHashes(hash, sort_columns_[i]->Hash());
    hash = HashUtil::CombineHashes(hash, sort_ascending_[i]);
  }
  return hash;
}

void PropertySort::Accept(PropertyVisitor *v) const {
  v->Visit((const PropertySort *)this);
}

std::string PropertySort::ToString() const {
  return PropertyTypeToString(Type()) + "\n";
}

}  // namespace optimizer
}  // namespace peloton
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: drformsh.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: mh $ $Date: 2001-10-22 17:23:45 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

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

#include <svx/eeitem.hxx>
#include <svx/fontwork.hxx>
#include <svx/labdlg.hxx>
#include <svx/srchitem.hxx>
#include <svx/tabarea.hxx>
#include <svx/tabline.hxx>
#include <svx/textanim.hxx>
#include <svx/transfrm.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objface.hxx>
#include <sfx2/request.hxx>
#include <svtools/whiter.hxx>
#include <vcl/msgbox.hxx>

#include "drformsh.hxx"
#include "drwlayer.hxx"
#include "sc.hrc"
#include "viewdata.hxx"
#include "document.hxx"
#include "docpool.hxx"
#include "drawview.hxx"
#include "scresid.hxx"

#ifndef _SVDOBJ_HXX //autogen
#include <svx/svdobj.hxx>
#endif

#define ScDrawFormShell
#include "scslots.hxx"

SFX_IMPL_INTERFACE(ScDrawFormShell, ScDrawShell, ScResId(SCSTR_DRAWFORMSHELL) )
{
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
                                ScResId(RID_OBJECTBAR_DRAWFORM) );
    SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAWFORM) );
    SFX_OBJECTMENU_REGISTRATION( SID_OBJECTMENU0, ScResId(RID_OBJECTMENU_DRAWFORM) );
}

TYPEINIT1( ScDrawFormShell, ScDrawShell );

ScDrawFormShell::ScDrawFormShell(ScViewData* pData) :
    ScDrawShell(pData)
{
    SetHelpId(HID_SCSHELL_DRAWFORMSH);
    SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("DrawForm")));
}

ScDrawFormShell::~ScDrawFormShell()
{
}

<commit_msg>INTEGRATION: CWS dialogdiet (1.3.318); FILE MERGED 2004/01/13 02:56:42 mwu 1.3.318.2: DialogDiet 2004_01_13 2003/11/28 15:35:53 mba 1.3.318.1: #i22969#: obsolete include<commit_after>/*************************************************************************
 *
 *  $RCSfile: drformsh.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2004-02-03 20:31:57 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

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

#include <svx/eeitem.hxx>
#include <svx/fontwork.hxx>
//CHINA001 #include <svx/labdlg.hxx>
#include <svx/srchitem.hxx>
#include <svx/tabarea.hxx>
#include <svx/tabline.hxx>
//CHINA001 #include <svx/transfrm.hxx>
#include <sfx2/app.hxx>
#include <sfx2/objface.hxx>
#include <sfx2/request.hxx>
#include <svtools/whiter.hxx>
#include <vcl/msgbox.hxx>

#include "drformsh.hxx"
#include "drwlayer.hxx"
#include "sc.hrc"
#include "viewdata.hxx"
#include "document.hxx"
#include "docpool.hxx"
#include "drawview.hxx"
#include "scresid.hxx"

#ifndef _SVDOBJ_HXX //autogen
#include <svx/svdobj.hxx>
#endif

#define ScDrawFormShell
#include "scslots.hxx"

SFX_IMPL_INTERFACE(ScDrawFormShell, ScDrawShell, ScResId(SCSTR_DRAWFORMSHELL) )
{
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
                                ScResId(RID_OBJECTBAR_DRAWFORM) );
    SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAWFORM) );
    SFX_OBJECTMENU_REGISTRATION( SID_OBJECTMENU0, ScResId(RID_OBJECTMENU_DRAWFORM) );
}

TYPEINIT1( ScDrawFormShell, ScDrawShell );

ScDrawFormShell::ScDrawFormShell(ScViewData* pData) :
    ScDrawShell(pData)
{
    SetHelpId(HID_SCSHELL_DRAWFORMSH);
    SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("DrawForm")));
}

ScDrawFormShell::~ScDrawFormShell()
{
}

<|endoftext|>


<commit_before>/*
 * Copyright 2009 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBitmapProcState_opts_SSE2.h"
#include "SkBitmapProcState_opts_SSSE3.h"
#include "SkBitmapFilter_opts_SSE2.h"
#include "SkBlitMask.h"
#include "SkBlitRow.h"
#include "SkBlitRect_opts_SSE2.h"
#include "SkBlitRow_opts_SSE2.h"
#include "SkBlurImage_opts_SSE2.h"
#include "SkUtils_opts_SSE2.h"
#include "SkUtils.h"
#include "SkMorphology_opts.h"
#include "SkMorphology_opts_SSE2.h"
#include "SkXfermode.h"
#include "SkXfermode_proccoeff.h"

#include "SkRTConf.h"

#if defined(_MSC_VER) && defined(_WIN64)
#include <intrin.h>
#endif

/* This file must *not* be compiled with -msse or -msse2, otherwise
   gcc may generate sse2 even for scalar ops (and thus give an invalid
   instruction on Pentium3 on the code below).  Only files named *_SSE2.cpp
   in this directory should be compiled with -msse2. */

#ifdef _MSC_VER
static inline void getcpuid(int info_type, int info[4]) {
#if defined(_WIN64)
    __cpuid(info, info_type);
#else
    __asm {
        mov    eax, [info_type]
        cpuid
        mov    edi, [info]
        mov    [edi], eax
        mov    [edi+4], ebx
        mov    [edi+8], ecx
        mov    [edi+12], edx
    }
#endif
}
#else
#if defined(__x86_64__)
static inline void getcpuid(int info_type, int info[4]) {
    asm volatile (
        "cpuid \n\t"
        : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
        : "a"(info_type)
    );
}
#else
static inline void getcpuid(int info_type, int info[4]) {
    // We save and restore ebx, so this code can be compatible with -fPIC
    asm volatile (
        "pushl %%ebx      \n\t"
        "cpuid            \n\t"
        "movl %%ebx, %1   \n\t"
        "popl %%ebx       \n\t"
        : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
        : "a"(info_type)
    );
}
#endif
#endif

#if defined(__x86_64__) || defined(_WIN64) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
/* All x86_64 machines have SSE2, or we know it's supported at compile time,  so don't even bother checking. */
static inline bool hasSSE2() {
    return true;
}
#else

static inline bool hasSSE2() {
    int cpu_info[4] = { 0 };
    getcpuid(1, cpu_info);
    return (cpu_info[3] & (1<<26)) != 0;
}
#endif

#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
/* If we know SSSE3 is supported at compile time, don't even bother checking. */
static inline bool hasSSSE3() {
    return true;
}
#else

static inline bool hasSSSE3() {
    int cpu_info[4] = { 0 };
    getcpuid(1, cpu_info);
    return (cpu_info[2] & 0x200) != 0;
}
#endif

static bool cachedHasSSE2() {
    static bool gHasSSE2 = hasSSE2();
    return gHasSSE2;
}

static bool cachedHasSSSE3() {
    static bool gHasSSSE3 = hasSSSE3();
    return gHasSSSE3;
}

SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", false, "Use SSE optimized version of high quality image filters");

void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) {
    if (cachedHasSSE2()) {
        procs->fExtraHorizontalReads = 3;
        procs->fConvolveVertically = &convolveVertically_SSE2;
        procs->fConvolve4RowsHorizontally = &convolve4RowsHorizontally_SSE2;
        procs->fConvolveHorizontally = &convolveHorizontally_SSE2;
        procs->fApplySIMDPadding = &applySIMDPadding_SSE2;
    }
}

void SkBitmapProcState::platformProcs() {
    if (cachedHasSSSE3()) {
        if (fSampleProc32 == S32_opaque_D32_filter_DX) {
            fSampleProc32 = S32_opaque_D32_filter_DX_SSSE3;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
            fSampleProc32 = S32_alpha_D32_filter_DX_SSSE3;
        }

        if (fSampleProc32 == S32_opaque_D32_filter_DXDY) {
            fSampleProc32 = S32_opaque_D32_filter_DXDY_SSSE3;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DXDY) {
            fSampleProc32 = S32_alpha_D32_filter_DXDY_SSSE3;
        }
    } else if (cachedHasSSE2()) {
        if (fSampleProc32 == S32_opaque_D32_filter_DX) {
            fSampleProc32 = S32_opaque_D32_filter_DX_SSE2;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
            fSampleProc32 = S32_alpha_D32_filter_DX_SSE2;
        }

        if (fSampleProc16 == S32_D16_filter_DX) {
            fSampleProc16 = S32_D16_filter_DX_SSE2;
        }
    }

    if (cachedHasSSSE3() || cachedHasSSE2()) {
        if (fMatrixProc == ClampX_ClampY_filter_scale) {
            fMatrixProc = ClampX_ClampY_filter_scale_SSE2;
        } else if (fMatrixProc == ClampX_ClampY_nofilter_scale) {
            fMatrixProc = ClampX_ClampY_nofilter_scale_SSE2;
        }

        if (fMatrixProc == ClampX_ClampY_filter_affine) {
            fMatrixProc = ClampX_ClampY_filter_affine_SSE2;
        } else if (fMatrixProc == ClampX_ClampY_nofilter_affine) {
            fMatrixProc = ClampX_ClampY_nofilter_affine_SSE2;
        }
        if (c_hqfilter_sse) {
            if (fShaderProc32 == highQualityFilter32) {
                fShaderProc32 = highQualityFilter_SSE2;
            }
        }
    }
}

static SkBlitRow::Proc platform_16_procs[] = {
    S32_D565_Opaque_SSE2,               // S32_D565_Opaque
    NULL,                               // S32_D565_Blend
    S32A_D565_Opaque_SSE2,              // S32A_D565_Opaque
    NULL,                               // S32A_D565_Blend
    S32_D565_Opaque_Dither_SSE2,        // S32_D565_Opaque_Dither
    NULL,                               // S32_D565_Blend_Dither
    S32A_D565_Opaque_Dither_SSE2,       // S32A_D565_Opaque_Dither
    NULL,                               // S32A_D565_Blend_Dither
};

static SkBlitRow::Proc32 platform_32_procs[] = {
    NULL,                               // S32_Opaque,
    S32_Blend_BlitRow32_SSE2,           // S32_Blend,
    S32A_Opaque_BlitRow32_SSE2,         // S32A_Opaque
    S32A_Blend_BlitRow32_SSE2,          // S32A_Blend,
};

SkBlitRow::Proc SkBlitRow::PlatformProcs565(unsigned flags) {
    if (cachedHasSSE2()) {
        return platform_16_procs[flags];
    } else {
        return NULL;
    }
}

SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
    if (cachedHasSSE2()) {
        return Color32_SSE2;
    } else {
        return NULL;
    }
}

SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
    if (cachedHasSSE2()) {
        return platform_32_procs[flags];
    } else {
        return NULL;
    }
}

SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkBitmap::Config dstConfig,
                                                     SkMask::Format maskFormat,
                                                     SkColor color) {
    if (SkMask::kA8_Format != maskFormat) {
        return NULL;
    }

    ColorProc proc = NULL;
    if (cachedHasSSE2()) {
        switch (dstConfig) {
            case SkBitmap::kARGB_8888_Config:
                // The SSE2 version is not (yet) faster for black, so we check
                // for that.
                if (SK_ColorBLACK != color) {
                    proc = SkARGB32_A8_BlitMask_SSE2;
                }
                break;
            default:
                break;
        }
    }
    return proc;
}

SkBlitMask::BlitLCD16RowProc SkBlitMask::PlatformBlitRowProcs16(bool isOpaque) {
    if (cachedHasSSE2()) {
        if (isOpaque) {
            return SkBlitLCD16OpaqueRow_SSE2;
        } else {
            return SkBlitLCD16Row_SSE2;
        }
    } else {
        return NULL;
    }

}
SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkBitmap::Config dstConfig,
                                                 SkMask::Format maskFormat,
                                                 RowFlags flags) {
    return NULL;
}

SkMemset16Proc SkMemset16GetPlatformProc() {
    if (cachedHasSSE2()) {
        return sk_memset16_SSE2;
    } else {
        return NULL;
    }
}

SkMemset32Proc SkMemset32GetPlatformProc() {
    if (cachedHasSSE2()) {
        return sk_memset32_SSE2;
    } else {
        return NULL;
    }
}

SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
    if (!cachedHasSSE2()) {
        return NULL;
    }
    switch (type) {
        case kDilateX_SkMorphologyProcType:
            return SkDilateX_SSE2;
        case kDilateY_SkMorphologyProcType:
            return SkDilateY_SSE2;
        case kErodeX_SkMorphologyProcType:
            return SkErodeX_SSE2;
        case kErodeY_SkMorphologyProcType:
            return SkErodeY_SSE2;
        default:
            return NULL;
    }
}

bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
                               SkBoxBlurProc* boxBlurY,
                               SkBoxBlurProc* boxBlurXY,
                               SkBoxBlurProc* boxBlurYX) {
#ifdef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
    return false;
#else
    if (!cachedHasSSE2()) {
        return false;
    }
    return SkBoxBlurGetPlatformProcs_SSE2(boxBlurX, boxBlurY, boxBlurXY, boxBlurYX);
#endif
}

SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); // suppress warning

SkBlitRow::ColorRectProc PlatformColorRectProcFactory() {
    if (cachedHasSSE2()) {
        return ColorRect32_SSE2;
    } else {
        return NULL;
    }
}

extern SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
                                                                SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
                                                    SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
                                                    SkXfermode::Mode mode) {
    return NULL;
}

SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
                                               SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
                                               SkXfermode::Mode mode) {
    if (cachedHasSSE2()) {
        return SkPlatformXfermodeFactory_impl_SSE2(rec, mode);
    } else {
        return SkPlatformXfermodeFactory_impl(rec, mode);
    }
}

SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode);

SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode) {
    return NULL;
}
<commit_msg>fix x86 emulator for Android framework.<commit_after>/*
 * Copyright 2009 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkBitmapProcState_opts_SSE2.h"
#include "SkBitmapProcState_opts_SSSE3.h"
#include "SkBitmapFilter_opts_SSE2.h"
#include "SkBlitMask.h"
#include "SkBlitRow.h"
#include "SkBlitRect_opts_SSE2.h"
#include "SkBlitRow_opts_SSE2.h"
#include "SkBlurImage_opts_SSE2.h"
#include "SkUtils_opts_SSE2.h"
#include "SkUtils.h"
#include "SkMorphology_opts.h"
#include "SkMorphology_opts_SSE2.h"
#include "SkXfermode.h"
#include "SkXfermode_proccoeff.h"

#include "SkRTConf.h"

#if defined(_MSC_VER) && defined(_WIN64)
#include <intrin.h>
#endif

/* This file must *not* be compiled with -msse or -msse2, otherwise
   gcc may generate sse2 even for scalar ops (and thus give an invalid
   instruction on Pentium3 on the code below).  Only files named *_SSE2.cpp
   in this directory should be compiled with -msse2. */

#ifdef _MSC_VER
static inline void getcpuid(int info_type, int info[4]) {
#if defined(_WIN64)
    __cpuid(info, info_type);
#else
    __asm {
        mov    eax, [info_type]
        cpuid
        mov    edi, [info]
        mov    [edi], eax
        mov    [edi+4], ebx
        mov    [edi+8], ecx
        mov    [edi+12], edx
    }
#endif
}
#else
#if defined(__x86_64__)
static inline void getcpuid(int info_type, int info[4]) {
    asm volatile (
        "cpuid \n\t"
        : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
        : "a"(info_type)
    );
}
#else
static inline void getcpuid(int info_type, int info[4]) {
    // We save and restore ebx, so this code can be compatible with -fPIC
    asm volatile (
        "pushl %%ebx      \n\t"
        "cpuid            \n\t"
        "movl %%ebx, %1   \n\t"
        "popl %%ebx       \n\t"
        : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
        : "a"(info_type)
    );
}
#endif
#endif

#if defined(__x86_64__) || defined(_WIN64) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
/* All x86_64 machines have SSE2, or we know it's supported at compile time,  so don't even bother checking. */
static inline bool hasSSE2() {
    return true;
}
#else

static inline bool hasSSE2() {
    int cpu_info[4] = { 0 };
    getcpuid(1, cpu_info);
    return (cpu_info[3] & (1<<26)) != 0;
}
#endif

#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
/* If we know SSSE3 is supported at compile time, don't even bother checking. */
static inline bool hasSSSE3() {
    return true;
}
#elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
/* For the Android framework we should always know at compile time if the device
 * we are building for supports SSSE3.  The one exception to this rule is on the
 * emulator where we are compiled without the -msse3 option (so we have no SSSE3
 * procs) but can be run on a host machine that supports SSSE3 instructions. So
 * for that particular case we disable our SSSE3 options.
 */
static inline bool hasSSSE3() {
    return false;
}
#else

static inline bool hasSSSE3() {
    int cpu_info[4] = { 0 };
    getcpuid(1, cpu_info);
    return (cpu_info[2] & 0x200) != 0;
}
#endif

static bool cachedHasSSE2() {
    static bool gHasSSE2 = hasSSE2();
    return gHasSSE2;
}

static bool cachedHasSSSE3() {
    static bool gHasSSSE3 = hasSSSE3();
    return gHasSSSE3;
}

SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", false, "Use SSE optimized version of high quality image filters");

void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) {
    if (cachedHasSSE2()) {
        procs->fExtraHorizontalReads = 3;
        procs->fConvolveVertically = &convolveVertically_SSE2;
        procs->fConvolve4RowsHorizontally = &convolve4RowsHorizontally_SSE2;
        procs->fConvolveHorizontally = &convolveHorizontally_SSE2;
        procs->fApplySIMDPadding = &applySIMDPadding_SSE2;
    }
}

void SkBitmapProcState::platformProcs() {
    if (cachedHasSSSE3()) {
        if (fSampleProc32 == S32_opaque_D32_filter_DX) {
            fSampleProc32 = S32_opaque_D32_filter_DX_SSSE3;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
            fSampleProc32 = S32_alpha_D32_filter_DX_SSSE3;
        }

        if (fSampleProc32 == S32_opaque_D32_filter_DXDY) {
            fSampleProc32 = S32_opaque_D32_filter_DXDY_SSSE3;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DXDY) {
            fSampleProc32 = S32_alpha_D32_filter_DXDY_SSSE3;
        }
    } else if (cachedHasSSE2()) {
        if (fSampleProc32 == S32_opaque_D32_filter_DX) {
            fSampleProc32 = S32_opaque_D32_filter_DX_SSE2;
        } else if (fSampleProc32 == S32_alpha_D32_filter_DX) {
            fSampleProc32 = S32_alpha_D32_filter_DX_SSE2;
        }

        if (fSampleProc16 == S32_D16_filter_DX) {
            fSampleProc16 = S32_D16_filter_DX_SSE2;
        }
    }

    if (cachedHasSSSE3() || cachedHasSSE2()) {
        if (fMatrixProc == ClampX_ClampY_filter_scale) {
            fMatrixProc = ClampX_ClampY_filter_scale_SSE2;
        } else if (fMatrixProc == ClampX_ClampY_nofilter_scale) {
            fMatrixProc = ClampX_ClampY_nofilter_scale_SSE2;
        }

        if (fMatrixProc == ClampX_ClampY_filter_affine) {
            fMatrixProc = ClampX_ClampY_filter_affine_SSE2;
        } else if (fMatrixProc == ClampX_ClampY_nofilter_affine) {
            fMatrixProc = ClampX_ClampY_nofilter_affine_SSE2;
        }
        if (c_hqfilter_sse) {
            if (fShaderProc32 == highQualityFilter32) {
                fShaderProc32 = highQualityFilter_SSE2;
            }
        }
    }
}

static SkBlitRow::Proc platform_16_procs[] = {
    S32_D565_Opaque_SSE2,               // S32_D565_Opaque
    NULL,                               // S32_D565_Blend
    S32A_D565_Opaque_SSE2,              // S32A_D565_Opaque
    NULL,                               // S32A_D565_Blend
    S32_D565_Opaque_Dither_SSE2,        // S32_D565_Opaque_Dither
    NULL,                               // S32_D565_Blend_Dither
    S32A_D565_Opaque_Dither_SSE2,       // S32A_D565_Opaque_Dither
    NULL,                               // S32A_D565_Blend_Dither
};

static SkBlitRow::Proc32 platform_32_procs[] = {
    NULL,                               // S32_Opaque,
    S32_Blend_BlitRow32_SSE2,           // S32_Blend,
    S32A_Opaque_BlitRow32_SSE2,         // S32A_Opaque
    S32A_Blend_BlitRow32_SSE2,          // S32A_Blend,
};

SkBlitRow::Proc SkBlitRow::PlatformProcs565(unsigned flags) {
    if (cachedHasSSE2()) {
        return platform_16_procs[flags];
    } else {
        return NULL;
    }
}

SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
    if (cachedHasSSE2()) {
        return Color32_SSE2;
    } else {
        return NULL;
    }
}

SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
    if (cachedHasSSE2()) {
        return platform_32_procs[flags];
    } else {
        return NULL;
    }
}

SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkBitmap::Config dstConfig,
                                                     SkMask::Format maskFormat,
                                                     SkColor color) {
    if (SkMask::kA8_Format != maskFormat) {
        return NULL;
    }

    ColorProc proc = NULL;
    if (cachedHasSSE2()) {
        switch (dstConfig) {
            case SkBitmap::kARGB_8888_Config:
                // The SSE2 version is not (yet) faster for black, so we check
                // for that.
                if (SK_ColorBLACK != color) {
                    proc = SkARGB32_A8_BlitMask_SSE2;
                }
                break;
            default:
                break;
        }
    }
    return proc;
}

SkBlitMask::BlitLCD16RowProc SkBlitMask::PlatformBlitRowProcs16(bool isOpaque) {
    if (cachedHasSSE2()) {
        if (isOpaque) {
            return SkBlitLCD16OpaqueRow_SSE2;
        } else {
            return SkBlitLCD16Row_SSE2;
        }
    } else {
        return NULL;
    }

}
SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkBitmap::Config dstConfig,
                                                 SkMask::Format maskFormat,
                                                 RowFlags flags) {
    return NULL;
}

SkMemset16Proc SkMemset16GetPlatformProc() {
    if (cachedHasSSE2()) {
        return sk_memset16_SSE2;
    } else {
        return NULL;
    }
}

SkMemset32Proc SkMemset32GetPlatformProc() {
    if (cachedHasSSE2()) {
        return sk_memset32_SSE2;
    } else {
        return NULL;
    }
}

SkMorphologyImageFilter::Proc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
    if (!cachedHasSSE2()) {
        return NULL;
    }
    switch (type) {
        case kDilateX_SkMorphologyProcType:
            return SkDilateX_SSE2;
        case kDilateY_SkMorphologyProcType:
            return SkDilateY_SSE2;
        case kErodeX_SkMorphologyProcType:
            return SkErodeX_SSE2;
        case kErodeY_SkMorphologyProcType:
            return SkErodeY_SSE2;
        default:
            return NULL;
    }
}

bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
                               SkBoxBlurProc* boxBlurY,
                               SkBoxBlurProc* boxBlurXY,
                               SkBoxBlurProc* boxBlurYX) {
#ifdef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
    return false;
#else
    if (!cachedHasSSE2()) {
        return false;
    }
    return SkBoxBlurGetPlatformProcs_SSE2(boxBlurX, boxBlurY, boxBlurXY, boxBlurYX);
#endif
}

SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); // suppress warning

SkBlitRow::ColorRectProc PlatformColorRectProcFactory() {
    if (cachedHasSSE2()) {
        return ColorRect32_SSE2;
    } else {
        return NULL;
    }
}

extern SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
                                                                SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
                                                    SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl(const ProcCoeff& rec,
                                                    SkXfermode::Mode mode) {
    return NULL;
}

SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
                                               SkXfermode::Mode mode);

SkProcCoeffXfermode* SkPlatformXfermodeFactory(const ProcCoeff& rec,
                                               SkXfermode::Mode mode) {
    if (cachedHasSSE2()) {
        return SkPlatformXfermodeFactory_impl_SSE2(rec, mode);
    } else {
        return SkPlatformXfermodeFactory_impl(rec, mode);
    }
}

SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode);

SkXfermodeProc SkPlatformXfermodeProcFactory(SkXfermode::Mode mode) {
    return NULL;
}
<|endoftext|>