<commit_before>#include "optionsmodel.h"
#include "bitcoinunits.h"

#include "headers.h"
#include "init.h"

OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
    QAbstractListModel(parent),
    wallet(wallet),
    nDisplayUnit(BitcoinUnits::BTC),
    bDisplayAddresses(false)
{
    // Read our specific settings from the wallet db
    CWalletDB walletdb(wallet->strWalletFile);
    walletdb.ReadSetting("nDisplayUnit", nDisplayUnit);
    walletdb.ReadSetting("bDisplayAddresses", bDisplayAddresses);
}

int OptionsModel::rowCount(const QModelIndex & parent) const
{
    return OptionIDRowCount;
}

QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
    if(role == Qt::EditRole)
    {
        switch(index.row())
        {
        case StartAtStartup:
            return QVariant(GetStartOnSystemStartup());
        case MinimizeToTray:
            return QVariant(fMinimizeToTray);
        case MapPortUPnP:
            return QVariant(fUseUPnP);
        case MinimizeOnClose:
            return QVariant(fMinimizeOnClose);
        case ConnectSOCKS4:
            return QVariant(fUseProxy);
        case ProxyIP:
            return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
        case ProxyPort:
            return QVariant(QString::fromStdString(addrProxy.ToStringPort()));
        case Fee:
            return QVariant(nTransactionFee);
        case DisplayUnit:
            return QVariant(nDisplayUnit);
        case DisplayAddresses:
            return QVariant(bDisplayAddresses);
        default:
            return QVariant();
        }
    }
    return QVariant();
}

bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
    bool successful = true; /* set to false on parse error */
    if(role == Qt::EditRole)
    {
        CWalletDB walletdb(wallet->strWalletFile);
        switch(index.row())
        {
        case StartAtStartup:
            successful = SetStartOnSystemStartup(value.toBool());
            break;
        case MinimizeToTray:
            fMinimizeToTray = value.toBool();
            walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
            break;
        case MapPortUPnP:
            fUseUPnP = value.toBool();
            walletdb.WriteSetting("fUseUPnP", fUseUPnP);
#ifdef USE_UPNP
            MapPort(fUseUPnP);
#endif
            break;
        case MinimizeOnClose:
            fMinimizeOnClose = value.toBool();
            walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
            break;
        case ConnectSOCKS4:
            fUseProxy = value.toBool();
            walletdb.WriteSetting("fUseProxy", fUseProxy);
            break;
        case ProxyIP:
            {
                // Use CAddress to parse and check IP
                CAddress addr(value.toString().toStdString() + ":1");
                if (addr.IsValid())
                {
                    addrProxy.SetIP(addr);
                    walletdb.WriteSetting("addrProxy", addrProxy);
                }
                else
                {
                    successful = false;
                }
            }
            break;
        case ProxyPort:
            {
                int nPort = atoi(value.toString().toAscii().data());
                if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
                {
                    addrProxy.SetPort(nPort);
                    walletdb.WriteSetting("addrProxy", addrProxy);
                }
                else
                {
                    successful = false;
                }
            }
            break;
        case Fee: {
            nTransactionFee = value.toLongLong();
            walletdb.WriteSetting("nTransactionFee", nTransactionFee);
            }
            break;
        case DisplayUnit: {
            int unit = value.toInt();
            nDisplayUnit = unit;
            walletdb.WriteSetting("nDisplayUnit", nDisplayUnit);
            emit displayUnitChanged(unit);
            }
        case DisplayAddresses: {
            bDisplayAddresses = value.toBool();
            walletdb.WriteSetting("bDisplayAddresses", bDisplayAddresses);
            }
        default:
            break;
        }
    }
    emit dataChanged(index, index);

    return successful;
}

qint64 OptionsModel::getTransactionFee()
{
    return nTransactionFee;
}

bool OptionsModel::getMinimizeToTray()
{
    return fMinimizeToTray;
}

bool OptionsModel::getMinimizeOnClose()
{
    return fMinimizeOnClose;
}

int OptionsModel::getDisplayUnit()
{
    return nDisplayUnit;
}

bool OptionsModel::getDisplayAddresses()
{
    return bDisplayAddresses;
}
<commit_msg>fix the build (port IP validation in options to network refactoring)<commit_after>#include "optionsmodel.h"
#include "bitcoinunits.h"

#include "headers.h"
#include "init.h"

OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
    QAbstractListModel(parent),
    wallet(wallet),
    nDisplayUnit(BitcoinUnits::BTC),
    bDisplayAddresses(false)
{
    // Read our specific settings from the wallet db
    CWalletDB walletdb(wallet->strWalletFile);
    walletdb.ReadSetting("nDisplayUnit", nDisplayUnit);
    walletdb.ReadSetting("bDisplayAddresses", bDisplayAddresses);
}

int OptionsModel::rowCount(const QModelIndex & parent) const
{
    return OptionIDRowCount;
}

QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
    if(role == Qt::EditRole)
    {
        switch(index.row())
        {
        case StartAtStartup:
            return QVariant(GetStartOnSystemStartup());
        case MinimizeToTray:
            return QVariant(fMinimizeToTray);
        case MapPortUPnP:
            return QVariant(fUseUPnP);
        case MinimizeOnClose:
            return QVariant(fMinimizeOnClose);
        case ConnectSOCKS4:
            return QVariant(fUseProxy);
        case ProxyIP:
            return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
        case ProxyPort:
            return QVariant(QString::fromStdString(addrProxy.ToStringPort()));
        case Fee:
            return QVariant(nTransactionFee);
        case DisplayUnit:
            return QVariant(nDisplayUnit);
        case DisplayAddresses:
            return QVariant(bDisplayAddresses);
        default:
            return QVariant();
        }
    }
    return QVariant();
}

bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
    bool successful = true; /* set to false on parse error */
    if(role == Qt::EditRole)
    {
        CWalletDB walletdb(wallet->strWalletFile);
        switch(index.row())
        {
        case StartAtStartup:
            successful = SetStartOnSystemStartup(value.toBool());
            break;
        case MinimizeToTray:
            fMinimizeToTray = value.toBool();
            walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
            break;
        case MapPortUPnP:
            fUseUPnP = value.toBool();
            walletdb.WriteSetting("fUseUPnP", fUseUPnP);
#ifdef USE_UPNP
            MapPort(fUseUPnP);
#endif
            break;
        case MinimizeOnClose:
            fMinimizeOnClose = value.toBool();
            walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
            break;
        case ConnectSOCKS4:
            fUseProxy = value.toBool();
            walletdb.WriteSetting("fUseProxy", fUseProxy);
            break;
        case ProxyIP:
            {
                // Use CAddress to parse and check IP
                CNetAddr addr(value.toString().toStdString());
                if (addr.IsValid())
                {
                    addrProxy.SetIP(addr);
                    walletdb.WriteSetting("addrProxy", addrProxy);
                }
                else
                {
                    successful = false;
                }
            }
            break;
        case ProxyPort:
            {
                int nPort = atoi(value.toString().toAscii().data());
                if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
                {
                    addrProxy.SetPort(nPort);
                    walletdb.WriteSetting("addrProxy", addrProxy);
                }
                else
                {
                    successful = false;
                }
            }
            break;
        case Fee: {
            nTransactionFee = value.toLongLong();
            walletdb.WriteSetting("nTransactionFee", nTransactionFee);
            }
            break;
        case DisplayUnit: {
            int unit = value.toInt();
            nDisplayUnit = unit;
            walletdb.WriteSetting("nDisplayUnit", nDisplayUnit);
            emit displayUnitChanged(unit);
            }
        case DisplayAddresses: {
            bDisplayAddresses = value.toBool();
            walletdb.WriteSetting("bDisplayAddresses", bDisplayAddresses);
            }
        default:
            break;
        }
    }
    emit dataChanged(index, index);

    return successful;
}

qint64 OptionsModel::getTransactionFee()
{
    return nTransactionFee;
}

bool OptionsModel::getMinimizeToTray()
{
    return fMinimizeToTray;
}

bool OptionsModel::getMinimizeOnClose()
{
    return fMinimizeOnClose;
}

int OptionsModel::getDisplayUnit()
{
    return nDisplayUnit;
}

bool OptionsModel::getDisplayAddresses()
{
    return bDisplayAddresses;
}
<|endoftext|>


<commit_before>#include "qrcodedialog.h"
#include "ui_qrcodedialog.h"

#include "bitcoinunits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"

#include <QPixmap>
#include <QUrl>

#include <qrencode.h>

QRCodeDialog::QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QRCodeDialog),
    model(0),
    address(addr)
{
    ui->setupUi(this);
    this->setStyleSheet("background-color: #FFFFFF;");
    setWindowTitle(QString("%1").arg(address));

    ui->chkReqPayment->setVisible(enableReq);
    ui->lblAmount->setVisible(enableReq);
    ui->lnReqAmount->setVisible(enableReq);

    ui->lnLabel->setText(label);

    ui->btnSaveAs->setEnabled(false);

    genCode();
}

QRCodeDialog::~QRCodeDialog()
{
    delete ui;
}

void QRCodeDialog::setModel(OptionsModel *model)
{
    this->model = model;

    if (model)
    {
        connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
        connect(model, SIGNAL(decimalPointsChanged(int)), this, SLOT(updateDecimalPoints()));
    }

    // update the display unit, to not use the default ("VRC")
    updateDisplayUnit();
    // update the decimal points
    updateDecimalPoints();
}

void QRCodeDialog::genCode()
{
    QString uri = getURI();

    if (uri != "")
    {
        ui->lblQRCode->setText("");

        QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
        if (!code)
        {
            ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
            return;
        }
        myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
        myImage.fill(0xffffff);
        unsigned char *p = code->data;
        for (int y = 0; y < code->width; y++)
        {
            for (int x = 0; x < code->width; x++)
            {
                myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
                p++;
            }
        }
        QRcode_free(code);

        ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));

        ui->outUri->setPlainText(uri);
    }
}

QString QRCodeDialog::getURI()
{
    QString ret = QString("vericoin:%1").arg(address);
    int paramCount = 0;

    ui->outUri->clear();

    if (ui->chkReqPayment->isChecked())
    {
        if (ui->lnReqAmount->validate())
        {
            // even if we allow a non VRC unit input in lnReqAmount, we generate the URI with VRC as unit (as defined in BIP21)
            ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::VRC, ui->lnReqAmount->value()));
            paramCount++;
        }
        else
        {
            ui->btnSaveAs->setEnabled(false);
            ui->lblQRCode->setText(tr("The entered amount is invalid, please check."));
            return QString("");
        }
    }

    if (!ui->lnLabel->text().isEmpty())
    {
        QString lbl(QUrl::toPercentEncoding(ui->lnLabel->text()));
        ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl);
        paramCount++;
    }

    if (!ui->lnMessage->text().isEmpty())
    {
        QString msg(QUrl::toPercentEncoding(ui->lnMessage->text()));
        ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg);
        paramCount++;
    }

    // limit URI length to prevent a DoS against the QR-Code dialog
    if (ret.length() > MAX_URI_LENGTH)
    {
        ui->btnSaveAs->setEnabled(false);
        ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
        return QString("");
    }

    ui->btnSaveAs->setEnabled(true);
    return ret;
}

void QRCodeDialog::on_lnReqAmount_textChanged()
{
    genCode();
}

void QRCodeDialog::on_lnLabel_textChanged()
{
    genCode();
}

void QRCodeDialog::on_lnMessage_textChanged()
{
    genCode();
}

void QRCodeDialog::on_btnSaveAs_clicked()
{
    QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Images (*.png)"));
    if (!fn.isEmpty())
        myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn);
}

void QRCodeDialog::on_chkReqPayment_toggled(bool fChecked)
{
    if (!fChecked)
        // if chkReqPayment is not active, don't display lnReqAmount as invalid
        ui->lnReqAmount->setValid(true);

    genCode();
}

void QRCodeDialog::updateDisplayUnit()
{
    if (model)
    {
        // Update lnReqAmount with the current unit
        ui->lnReqAmount->setDisplayUnit(model->getDisplayUnit());
    }
}

void QRCodeDialog::updateDecimalPoints()
{
    if (model)
    {
        // Update lnReqAmount with the current unit
        ui->lnReqAmount->setDisplayDecimals(model->getDecimalPoints());
    }
}
<commit_msg>fix for qr code address when scanning from mobile wallet<commit_after>#include "qrcodedialog.h"
#include "ui_qrcodedialog.h"

#include "bitcoinunits.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"

#include <QPixmap>
#include <QUrl>

#include <qrencode.h>

QRCodeDialog::QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QRCodeDialog),
    model(0),
    address(addr)
{
    ui->setupUi(this);
    this->setStyleSheet("background-color: #FFFFFF;");
    setWindowTitle(QString("%1").arg(address));

    ui->chkReqPayment->setVisible(enableReq);
    ui->lblAmount->setVisible(enableReq);
    ui->lnReqAmount->setVisible(enableReq);

    ui->lnLabel->setText(label);

    ui->btnSaveAs->setEnabled(false);

    genCode();
}

QRCodeDialog::~QRCodeDialog()
{
    delete ui;
}

void QRCodeDialog::setModel(OptionsModel *model)
{
    this->model = model;

    if (model)
    {
        connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
        connect(model, SIGNAL(decimalPointsChanged(int)), this, SLOT(updateDecimalPoints()));
    }

    // update the display unit, to not use the default ("VRC")
    updateDisplayUnit();
    // update the decimal points
    updateDecimalPoints();
}

void QRCodeDialog::genCode()
{
    QString uri = getURI();

    if (uri != "")
    {
        ui->lblQRCode->setText("");

        QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
        if (!code)
        {
            ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
            return;
        }
        myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
        myImage.fill(0xffffff);
        unsigned char *p = code->data;
        for (int y = 0; y < code->width; y++)
        {
            for (int x = 0; x < code->width; x++)
            {
                myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
                p++;
            }
        }
        QRcode_free(code);

        ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));

        ui->outUri->setPlainText(uri);
    }
}

QString QRCodeDialog::getURI()
{
    QString ret = QString("%1").arg(address);
    int paramCount = 0;

    ui->outUri->clear();

    if (ui->chkReqPayment->isChecked())
    {
        if (ui->lnReqAmount->validate())
        {
            // even if we allow a non VRC unit input in lnReqAmount, we generate the URI with VRC as unit (as defined in BIP21)
            ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::VRC, ui->lnReqAmount->value()));
            paramCount++;
        }
        else
        {
            ui->btnSaveAs->setEnabled(false);
            ui->lblQRCode->setText(tr("The entered amount is invalid, please check."));
            return QString("");
        }
    }

    if (!ui->lnLabel->text().isEmpty())
    {
        QString lbl(QUrl::toPercentEncoding(ui->lnLabel->text()));
        ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl);
        paramCount++;
    }

    if (!ui->lnMessage->text().isEmpty())
    {
        QString msg(QUrl::toPercentEncoding(ui->lnMessage->text()));
        ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg);
        paramCount++;
    }

    // limit URI length to prevent a DoS against the QR-Code dialog
    if (ret.length() > MAX_URI_LENGTH)
    {
        ui->btnSaveAs->setEnabled(false);
        ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message."));
        return QString("");
    }

    ui->btnSaveAs->setEnabled(true);
    return ret;
}

void QRCodeDialog::on_lnReqAmount_textChanged()
{
    genCode();
}

void QRCodeDialog::on_lnLabel_textChanged()
{
    genCode();
}

void QRCodeDialog::on_lnMessage_textChanged()
{
    genCode();
}

void QRCodeDialog::on_btnSaveAs_clicked()
{
    QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Images (*.png)"));
    if (!fn.isEmpty())
        myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn);
}

void QRCodeDialog::on_chkReqPayment_toggled(bool fChecked)
{
    if (!fChecked)
        // if chkReqPayment is not active, don't display lnReqAmount as invalid
        ui->lnReqAmount->setValid(true);

    genCode();
}

void QRCodeDialog::updateDisplayUnit()
{
    if (model)
    {
        // Update lnReqAmount with the current unit
        ui->lnReqAmount->setDisplayUnit(model->getDisplayUnit());
    }
}

void QRCodeDialog::updateDecimalPoints()
{
    if (model)
    {
        // Update lnReqAmount with the current unit
        ui->lnReqAmount->setDisplayDecimals(model->getDecimalPoints());
    }
}
<|endoftext|>


<commit_before>#include "splashscreen.h"
#include "clientversion.h"
#include "util.h"

#include <QPainter>
#undef loop /* ugh, remove this when the #define loop is gone from util.h */
#include <QApplication>

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
    QSplashScreen(pixmap, f)
{
    // set reference point, paddings
    int paddingLeftCol2         = 230;
    int paddingTopCol2          = 376;
    int line1 = 0;
    int line2 = 13;
    int line3 = 26;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive); // cut of testnet, place it as single object further down
    QString versionText     = QString("Version %1 ").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText1   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin developers"));
    QString copyrightText2   = QChar(0xA9)+QString(" %1 ").arg(COPYRIGHT_YEAR) + QString(tr("The FlappyCoin developers"));

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(GetBoolArg("-testnet")) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(70,70,70));

    pixPaint.setFont(QFont(font, 9*fontFactor));
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line3,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 9*fontFactor));
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line1,copyrightText1);
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line2,copyrightText2);

    pixPaint.end();

    this->setPixmap(newPixmap);
}
<commit_msg>Update splashscreen.cpp<commit_after>#include "splashscreen.h"
#include "clientversion.h"
#include "util.h"

#include <QPainter>
#undef loop /* ugh, remove this when the #define loop is gone from util.h */
#include <QApplication>

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
    QSplashScreen(pixmap, f)
{
    // set reference point, paddings
    int paddingLeftCol2         = 130;
    int paddingTopCol2          = 376;
    int line1 = 0;
    int line2 = 13;
    int line3 = 26;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive); // cut of testnet, place it as single object further down
    QString versionText     = QString("Version %1 ").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText1   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin developers"));
    QString copyrightText2   = QChar(0xA9)+QString(" %1 ").arg(COPYRIGHT_YEAR) + QString(tr("The FlappyCoin developers"));

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(GetBoolArg("-testnet")) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(70,70,70));

    pixPaint.setFont(QFont(font, 9*fontFactor));
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line3,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 9*fontFactor));
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line1,copyrightText1);
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line2,copyrightText2);

    pixPaint.end();

    this->setPixmap(newPixmap);
}
<|endoftext|>


<commit_before>#include "splashscreen.h"
#include "clientversion.h"
#include "util.h"

#include <QPainter>
#include <QApplication>

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
    QSplashScreen(pixmap, f)
{
    // set reference point, paddings
    int paddingRight            = 50;
    int paddingTop              = 50;
    int titleVersionVSpace      = 17;
    int titleCopyrightVSpace    = 35;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive); // cut of testnet, place it as single object further down
    QString versionText     = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Developers"));
    QString copyrightText2  = QChar(0xA9)+QString(" 2014 ") + QString(tr("The QubitCoin Developers"));
    QString testnetAddText  = QString(tr("[testnet]")); // define text to place as single text object

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(GetBoolArg("-testnet")) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 33*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    pixPaint.setFont(QFont(font, 33*fontFactor));
    fm = pixPaint.fontMetrics();
    titleTextWidth  = fm.width(titleText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);

    pixPaint.setFont(QFont(font, 15*fontFactor));

    // if the version string is to long, reduce size
    fm = pixPaint.fontMetrics();
    int versionTextWidth  = fm.width(versionText);
    if(versionTextWidth > titleTextWidth+paddingRight-10) {
        pixPaint.setFont(QFont(font, 10*fontFactor));
        titleVersionVSpace -= 5;
    }
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 10*fontFactor));
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace+12,copyrightText2);

    // draw testnet string if -testnet is on
    if(QApplication::applicationName().contains(QString("-testnet"))) {
        // draw copyright stuff
        QFont boldFont = QFont(font, 10*fontFactor);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    this->setPixmap(newPixmap);
}
<commit_msg>change font size<commit_after>#include "splashscreen.h"
#include "clientversion.h"
#include "util.h"

#include <QPainter>
#include <QApplication>

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
    QSplashScreen(pixmap, f)
{
    // set reference point, paddings
    int paddingRight            = 30;
    int paddingTop              = 50;
    int titleVersionVSpace      = 17;
    int titleCopyrightVSpace    = 35;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive); // cut of testnet, place it as single object further down
    QString versionText     = QString("Version %1").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Developers"));
    QString copyrightText2  = QChar(0xA9)+QString(" 2014 ") + QString(tr("The QubitCoin Developers"));
    QString testnetAddText  = QString(tr("[testnet]")); // define text to place as single text object

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(GetBoolArg("-testnet")) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 23*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    pixPaint.setFont(QFont(font, 23*fontFactor));
    fm = pixPaint.fontMetrics();
    titleTextWidth  = fm.width(titleText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop,titleText);

    pixPaint.setFont(QFont(font, 15*fontFactor));

    // if the version string is to long, reduce size
    fm = pixPaint.fontMetrics();
    int versionTextWidth  = fm.width(versionText);
    if(versionTextWidth > titleTextWidth+paddingRight-10) {
        pixPaint.setFont(QFont(font, 10*fontFactor));
        titleVersionVSpace -= 5;
    }
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 10*fontFactor));
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace+12,copyrightText2);

    // draw testnet string if -testnet is on
    if(QApplication::applicationName().contains(QString("-testnet"))) {
        // draw copyright stuff
        QFont boldFont = QFont(font, 10*fontFactor);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    this->setPixmap(newPixmap);
}
<|endoftext|>


<commit_before>// Copyright (c) 2011-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "splashscreen.h"

#include "clientversion.h"
#include "init.h"
#include "ui_interface.h"
#include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h"
#endif
#include <QMessageBox>
#include <QApplication>
#include <QPainter>
#include "mastercore_version.h"

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
    QSplashScreen(pixmap, f)
{
    setAutoFillBackground(true);

    // set reference point, paddings
    int paddingLeft             = 33;
    int paddingTop              = 245;
    int titleVersionVSpace      = 40;
    int titleCopyrightVSpace    = 58;

    float fontFactor            = 1.0;

    // define text to place
    string coreVersionStr = "Experimental UI 0.0." + strprintf("%.1f",(double)OMNICORE_VERSION_BASE/10) + OMNICORE_VERSION_TYPE;
    QString titleText       = tr("Omni Core");
    QString versionText     = QString::fromStdString(coreVersionStr);
    QString copyrightText   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers, ")) + QChar(0xA9)+QString(" 2013-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Omni Protocol developers"));
    QString testnetAddText  = QString(tr("[testnet]")); // define text to place as single text object

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(isTestNet) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 33*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    // draw version
    pixPaint.setFont(QFont(font, 20*fontFactor));
    fm = pixPaint.fontMetrics();
    pixPaint.drawText(paddingLeft,paddingTop+titleVersionVSpace,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 10*fontFactor));
    fm = pixPaint.fontMetrics();
    pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace,copyrightText);

    // draw testnet string if testnet is on
    if(isTestNet) {
        QFont boldFont = QFont(font, 10*fontFactor);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    this->setPixmap(newPixmap);

    subscribeToCoreSignals();
}

SplashScreen::~SplashScreen()
{
    unsubscribeFromCoreSignals();
}

void SplashScreen::slotFinish(QWidget *mainWin)
{
    finish(mainWin);
}

static void InitMessage(SplashScreen *splash, const std::string &message)
{
    QMetaObject::invokeMethod(splash, "showMessage",
        Qt::QueuedConnection,
        Q_ARG(QString, QString::fromStdString("\n\n" + message)), // shift down a little from absolute center
        Q_ARG(int, Qt::AlignCenter),
        Q_ARG(QColor, QColor(100,100,100)));
}

static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
{
    InitMessage(splash, title + strprintf("%d", nProgress) + "%");
}

#ifdef ENABLE_WALLET
static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
{
    wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
}
#endif

void SplashScreen::subscribeToCoreSignals()
{
    // Connect signals to client
    uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
#ifdef ENABLE_WALLET
    uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
#endif
}

void SplashScreen::unsubscribeFromCoreSignals()
{
    // Disconnect signals from client
    uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
#ifdef ENABLE_WALLET
    if(pwalletMain)
        pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
#endif
}
<commit_msg>A little more padding for splash<commit_after>// Copyright (c) 2011-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "splashscreen.h"

#include "clientversion.h"
#include "init.h"
#include "ui_interface.h"
#include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h"
#endif
#include <QMessageBox>
#include <QApplication>
#include <QPainter>
#include "mastercore_version.h"

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
    QSplashScreen(pixmap, f)
{
    setAutoFillBackground(true);

    // set reference point, paddings
    int paddingLeft             = 33;
    int paddingTop              = 245;
    int titleVersionVSpace      = 40;
    int titleCopyrightVSpace    = 58;

    float fontFactor            = 1.0;

    // define text to place
    string coreVersionStr = "Experimental UI 0.0." + strprintf("%.1f",(double)OMNICORE_VERSION_BASE/10) + OMNICORE_VERSION_TYPE;
    QString titleText       = tr("Omni Core");
    QString versionText     = QString::fromStdString(coreVersionStr);
    QString copyrightText   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers, ")) + QChar(0xA9)+QString(" 2013-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Omni Protocol developers"));
    QString testnetAddText  = QString(tr("[testnet]")); // define text to place as single text object

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(isTestNet) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 33*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    // draw version
    pixPaint.setFont(QFont(font, 20*fontFactor));
    fm = pixPaint.fontMetrics();
    pixPaint.drawText(paddingLeft,paddingTop+titleVersionVSpace,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 10*fontFactor));
    fm = pixPaint.fontMetrics();
    pixPaint.drawText(paddingLeft,paddingTop+titleCopyrightVSpace,copyrightText);

    // draw testnet string if testnet is on
    if(isTestNet) {
        QFont boldFont = QFont(font, 10*fontFactor);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    this->setPixmap(newPixmap);

    subscribeToCoreSignals();
}

SplashScreen::~SplashScreen()
{
    unsubscribeFromCoreSignals();
}

void SplashScreen::slotFinish(QWidget *mainWin)
{
    finish(mainWin);
}

static void InitMessage(SplashScreen *splash, const std::string &message)
{
    QMetaObject::invokeMethod(splash, "showMessage",
        Qt::QueuedConnection,
        Q_ARG(QString, QString::fromStdString("\n\n\n\n" + message)), // shift down a little from absolute center
        Q_ARG(int, Qt::AlignCenter),
        Q_ARG(QColor, QColor(100,100,100)));
}

static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
{
    InitMessage(splash, title + strprintf("%d", nProgress) + "%");
}

#ifdef ENABLE_WALLET
static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
{
    wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
}
#endif

void SplashScreen::subscribeToCoreSignals()
{
    // Connect signals to client
    uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
#ifdef ENABLE_WALLET
    uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
#endif
}

void SplashScreen::unsubscribeFromCoreSignals()
{
    // Disconnect signals from client
    uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
#ifdef ENABLE_WALLET
    if(pwalletMain)
        pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
#endif
}
<|endoftext|>


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

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif

class SwFilterBase
{
protected:
    SvStream    *pIn;
    sal_Char    *pReadBuff; //      Groessenangabe
    INT32       nBytesLeft; // noch zu lesende Bytes des aktuelle Records

    CharSet     eQuellChar; // Quell-Zeichensatz (interner Zeichensatz)
//  CharSet     eZielChar;  // Ziel-Zeichensatz

    USHORT      nTab;       // z.Zt. bearbeitete Tabelle
    USHORT      nReadBuffSize;// temporaerer Lesepuffer mit

    // ----------------------------------------------------------
    inline void ReadChar( char &rC );
    inline void ReadByte( BYTE &rN );
    inline void Read( short &rN );
    inline void ReadUnicode( sal_Unicode &rU );
    inline void Read( BYTE &rN0, USHORT &rN1, USHORT &rN2 );
    inline void Read( USHORT &rN );
    inline void Read( USHORT &rN1, USHORT &rN2 );
    inline void Read( USHORT &rN1, USHORT &rN2, USHORT &rN3, USHORT &rN4 );
    inline void Read( double &rF );
            void Read( String &rS );        // liest 0-terminierten C-String!
    inline void ClearBytesLeft( void );
};

inline void SwFilterBase::ReadChar( char &rC )
    {
    *pIn >> rC;
    nBytesLeft--;
    }

inline void SwFilterBase::ReadByte( BYTE &rN )
    {
    *pIn >> rN;
    nBytesLeft--;
    }

inline void SwFilterBase::ReadUnicode( sal_Unicode &rU )
{
    {
    sal_Char cC;
    *pIn >> cC;
    rU = ByteString::ConvertToUnicode(cC, eQuellChar);
    nBytesLeft--;
    }
}

inline void SwFilterBase::Read( short &rN )
    {
    *pIn >> rN;
    nBytesLeft -= 2;
    }

inline void SwFilterBase::Read( BYTE &rN0, USHORT &rN1, USHORT &rN2 )
    {
    *pIn >> rN0 >> rN1 >> rN2;
    nBytesLeft -= 5;
    }

inline void SwFilterBase::Read( USHORT &rN )
    {
    *pIn >> rN;
    nBytesLeft -= 2;
    }

inline void SwFilterBase::Read( USHORT &rN1, USHORT &rN2 )
    {
    *pIn >> rN1 >> rN2;
    nBytesLeft -= 4;
    }

inline void SwFilterBase::Read( USHORT &rN1, USHORT &rN2, USHORT &rN3, USHORT &rN4 )
    {
    *pIn >> rN1 >> rN2 >> rN3 >> rN4;
    nBytesLeft -= 8;
    }

inline void SwFilterBase::Read( double &rF )
    {
    *pIn >> rF;
    nBytesLeft -= 8;
    }

inline void SwFilterBase::ClearBytesLeft( void )
    {
    pIn->SeekRel( nBytesLeft );
    nBytesLeft = 0;
    }

#endif

<commit_msg>INTEGRATION: CWS ooo19126 (1.1.1.1.1462); FILE MERGED 2005/09/05 13:42:10 rt 1.1.1.1.1462.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: fltbase.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 05:49:01 $
 *
 *  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 __FLTBASE_HXX__
#define __FLTBASE_HXX__

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif

class SwFilterBase
{
protected:
    SvStream    *pIn;
    sal_Char    *pReadBuff; //      Groessenangabe
    INT32       nBytesLeft; // noch zu lesende Bytes des aktuelle Records

    CharSet     eQuellChar; // Quell-Zeichensatz (interner Zeichensatz)
//  CharSet     eZielChar;  // Ziel-Zeichensatz

    USHORT      nTab;       // z.Zt. bearbeitete Tabelle
    USHORT      nReadBuffSize;// temporaerer Lesepuffer mit

    // ----------------------------------------------------------
    inline void ReadChar( char &rC );
    inline void ReadByte( BYTE &rN );
    inline void Read( short &rN );
    inline void ReadUnicode( sal_Unicode &rU );
    inline void Read( BYTE &rN0, USHORT &rN1, USHORT &rN2 );
    inline void Read( USHORT &rN );
    inline void Read( USHORT &rN1, USHORT &rN2 );
    inline void Read( USHORT &rN1, USHORT &rN2, USHORT &rN3, USHORT &rN4 );
    inline void Read( double &rF );
            void Read( String &rS );        // liest 0-terminierten C-String!
    inline void ClearBytesLeft( void );
};

inline void SwFilterBase::ReadChar( char &rC )
    {
    *pIn >> rC;
    nBytesLeft--;
    }

inline void SwFilterBase::ReadByte( BYTE &rN )
    {
    *pIn >> rN;
    nBytesLeft--;
    }

inline void SwFilterBase::ReadUnicode( sal_Unicode &rU )
{
    {
    sal_Char cC;
    *pIn >> cC;
    rU = ByteString::ConvertToUnicode(cC, eQuellChar);
    nBytesLeft--;
    }
}

inline void SwFilterBase::Read( short &rN )
    {
    *pIn >> rN;
    nBytesLeft -= 2;
    }

inline void SwFilterBase::Read( BYTE &rN0, USHORT &rN1, USHORT &rN2 )
    {
    *pIn >> rN0 >> rN1 >> rN2;
    nBytesLeft -= 5;
    }

inline void SwFilterBase::Read( USHORT &rN )
    {
    *pIn >> rN;
    nBytesLeft -= 2;
    }

inline void SwFilterBase::Read( USHORT &rN1, USHORT &rN2 )
    {
    *pIn >> rN1 >> rN2;
    nBytesLeft -= 4;
    }

inline void SwFilterBase::Read( USHORT &rN1, USHORT &rN2, USHORT &rN3, USHORT &rN4 )
    {
    *pIn >> rN1 >> rN2 >> rN3 >> rN4;
    nBytesLeft -= 8;
    }

inline void SwFilterBase::Read( double &rF )
    {
    *pIn >> rF;
    nBytesLeft -= 8;
    }

inline void SwFilterBase::ClearBytesLeft( void )
    {
    pIn->SeekRel( nBytesLeft );
    nBytesLeft = 0;
    }

#endif

<|endoftext|>


<commit_before>#include "PointLightShadow.h"
#include "PointLight.h"

using namespace Rendering::Shadow;
using namespace Rendering::Light;

PointLightShadow::PointLightShadow(const LightForm* owner,
								   const std::function<void()>& ownerUpdateCounter)
	: ShadowCommon(owner, ownerUpdateCounter)
{
}

PointLightShadow::~PointLightShadow()
{
}

void PointLightShadow::MakeParam(Param& outParam, bool useVSM) const
{
	ShadowCommon::MakeParam(outParam);

	const PointLight* light = dynamic_cast<const PointLight*>(_owner);

#ifdef USE_SHADOW_INVERTED_DEPTH
	if(useVSM)
		light->GetInvViewProjectionMatrices(outParam.viewProjMat);
	else
#else
		light->GetViewProjectionMatrices(outParam.viewProjMat);
#endif

	for(uint i=0; i<6; ++i)
		Math::Matrix::Transpose(outParam.viewProjMat[i], outParam.viewProjMat[i]);
}<commit_msg>PointLightShadow - 오타 수정<commit_after>#include "PointLightShadow.h"
#include "PointLight.h"

using namespace Rendering::Shadow;
using namespace Rendering::Light;

PointLightShadow::PointLightShadow(const LightForm* owner,
								   const std::function<void()>& ownerUpdateCounter)
	: ShadowCommon(owner, ownerUpdateCounter)
{
}

PointLightShadow::~PointLightShadow()
{
}

void PointLightShadow::MakeParam(Param& outParam, bool useVSM) const
{
	ShadowCommon::MakeParam(outParam);

	const PointLight* light = dynamic_cast<const PointLight*>(_owner);

#ifdef USE_SHADOW_INVERTED_DEPTH
	if(useVSM)
		light->GetInvViewProjMatrices(outParam.viewProjMat);
	else
#else
		light->GetViewProjectionMatrices(outParam.viewProjMat);
#endif

	for(uint i=0; i<6; ++i)
		Math::Matrix::Transpose(outParam.viewProjMat[i], outParam.viewProjMat[i]);
}<|endoftext|>


<commit_before>//---
//
// License: MIT
//
// Description: OSSIM Amazon Web Services (AWS) plugin initialization
// code.
//
//---
// $Id$

#include "ossimAwsStreamFactory.h"
#include <ossim/plugin/ossimSharedObjectBridge.h>
#include <ossim/plugin/ossimPluginConstants.h>
#include <ossim/base/ossimStreamFactoryRegistry.h>
#include <aws/core/Aws.h>

static void setDescription(ossimString& description)
{
   description = "AWS S3 plugin\n\n";
}

extern "C"
{
   ossimSharedObjectInfo  myInfo;
   ossimString theDescription;
   std::vector<ossimString> theObjList;

   const char* getDescription()
   {
      return theDescription.c_str();
   }

   int getNumberOfClassNames()
   {
      return (int)theObjList.size();
   }

   const char* getClassName(int idx)
   {
      if(idx < (int)theObjList.size())
      {
         return theObjList[0].c_str();
      }
      return (const char*)0;
   }

   /* Note symbols need to be exported on windoze... */
   OSSIM_PLUGINS_DLL void ossimSharedLibraryInitialize(
      ossimSharedObjectInfo** info, const char* /*options*/)
   {
      Aws::SDKOptions options;
      Aws::InitAPI(options);

      myInfo.getDescription = getDescription;
      myInfo.getNumberOfClassNames = getNumberOfClassNames;
      myInfo.getClassName = getClassName;

      *info = &myInfo;

      /* Register our stream factory... */
      ossim::StreamFactoryRegistry::instance()->
         registerFactory( ossim::AwsStreamFactory::instance() );

      setDescription(theDescription);
  }

   /* Note symbols need to be exported on windoze... */
  OSSIM_PLUGINS_DLL void ossimSharedLibraryFinalize()
  {
     ossim::StreamFactoryRegistry::instance()->
        unregisterFactory( ossim::AwsStreamFactory::instance() );
  }
}
<commit_msg>Adding some debug to help on centos<commit_after>//---
//
// License: MIT
//
// Description: OSSIM Amazon Web Services (AWS) plugin initialization
// code.
//
//---
// $Id$

#include "ossimAwsStreamFactory.h"
#include <ossim/plugin/ossimSharedObjectBridge.h>
#include <ossim/plugin/ossimPluginConstants.h>
#include <ossim/base/ossimStreamFactoryRegistry.h>
#include <aws/core/Aws.h>

static void setDescription(ossimString& description)
{
   description = "AWS S3 plugin\n\n";
}

extern "C"
{
   ossimSharedObjectInfo  myInfo;
   ossimString theDescription;
   std::vector<ossimString> theObjList;

   const char* getDescription()
   {
      return theDescription.c_str();
   }

   int getNumberOfClassNames()
   {
      return (int)theObjList.size();
   }

   const char* getClassName(int idx)
   {
      if(idx < (int)theObjList.size())
      {
         return theObjList[0].c_str();
      }
      return (const char*)0;
   }

   /* Note symbols need to be exported on windoze... */
   OSSIM_PLUGINS_DLL void ossimSharedLibraryInitialize(
      ossimSharedObjectInfo** info, const char* /*options*/)
   {
      std::cout << "AWS Plugin ossimSharedLibraryInitialize INITIALIZING THE API\n";
      Aws::SDKOptions options;
      Aws::InitAPI(options);

      myInfo.getDescription = getDescription;
      myInfo.getNumberOfClassNames = getNumberOfClassNames;
      myInfo.getClassName = getClassName;

      *info = &myInfo;

      /* Register our stream factory... */
      ossim::StreamFactoryRegistry::instance()->
         registerFactory( ossim::AwsStreamFactory::instance() );

      setDescription(theDescription);
      std::cout << "AWS Plugin ossimSharedLibraryInitialize FINISHED INITIALIZING THE API\n";
  }

   /* Note symbols need to be exported on windoze... */
  OSSIM_PLUGINS_DLL void ossimSharedLibraryFinalize()
  {
     ossim::StreamFactoryRegistry::instance()->
        unregisterFactory( ossim::AwsStreamFactory::instance() );
  }
}
<|endoftext|>


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

#ifndef _UNIVERSALL_REFERENCE_HXX
#include "uniref.hxx"
#endif
#ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
#include "xmlprmap.hxx"
#endif
#ifndef _XMLOFF_XMLEXPPR_HXX
#include "xmlexppr.hxx"
#endif
#ifndef _XMLOFF_XMLIMPPR_HXX
#include "xmlimppr.hxx"
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include "xmlimp.hxx"
#endif

namespace rtl { class OUString; }

extern const XMLPropertyMapEntry aXMLChartPropMap[];

class SvXMLExport;

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

class XMLChartPropHdlFactory : public XMLPropertyHandlerFactory
{
private:
    const XMLPropertyHandler* GetShapePropertyHandler( sal_Int32 nType ) const;

public:
    virtual ~XMLChartPropHdlFactory();
    virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const;
};

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

class XMLChartPropertySetMapper : public XMLPropertySetMapper
{
public:
    XMLChartPropertySetMapper();
    ~XMLChartPropertySetMapper();
};

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

class XMLChartExportPropertyMapper : public SvXMLExportPropertyMapper
{
private:
    const rtl::OUString msTrue;
    const rtl::OUString msFalse;

    SvXMLExport& mrExport;

protected:
    virtual void ContextFilter(
        ::std::vector< XMLPropertyState >& rProperties,
        ::com::sun::star::uno::Reference<
            ::com::sun::star::beans::XPropertySet > rPropSet ) const;

private:
    /// this method is called for every item that has the MID_FLAG_ELEMENT_EXPORT flag set
    virtual void handleElementItem(
        SvXMLExport& rExport,
        const XMLPropertyState& rProperty, sal_uInt16 nFlags,
        const ::std::vector< XMLPropertyState > *pProperties = 0,
        sal_uInt32 nIdx = 0  ) const;

    /// this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_EXPORT flag set
    virtual void handleSpecialItem(
        SvXMLAttributeList& rAttrList, const XMLPropertyState& rProperty,
        const SvXMLUnitConverter& rUnitConverter, const SvXMLNamespaceMap& rNamespaceMap,
        const ::std::vector< XMLPropertyState > *pProperties = 0,
        sal_uInt32 nIdx = 0  ) const;

public:
    XMLChartExportPropertyMapper( const UniReference< XMLPropertySetMapper >& rMapper,
                                  SvXMLExport& rExport );
    virtual ~XMLChartExportPropertyMapper();
};

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

class XMLChartImportPropertyMapper : public SvXMLImportPropertyMapper
{
private:
    SvXMLImport& mrImport;

public:
    XMLChartImportPropertyMapper( const UniReference< XMLPropertySetMapper >& rMapper,
                                  const SvXMLImport& rImport );
    virtual ~XMLChartImportPropertyMapper();

    virtual sal_Bool handleSpecialItem(
        XMLPropertyState& rProperty,
        ::std::vector< XMLPropertyState >& rProperties,
        const ::rtl::OUString& rValue,
        const SvXMLUnitConverter& rUnitConverter,
        const SvXMLNamespaceMap& rNamespaceMap ) const;

    virtual void finished(
        ::std::vector< XMLPropertyState >& rProperties,
        sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
};

#endif  // _XMLOFF_CHARTPROPERTYSETMAPPER_HXX_
<commit_msg>INTEGRATION: CWS ooo19126 (1.7.538); FILE MERGED 2005/09/05 14:37:54 rt 1.7.538.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: XMLChartPropertySetMapper.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 12:46:40 $
 *
 *  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 _XMLOFF_CHARTPROPERTYSETMAPPER_HXX_
#define _XMLOFF_CHARTPROPERTYSETMAPPER_HXX_

#ifndef _UNIVERSALL_REFERENCE_HXX
#include "uniref.hxx"
#endif
#ifndef _XMLOFF_PROPERTYSETMAPPER_HXX
#include "xmlprmap.hxx"
#endif
#ifndef _XMLOFF_XMLEXPPR_HXX
#include "xmlexppr.hxx"
#endif
#ifndef _XMLOFF_XMLIMPPR_HXX
#include "xmlimppr.hxx"
#endif
#ifndef _XMLOFF_XMLIMP_HXX
#include "xmlimp.hxx"
#endif

namespace rtl { class OUString; }

extern const XMLPropertyMapEntry aXMLChartPropMap[];

class SvXMLExport;

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

class XMLChartPropHdlFactory : public XMLPropertyHandlerFactory
{
private:
    const XMLPropertyHandler* GetShapePropertyHandler( sal_Int32 nType ) const;

public:
    virtual ~XMLChartPropHdlFactory();
    virtual const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nType ) const;
};

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

class XMLChartPropertySetMapper : public XMLPropertySetMapper
{
public:
    XMLChartPropertySetMapper();
    ~XMLChartPropertySetMapper();
};

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

class XMLChartExportPropertyMapper : public SvXMLExportPropertyMapper
{
private:
    const rtl::OUString msTrue;
    const rtl::OUString msFalse;

    SvXMLExport& mrExport;

protected:
    virtual void ContextFilter(
        ::std::vector< XMLPropertyState >& rProperties,
        ::com::sun::star::uno::Reference<
            ::com::sun::star::beans::XPropertySet > rPropSet ) const;

private:
    /// this method is called for every item that has the MID_FLAG_ELEMENT_EXPORT flag set
    virtual void handleElementItem(
        SvXMLExport& rExport,
        const XMLPropertyState& rProperty, sal_uInt16 nFlags,
        const ::std::vector< XMLPropertyState > *pProperties = 0,
        sal_uInt32 nIdx = 0  ) const;

    /// this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_EXPORT flag set
    virtual void handleSpecialItem(
        SvXMLAttributeList& rAttrList, const XMLPropertyState& rProperty,
        const SvXMLUnitConverter& rUnitConverter, const SvXMLNamespaceMap& rNamespaceMap,
        const ::std::vector< XMLPropertyState > *pProperties = 0,
        sal_uInt32 nIdx = 0  ) const;

public:
    XMLChartExportPropertyMapper( const UniReference< XMLPropertySetMapper >& rMapper,
                                  SvXMLExport& rExport );
    virtual ~XMLChartExportPropertyMapper();
};

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

class XMLChartImportPropertyMapper : public SvXMLImportPropertyMapper
{
private:
    SvXMLImport& mrImport;

public:
    XMLChartImportPropertyMapper( const UniReference< XMLPropertySetMapper >& rMapper,
                                  const SvXMLImport& rImport );
    virtual ~XMLChartImportPropertyMapper();

    virtual sal_Bool handleSpecialItem(
        XMLPropertyState& rProperty,
        ::std::vector< XMLPropertyState >& rProperties,
        const ::rtl::OUString& rValue,
        const SvXMLUnitConverter& rUnitConverter,
        const SvXMLNamespaceMap& rNamespaceMap ) const;

    virtual void finished(
        ::std::vector< XMLPropertyState >& rProperties,
        sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
};

#endif  // _XMLOFF_CHARTPROPERTYSETMAPPER_HXX_
<|endoftext|>


<commit_before>#ifndef _METALUA_CLASSDEFINE_HPP_
#define _METALUA_CLASSDEFINE_HPP_

#include <cassert>
#include <new>

#include "MetaLua/BaseDefine.hpp"

DECL_NAMESPACE_METALUA_BEGIN

/* macros */

#define CTYPENAME_LIST_0 typename R, typename T
#define CTYPENAME_LIST_1 CTYPENAME_LIST_0, typename P1
#define CTYPENAME_LIST_2 CTYPENAME_LIST_1, typename P2
#define CTYPENAME_LIST_3 CTYPENAME_LIST_2, typename P3
#define CTYPENAME_LIST_4 CTYPENAME_LIST_3, typename P4
#define CTYPENAME_LIST_5 CTYPENAME_LIST_4, typename P5
#define CTYPENAME_LIST_6 CTYPENAME_LIST_5, typename P6
#define CTYPENAME_LIST_7 CTYPENAME_LIST_6, typename P7
#define CTYPENAME_LIST_8 CTYPENAME_LIST_7, typename P8
#define CTYPENAME_LIST_9 CTYPENAME_LIST_8, typename P9

#define CTYPENAME_VOID_LIST_0 typename T
#define CTYPENAME_VOID_LIST_1 CTYPENAME_VOID_LIST_0, typename P1
#define CTYPENAME_VOID_LIST_2 CTYPENAME_VOID_LIST_1, typename P2
#define CTYPENAME_VOID_LIST_3 CTYPENAME_VOID_LIST_2, typename P3
#define CTYPENAME_VOID_LIST_4 CTYPENAME_VOID_LIST_3, typename P4
#define CTYPENAME_VOID_LIST_5 CTYPENAME_VOID_LIST_4, typename P5
#define CTYPENAME_VOID_LIST_6 CTYPENAME_VOID_LIST_5, typename P6
#define CTYPENAME_VOID_LIST_7 CTYPENAME_VOID_LIST_6, typename P7
#define CTYPENAME_VOID_LIST_8 CTYPENAME_VOID_LIST_7, typename P8
#define CTYPENAME_VOID_LIST_9 CTYPENAME_VOID_LIST_8, typename P9

#define CTYPE_LIST_0 R, T
#define CTYPE_LIST_1 CTYPE_LIST_0, P1
#define CTYPE_LIST_2 CTYPE_LIST_1, P2
#define CTYPE_LIST_3 CTYPE_LIST_2, P3
#define CTYPE_LIST_4 CTYPE_LIST_3, P4
#define CTYPE_LIST_5 CTYPE_LIST_4, P5
#define CTYPE_LIST_6 CTYPE_LIST_5, P6
#define CTYPE_LIST_7 CTYPE_LIST_6, P7
#define CTYPE_LIST_8 CTYPE_LIST_7, P8
#define CTYPE_LIST_9 CTYPE_LIST_8, P9

#define CTYPE_VOID_LIST_0 void, T
#define CTYPE_VOID_LIST_1 CTYPE_VOID_LIST_0, P1
#define CTYPE_VOID_LIST_2 CTYPE_VOID_LIST_1, P2
#define CTYPE_VOID_LIST_3 CTYPE_VOID_LIST_2, P3
#define CTYPE_VOID_LIST_4 CTYPE_VOID_LIST_3, P4
#define CTYPE_VOID_LIST_5 CTYPE_VOID_LIST_4, P5
#define CTYPE_VOID_LIST_6 CTYPE_VOID_LIST_5, P6
#define CTYPE_VOID_LIST_7 CTYPE_VOID_LIST_6, P7
#define CTYPE_VOID_LIST_8 CTYPE_VOID_LIST_7, P8
#define CTYPE_VOID_LIST_9 CTYPE_VOID_LIST_8, P9

#define CPARAM_TYPE_LIST_0
#define CPARAM_TYPE_LIST_1 CPARAM_TYPE_LIST_0  P1
#define CPARAM_TYPE_LIST_2 CPARAM_TYPE_LIST_1, P2
#define CPARAM_TYPE_LIST_3 CPARAM_TYPE_LIST_2, P3
#define CPARAM_TYPE_LIST_4 CPARAM_TYPE_LIST_3, P4
#define CPARAM_TYPE_LIST_5 CPARAM_TYPE_LIST_4, P5
#define CPARAM_TYPE_LIST_6 CPARAM_TYPE_LIST_5, P6
#define CPARAM_TYPE_LIST_7 CPARAM_TYPE_LIST_6, P7
#define CPARAM_TYPE_LIST_8 CPARAM_TYPE_LIST_7, P8
#define CPARAM_TYPE_LIST_9 CPARAM_TYPE_LIST_8, P9

#define CARG_LIST_0
#define CARG_LIST_1 CARG_LIST_0  ReadToCpp<P1>(L, 2)
#define CARG_LIST_2 CARG_LIST_1, ReadToCpp<P2>(L, 3)
#define CARG_LIST_3 CARG_LIST_2, ReadToCpp<P3>(L, 4)
#define CARG_LIST_4 CARG_LIST_3, ReadToCpp<P4>(L, 5)
#define CARG_LIST_5 CARG_LIST_4, ReadToCpp<P5>(L, 6)
#define CARG_LIST_6 CARG_LIST_5, ReadToCpp<P6>(L, 7)
#define CARG_LIST_7 CARG_LIST_6, ReadToCpp<P7>(L, 8)
#define CARG_LIST_8 CARG_LIST_7, ReadToCpp<P8>(L, 9)
#define CARG_LIST_9 CARG_LIST_8, ReadToCpp<P9>(L, 10)

/* register class method */

struct GenericMethod {
    virtual int Call(lua_State *L) = 0;
};

#define DEF_METHOD_DATA(N) \
template<CTYPENAME_LIST_##N> \
struct MethodData##N : public GenericMethod { \
    typedef R (T::*Method)(CPARAM_TYPE_LIST_##N); \
    Method m_method; \
    MethodData##N(Method method) : m_method(method) {} \
    int Call(lua_State* L) override final { \
        auto object = ReadToCpp<T*>(L, 1); \
        auto result = (object->*m_method)(CARG_LIST_##N); \
        PushToLua<R>(L, result); \
        return 1; \
    } \
};

#define DEF_VOID_METHOD_DATA(N) \
template<CTYPENAME_VOID_LIST_##N> \
struct MethodData##N<CTYPE_VOID_LIST_##N> : public GenericMethod { \
    typedef void (T::*Method)(CPARAM_TYPE_LIST_##N); \
    Method m_method; \
    MethodData##N(Method method) : m_method(method) {} \
    int Call(lua_State* L) override final { \
        auto object = ReadToCpp<T*>(L, 1); \
        (object->*m_method)(CARG_LIST_##N); \
        return 0; \
    } \
};

template<typename T>
inline int ProxyMethodCall(lua_State *L) {
    auto index = lua_upvalueindex(1);
    auto memory = lua_touserdata(L, index);
    auto method = static_cast<GenericMethod*>(memory);
    return method->Call(L);
}

#define DEF_REGISTER_METHOD(N) \
template<CTYPENAME_LIST_##N> \
inline void RegisterMethodToLua(lua_State* L, const char* name, \
    R (T::*method)(CPARAM_TYPE_LIST_##N)) { \
    luaL_getmetatable(L, ClassInfo<T>::Name()); \
    lua_pushstring(L, name); \
    typedef MethodData##N<CTYPE_LIST_##N> MethodData_t; \
    auto memory = lua_newuserdata(L, sizeof(MethodData_t)); \
    new(memory) MethodData_t(method); \
    lua_pushcclosure(L, &ProxyMethodCall<T>, 1); \
    lua_rawset(L, -3); \
    lua_pop(L, 1); \
}

DEF_METHOD_DATA(9)
DEF_METHOD_DATA(8)
DEF_METHOD_DATA(7)
DEF_METHOD_DATA(6)
DEF_METHOD_DATA(5)
DEF_METHOD_DATA(4)
DEF_METHOD_DATA(3)
DEF_METHOD_DATA(2)
DEF_METHOD_DATA(1)
DEF_METHOD_DATA(0)

DEF_VOID_METHOD_DATA(9)
DEF_VOID_METHOD_DATA(8)
DEF_VOID_METHOD_DATA(7)
DEF_VOID_METHOD_DATA(6)
DEF_VOID_METHOD_DATA(5)
DEF_VOID_METHOD_DATA(4)
DEF_VOID_METHOD_DATA(3)
DEF_VOID_METHOD_DATA(2)
DEF_VOID_METHOD_DATA(1)
DEF_VOID_METHOD_DATA(0)

DEF_REGISTER_METHOD(9)
DEF_REGISTER_METHOD(8)
DEF_REGISTER_METHOD(7)
DEF_REGISTER_METHOD(6)
DEF_REGISTER_METHOD(5)
DEF_REGISTER_METHOD(4)
DEF_REGISTER_METHOD(3)
DEF_REGISTER_METHOD(2)
DEF_REGISTER_METHOD(1)
DEF_REGISTER_METHOD(0)

/* register class member */

struct GenericMember {
    virtual int Get(lua_State* L) = 0;
    virtual int Set(lua_State* L) = 0;
};

template<typename T, typename V>
struct MemberData : public GenericMember {
    typedef V T::*Var;
    Var m_var;
    MemberData(Var var) : m_var(var) {}
    int Get(lua_State* L) override final {
        auto object = ReadToCpp<T*>(L, 1);
        auto member = object->*m_var;
        PushToLua<V>(L, member);
        return 1;
    }
    int Set(lua_State* L) override final {
        auto object = ReadToCpp<T*>(L, 1);
        auto& member = object->*m_var;
        member = ReadToCpp<V>(L, 3);
        return 0;
    }
};

template<typename T, typename P>
void RegisterMemberToLua(lua_State* L, const char* name, P T::*member) {
    luaL_getmetatable(L, ClassInfo<T>::Name());
    typedef MemberData<T, P> MemberData_t;
    lua_pushstring(L, name);
    auto memory = lua_newuserdata(L, sizeof(MemberData_t));
    new(memory) MemberData_t(member);
    lua_rawset(L, -3);
    lua_pop(L, 1);
}

/* register class object */

template<typename T>
void RegisterObjectToLua(lua_State* L, const char* name, T* object) {
    typedef UserData<T*> UserData_t;
    auto memory = lua_newuserdata(L, sizeof(UserData_t));
    new(memory) UserData_t(object);
    luaL_getmetatable(L, ClassInfo<T>::Name());
    lua_setmetatable(L, -2);
    lua_setglobal(L, name);
}

/* inherit parent class */

template<typename T, typename P>
void InheritParentToLua(lua_State* L) {
    luaL_getmetatable(L, ClassInfo<T>::Name());
    if (lua_istable(L, -1)) {
        lua_pushstring(L, "__parent");
        luaL_getmetatable(L, ClassInfo<P>::Name());
        lua_rawset(L, -3);
    }
    lua_pop(L, 1);
}

inline void InvokeParent(lua_State *L) {
    lua_pushstring(L, "__parent");
    lua_rawget(L, -2);
    if (lua_istable(L, -1)) {
        lua_pushvalue(L, 2);
        lua_rawget(L, -2);
        if (lua_isnil(L, -1)) {
            lua_remove(L, -1);
            InvokeParent(L);
        }
        lua_remove(L, -2);
    }
}

/* set metatable for class */

template<typename T>
inline int MetaGet(lua_State* L) {
    lua_getmetatable(L, 1);
    lua_pushvalue(L, 2);
    lua_rawget(L, -2);
    if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
    }
    if (lua_isuserdata(L, -1)) {
        auto memory = lua_touserdata(L, -1);
        auto member = static_cast<GenericMember*>(memory);
        member->Get(L);
        lua_remove(L, -2);
    }
    else if (lua_isfunction(L, -1)) {
        // methods
    }
    else if (lua_isnil(L, -1)) {
        lua_error(L);
    }
    lua_remove(L, -2);
    return 1;
}

template<typename T>
inline int MetaSet(lua_State* L) {
    lua_getmetatable(L, 1);
    lua_pushvalue(L, 2);
    lua_rawget(L, -2);
    if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
    }
    if (lua_isuserdata(L, -1)) {
        auto memory = lua_touserdata(L, -1);
        auto member = static_cast<GenericMember*>(memory);
        member->Set(L);
    }
    else if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
        if (lua_isnil(L, -1)) {
            lua_pushvalue(L, 2);
            lua_pushvalue(L, 3);
            lua_rawset(L, -4);
        }
    }
    lua_settop(L, 3);
    return 0;
}

template<typename T>
inline int DoGc(lua_State* L) {
    return 0;
}

template<typename T>
void SetMetatable(lua_State* L, const char* className) {
    luaL_newmetatable(L, className);

    lua_pushliteral(L, "__index");
    lua_pushcfunction(L, MetaGet<T>);
    lua_settable(L, -3);

    lua_pushliteral(L, "__newindex");
    lua_pushcfunction(L, MetaSet<T>);
    lua_settable(L, -3);

    lua_pushliteral(L, "__gc");
    lua_pushcfunction(L, DoGc<T>);
    lua_settable(L, -3);

    lua_setmetatable(L, -2);
}

/* register class type */

template<typename T>
void RegisterClassToLua(lua_State* L, const char* className) {
    ClassInfo<T>::Name(className);
    lua_newtable(L);
    SetMetatable<T>(L, className);
    lua_setglobal(L, className);
}

DECL_NAMESPACE_METALUA_END

#endif // _METALUA_CLASSDEFINE_HPP_
<commit_msg>Add more features.<commit_after>#ifndef _METALUA_CLASSDEFINE_HPP_
#define _METALUA_CLASSDEFINE_HPP_

#include <cassert>
#include <new>

#include "MetaLua/BaseDefine.hpp"

DECL_NAMESPACE_METALUA_BEGIN

/* macros */

#define CTYPENAME_LIST_0 typename R, typename T
#define CTYPENAME_LIST_1 CTYPENAME_LIST_0, typename P1
#define CTYPENAME_LIST_2 CTYPENAME_LIST_1, typename P2
#define CTYPENAME_LIST_3 CTYPENAME_LIST_2, typename P3
#define CTYPENAME_LIST_4 CTYPENAME_LIST_3, typename P4
#define CTYPENAME_LIST_5 CTYPENAME_LIST_4, typename P5
#define CTYPENAME_LIST_6 CTYPENAME_LIST_5, typename P6
#define CTYPENAME_LIST_7 CTYPENAME_LIST_6, typename P7
#define CTYPENAME_LIST_8 CTYPENAME_LIST_7, typename P8
#define CTYPENAME_LIST_9 CTYPENAME_LIST_8, typename P9

#define CTYPENAME_VOID_LIST_0 typename T
#define CTYPENAME_VOID_LIST_1 CTYPENAME_VOID_LIST_0, typename P1
#define CTYPENAME_VOID_LIST_2 CTYPENAME_VOID_LIST_1, typename P2
#define CTYPENAME_VOID_LIST_3 CTYPENAME_VOID_LIST_2, typename P3
#define CTYPENAME_VOID_LIST_4 CTYPENAME_VOID_LIST_3, typename P4
#define CTYPENAME_VOID_LIST_5 CTYPENAME_VOID_LIST_4, typename P5
#define CTYPENAME_VOID_LIST_6 CTYPENAME_VOID_LIST_5, typename P6
#define CTYPENAME_VOID_LIST_7 CTYPENAME_VOID_LIST_6, typename P7
#define CTYPENAME_VOID_LIST_8 CTYPENAME_VOID_LIST_7, typename P8
#define CTYPENAME_VOID_LIST_9 CTYPENAME_VOID_LIST_8, typename P9

#define CTYPE_LIST_0 R, T
#define CTYPE_LIST_1 CTYPE_LIST_0, P1
#define CTYPE_LIST_2 CTYPE_LIST_1, P2
#define CTYPE_LIST_3 CTYPE_LIST_2, P3
#define CTYPE_LIST_4 CTYPE_LIST_3, P4
#define CTYPE_LIST_5 CTYPE_LIST_4, P5
#define CTYPE_LIST_6 CTYPE_LIST_5, P6
#define CTYPE_LIST_7 CTYPE_LIST_6, P7
#define CTYPE_LIST_8 CTYPE_LIST_7, P8
#define CTYPE_LIST_9 CTYPE_LIST_8, P9

#define CTYPE_VOID_LIST_0 void, T
#define CTYPE_VOID_LIST_1 CTYPE_VOID_LIST_0, P1
#define CTYPE_VOID_LIST_2 CTYPE_VOID_LIST_1, P2
#define CTYPE_VOID_LIST_3 CTYPE_VOID_LIST_2, P3
#define CTYPE_VOID_LIST_4 CTYPE_VOID_LIST_3, P4
#define CTYPE_VOID_LIST_5 CTYPE_VOID_LIST_4, P5
#define CTYPE_VOID_LIST_6 CTYPE_VOID_LIST_5, P6
#define CTYPE_VOID_LIST_7 CTYPE_VOID_LIST_6, P7
#define CTYPE_VOID_LIST_8 CTYPE_VOID_LIST_7, P8
#define CTYPE_VOID_LIST_9 CTYPE_VOID_LIST_8, P9

#define CPARAM_TYPE_LIST_0
#define CPARAM_TYPE_LIST_1 CPARAM_TYPE_LIST_0  P1
#define CPARAM_TYPE_LIST_2 CPARAM_TYPE_LIST_1, P2
#define CPARAM_TYPE_LIST_3 CPARAM_TYPE_LIST_2, P3
#define CPARAM_TYPE_LIST_4 CPARAM_TYPE_LIST_3, P4
#define CPARAM_TYPE_LIST_5 CPARAM_TYPE_LIST_4, P5
#define CPARAM_TYPE_LIST_6 CPARAM_TYPE_LIST_5, P6
#define CPARAM_TYPE_LIST_7 CPARAM_TYPE_LIST_6, P7
#define CPARAM_TYPE_LIST_8 CPARAM_TYPE_LIST_7, P8
#define CPARAM_TYPE_LIST_9 CPARAM_TYPE_LIST_8, P9

#define CARG_LIST_0
#define CARG_LIST_1 CARG_LIST_0  ReadToCpp<P1>(L, 2)
#define CARG_LIST_2 CARG_LIST_1, ReadToCpp<P2>(L, 3)
#define CARG_LIST_3 CARG_LIST_2, ReadToCpp<P3>(L, 4)
#define CARG_LIST_4 CARG_LIST_3, ReadToCpp<P4>(L, 5)
#define CARG_LIST_5 CARG_LIST_4, ReadToCpp<P5>(L, 6)
#define CARG_LIST_6 CARG_LIST_5, ReadToCpp<P6>(L, 7)
#define CARG_LIST_7 CARG_LIST_6, ReadToCpp<P7>(L, 8)
#define CARG_LIST_8 CARG_LIST_7, ReadToCpp<P8>(L, 9)
#define CARG_LIST_9 CARG_LIST_8, ReadToCpp<P9>(L, 10)

/* register class method */

struct GenericMethod {
    virtual int Call(lua_State *L) = 0;
};

#define DEF_METHOD_DATA(N) \
template<CTYPENAME_LIST_##N> \
struct MethodData##N : public GenericMethod { \
    typedef R (T::*Method)(CPARAM_TYPE_LIST_##N); \
    Method m_method; \
    MethodData##N(Method method) : m_method(method) {} \
    int Call(lua_State* L) override final { \
        auto object = ReadToCpp<T*>(L, 1); \
        auto result = (object->*m_method)(CARG_LIST_##N); \
        PushToLua<R>(L, result); \
        return 1; \
    } \
};

#define DEF_VOID_METHOD_DATA(N) \
template<CTYPENAME_VOID_LIST_##N> \
struct MethodData##N<CTYPE_VOID_LIST_##N> : public GenericMethod { \
    typedef void (T::*Method)(CPARAM_TYPE_LIST_##N); \
    Method m_method; \
    MethodData##N(Method method) : m_method(method) {} \
    int Call(lua_State* L) override final { \
        auto object = ReadToCpp<T*>(L, 1); \
        (object->*m_method)(CARG_LIST_##N); \
        return 0; \
    } \
};

template<typename T>
inline int ProxyMethodCall(lua_State *L) {
    auto index = lua_upvalueindex(1);
    auto memory = lua_touserdata(L, index);
    auto method = static_cast<GenericMethod*>(memory);
    return method->Call(L);
}

#define DEF_REGISTER_METHOD(N) \
template<CTYPENAME_LIST_##N> \
inline void RegisterMethodToLua(lua_State* L, const char* name, \
    R (T::*method)(CPARAM_TYPE_LIST_##N)) { \
    luaL_getmetatable(L, ClassInfo<T>::Name()); \
    lua_pushstring(L, name); \
    typedef MethodData##N<CTYPE_LIST_##N> MethodData_t; \
    auto memory = lua_newuserdata(L, sizeof(MethodData_t)); \
    new(memory) MethodData_t(method); \
    lua_pushcclosure(L, &ProxyMethodCall<T>, 1); \
    lua_rawset(L, -3); \
    lua_pop(L, 1); \
}

DEF_METHOD_DATA(9)
DEF_METHOD_DATA(8)
DEF_METHOD_DATA(7)
DEF_METHOD_DATA(6)
DEF_METHOD_DATA(5)
DEF_METHOD_DATA(4)
DEF_METHOD_DATA(3)
DEF_METHOD_DATA(2)
DEF_METHOD_DATA(1)
DEF_METHOD_DATA(0)

DEF_VOID_METHOD_DATA(9)
DEF_VOID_METHOD_DATA(8)
DEF_VOID_METHOD_DATA(7)
DEF_VOID_METHOD_DATA(6)
DEF_VOID_METHOD_DATA(5)
DEF_VOID_METHOD_DATA(4)
DEF_VOID_METHOD_DATA(3)
DEF_VOID_METHOD_DATA(2)
DEF_VOID_METHOD_DATA(1)
DEF_VOID_METHOD_DATA(0)

DEF_REGISTER_METHOD(9)
DEF_REGISTER_METHOD(8)
DEF_REGISTER_METHOD(7)
DEF_REGISTER_METHOD(6)
DEF_REGISTER_METHOD(5)
DEF_REGISTER_METHOD(4)
DEF_REGISTER_METHOD(3)
DEF_REGISTER_METHOD(2)
DEF_REGISTER_METHOD(1)
DEF_REGISTER_METHOD(0)

/* register class member */

struct GenericMember {
    virtual int Get(lua_State* L) = 0;
    virtual int Set(lua_State* L) = 0;
};

template<typename T, typename V>
struct MemberData : public GenericMember {
    typedef V T::*Var;
    Var m_var;
    MemberData(Var var) : m_var(var) {}
    int Get(lua_State* L) override final {
        auto object = ReadToCpp<T*>(L, 1);
        auto member = object->*m_var;
        PushToLua<V>(L, member);
        return 1;
    }
    int Set(lua_State* L) override final {
        auto object = ReadToCpp<T*>(L, 1);
        auto& member = object->*m_var;
        member = ReadToCpp<V>(L, 3);
        return 0;
    }
};

template<typename T, typename V>
void RegisterMemberToLua(lua_State* L, const char* name, V T::*member) {
    luaL_getmetatable(L, ClassInfo<T>::Name());
    typedef MemberData<T, V> MemberData_t;
    lua_pushstring(L, name);
    auto memory = lua_newuserdata(L, sizeof(MemberData_t));
    new(memory) MemberData_t(member);
    lua_rawset(L, -3);
    lua_pop(L, 1);
}

/* register class object */

template<typename T>
void RegisterObjectToLua(lua_State* L, const char* name, T* object) {
    typedef UserData<T*> UserData_t;
    auto memory = lua_newuserdata(L, sizeof(UserData_t));
    new(memory) UserData_t(object);
    luaL_getmetatable(L, ClassInfo<T>::Name());
    lua_setmetatable(L, -2);
    lua_setglobal(L, name);
}

/* inherit parent class */

template<typename T, typename P>
void InheritParentToLua(lua_State* L) {
    luaL_getmetatable(L, ClassInfo<T>::Name());
    if (lua_istable(L, -1)) {
        lua_pushstring(L, "__parent");
        luaL_getmetatable(L, ClassInfo<P>::Name());
        lua_rawset(L, -3);
    }
    lua_pop(L, 1);
}

inline void InvokeParent(lua_State *L) {
    lua_pushstring(L, "__parent");
    lua_rawget(L, -2);
    if (lua_istable(L, -1)) {
        lua_pushvalue(L, 2);
        lua_rawget(L, -2);
        if (lua_isnil(L, -1)) {
            lua_remove(L, -1);
            InvokeParent(L);
        }
        lua_remove(L, -2);
    }
}

/* set metatable for class */

template<typename T>
inline int MetaGet(lua_State* L) {
    lua_getmetatable(L, 1);
    lua_pushvalue(L, 2);
    lua_rawget(L, -2);
    if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
    }
    if (lua_isuserdata(L, -1)) {
        auto memory = lua_touserdata(L, -1);
        auto member = static_cast<GenericMember*>(memory);
        member->Get(L);
        lua_remove(L, -2);
    }
    else if (lua_isfunction(L, -1)) {
        // methods
    }
    else if (lua_isnil(L, -1)) {
        lua_error(L);
    }
    lua_remove(L, -2);
    return 1;
}

template<typename T>
inline int MetaSet(lua_State* L) {
    lua_getmetatable(L, 1);
    lua_pushvalue(L, 2);
    lua_rawget(L, -2);
    if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
    }
    if (lua_isuserdata(L, -1)) {
        auto memory = lua_touserdata(L, -1);
        auto member = static_cast<GenericMember*>(memory);
        member->Set(L);
    }
    else if (lua_isnil(L, -1)) {
        lua_remove(L, -1);
        InvokeParent(L);
        if (lua_isnil(L, -1)) {
            lua_pushvalue(L, 2);
            lua_pushvalue(L, 3);
            lua_rawset(L, -4);
        }
    }
    lua_settop(L, 3);
    return 0;
}

template<typename T>
inline int DoGc(lua_State* L) {
    return 0;
}

template<typename T>
void SetMetatable(lua_State* L, const char* className) {
    luaL_newmetatable(L, className);

    lua_pushliteral(L, "__index");
    lua_pushcfunction(L, MetaGet<T>);
    lua_settable(L, -3);

    lua_pushliteral(L, "__newindex");
    lua_pushcfunction(L, MetaSet<T>);
    lua_settable(L, -3);

    lua_pushliteral(L, "__gc");
    lua_pushcfunction(L, DoGc<T>);
    lua_settable(L, -3);

    lua_setmetatable(L, -2);
}

/* register class type */

template<typename T>
void RegisterClassToLua(lua_State* L, const char* className) {
    ClassInfo<T>::Name(className);
    lua_newtable(L);
    SetMetatable<T>(L, className);
    lua_setglobal(L, className);
}

DECL_NAMESPACE_METALUA_END

#endif // _METALUA_CLASSDEFINE_HPP_
<|endoftext|>


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

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

//___________________________________________________________________

#ifndef _XMLOFF_PROGRESSBARHELPER_HXX
#include <xmloff/ProgressBarHelper.hxx>
#endif

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

#include <stdlib.h>

using namespace ::com::sun::star;

const sal_Int32 nDefaultProgressBarRange = 1000000;
const float fProgressStep = 0.5;

ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator,
                                    const sal_Bool bTempStrict)
: xStatusIndicator(xTempStatusIndicator)
, nRange(nDefaultProgressBarRange)
, nReference(100)
, nValue(0)
, fOldPercent(0.0)
, bStrict(bTempStrict)
, bRepeat(sal_True)
#ifndef PRODUCT
, bFailure(sal_False)
#endif
{
}

ProgressBarHelper::~ProgressBarHelper()
{
}

sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
{
    if((nNewReference > 0) && (nNewReference != nReference))
    {
        if (nReference)
        {
            double fPercent(nNewReference / nReference);
            double fValue(nValue * fPercent);
#if OSL_DEBUG_LEVEL > 0
            // workaround for toolchain bug on solaris/x86 Sun C++ 5.5
            // just call some function here
            (void) abs(nValue);
#endif
            nValue = static_cast< sal_Int32 >(fValue);
            nReference = nNewReference;
        }
        else
        {
            nReference = nNewReference;
            nValue = 0;
        }
    }
    return nValue;
}

void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
{
    if (xStatusIndicator.is() && (nReference > 0))
    {
        if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference))))
        {
            // #91317# no progress bar with values > 100%
            if (nTempValue > nReference)
            {
                if (!bRepeat)
                    nValue = nReference;
                else
                {
//                    xStatusIndicator->end();
//                    xStatusIndicator->start();
                    xStatusIndicator->reset();
                    nValue = 0;
                }
            }
            else
                nValue = nTempValue;

            double fValue(nValue);
            double fNewValue ((fValue * nRange) / nReference);

            xmloff::token::IncRescheduleCount();

            xStatusIndicator->setValue((sal_Int32)fNewValue);

            xmloff::token::DecRescheduleCount();

            // #95181# disabled, because we want to call setValue very often to enable a good reschedule
//          double fPercent ((fNewValue * 100) / nRange);
//          if (fPercent >= (fOldPercent + fProgressStep))
//          {
//              xStatusIndicator->setValue((sal_Int32)fNewValue);
//              fOldPercent = fPercent;
//          }
        }
#ifndef PRODUCT
        else if (!bFailure)
        {
            DBG_ERROR("tried to set a wrong value on the progressbar");
            bFailure = sal_True;
        }
#endif
    }
}

<commit_msg>INTEGRATION: CWS changefileheader (1.22.28); FILE MERGED 2008/04/01 16:09:34 thb 1.22.28.3: #i85898# Stripping all external header guards 2008/04/01 13:04:34 thb 1.22.28.2: #i85898# Stripping all external header guards 2008/03/31 16:28:03 rt 1.22.28.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: ProgressBarHelper.cxx,v $
 * $Revision: 1.23 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

//___________________________________________________________________
#include <xmloff/ProgressBarHelper.hxx>
#include <tools/debug.hxx>
#include <xmloff/xmltoken.hxx>

#include <stdlib.h>

using namespace ::com::sun::star;

const sal_Int32 nDefaultProgressBarRange = 1000000;
const float fProgressStep = 0.5;

ProgressBarHelper::ProgressBarHelper(const ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator>& xTempStatusIndicator,
                                    const sal_Bool bTempStrict)
: xStatusIndicator(xTempStatusIndicator)
, nRange(nDefaultProgressBarRange)
, nReference(100)
, nValue(0)
, fOldPercent(0.0)
, bStrict(bTempStrict)
, bRepeat(sal_True)
#ifndef PRODUCT
, bFailure(sal_False)
#endif
{
}

ProgressBarHelper::~ProgressBarHelper()
{
}

sal_Int32 ProgressBarHelper::ChangeReference(sal_Int32 nNewReference)
{
    if((nNewReference > 0) && (nNewReference != nReference))
    {
        if (nReference)
        {
            double fPercent(nNewReference / nReference);
            double fValue(nValue * fPercent);
#if OSL_DEBUG_LEVEL > 0
            // workaround for toolchain bug on solaris/x86 Sun C++ 5.5
            // just call some function here
            (void) abs(nValue);
#endif
            nValue = static_cast< sal_Int32 >(fValue);
            nReference = nNewReference;
        }
        else
        {
            nReference = nNewReference;
            nValue = 0;
        }
    }
    return nValue;
}

void ProgressBarHelper::SetValue(sal_Int32 nTempValue)
{
    if (xStatusIndicator.is() && (nReference > 0))
    {
        if ((nTempValue >= nValue) && (!bStrict || (bStrict && (nTempValue <= nReference))))
        {
            // #91317# no progress bar with values > 100%
            if (nTempValue > nReference)
            {
                if (!bRepeat)
                    nValue = nReference;
                else
                {
//                    xStatusIndicator->end();
//                    xStatusIndicator->start();
                    xStatusIndicator->reset();
                    nValue = 0;
                }
            }
            else
                nValue = nTempValue;

            double fValue(nValue);
            double fNewValue ((fValue * nRange) / nReference);

            xmloff::token::IncRescheduleCount();

            xStatusIndicator->setValue((sal_Int32)fNewValue);

            xmloff::token::DecRescheduleCount();

            // #95181# disabled, because we want to call setValue very often to enable a good reschedule
//          double fPercent ((fNewValue * 100) / nRange);
//          if (fPercent >= (fOldPercent + fProgressStep))
//          {
//              xStatusIndicator->setValue((sal_Int32)fNewValue);
//              fOldPercent = fPercent;
//          }
        }
#ifndef PRODUCT
        else if (!bFailure)
        {
            DBG_ERROR("tried to set a wrong value on the progressbar");
            bFailure = sal_True;
        }
#endif
    }
}

<|endoftext|>


<commit_before>#include <cstdio>
#include <cmath>
#include <vector>
#include <random>
#include <chrono>

namespace NQueens
{
    class Board
    {
        std::default_random_engine generator;
        std::vector<int> rows;

        int getConflictCount(int row, int col) const
        {
            int count = 0;

            for (int i = 0; i < rows.size(); ++i)
                if (i != col && (rows[i] == row || abs(rows[i] - row) == abs(i - col)))
                    count++;

            return count;
        }

    public:
        Board(unsigned seed, int n): generator(seed), rows(n)
        {
            Refill();
        }

        void Refill()
        {
            for (int i = 0; i < rows.size(); ++i)
                rows[i] = i;

            for (int i = 0; i < rows.size(); ++i)
                std::swap(rows[i], rows[generator() % rows.size()]);
        }

        void Solve()
        {
            int moveCount = 0;

            while (true)
            {
                std::vector<int> candidates;

                int maxConflicts = 0;
                for (int i = 0; i < rows.size(); ++i)
                {
                    int conflictCount = getConflictCount(rows[i], i);
                    if (conflictCount > maxConflicts)
                    {
                        maxConflicts = conflictCount;
                        candidates.clear();
                    }
                    candidates.push_back(i);
                }
                if (maxConflicts == 0)
                    return;

                int worstQueenColumn = candidates[generator() % candidates.size()];
                int minConflictCount = rows.size();
                candidates.clear();
                for (int i = 0; i < rows.size(); ++i)
                {
                    int conflictCount = getConflictCount(i, worstQueenColumn);
                    if (conflictCount < minConflictCount)
                    {
                        minConflictCount = conflictCount;
                        candidates.clear();
                    }
                    candidates.push_back(i);
                }

                if (!candidates.empty())
                    rows[worstQueenColumn] = candidates[generator() % candidates.size()];

                ++moveCount;
                if (2 * rows.size() == moveCount)
                {
                    Refill();
                    moveCount = 0;
                }
            }
        }

        void Print() const
        {
            for (int i = 0; i < rows.size(); ++i)
            {
                for (int j = 0; j < rows.size(); ++j)
                    printf(rows[j] == i ? "*" : "_");

                printf("\n");
            }
        }
    };
}

int main()
{
    int n;
    scanf("%d", &n);
    if (n < 0)
        return 1;

    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    NQueens::Board queens(seed, n);
    queens.Solve();
    queens.Print();
    return 0;
}
<commit_msg>nqueens: reworked the algorithm a bit<commit_after>#include <cstdio>
#include <cmath>
#include <vector>
#include <random>
#include <chrono>

namespace NQueens
{
    class Board
    {
        std::default_random_engine generator;
        std::vector<int> rows;

        int getConflictCount(int row, int col) const
        {
            int count = 0;

            for (int i = 0; i < rows.size(); ++i)
                if (i != col && (rows[i] == row || abs(rows[i] - row) == abs(i - col)))
                    count++;

            return count;
        }

    public:
        Board(unsigned seed, int n): generator(seed), rows(n)
        {
            Refill();
        }

        void Refill()
        {
            for (int i = 0; i < rows.size(); ++i)
                rows[i] = i;

            for (int i = 0; i < rows.size(); ++i)
                std::swap(rows[i], rows[generator() % rows.size()]);
        }

        void Solve()
        {
            int moveCount = 0;

            while (true)
            {
                std::vector<int> candidates;

                int totalConflictCount = 0;
                for (int i = 0; i < rows.size(); ++i)
                {
                    int conflictCount = getConflictCount(rows[i], i);
                    if (conflictCount > 0)
                        candidates.push_back(i);
                    totalConflictCount += conflictCount;
                }
                if (0 == totalConflictCount)
                    return;

                int worstQueenColumn = candidates[generator() % candidates.size()];
                int minConflictCount = rows.size();
                candidates.clear();
                for (int i = 0; i < rows.size(); ++i)
                {
                    int conflictCount = getConflictCount(i, worstQueenColumn);
                    if (conflictCount < minConflictCount)
                    {
                        minConflictCount = conflictCount;
                        candidates.clear();
                    }
                    if (conflictCount == minConflictCount)
                        candidates.push_back(i);
                }

                if (!candidates.empty())
                    rows[worstQueenColumn] = candidates[generator() % candidates.size()];

                ++moveCount;
                if (2 * rows.size() == moveCount)
                {
                    Refill();
                    moveCount = 0;
                }
            }
        }

        void Print() const
        {
            for (int i = 0; i < rows.size(); ++i)
            {
                for (int j = 0; j < rows.size(); ++j)
                    printf(rows[j] == i ? "*" : "_");

                printf("\n");
            }
        }
    };
}

int main()
{
    int n;
    scanf("%d", &n);
    if (n < 0)
        return 1;

    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    NQueens::Board queens(seed, n);
    queens.Solve();
    queens.Print();
    return 0;
}
<|endoftext|>