<commit_before>
#include "potentialfunctioncbspl.h"

PotentialFunctionCBSPL::PotentialFunctionCBSPL(const int nlam_,
        const int ncutcoeff_, const double min_, const double max_) :
                        PotentialFunction(nlam_,min_,max_) {

    /* Here nlam_ is the total number of coeff values that are to be optimized
     * To ensure that potential and force go to zero smoothly near cut-off,
     * as suggested in Ref. PCCP, 11, 1901, 2009, coeff values leading up to
     * cut-off and beyond take a value of zero.
     *
     * Since region less than rmin is not sampled sufficiently for stability
     * first _nexcl coefficients are not optimized instead their values are
     * extrapolated from first statistically significant knot values near rmin
     */

    // number of break points = _lam.size() - 2
    _nbreak = _lam.size() - 2;

     _dr = ( _cut_off )/( double (_nbreak - 1) );

    // break point locations
    // since ncoeff = nbreak +2 , r values for last two coefficients are also
    // computed
    _rbreak.resize(_lam.size(),false);

    _rbreak.clear();

    for( int i = 0; i < _lam.size(); i++)
        _rbreak(i) = i*_dr;

    _nexcl = min( int( ( _min )/_dr ), _nbreak - 2 ) + 1;

    _ncutcoeff = ncutcoeff_;

    _M.resize(4,4,false);
    _M.clear();
    _M(0,0) =  1.0; _M(0,1) =  4.0; _M(0,2) =  1.0; _M(0,3) = 0.0;
    _M(1,0) = -3.0; _M(1,1) =  0.0; _M(1,2) =  3.0; _M(1,3) = 0.0;
    _M(2,0) =  3.0; _M(2,1) = -6.0; _M(2,2) =  3.0; _M(2,3) = 0.0;
    _M(3,0) = -1.0; _M(3,1) =  3.0; _M(3,2) = -3.0; _M(3,3) = 1.0;
    _M /= 6.0;

}

int PotentialFunctionCBSPL::getOptParamSize() const {

    return _lam.size() - _nexcl - _ncutcoeff;
}

void PotentialFunctionCBSPL::setParam(string filename) {

        Table param;
        param.Load(filename);

        _lam.clear();

        if( param.size() != _lam.size()) {

            throw std::runtime_error("Potential parameters size mismatch!\n"
                    "Check input parameter file \""
                    + filename + "\" \nThere should be "
                    + boost::lexical_cast<string>( _lam.size() ) + " parameters");
        } else {
            // force last _ncutcoeff to be zero
            for( int i = 0; i < _lam.size() - _ncutcoeff; i++){

                _rbreak(i) = param.x(i);
                _lam(i) = param.y(i);

            }

        }

    }

void PotentialFunctionCBSPL::SaveParam(const string& filename){

    extrapolExclParam();

    Table param;
    param.SetHasYErr(false);
    param.resize(_lam.size(), false);

    for (int i = 0; i < _lam.size(); i++){

        param.set(i, _rbreak(i), _lam(i), 'i');
    }

    param.Save(filename);

}

void PotentialFunctionCBSPL::SavePotTab(const string& filename,
        const double step) {

    extrapolExclParam();

    PotentialFunction::SavePotTab(filename,step);

}

void PotentialFunctionCBSPL::extrapolExclParam(){

    // extrapolate first _nexcl knot values using exponential extrapolation
    // u(r) = a * exp( b * r)
    // a = u0 * exp ( - m * r0/u0 )
    // b = m/u0
    // m = (u1-u0)/(r1-r0)

    double u0 = _lam(_nexcl);
    double r0 = _rbreak(_nexcl);
    double m = (_lam(_nexcl + 1) - _lam(_nexcl)) /
            (_rbreak(_nexcl + 1) - _rbreak(_nexcl));
    double a = u0 * exp(-m * r0 / u0);
    double b = m / u0;

    for (int i = 0; i < _nexcl; i++) {

        double r = _rbreak(i);
        double u = a * exp(b * r);
        _lam(i) = u;

    }

}

void PotentialFunctionCBSPL::setOptParam(const int i, const double val){

    _lam( i + _nexcl ) = val;

}

double PotentialFunctionCBSPL::getOptParam(const int i) const{

    return _lam( i + _nexcl );

}

double PotentialFunctionCBSPL::CalculateF (const double r) const {

    if( r >= _min && r <= _cut_off){

        ub::vector<double> R;
        ub::vector<double> B;

        int indx = min( int( r /_dr ) , _nbreak-2 );

        double rk = indx*_dr;

        double t = ( r - rk)/_dr;

        R.resize(4,false); R.clear();

        R(0) = 1.0; R(1) = t; R(2) = t*t; R(3) = t*t*t;

        ub::vector<double> RM = ub::prod(R,_M);

        B.resize(4,false); B.clear();

        B(0) = _lam(indx); B(1) = _lam(indx+1); B(2) = _lam(indx+2);
        B(3) = _lam(indx+3);

        double u = ub::inner_prod(B,RM);

        return u;

    } else {

        return 0.0;

    }

}
    // calculate first derivative w.r.t. ith parameter
double PotentialFunctionCBSPL::CalculateDF(const int i, const double r) const{

    // since first _nexcl parameters are not optimized for stability reasons
    //i = i + _nexcl;

    if ( r >= _min && r <= _cut_off ) {

        int indx = min( int( ( r )/_dr ), _nbreak-2 );

        if ( i + _nexcl >= indx && i + _nexcl <= indx+3 ){

            ub::vector<double> R;

            double rk = indx*_dr;

            double t = ( r - rk)/_dr;

            R.resize(4,false); R.clear();

            R(0) = 1.0; R(1) = t; R(2) = t*t; R(3) = t*t*t;

            ub::vector<double> RM = ub::prod(R,_M);

            return RM(i + _nexcl-indx);

        }else{

            return 0.0;

        }

    } else {

        return 0;

    }
}
    // calculate second derivative w.r.t. ith parameter
double PotentialFunctionCBSPL::CalculateD2F(const int i, const int j,
        const double r) const {

    // for cubic B-SPlines D2F is zero for all lamdas
    return 0.0;

}
<commit_msg>modified to save extrapolatated bspl knots with o flag<commit_after>
#include "potentialfunctioncbspl.h"

PotentialFunctionCBSPL::PotentialFunctionCBSPL(const int nlam_,
        const int ncutcoeff_, const double min_, const double max_) :
                        PotentialFunction(nlam_,min_,max_) {

    /* Here nlam_ is the total number of coeff values that are to be optimized
     * To ensure that potential and force go to zero smoothly near cut-off,
     * as suggested in Ref. PCCP, 11, 1901, 2009, coeff values leading up to
     * cut-off and beyond take a value of zero.
     *
     * Since region less than rmin is not sampled sufficiently for stability
     * first _nexcl coefficients are not optimized instead their values are
     * extrapolated from first statistically significant knot values near rmin
     */

    // number of break points = _lam.size() - 2
    _nbreak = _lam.size() - 2;

     _dr = ( _cut_off )/( double (_nbreak - 1) );

    // break point locations
    // since ncoeff = nbreak +2 , r values for last two coefficients are also
    // computed
    _rbreak.resize(_lam.size(),false);

    _rbreak.clear();

    for( int i = 0; i < _lam.size(); i++)
        _rbreak(i) = i*_dr;

    _nexcl = min( int( ( _min )/_dr ), _nbreak - 2 ) + 1;

    _ncutcoeff = ncutcoeff_;

    _M.resize(4,4,false);
    _M.clear();
    _M(0,0) =  1.0; _M(0,1) =  4.0; _M(0,2) =  1.0; _M(0,3) = 0.0;
    _M(1,0) = -3.0; _M(1,1) =  0.0; _M(1,2) =  3.0; _M(1,3) = 0.0;
    _M(2,0) =  3.0; _M(2,1) = -6.0; _M(2,2) =  3.0; _M(2,3) = 0.0;
    _M(3,0) = -1.0; _M(3,1) =  3.0; _M(3,2) = -3.0; _M(3,3) = 1.0;
    _M /= 6.0;

}

int PotentialFunctionCBSPL::getOptParamSize() const {

    return _lam.size() - _nexcl - _ncutcoeff;
}

void PotentialFunctionCBSPL::setParam(string filename) {

        Table param;
        param.Load(filename);

        _lam.clear();

        if( param.size() != _lam.size()) {

            throw std::runtime_error("Potential parameters size mismatch!\n"
                    "Check input parameter file \""
                    + filename + "\" \nThere should be "
                    + boost::lexical_cast<string>( _lam.size() ) + " parameters");
        } else {
            // force last _ncutcoeff to be zero
            for( int i = 0; i < _lam.size() - _ncutcoeff; i++){

                _rbreak(i) = param.x(i);
                _lam(i) = param.y(i);

            }

        }

    }

void PotentialFunctionCBSPL::SaveParam(const string& filename){

    extrapolExclParam();

    Table param;
    param.SetHasYErr(false);
    param.resize(_lam.size(), false);

    // write extrapolated knots with flat 'o'
    for (int i = 0; i < _nexcl; i++){

        param.set(i, _rbreak(i), _lam(i), 'o');
    }

    for (int i = _nexcl; i < _lam.size(); i++){

        param.set(i, _rbreak(i), _lam(i), 'i');
    }

    param.Save(filename);

}

void PotentialFunctionCBSPL::SavePotTab(const string& filename,
        const double step) {

    extrapolExclParam();

    PotentialFunction::SavePotTab(filename,step);

}

void PotentialFunctionCBSPL::extrapolExclParam(){

    // extrapolate first _nexcl knot values using exponential extrapolation
    // u(r) = a * exp( b * r)
    // a = u0 * exp ( - m * r0/u0 )
    // b = m/u0
    // m = (u1-u0)/(r1-r0)

    double u0 = _lam(_nexcl);
    double r0 = _rbreak(_nexcl);
    double m = (_lam(_nexcl + 1) - _lam(_nexcl)) /
            (_rbreak(_nexcl + 1) - _rbreak(_nexcl));
    double a = u0 * exp(-m * r0 / u0);
    double b = m / u0;

    for (int i = 0; i < _nexcl; i++) {

        double r = _rbreak(i);
        double u = a * exp(b * r);
        _lam(i) = u;

    }

}

void PotentialFunctionCBSPL::setOptParam(const int i, const double val){

    _lam( i + _nexcl ) = val;

}

double PotentialFunctionCBSPL::getOptParam(const int i) const{

    return _lam( i + _nexcl );

}

double PotentialFunctionCBSPL::CalculateF (const double r) const {

    if( r >= _min && r <= _cut_off){

        ub::vector<double> R;
        ub::vector<double> B;

        int indx = min( int( r /_dr ) , _nbreak-2 );

        double rk = indx*_dr;

        double t = ( r - rk)/_dr;

        R.resize(4,false); R.clear();

        R(0) = 1.0; R(1) = t; R(2) = t*t; R(3) = t*t*t;

        ub::vector<double> RM = ub::prod(R,_M);

        B.resize(4,false); B.clear();

        B(0) = _lam(indx); B(1) = _lam(indx+1); B(2) = _lam(indx+2);
        B(3) = _lam(indx+3);

        double u = ub::inner_prod(B,RM);

        return u;

    } else {

        return 0.0;

    }

}
    // calculate first derivative w.r.t. ith parameter
double PotentialFunctionCBSPL::CalculateDF(const int i, const double r) const{

    // since first _nexcl parameters are not optimized for stability reasons
    //i = i + _nexcl;

    if ( r >= _min && r <= _cut_off ) {

        int indx = min( int( ( r )/_dr ), _nbreak-2 );

        if ( i + _nexcl >= indx && i + _nexcl <= indx+3 ){

            ub::vector<double> R;

            double rk = indx*_dr;

            double t = ( r - rk)/_dr;

            R.resize(4,false); R.clear();

            R(0) = 1.0; R(1) = t; R(2) = t*t; R(3) = t*t*t;

            ub::vector<double> RM = ub::prod(R,_M);

            return RM(i + _nexcl-indx);

        }else{

            return 0.0;

        }

    } else {

        return 0;

    }
}
    // calculate second derivative w.r.t. ith parameter
double PotentialFunctionCBSPL::CalculateD2F(const int i, const int j,
        const double r) const {

    // for cubic B-SPlines D2F is zero for all lamdas
    return 0.0;

}
<|endoftext|>


<commit_before><commit_msg>Linux: For mouse button clicks, only send buttons 1, 2, 3 to the renderer.<commit_after><|endoftext|>


<commit_before><commit_msg>An experimental fix for Issue 9718. This change enables the keyboard shortcuts "control + right-shift" and "control + left-shift" only on a PC having RTL languages (i.e. Arabic or Hebrew) installed.<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: mmoutputpage.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: hr $ $Date: 2007-09-27 11:34:58 $
 *
 *  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 _MAILMERGEOUTPUTPAGE_HXX
#define _MAILMERGEOUTPUTPAGE_HXX
#ifndef _SVTOOLS_WIZARDMACHINE_HXX_
#include <svtools/wizardmachine.hxx>
#endif
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SV_COMBOBOX_HXX
#include <vcl/combobox.hxx>
#endif
#ifndef _SV_FIELD_HXX
#include <vcl/field.hxx>
#endif
#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SFX_OBJSH_HXX
#include <sfx2/objsh.hxx>
#endif
#ifndef _BASEDLGS_HXX
#include <sfx2/basedlgs.hxx>
#endif
#ifndef _SVTABBX_HXX
#include <svtools/svtabbx.hxx>
#endif
#ifndef _HEADBAR_HXX
#include <svtools/headbar.hxx>
#endif
#ifndef _PRGSBAR_HXX
#include <svtools/prgsbar.hxx>
#endif

#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif
#ifndef _MAILMERGEHELPER_HXX
#include "mailmergehelper.hxx"
#endif

class SwMailMergeWizard;
class SfxPrinter;
class SwSendMailDialog;

namespace com{ namespace sun{ namespace star{
    namespace mail{
        class XMailMessage;
    }
}}}
/*-- 02.04.2004 09:21:06---------------------------------------------------

  -----------------------------------------------------------------------*/
class SwMailMergeOutputPage : public svt::OWizardPage
{
    SwBoldFixedInfo m_aHeaderFI;
    FixedInfo       m_aOptionsFI;
    RadioButton     m_aSaveStartDocRB;
    RadioButton     m_aSaveMergedDocRB;
    RadioButton     m_aPrintRB;
    RadioButton     m_aSendMailRB;

    FixedLine       m_aSeparatorFL;

    PushButton      m_aSaveStartDocPB;

    RadioButton     m_aSaveAsOneRB;
    RadioButton     m_aSaveIndividualRB;
    RadioButton     m_aPrintAllRB; //has to be here for tab control reasons
    RadioButton     m_aSendAllRB;  //has to be here for tab control reasons
    //this group is used in save and print
    RadioButton     m_aFromRB;
    NumericField    m_aFromNF;
    FixedText       m_aToFT;
    NumericField    m_aToNF;
    PushButton      m_aSaveNowPB;

    FixedText       m_aPrinterFT;
    ListBox         m_aPrinterLB;
    PushButton      m_aPrinterSettingsPB;
    PushButton      m_aPrintNowPB;

    FixedText       m_aMailToFT;
    ListBox         m_aMailToLB;
    PushButton      m_aCopyToPB;
    FixedText       m_aSubjectFT;
    Edit            m_aSubjectED;
    FixedText       m_aSendAsFT;
    ListBox         m_aSendAsLB;
    FixedText       m_aAttachmentFT;
    Edit            m_aAttachmentED;
    PushButton      m_aSendAsPB;
    PushButton      m_aSendDocumentsPB;

    //some FixedLine labels
    String          m_sSaveStartST;
    String          m_sSaveMergedST;
    String          m_sPrintST;
    String          m_sSendMailST;

    //misc strings
    String          m_sDefaultAttachmentST;
    String          m_sNoSubjectQueryST;
    String          m_sNoSubjectST;
    String          m_sNoAttachmentNameST;
    String          m_sConfigureMail;

    String          m_sBody;

    long            m_nFromToRBPos;
    long            m_nFromToFTPos;
    long            m_nFromToNFPos;
    long            m_nRBOffset;

    SwMailMergeWizard*  m_pWizard;

    //some dialog data
    Printer*        m_pTempPrinter;
    SfxPrinter*     m_pDocumentPrinterCopy;
    String          m_sCC;
    String          m_sBCC;

    DECL_LINK(OutputTypeHdl_Impl, RadioButton*);
    DECL_LINK(CopyToHdl_Impl, PushButton*);
    DECL_LINK(SaveStartHdl_Impl, PushButton* );
    DECL_LINK(SaveOutputHdl_Impl, PushButton* );
    DECL_LINK(PrinterChangeHdl_Impl, ListBox* );
    DECL_LINK(PrintHdl_Impl, PushButton* );
    DECL_LINK(PrinterSetupHdl_Impl, PushButton* );
    DECL_LINK(SendTypeHdl_Impl, ListBox*);
    DECL_LINK(SendAsHdl_Impl, PushButton*);
    DECL_LINK(SendDocumentsHdl_Impl, PushButton*);
    DECL_LINK(DocumentSelectionHdl_Impl, RadioButton*);

protected:
        virtual sal_Bool determineNextButtonState();
        virtual void     ActivatePage();
public:
        SwMailMergeOutputPage( SwMailMergeWizard* _pParent);
        ~SwMailMergeOutputPage();

};
/*-- 21.05.2004 12:48:50---------------------------------------------------

  -----------------------------------------------------------------------*/
struct SwMailDescriptor
{
    ::rtl::OUString                             sEMail;
    ::rtl::OUString                             sAttachmentURL;
    ::rtl::OUString                             sAttachmentName;
    ::rtl::OUString                             sMimeType;
    ::rtl::OUString                             sSubject;
    ::rtl::OUString                             sBodyMimeType;
    ::rtl::OUString                             sBodyContent;

    ::rtl::OUString                             sCC;
    ::rtl::OUString                             sBCC;
};
struct SwSendMailDialog_Impl;
class SwMailMergeConfigItem;
class SW_DLLPUBLIC SwSendMailDialog : public ModelessDialog //SfxModalDialog
{
    FixedLine               m_aStatusFL;
    FixedText               m_aStatusFT;

    FixedLine               m_aTransferStatusFL;
    FixedText               m_aTransferStatusFT;
    FixedInfo               m_PausedFI;
    ProgressBar             m_aProgressBar;
    FixedText               m_aErrorStatusFT;

    PushButton              m_aDetailsPB;
    HeaderBar               m_aStatusHB;
    SvTabListBox            m_aStatusLB;

    FixedLine               m_aSeparatorFL;

    PushButton              m_aStopPB;
    PushButton              m_aClosePB;

    String                  m_sMore;
    String                  m_sLess;
    String                  m_sContinue;
    String                  m_sStop;
    String                  m_sSend;
    String                  m_sTransferStatus;
    String                  m_sErrorStatus;
    String                  m_sSendingTo;
    String                  m_sCompleted;
    String                  m_sFailed;
    String                  m_sTerminateQuery;

    bool                    m_bCancel;
    bool                    m_bDesctructionEnabled;

    ImageList               m_aImageList;
    ImageList               m_aImageListHC;

    SwSendMailDialog_Impl*  m_pImpl;
    SwMailMergeConfigItem*  m_pConfigItem;
    sal_Int32               m_nStatusHeight;
    sal_Int32               m_nSendCount;
    sal_Int32               m_nErrorCount;

    SW_DLLPRIVATE DECL_LINK( DetailsHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_LINK( StopHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_LINK( CloseHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, StartSendMails, SwSendMailDialog* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, StopSendMails, SwSendMailDialog* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer* );

    SW_DLLPRIVATE void        IterateMails();
    SW_DLLPRIVATE void        SendMails();
    SW_DLLPRIVATE void        UpdateTransferStatus();

    virtual void        StateChanged( StateChangedType nStateChange );

public:
    SwSendMailDialog( Window* pParent, SwMailMergeConfigItem& );
    ~SwSendMailDialog();

    void                AddDocument( SwMailDescriptor& rDesc );
    void                SetDocumentCount( sal_Int32 nAllDocuments );
    void                EnableDesctruction() {m_bDesctructionEnabled = true;}
    void                ShowDialog();

    void                DocumentSent( ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage>,
                                        bool bResult,
                                        const ::rtl::OUString* pError );
    void                AllMailsSent();

};
#endif

<commit_msg>INTEGRATION: CWS odbmacros2 (1.8.126); FILE MERGED 2008/01/30 13:31:34 fs 1.8.126.2: canAdvance made const 2008/01/15 11:50:41 fs 1.8.126.1: some re-factoring of OWizardMachine, RoadmapWizard and derived classes, to prepare the migration UI for #i49133#<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: mmoutputpage.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2008-03-06 19:06:56 $
 *
 *  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 _MAILMERGEOUTPUTPAGE_HXX
#define _MAILMERGEOUTPUTPAGE_HXX
#ifndef _SVTOOLS_WIZARDMACHINE_HXX_
#include <svtools/wizardmachine.hxx>
#endif
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef _SV_COMBOBOX_HXX
#include <vcl/combobox.hxx>
#endif
#ifndef _SV_FIELD_HXX
#include <vcl/field.hxx>
#endif
#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _SFX_OBJSH_HXX
#include <sfx2/objsh.hxx>
#endif
#ifndef _BASEDLGS_HXX
#include <sfx2/basedlgs.hxx>
#endif
#ifndef _SVTABBX_HXX
#include <svtools/svtabbx.hxx>
#endif
#ifndef _HEADBAR_HXX
#include <svtools/headbar.hxx>
#endif
#ifndef _PRGSBAR_HXX
#include <svtools/prgsbar.hxx>
#endif

#ifndef INCLUDED_SWDLLAPI_H
#include "swdllapi.h"
#endif
#ifndef _MAILMERGEHELPER_HXX
#include "mailmergehelper.hxx"
#endif

class SwMailMergeWizard;
class SfxPrinter;
class SwSendMailDialog;

namespace com{ namespace sun{ namespace star{
    namespace mail{
        class XMailMessage;
    }
}}}
/*-- 02.04.2004 09:21:06---------------------------------------------------

  -----------------------------------------------------------------------*/
class SwMailMergeOutputPage : public svt::OWizardPage
{
    SwBoldFixedInfo m_aHeaderFI;
    FixedInfo       m_aOptionsFI;
    RadioButton     m_aSaveStartDocRB;
    RadioButton     m_aSaveMergedDocRB;
    RadioButton     m_aPrintRB;
    RadioButton     m_aSendMailRB;

    FixedLine       m_aSeparatorFL;

    PushButton      m_aSaveStartDocPB;

    RadioButton     m_aSaveAsOneRB;
    RadioButton     m_aSaveIndividualRB;
    RadioButton     m_aPrintAllRB; //has to be here for tab control reasons
    RadioButton     m_aSendAllRB;  //has to be here for tab control reasons
    //this group is used in save and print
    RadioButton     m_aFromRB;
    NumericField    m_aFromNF;
    FixedText       m_aToFT;
    NumericField    m_aToNF;
    PushButton      m_aSaveNowPB;

    FixedText       m_aPrinterFT;
    ListBox         m_aPrinterLB;
    PushButton      m_aPrinterSettingsPB;
    PushButton      m_aPrintNowPB;

    FixedText       m_aMailToFT;
    ListBox         m_aMailToLB;
    PushButton      m_aCopyToPB;
    FixedText       m_aSubjectFT;
    Edit            m_aSubjectED;
    FixedText       m_aSendAsFT;
    ListBox         m_aSendAsLB;
    FixedText       m_aAttachmentFT;
    Edit            m_aAttachmentED;
    PushButton      m_aSendAsPB;
    PushButton      m_aSendDocumentsPB;

    //some FixedLine labels
    String          m_sSaveStartST;
    String          m_sSaveMergedST;
    String          m_sPrintST;
    String          m_sSendMailST;

    //misc strings
    String          m_sDefaultAttachmentST;
    String          m_sNoSubjectQueryST;
    String          m_sNoSubjectST;
    String          m_sNoAttachmentNameST;
    String          m_sConfigureMail;

    String          m_sBody;

    long            m_nFromToRBPos;
    long            m_nFromToFTPos;
    long            m_nFromToNFPos;
    long            m_nRBOffset;

    SwMailMergeWizard*  m_pWizard;

    //some dialog data
    Printer*        m_pTempPrinter;
    SfxPrinter*     m_pDocumentPrinterCopy;
    String          m_sCC;
    String          m_sBCC;

    DECL_LINK(OutputTypeHdl_Impl, RadioButton*);
    DECL_LINK(CopyToHdl_Impl, PushButton*);
    DECL_LINK(SaveStartHdl_Impl, PushButton* );
    DECL_LINK(SaveOutputHdl_Impl, PushButton* );
    DECL_LINK(PrinterChangeHdl_Impl, ListBox* );
    DECL_LINK(PrintHdl_Impl, PushButton* );
    DECL_LINK(PrinterSetupHdl_Impl, PushButton* );
    DECL_LINK(SendTypeHdl_Impl, ListBox*);
    DECL_LINK(SendAsHdl_Impl, PushButton*);
    DECL_LINK(SendDocumentsHdl_Impl, PushButton*);
    DECL_LINK(DocumentSelectionHdl_Impl, RadioButton*);

protected:
        virtual bool    canAdvance() const;
        virtual void    ActivatePage();
public:
        SwMailMergeOutputPage( SwMailMergeWizard* _pParent);
        ~SwMailMergeOutputPage();

};
/*-- 21.05.2004 12:48:50---------------------------------------------------

  -----------------------------------------------------------------------*/
struct SwMailDescriptor
{
    ::rtl::OUString                             sEMail;
    ::rtl::OUString                             sAttachmentURL;
    ::rtl::OUString                             sAttachmentName;
    ::rtl::OUString                             sMimeType;
    ::rtl::OUString                             sSubject;
    ::rtl::OUString                             sBodyMimeType;
    ::rtl::OUString                             sBodyContent;

    ::rtl::OUString                             sCC;
    ::rtl::OUString                             sBCC;
};
struct SwSendMailDialog_Impl;
class SwMailMergeConfigItem;
class SW_DLLPUBLIC SwSendMailDialog : public ModelessDialog //SfxModalDialog
{
    FixedLine               m_aStatusFL;
    FixedText               m_aStatusFT;

    FixedLine               m_aTransferStatusFL;
    FixedText               m_aTransferStatusFT;
    FixedInfo               m_PausedFI;
    ProgressBar             m_aProgressBar;
    FixedText               m_aErrorStatusFT;

    PushButton              m_aDetailsPB;
    HeaderBar               m_aStatusHB;
    SvTabListBox            m_aStatusLB;

    FixedLine               m_aSeparatorFL;

    PushButton              m_aStopPB;
    PushButton              m_aClosePB;

    String                  m_sMore;
    String                  m_sLess;
    String                  m_sContinue;
    String                  m_sStop;
    String                  m_sSend;
    String                  m_sTransferStatus;
    String                  m_sErrorStatus;
    String                  m_sSendingTo;
    String                  m_sCompleted;
    String                  m_sFailed;
    String                  m_sTerminateQuery;

    bool                    m_bCancel;
    bool                    m_bDesctructionEnabled;

    ImageList               m_aImageList;
    ImageList               m_aImageListHC;

    SwSendMailDialog_Impl*  m_pImpl;
    SwMailMergeConfigItem*  m_pConfigItem;
    sal_Int32               m_nStatusHeight;
    sal_Int32               m_nSendCount;
    sal_Int32               m_nErrorCount;

    SW_DLLPRIVATE DECL_LINK( DetailsHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_LINK( StopHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_LINK( CloseHdl_Impl, PushButton* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, StartSendMails, SwSendMailDialog* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, StopSendMails, SwSendMailDialog* );
    SW_DLLPRIVATE DECL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer* );

    SW_DLLPRIVATE void        IterateMails();
    SW_DLLPRIVATE void        SendMails();
    SW_DLLPRIVATE void        UpdateTransferStatus();

    virtual void        StateChanged( StateChangedType nStateChange );

public:
    SwSendMailDialog( Window* pParent, SwMailMergeConfigItem& );
    ~SwSendMailDialog();

    void                AddDocument( SwMailDescriptor& rDesc );
    void                SetDocumentCount( sal_Int32 nAllDocuments );
    void                EnableDesctruction() {m_bDesctructionEnabled = true;}
    void                ShowDialog();

    void                DocumentSent( ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage>,
                                        bool bResult,
                                        const ::rtl::OUString* pError );
    void                AllMailsSent();

};
#endif

<|endoftext|>


<commit_before><commit_msg>Removed #ifdef in IncrementErrorCount() now that it's platform-independent.<commit_after><|endoftext|>


<commit_before><commit_msg>Fix uninitialized variables.<commit_after><|endoftext|>


<commit_before><commit_msg>Fix a crash when trying to sign in with an account already signed in.<commit_after><|endoftext|>


<commit_before>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2011, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/console/parse.h>
#include <pcl/common/time.h>

#define FPS_CALC(_WHAT_) \
do \
{ \
    static unsigned count = 0;\
    static double last = pcl::getTime ();\
    if (++count == 100) \
    { \
      double now = pcl::getTime (); \
      std::cout << "Average framerate("<< _WHAT_ << "): " << double(count)/double(now - last) << " Hz" <<  std::endl; \
      count = 0; \
      last = now; \
    } \
}while(false)

template <typename PointType>
class OpenNIIntegralImageNormalEstimation
{
  public:
    typedef pcl::PointCloud<PointType> Cloud;
    typedef typename Cloud::Ptr CloudPtr;
    typedef typename Cloud::ConstPtr CloudConstPtr;

    OpenNIIntegralImageNormalEstimation (const std::string& device_id = "")
      : viewer ("PCL OpenNI NormalEstimation Viewer")
    , device_id_(device_id)
    {
      ne_.setNormalEstimationMethod (pcl::IntegralImageNormalEstimation<PointType, pcl::Normal>::AVERAGE_3D_GRADIENT);
//      ne_.setNormalEstimationMethod (pcl::IntegralImageNormalEstimation<PointType, pcl::Normal>::COVARIANCE_MATRIX);
      ne_.setRectSize (2, 2);
      new_cloud_ = false;
    }

    void
    cloud_cb (const CloudConstPtr& cloud)
    {
      boost::mutex::scoped_lock lock (mtx_);
      //lock while we set our cloud;
      FPS_CALC ("computation");
      // Estimate surface normals
      ne_.setInputCloud (cloud);

      normals_.reset (new pcl::PointCloud<pcl::Normal>);
      ne_.compute (*normals_);
      cloud_ = cloud;

      new_cloud_ = true;
    }

    void
    viz_cb (pcl::visualization::PCLVisualizer& viz)
    {
      boost::mutex::scoped_lock lock (mtx_);
      if (!cloud_)
      {
        sleep (1);
        return;
      }

      CloudConstPtr temp_cloud;
      temp_cloud.swap (cloud_); //here we set cloud_ to null, so that

      if (!viz.updatePointCloud<PointType> (temp_cloud, "OpenNICloud"))
      {
        viz.addPointCloud<PointType> (temp_cloud, "OpenNICloud");
        viz.resetCameraViewpoint ("OpenNICloud");
      }
      // Render the data
      if (new_cloud_ && normals_)
      {
        viz.removePointCloud ("normalcloud");
        viz.addPointCloudNormals<PointType, pcl::Normal> (temp_cloud, normals_, 200, 0.1, "normalcloud");
        new_cloud_ = false;
      }
    }

    void
    run ()
    {
      pcl::Grabber* interface = new pcl::OpenNIGrabber (device_id_);

      boost::function<void (const CloudConstPtr&)> f = boost::bind (&OpenNIIntegralImageNormalEstimation::cloud_cb, this, _1);
      boost::signals2::connection c = interface->registerCallback (f);

      viewer.runOnVisualizationThread (boost::bind(&OpenNIIntegralImageNormalEstimation::viz_cb, this, _1), "viz_cb");

      interface->start ();

      while (!viewer.wasStopped ())
      {
        sleep (10);
      }

      interface->stop ();
    }

    pcl::IntegralImageNormalEstimation<PointType, pcl::Normal> ne_;
    pcl::visualization::CloudViewer viewer;
    std::string device_id_;
    boost::mutex mtx_;
    // Data
    pcl::PointCloud<pcl::Normal>::Ptr normals_;
    CloudConstPtr cloud_;
    bool new_cloud_;
};

void
usage (char ** argv)
{
  std::cout << "usage: " << argv[0] << " <device_id> <options>\n\n";

  openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance ();
  if (driver.getNumberDevices () > 0)
  {
    for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices (); ++deviceIdx)
    {
      cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
              << ", connected: " << (int)driver.getBus (deviceIdx) << " @ " << (int)driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << endl;
      cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << endl
           << "                 bus@address for the device connected to a specific usb-bus / address combination (wotks only in Linux) or" << endl
           << "                 <serial-number> (only in Linux and for devices which provide serial numbers)"  << endl;
    }
  }
  else
    cout << "No devices connected." << endl;
}

int
main (int argc, char ** argv)
{
  if (argc < 2)
  {
    usage (argv);
    return 1;
  }

  std::string arg (argv[1]);

  if (arg == "--help" || arg == "-h")
  {
    usage (argv);
    return 1;
  }

  pcl::OpenNIGrabber grabber (arg);
  if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgb> ())
  {
    OpenNIIntegralImageNormalEstimation<pcl::PointXYZRGB> v (arg);
    v.run ();
  }
  else
  {
    OpenNIIntegralImageNormalEstimation<pcl::PointXYZ> v (arg);
    v.run ();
  }

  return (0);
}
<commit_msg>replacing with boost::this_thread::sleep<commit_after>/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2011, Willow Garage, Inc.
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of Willow Garage, Inc. nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/io/openni_camera/openni_driver.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/console/parse.h>
#include <pcl/common/time.h>

#define FPS_CALC(_WHAT_) \
do \
{ \
    static unsigned count = 0;\
    static double last = pcl::getTime ();\
    if (++count == 100) \
    { \
      double now = pcl::getTime (); \
      std::cout << "Average framerate("<< _WHAT_ << "): " << double(count)/double(now - last) << " Hz" <<  std::endl; \
      count = 0; \
      last = now; \
    } \
}while(false)

template <typename PointType>
class OpenNIIntegralImageNormalEstimation
{
  public:
    typedef pcl::PointCloud<PointType> Cloud;
    typedef typename Cloud::Ptr CloudPtr;
    typedef typename Cloud::ConstPtr CloudConstPtr;

    OpenNIIntegralImageNormalEstimation (const std::string& device_id = "")
      : viewer ("PCL OpenNI NormalEstimation Viewer")
    , device_id_(device_id)
    {
      ne_.setNormalEstimationMethod (pcl::IntegralImageNormalEstimation<PointType, pcl::Normal>::AVERAGE_3D_GRADIENT);
//      ne_.setNormalEstimationMethod (pcl::IntegralImageNormalEstimation<PointType, pcl::Normal>::COVARIANCE_MATRIX);
      ne_.setRectSize (2, 2);
      new_cloud_ = false;
    }

    void
    cloud_cb (const CloudConstPtr& cloud)
    {
      boost::mutex::scoped_lock lock (mtx_);
      //lock while we set our cloud;
      FPS_CALC ("computation");
      // Estimate surface normals
      ne_.setInputCloud (cloud);

      normals_.reset (new pcl::PointCloud<pcl::Normal>);
      ne_.compute (*normals_);
      cloud_ = cloud;

      new_cloud_ = true;
    }

    void
    viz_cb (pcl::visualization::PCLVisualizer& viz)
    {
      boost::mutex::scoped_lock lock (mtx_);
      if (!cloud_)
      {
        boost::this_thread::sleep (1);
        return;
      }

      CloudConstPtr temp_cloud;
      temp_cloud.swap (cloud_); //here we set cloud_ to null, so that

      if (!viz.updatePointCloud<PointType> (temp_cloud, "OpenNICloud"))
      {
        viz.addPointCloud<PointType> (temp_cloud, "OpenNICloud");
        viz.resetCameraViewpoint ("OpenNICloud");
      }
      // Render the data
      if (new_cloud_ && normals_)
      {
        viz.removePointCloud ("normalcloud");
        viz.addPointCloudNormals<PointType, pcl::Normal> (temp_cloud, normals_, 200, 0.1, "normalcloud");
        new_cloud_ = false;
      }
    }

    void
    run ()
    {
      pcl::Grabber* interface = new pcl::OpenNIGrabber (device_id_);

      boost::function<void (const CloudConstPtr&)> f = boost::bind (&OpenNIIntegralImageNormalEstimation::cloud_cb, this, _1);
      boost::signals2::connection c = interface->registerCallback (f);

      viewer.runOnVisualizationThread (boost::bind(&OpenNIIntegralImageNormalEstimation::viz_cb, this, _1), "viz_cb");

      interface->start ();

      while (!viewer.wasStopped ())
      {
        boost::this_thread::sleep (1);
      }

      interface->stop ();
    }

    pcl::IntegralImageNormalEstimation<PointType, pcl::Normal> ne_;
    pcl::visualization::CloudViewer viewer;
    std::string device_id_;
    boost::mutex mtx_;
    // Data
    pcl::PointCloud<pcl::Normal>::Ptr normals_;
    CloudConstPtr cloud_;
    bool new_cloud_;
};

void
usage (char ** argv)
{
  std::cout << "usage: " << argv[0] << " <device_id> <options>\n\n";

  openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance ();
  if (driver.getNumberDevices () > 0)
  {
    for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices (); ++deviceIdx)
    {
      cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx)
              << ", connected: " << (int)driver.getBus (deviceIdx) << " @ " << (int)driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << endl;
      cout << "device_id may be #1, #2, ... for the first second etc device in the list or" << endl
           << "                 bus@address for the device connected to a specific usb-bus / address combination (wotks only in Linux) or" << endl
           << "                 <serial-number> (only in Linux and for devices which provide serial numbers)"  << endl;
    }
  }
  else
    cout << "No devices connected." << endl;
}

int
main (int argc, char ** argv)
{
  if (argc < 2)
  {
    usage (argv);
    return 1;
  }

  std::string arg (argv[1]);

  if (arg == "--help" || arg == "-h")
  {
    usage (argv);
    return 1;
  }

  pcl::OpenNIGrabber grabber (arg);
  if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgb> ())
  {
    OpenNIIntegralImageNormalEstimation<pcl::PointXYZRGB> v (arg);
    v.run ();
  }
  else
  {
    OpenNIIntegralImageNormalEstimation<pcl::PointXYZ> v (arg);
    v.run ();
  }

  return (0);
}
<|endoftext|>


<commit_before>/*
 * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @defgroup    sys_c11_atomics_cpp_compat C++ compatibility with C11 atomics
 * @ingroup     sys
 * @brief       C++ compatibility of default C11 atomics types
 *
 * This module provides opaque `typedef`s for each standard C11 atomic type with
 * the same size and alignment requirements. The contents of types are not
 * accessible to C++ code, but this allows `struct`s to be defined with the
 * same memory layout as the C version, so that they can be allocated from C++.
 *
 * @{
 *
 * @file
 * @brief       C++ compatibility of default C11 atomics types
 *
 * @author      Marian Buschsieweke <marian.buschsieweke@ovgu.de>
 */

#pragma once

#include "c11_atomics_compat_cpu.hpp"

/**
 * @brief   Initialize an atomic variable
 *
 * Usage (same syntax as the real C11 atomic initializer):
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * atomic_int foo = ATOMIC_VAR_INIT(42);
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#define ATOMIC_VAR_INIT(x) { x }

/**
  * @brief Type with the same alignment and size as `atomic_bool`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_BOOL_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_bool;

/**
  * @brief Type with the same alignment and size as `atomic_char`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_CHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_char;

/**
  * @brief Type with the same alignment and size as `atomic_schar`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SCHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_schar;

/**
  * @brief Type with the same alignment and size as `atomic_uchar`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UCHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uchar;

/**
  * @brief Type with the same alignment and size as `atomic_short`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SHORT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_short;

/**
  * @brief Type with the same alignment and size as `atomic_ushort`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_USHORT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ushort;

/**
  * @brief Type with the same alignment and size as `atomic_int`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int;

/**
  * @brief Type with the same alignment and size as `atomic_uint`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint;

/**
  * @brief Type with the same alignment and size as `atomic_long`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_LONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_long;

/**
  * @brief Type with the same alignment and size as `atomic_ulong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_ULONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ulong;

/**
  * @brief Type with the same alignment and size as `atomic_llong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_LLONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_llong;

/**
  * @brief Type with the same alignment and size as `atomic_ullong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_ULLONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ullong;

/**
  * @brief Type with the same alignment and size as `atomic_int_least8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least8_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least8_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least16_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least16_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least32_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least32_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least64_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least64_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast8_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast8_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast16_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast16_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast32_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast32_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast64_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast64_t;

/**
  * @brief Type with the same alignment and size as `atomic_intptr_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INTPTR_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_intptr_t;

/**
  * @brief Type with the same alignment and size as `atomic_uintptr_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINTPTR_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uintptr_t;

/**
  * @brief Type with the same alignment and size as `atomic_size_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SIZE_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_size_t;

/**
  * @brief Type with the same alignment and size as `atomic_intmax_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INTMAX_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_intmax_t;

/**
  * @brief Type with the same alignment and size as `atomic_uintmax_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINTMAX_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uintmax_t;

/** @} */
<commit_msg>sys/include/c11_atomics_compat.hpp: fix for esp32<commit_after>/*
 * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @defgroup    sys_c11_atomics_cpp_compat C++ compatibility with C11 atomics
 * @ingroup     sys
 * @brief       C++ compatibility of default C11 atomics types
 *
 * This module provides opaque `typedef`s for each standard C11 atomic type with
 * the same size and alignment requirements. The contents of types are not
 * accessible to C++ code, but this allows `struct`s to be defined with the
 * same memory layout as the C version, so that they can be allocated from C++.
 *
 * @{
 *
 * @file
 * @brief       C++ compatibility of default C11 atomics types
 *
 * @author      Marian Buschsieweke <marian.buschsieweke@ovgu.de>
 */

#pragma once

#include "c11_atomics_compat_cpu.hpp"

/**
 * @brief   Initialize an atomic variable
 *
 * Usage (same syntax as the real C11 atomic initializer):
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * atomic_int foo = ATOMIC_VAR_INIT(42);
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#ifndef ATOMIC_VAR_INIT
#define ATOMIC_VAR_INIT(x) { x }
#endif

/**
  * @brief Type with the same alignment and size as `atomic_bool`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_BOOL_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_bool;

/**
  * @brief Type with the same alignment and size as `atomic_char`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_CHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_char;

/**
  * @brief Type with the same alignment and size as `atomic_schar`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SCHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_schar;

/**
  * @brief Type with the same alignment and size as `atomic_uchar`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UCHAR_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uchar;

/**
  * @brief Type with the same alignment and size as `atomic_short`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SHORT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_short;

/**
  * @brief Type with the same alignment and size as `atomic_ushort`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_USHORT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ushort;

/**
  * @brief Type with the same alignment and size as `atomic_int`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int;

/**
  * @brief Type with the same alignment and size as `atomic_uint`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint;

/**
  * @brief Type with the same alignment and size as `atomic_long`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_LONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_long;

/**
  * @brief Type with the same alignment and size as `atomic_ulong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_ULONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ulong;

/**
  * @brief Type with the same alignment and size as `atomic_llong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_LLONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_llong;

/**
  * @brief Type with the same alignment and size as `atomic_ullong`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_ULLONG_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_ullong;

/**
  * @brief Type with the same alignment and size as `atomic_int_least8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least8_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least8_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least16_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least16_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least32_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least32_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_least64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_LEAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_least64_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_least64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_LEAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_least64_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast8_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast8_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST8_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast8_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast16_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast16_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST16_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast16_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast32_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast32_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST32_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast32_t;

/**
  * @brief Type with the same alignment and size as `atomic_int_fast64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INT_FAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_int_fast64_t;

/**
  * @brief Type with the same alignment and size as `atomic_uint_fast64_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINT_FAST64_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uint_fast64_t;

/**
  * @brief Type with the same alignment and size as `atomic_intptr_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INTPTR_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_intptr_t;

/**
  * @brief Type with the same alignment and size as `atomic_uintptr_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINTPTR_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uintptr_t;

/**
  * @brief Type with the same alignment and size as `atomic_size_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_SIZE_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_size_t;

/**
  * @brief Type with the same alignment and size as `atomic_intmax_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_INTMAX_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_intmax_t;

/**
  * @brief Type with the same alignment and size as `atomic_uintmax_t`
 */
typedef struct {
    /**
     * @brief Opaque content placeholder
     *
     * Access only for initializing from C++
     */
    ATOMIC_UINTMAX_T_SAME_SIZED_TYPE do_not_access_from_cpp;
} atomic_uintmax_t;

/** @} */
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtCore/QFile>
#include <QtCore/QTextCodec>
#include <QtCore/QTimer>
#include <QtCore/QXmlStreamReader>

#include <QtNetwork/QNetworkRequest>

#include "qacceltreebuilder_p.h"
#include "qatomicstring_p.h"
#include "qautoptr_p.h"
#include "qcommonsequencetypes_p.h"

#include "qacceltreeresourceloader_p.h"

QT_BEGIN_NAMESPACE

using namespace QPatternist;

static inline uint qHash(const QUrl &uri)
{
        return qHash(uri.toString());
}

AccelTreeResourceLoader::AccelTreeResourceLoader(const NamePool::Ptr &np,
                                                 const NetworkAccessDelegator::Ptr &manager) : m_namePool(np)
                                                                                , m_networkAccessDelegator(manager)
{
    Q_ASSERT(m_namePool);
    Q_ASSERT(m_networkAccessDelegator);
}

bool AccelTreeResourceLoader::retrieveDocument(const QUrl &uri,
                                               const ReportContext::Ptr &context)
{
    Q_ASSERT(uri.isValid());
    AccelTreeBuilder<true> builder(uri, uri, m_namePool, context.data());

    const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));

    if(!reply)
        return false;

    bool success = false;
    success = streamToReceiver(reply.data(), &builder, m_namePool, context, uri);

    m_loadedDocuments.insert(uri, builder.builtDocument());
    return success;
}

QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
                                             const NetworkAccessDelegator::Ptr &networkDelegator,
                                             const ReportContext::Ptr &context)
{
    return load(uri,
                networkDelegator->managerFor(uri),
                context);
}

QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
                                             QNetworkAccessManager *const networkManager,
                                             const ReportContext::Ptr &context)
{
    Q_ASSERT(networkManager);
    Q_ASSERT(uri.isValid());

    NetworkLoop networkLoop;

    QNetworkRequest request(uri);
    QNetworkReply *const reply = networkManager->get(request);
    networkLoop.connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(error(QNetworkReply::NetworkError)));
    networkLoop.connect(reply, SIGNAL(finished()), SLOT(finished()));

    if(networkLoop.exec())
    {
        const QString errorMessage(escape(reply->errorString()));

        /* Note, we delete reply before we exit this function with error(). */
        delete reply;

        const QSourceLocation location(uri);

        if(context)
            context->error(errorMessage, ReportContext::FODC0002, location);

        return 0;
    }
    else
        return reply;
}

bool AccelTreeResourceLoader::streamToReceiver(QIODevice *const dev,
                                               QAbstractXmlReceiver *const receiver,
                                               const NamePool::Ptr &np,
                                               const ReportContext::Ptr &context,
                                               const QUrl &uri)
{
    Q_ASSERT(dev);
    Q_ASSERT(receiver);
    Q_ASSERT(np);

    QXmlStreamReader reader(dev);

    /* Optimize: change NamePool to take QStringRef such that we don't have to call toString() below. That
     * will save us a gazillion of temporary QStrings. */

    while(!reader.atEnd())
    {
        reader.readNext();

        switch(reader.tokenType())
        {
            case QXmlStreamReader::StartElement:
            {
                /* Send the name. */
                receiver->startElement(np->allocateQName(reader.namespaceUri().toString(), reader.name().toString(),
                                                         reader.prefix().toString()));

                /* Send namespace declarations. */
                const QXmlStreamNamespaceDeclarations &nss = reader.namespaceDeclarations();

                /* The far most common case, is for it to be empty. */
                if(!nss.isEmpty())
                {
                    const int len = nss.size();

                    for(int i = 0; i < len; ++i)
                    {
                        const QXmlStreamNamespaceDeclaration &ns = nss.at(i);
                        receiver->namespaceBinding(np->allocateBinding(ns.prefix().toString(), ns.namespaceUri().toString()));
                    }
                }

                /* Send attributes. */
                const QXmlStreamAttributes &attrs = reader.attributes();
                const int len = attrs.size();

                for(int i = 0; i < len; ++i)
                {
                    const QXmlStreamAttribute &attr = attrs.at(i);

                    receiver->attribute(np->allocateQName(attr.namespaceUri().toString(), attr.name().toString(),
                                                          attr.prefix().toString()),
                                        attr.value());
                }

                continue;
            }
            case QXmlStreamReader::EndElement:
            {
                receiver->endElement();
                continue;
            }
            case QXmlStreamReader::Characters:
            {
                if(reader.isWhitespace())
                    receiver->whitespaceOnly(reader.text());
                else
                    receiver->characters(reader.text());

                continue;
            }
            case QXmlStreamReader::Comment:
            {
                receiver->comment(reader.text().toString());
                continue;
            }
            case QXmlStreamReader::ProcessingInstruction:
            {
                receiver->processingInstruction(np->allocateQName(QString(), reader.processingInstructionTarget().toString()),
                                                reader.processingInstructionData().toString());
                continue;
            }
            case QXmlStreamReader::StartDocument:
            {
                receiver->startDocument();
                continue;
            }
            case QXmlStreamReader::EndDocument:
            {
                receiver->endDocument();
                continue;
            }
            case QXmlStreamReader::EntityReference:
            /* Fallthrough. */
            case QXmlStreamReader::DTD:
            {
                /* We just ignore any DTD and entity references. */
                continue;
            }
            case QXmlStreamReader::Invalid:
            {
                if(context)
                    context->error(escape(reader.errorString()), ReportContext::FODC0002, QSourceLocation(uri, reader.lineNumber(), reader.columnNumber()));

                return false;
            }
            case QXmlStreamReader::NoToken:
            {
                Q_ASSERT_X(false, Q_FUNC_INFO,
                           "This token is never expected to be received.");
                return false;
            }
        }
    }

    return true;
}

Item AccelTreeResourceLoader::openDocument(const QUrl &uri,
                                           const ReportContext::Ptr &context)
{
    const AccelTree::Ptr doc(m_loadedDocuments.value(uri));

    if(doc)
        return doc->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
    else
    {
        if(retrieveDocument(uri, context))
            return m_loadedDocuments.value(uri)->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
        else
            return Item();
    }
}

SequenceType::Ptr AccelTreeResourceLoader::announceDocument(const QUrl &uri, const Usage)
{
    // TODO deal with the usage thingy
    Q_ASSERT(uri.isValid());
    Q_ASSERT(!uri.isRelative());
    Q_UNUSED(uri); /* Needed when compiling in release mode. */

    return CommonSequenceTypes::ZeroOrOneDocumentNode;
}

bool AccelTreeResourceLoader::isDocumentAvailable(const QUrl &uri)
{
    return retrieveDocument(uri, ReportContext::Ptr());
}

static inline uint qHash(const QPair<QUrl, QString> &desc)
{
    /* Probably a lousy hash. */
    return qHash(desc.first) + qHash(desc.second);
}

bool AccelTreeResourceLoader::retrieveUnparsedText(const QUrl &uri,
                                                   const QString &encoding,
                                                   const ReportContext::Ptr &context,
                                                   const SourceLocationReflection *const where)
{
    const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));

    if(!reply)
        return false;

    const QTextCodec * codec;
    if(encoding.isEmpty())
    {
        /* XSL Transformations (XSLT) Version 2.0 16.2 Reading Text Files:
         *
         * "if the media type of the resource is text/xml or application/xml
         * (see [RFC2376]), or if it matches the conventions text/\*+xml or
         * application/\*+xml (see [RFC3023] and/or its successors), then the
         * encoding is recognized as specified in [XML 1.0]"
         */
        codec = QTextCodec::codecForMib(106);
    }
    else
    {
        codec = QTextCodec::codecForName(encoding.toLatin1());
        if(codec && context)
        {
            context->error(QtXmlPatterns::tr("%1 is an unsupported encoding.").arg(formatURI(encoding)),
                           ReportContext::XTDE1190,
                           where);
        }
        else
            return false;
    }

    QTextCodec::ConverterState converterState;
    const QByteArray inData(reply->readAll());
    const QString result(codec->toUnicode(inData.constData(), inData.length(), &converterState));

    if(converterState.invalidChars)
    {
        if(context)
        {
            context->error(QtXmlPatterns::tr("%1 contains octets which are disallowed in "
                                             "the requested encoding %2.").arg(formatURI(uri),
                                                                               formatURI(encoding)),
                           ReportContext::XTDE1190,
                           where);
        }
        else
            return false;
    }

    const int len = result.length();
    /* This code is a candidate for threading. Divide and conqueror. */
    for(int i = 0; i < len; ++i)
    {
        if(!QXmlUtils::isChar(result.at(i)))
        {
            if(context)
            {
                context->error(QtXmlPatterns::tr("The codepoint %1, occurring in %2 using encoding %3, "
                                                 "is an invalid XML character.").arg(formatData(result.at(i)),
                                                                                formatURI(uri),
                                                                                formatURI(encoding)),
                               ReportContext::XTDE1190,
                               where);
            }
            else
                return false;
        }
    }

    m_unparsedTexts.insert(qMakePair(uri, encoding), result);
    return true;
}

bool AccelTreeResourceLoader::isUnparsedTextAvailable(const QUrl &uri,
                                                      const QString &encoding)
{
    return retrieveUnparsedText(uri, encoding, ReportContext::Ptr(), 0);
}

Item AccelTreeResourceLoader::openUnparsedText(const QUrl &uri,
                                               const QString &encoding,
                                               const ReportContext::Ptr &context,
                                               const SourceLocationReflection *const where)
{
    const QString &text = m_unparsedTexts.value(qMakePair(uri, encoding));

    if(text.isNull())
    {
        if(retrieveUnparsedText(uri, encoding, context, where))
            return openUnparsedText(uri, encoding, context, where);
        else
            return Item();
    }
    else
        return AtomicString::fromValue(text);
}

QSet<QUrl> AccelTreeResourceLoader::deviceURIs() const
{
     QHash<QUrl, AccelTree::Ptr>::const_iterator it(m_loadedDocuments.constBegin());
     const QHash<QUrl, AccelTree::Ptr>::const_iterator end(m_loadedDocuments.constEnd());
     QSet<QUrl> retval;

     while (it != end)
     {
         if(it.key().toString().startsWith(QLatin1String("tag:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:")))
             retval.insert(it.key());

         ++it;
     }

     return retval;
}

void AccelTreeResourceLoader::clear(const QUrl &uri)
{
    m_loadedDocuments.remove(uri);
}

QT_END_NAMESPACE

<commit_msg>Don't process input events while waiting for network response.<commit_after>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtCore/QFile>
#include <QtCore/QTextCodec>
#include <QtCore/QTimer>
#include <QtCore/QXmlStreamReader>

#include <QtNetwork/QNetworkRequest>

#include "qacceltreebuilder_p.h"
#include "qatomicstring_p.h"
#include "qautoptr_p.h"
#include "qcommonsequencetypes_p.h"

#include "qacceltreeresourceloader_p.h"

QT_BEGIN_NAMESPACE

using namespace QPatternist;

static inline uint qHash(const QUrl &uri)
{
        return qHash(uri.toString());
}

AccelTreeResourceLoader::AccelTreeResourceLoader(const NamePool::Ptr &np,
                                                 const NetworkAccessDelegator::Ptr &manager) : m_namePool(np)
                                                                                , m_networkAccessDelegator(manager)
{
    Q_ASSERT(m_namePool);
    Q_ASSERT(m_networkAccessDelegator);
}

bool AccelTreeResourceLoader::retrieveDocument(const QUrl &uri,
                                               const ReportContext::Ptr &context)
{
    Q_ASSERT(uri.isValid());
    AccelTreeBuilder<true> builder(uri, uri, m_namePool, context.data());

    const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));

    if(!reply)
        return false;

    bool success = false;
    success = streamToReceiver(reply.data(), &builder, m_namePool, context, uri);

    m_loadedDocuments.insert(uri, builder.builtDocument());
    return success;
}

QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
                                             const NetworkAccessDelegator::Ptr &networkDelegator,
                                             const ReportContext::Ptr &context)
{
    return load(uri,
                networkDelegator->managerFor(uri),
                context);
}

QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
                                             QNetworkAccessManager *const networkManager,
                                             const ReportContext::Ptr &context)
{
    Q_ASSERT(networkManager);
    Q_ASSERT(uri.isValid());

    NetworkLoop networkLoop;

    QNetworkRequest request(uri);
    QNetworkReply *const reply = networkManager->get(request);
    networkLoop.connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(error(QNetworkReply::NetworkError)));
    networkLoop.connect(reply, SIGNAL(finished()), SLOT(finished()));

    if(networkLoop.exec(QEventLoop::ExcludeUserInputEvents))
    {
        const QString errorMessage(escape(reply->errorString()));

        /* Note, we delete reply before we exit this function with error(). */
        delete reply;

        const QSourceLocation location(uri);

        if(context)
            context->error(errorMessage, ReportContext::FODC0002, location);

        return 0;
    }
    else
        return reply;
}

bool AccelTreeResourceLoader::streamToReceiver(QIODevice *const dev,
                                               QAbstractXmlReceiver *const receiver,
                                               const NamePool::Ptr &np,
                                               const ReportContext::Ptr &context,
                                               const QUrl &uri)
{
    Q_ASSERT(dev);
    Q_ASSERT(receiver);
    Q_ASSERT(np);

    QXmlStreamReader reader(dev);

    /* Optimize: change NamePool to take QStringRef such that we don't have to call toString() below. That
     * will save us a gazillion of temporary QStrings. */

    while(!reader.atEnd())
    {
        reader.readNext();

        switch(reader.tokenType())
        {
            case QXmlStreamReader::StartElement:
            {
                /* Send the name. */
                receiver->startElement(np->allocateQName(reader.namespaceUri().toString(), reader.name().toString(),
                                                         reader.prefix().toString()));

                /* Send namespace declarations. */
                const QXmlStreamNamespaceDeclarations &nss = reader.namespaceDeclarations();

                /* The far most common case, is for it to be empty. */
                if(!nss.isEmpty())
                {
                    const int len = nss.size();

                    for(int i = 0; i < len; ++i)
                    {
                        const QXmlStreamNamespaceDeclaration &ns = nss.at(i);
                        receiver->namespaceBinding(np->allocateBinding(ns.prefix().toString(), ns.namespaceUri().toString()));
                    }
                }

                /* Send attributes. */
                const QXmlStreamAttributes &attrs = reader.attributes();
                const int len = attrs.size();

                for(int i = 0; i < len; ++i)
                {
                    const QXmlStreamAttribute &attr = attrs.at(i);

                    receiver->attribute(np->allocateQName(attr.namespaceUri().toString(), attr.name().toString(),
                                                          attr.prefix().toString()),
                                        attr.value());
                }

                continue;
            }
            case QXmlStreamReader::EndElement:
            {
                receiver->endElement();
                continue;
            }
            case QXmlStreamReader::Characters:
            {
                if(reader.isWhitespace())
                    receiver->whitespaceOnly(reader.text());
                else
                    receiver->characters(reader.text());

                continue;
            }
            case QXmlStreamReader::Comment:
            {
                receiver->comment(reader.text().toString());
                continue;
            }
            case QXmlStreamReader::ProcessingInstruction:
            {
                receiver->processingInstruction(np->allocateQName(QString(), reader.processingInstructionTarget().toString()),
                                                reader.processingInstructionData().toString());
                continue;
            }
            case QXmlStreamReader::StartDocument:
            {
                receiver->startDocument();
                continue;
            }
            case QXmlStreamReader::EndDocument:
            {
                receiver->endDocument();
                continue;
            }
            case QXmlStreamReader::EntityReference:
            /* Fallthrough. */
            case QXmlStreamReader::DTD:
            {
                /* We just ignore any DTD and entity references. */
                continue;
            }
            case QXmlStreamReader::Invalid:
            {
                if(context)
                    context->error(escape(reader.errorString()), ReportContext::FODC0002, QSourceLocation(uri, reader.lineNumber(), reader.columnNumber()));

                return false;
            }
            case QXmlStreamReader::NoToken:
            {
                Q_ASSERT_X(false, Q_FUNC_INFO,
                           "This token is never expected to be received.");
                return false;
            }
        }
    }

    return true;
}

Item AccelTreeResourceLoader::openDocument(const QUrl &uri,
                                           const ReportContext::Ptr &context)
{
    const AccelTree::Ptr doc(m_loadedDocuments.value(uri));

    if(doc)
        return doc->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
    else
    {
        if(retrieveDocument(uri, context))
            return m_loadedDocuments.value(uri)->root(QXmlNodeModelIndex()); /* Pass in dummy object. We know AccelTree doesn't use it. */
        else
            return Item();
    }
}

SequenceType::Ptr AccelTreeResourceLoader::announceDocument(const QUrl &uri, const Usage)
{
    // TODO deal with the usage thingy
    Q_ASSERT(uri.isValid());
    Q_ASSERT(!uri.isRelative());
    Q_UNUSED(uri); /* Needed when compiling in release mode. */

    return CommonSequenceTypes::ZeroOrOneDocumentNode;
}

bool AccelTreeResourceLoader::isDocumentAvailable(const QUrl &uri)
{
    return retrieveDocument(uri, ReportContext::Ptr());
}

static inline uint qHash(const QPair<QUrl, QString> &desc)
{
    /* Probably a lousy hash. */
    return qHash(desc.first) + qHash(desc.second);
}

bool AccelTreeResourceLoader::retrieveUnparsedText(const QUrl &uri,
                                                   const QString &encoding,
                                                   const ReportContext::Ptr &context,
                                                   const SourceLocationReflection *const where)
{
    const AutoPtr<QNetworkReply> reply(load(uri, m_networkAccessDelegator, context));

    if(!reply)
        return false;

    const QTextCodec * codec;
    if(encoding.isEmpty())
    {
        /* XSL Transformations (XSLT) Version 2.0 16.2 Reading Text Files:
         *
         * "if the media type of the resource is text/xml or application/xml
         * (see [RFC2376]), or if it matches the conventions text/\*+xml or
         * application/\*+xml (see [RFC3023] and/or its successors), then the
         * encoding is recognized as specified in [XML 1.0]"
         */
        codec = QTextCodec::codecForMib(106);
    }
    else
    {
        codec = QTextCodec::codecForName(encoding.toLatin1());
        if(codec && context)
        {
            context->error(QtXmlPatterns::tr("%1 is an unsupported encoding.").arg(formatURI(encoding)),
                           ReportContext::XTDE1190,
                           where);
        }
        else
            return false;
    }

    QTextCodec::ConverterState converterState;
    const QByteArray inData(reply->readAll());
    const QString result(codec->toUnicode(inData.constData(), inData.length(), &converterState));

    if(converterState.invalidChars)
    {
        if(context)
        {
            context->error(QtXmlPatterns::tr("%1 contains octets which are disallowed in "
                                             "the requested encoding %2.").arg(formatURI(uri),
                                                                               formatURI(encoding)),
                           ReportContext::XTDE1190,
                           where);
        }
        else
            return false;
    }

    const int len = result.length();
    /* This code is a candidate for threading. Divide and conqueror. */
    for(int i = 0; i < len; ++i)
    {
        if(!QXmlUtils::isChar(result.at(i)))
        {
            if(context)
            {
                context->error(QtXmlPatterns::tr("The codepoint %1, occurring in %2 using encoding %3, "
                                                 "is an invalid XML character.").arg(formatData(result.at(i)),
                                                                                formatURI(uri),
                                                                                formatURI(encoding)),
                               ReportContext::XTDE1190,
                               where);
            }
            else
                return false;
        }
    }

    m_unparsedTexts.insert(qMakePair(uri, encoding), result);
    return true;
}

bool AccelTreeResourceLoader::isUnparsedTextAvailable(const QUrl &uri,
                                                      const QString &encoding)
{
    return retrieveUnparsedText(uri, encoding, ReportContext::Ptr(), 0);
}

Item AccelTreeResourceLoader::openUnparsedText(const QUrl &uri,
                                               const QString &encoding,
                                               const ReportContext::Ptr &context,
                                               const SourceLocationReflection *const where)
{
    const QString &text = m_unparsedTexts.value(qMakePair(uri, encoding));

    if(text.isNull())
    {
        if(retrieveUnparsedText(uri, encoding, context, where))
            return openUnparsedText(uri, encoding, context, where);
        else
            return Item();
    }
    else
        return AtomicString::fromValue(text);
}

QSet<QUrl> AccelTreeResourceLoader::deviceURIs() const
{
     QHash<QUrl, AccelTree::Ptr>::const_iterator it(m_loadedDocuments.constBegin());
     const QHash<QUrl, AccelTree::Ptr>::const_iterator end(m_loadedDocuments.constEnd());
     QSet<QUrl> retval;

     while (it != end)
     {
         if(it.key().toString().startsWith(QLatin1String("tag:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:")))
             retval.insert(it.key());

         ++it;
     }

     return retval;
}

void AccelTreeResourceLoader::clear(const QUrl &uri)
{
    m_loadedDocuments.remove(uri);
}

QT_END_NAMESPACE

<|endoftext|>