<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9_cxa_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include "p9_cxa_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr auto literal_0x80031F98D8717 = 0x80031F98D8717;
constexpr auto literal_0x0B1C000104060 = 0x0B1C000104060;
constexpr auto literal_0x2B9C0001240E0 = 0x2B9C0001240E0;
constexpr auto literal_0b0000 = 0b0000;
constexpr auto literal_0b111 = 0b111;
constexpr auto literal_0b0010 = 0b0010;
constexpr auto literal_0b0001 = 0b0001;

fapi2::ReturnCode p9_cxa_scom(const fapi2::Target<fapi2::TARGET_TYPE_CAPP>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1)
{
    fapi2::ReturnCode l_rc = 0;

    do
    {
        fapi2::buffer<uint64_t> l_scom_buffer;
        {
            l_rc = fapi2::getScom( TGT0, 0x2010803ull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x2010803ull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0x80031F98D8717, 0, 52, 0 );
            }

            l_rc = fapi2::putScom(TGT0, 0x2010803ull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x2010803ull)");
                break;
            }
        }
        {
            l_rc = fapi2::getScom( TGT0, 0x2010806ull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x2010806ull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0x0B1C000104060, 0, 52, 12 );
            }

            l_rc = fapi2::putScom(TGT0, 0x2010806ull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x2010806ull)");
                break;
            }
        }
        {
            l_rc = fapi2::getScom( TGT0, 0x2010807ull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x2010807ull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0x2B9C0001240E0, 0, 52, 12 );
            }

            l_rc = fapi2::putScom(TGT0, 0x2010807ull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x2010807ull)");
                break;
            }
        }
        fapi2::ATTR_PROC_FABRIC_ADDR_BAR_MODE_Type l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE;
        l_rc = FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_ADDR_BAR_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE);

        if (l_rc)
        {
            FAPI_ERR("ERROR executing: FAPI_ATTR_GET (ATTR_PROC_FABRIC_ADDR_BAR_MODE)");
            break;
        }

        fapi2::ATTR_PROC_FABRIC_PUMP_MODE_Type l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE;
        l_rc = FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_PUMP_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE);

        if (l_rc)
        {
            FAPI_ERR("ERROR executing: FAPI_ATTR_GET (ATTR_PROC_FABRIC_PUMP_MODE)");
            break;
        }

        {
            l_rc = fapi2::getScom( TGT0, 0x2010818ull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x2010818ull)");
                break;
            }

            {
                if ((l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_ADDR_BAR_MODE_SMALL_SYSTEM))
                {
                    constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_ON = 0x1;
                    l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_ON, 1, 1, 63 );
                }
                else if ((l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_ADDR_BAR_MODE_LARGE_SYSTEM))
                {
                    constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF = 0x0;
                    l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF, 1, 1, 63 );
                }
            }

            {
                if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_GROUP))
                {
                    constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON = 0x1;
                    l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON, 6, 1, 63 );
                }
                else if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_NODE))
                {
                    constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF = 0x0;
                    l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF, 6, 1, 63 );
                }
            }

            l_rc = fapi2::putScom(TGT0, 0x2010818ull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x2010818ull)");
                break;
            }
        }

        {
            l_rc = fapi2::getScom( TGT0, 0x2010819ull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x2010819ull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0b0000, 4, 4, 60 );
            }

            l_rc = fapi2::putScom(TGT0, 0x2010819ull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x2010819ull)");
                break;
            }
        }

        {
            l_rc = fapi2::getScom( TGT0, 0x201081bull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x201081bull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0b111, 45, 3, 61 );
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0b0010, 48, 4, 60 );
            }

            l_rc = fapi2::putScom(TGT0, 0x201081bull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x201081bull)");
                break;
            }
        }

        {
            l_rc = fapi2::getScom( TGT0, 0x201081cull, l_scom_buffer );

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: getScom (0x201081cull)");
                break;
            }

            {
                l_scom_buffer.insert<uint64_t> (literal_0b0001, 18, 4, 60 );
            }

            l_rc = fapi2::putScom(TGT0, 0x201081cull, l_scom_buffer);

            if (l_rc)
            {
                FAPI_ERR("ERROR executing: putScom (0x201081cull)");
                break;
            }
        }
    }
    while (0);

    return l_rc;
}
<commit_msg>Add support for iterating over EC_LEVELS<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9_cxa_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include "p9_cxa_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr auto literal_0b0000 = 0b0000;
constexpr auto literal_0b111 = 0b111;
constexpr auto literal_0b0010 = 0b0010;
constexpr auto literal_0b0001 = 0b0001;
constexpr auto literal_0x0B1C000104060 = 0x0B1C000104060;
constexpr auto literal_0x2B9C0001240E0 = 0x2B9C0001240E0;
constexpr auto literal_0x80031F98D8717 = 0x80031F98D8717;

fapi2::ReturnCode p9_cxa_scom(const fapi2::Target<fapi2::TARGET_TYPE_CAPP>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1)
{
    fapi2::ReturnCode l_rc = 0;

    do
    {
        fapi2::ATTR_PROC_FABRIC_ADDR_BAR_MODE_Type l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE;
        l_rc = FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_ADDR_BAR_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE);

        if (l_rc)
        {
            FAPI_ERR("ERROR executing: FAPI_ATTR_GET (ATTR_PROC_FABRIC_ADDR_BAR_MODE)");
            break;
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010818ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010818ull)");
                    break;
                }

                {
                    if ((l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_ADDR_BAR_MODE_SMALL_SYSTEM))
                    {
                        constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_ON = 0x1;
                        l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_ON, 1, 1, 63 );
                    }
                    else if ((l_TGT1_ATTR_PROC_FABRIC_ADDR_BAR_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_ADDR_BAR_MODE_LARGE_SYSTEM))
                    {
                        constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF = 0x0;
                        l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_ADR_BAR_MODE_OFF, 1, 1, 63 );
                    }
                }

                l_rc = fapi2::putScom(TGT0, 0x2010818ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010818ull)");
                    break;
                }
            }
        }

        fapi2::ATTR_PROC_FABRIC_PUMP_MODE_Type l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE;
        l_rc = FAPI_ATTR_GET(fapi2::ATTR_PROC_FABRIC_PUMP_MODE, TGT1, l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE);

        if (l_rc)
        {
            FAPI_ERR("ERROR executing: FAPI_ATTR_GET (ATTR_PROC_FABRIC_PUMP_MODE)");
            break;
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010818ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010818ull)");
                    break;
                }

                {
                    if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_GROUP))
                    {
                        constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON = 0x1;
                        l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_ON, 6, 1, 63 );
                    }
                    else if ((l_TGT1_ATTR_PROC_FABRIC_PUMP_MODE == fapi2::ENUM_ATTR_PROC_FABRIC_PUMP_MODE_CHIP_IS_NODE))
                    {
                        constexpr auto l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF = 0x0;
                        l_scom_buffer.insert<uint64_t> (l_CAPP0_CXA_TOP_CXA_APC0_APCCTL_SKIP_G_OFF, 6, 1, 63 );
                    }
                }

                l_rc = fapi2::putScom(TGT0, 0x2010818ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010818ull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010819ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010819ull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0b0000, 4, 4, 60 );
                }

                l_rc = fapi2::putScom(TGT0, 0x2010819ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010819ull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x201081bull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x201081bull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0b111, 45, 3, 61 );
                }

                l_rc = fapi2::putScom(TGT0, 0x201081bull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x201081bull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x201081bull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x201081bull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0b0010, 48, 4, 60 );
                }

                l_rc = fapi2::putScom(TGT0, 0x201081bull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x201081bull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x201081cull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x201081cull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0b0001, 18, 4, 60 );
                }

                l_rc = fapi2::putScom(TGT0, 0x201081cull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x201081cull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010806ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010806ull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0x0B1C000104060, 0, 52, 12 );
                }

                l_rc = fapi2::putScom(TGT0, 0x2010806ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010806ull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010807ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010807ull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0x2B9C0001240E0, 0, 52, 12 );
                }

                l_rc = fapi2::putScom(TGT0, 0x2010807ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010807ull)");
                    break;
                }
            }
        }

        {
            fapi2::buffer<uint64_t> l_scom_buffer;
            {
                l_rc = fapi2::getScom( TGT0, 0x2010803ull, l_scom_buffer );

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: getScom (0x2010803ull)");
                    break;
                }

                {
                    l_scom_buffer.insert<uint64_t> (literal_0x80031F98D8717, 0, 52, 0 );
                }

                l_rc = fapi2::putScom(TGT0, 0x2010803ull, l_scom_buffer);

                if (l_rc)
                {
                    FAPI_ERR("ERROR executing: putScom (0x2010803ull)");
                    break;
                }
            }
        }

    }
    while(0);

    return l_rc;
}
<|endoftext|>


<commit_before>/*
 * DesktopPosixApplicationLaunch.cpp
 *
 * Copyright (C) 2009-18 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "DesktopApplicationLaunch.hpp"
#include "DesktopPosixApplication.hpp"
#include "DesktopOptions.hpp"

#include <core/system/Environment.hpp>
#include <core/r_util/RUserData.hpp>

#include <boost/foreach.hpp>

#include <QKeyEvent>

namespace rstudio {
namespace desktop {

namespace {

PosixApplication* app()
{
   return qobject_cast<PosixApplication*>(qApp);
}

// helper for swapping Ctrl, Meta modifiers
// https://bugreports.qt.io/browse/QTBUG-51293
class MacEventFilter : public QObject
{
public:
   MacEventFilter(QObject* parent)
      : QObject(parent)
   {
   }

protected:
   bool eventFilter(QObject* pObject, QEvent* pEvent)
   {
      if (pEvent->type() == QEvent::KeyPress)
      {
         auto* pKeyEvent = static_cast<QKeyEvent*>(pEvent);
         auto modifiers = pKeyEvent->modifiers();

         // translate backtab to regular tab
         if (pKeyEvent->key() == Qt::Key_Backtab)
         {
            auto* pTabEvent = new QKeyEvent(
                     pKeyEvent->type(),
                     Qt::Key_Tab,
                     pKeyEvent->modifiers() | Qt::ShiftModifier);
            QCoreApplication::postEvent(pObject, pTabEvent);
            return true;
         }

         // fix up modifiers
         if (modifiers.testFlag(Qt::MetaModifier) &&
             !modifiers.testFlag(Qt::ControlModifier))
         {
            modifiers |= Qt::ControlModifier;
            modifiers &= ~Qt::MetaModifier;
            pKeyEvent->setModifiers(modifiers);
         }
         else if (modifiers.testFlag(Qt::ControlModifier) &&
                  !modifiers.testFlag(Qt::MetaModifier))
         {
            modifiers |= Qt::MetaModifier;
            modifiers &= ~Qt::ControlModifier;
            pKeyEvent->setModifiers(modifiers);
         }
      }

      return QObject::eventFilter(pObject, pEvent);
   }
};

} // anonymous namespace

ApplicationLaunch::ApplicationLaunch() :
    QWidget(nullptr),
    pMainWindow_(nullptr)
{
   connect(app(), SIGNAL(messageReceived(QString)),
           this, SIGNAL(openFileRequest(QString)));

   launchEnv_ = QProcessEnvironment::systemEnvironment();
}

void ApplicationLaunch::init(QString appName,
                             int& argc,
                             char* argv[],
                             boost::scoped_ptr<QApplication>* ppApp,
                             boost::scoped_ptr<ApplicationLaunch>* ppAppLaunch)
{
   // Immediately stuffed into scoped_ptr
   PosixApplication* pSingleApplication = new PosixApplication(appName,
                                                               argc,
                                                               argv);
   // create app launch instance
   pSingleApplication->setApplicationName(appName);
   ppApp->reset(pSingleApplication);

   ppAppLaunch->reset(new ApplicationLaunch());
   pSingleApplication->setAppLauncher(ppAppLaunch->get());

   // connect app open file signal to app launch
   connect(app(), SIGNAL(openFileRequest(QString)),
           ppAppLaunch->get(), SIGNAL(openFileRequest(QString)));

#ifdef Q_OS_MAC
   pSingleApplication->installEventFilter(new MacEventFilter(pSingleApplication));
#endif
}

void ApplicationLaunch::setActivationWindow(QWidget* pWindow)
{
   pMainWindow_ = pWindow;
   app()->setActivationWindow(pWindow, true);
}

void ApplicationLaunch::activateWindow()
{
   app()->activateWindow();
}

void ApplicationLaunch::attemptToRegisterPeer()
{
   // side-effect of is running is to try to register ourselves as a peer
   app()->isRunning();
}

bool ApplicationLaunch::sendMessage(QString filename)
{
   return app()->sendMessage(filename);
}

QString ApplicationLaunch::startupOpenFileRequest() const
{
   return app()->startupOpenFileRequest();
}

void ApplicationLaunch::launchRStudio(const std::vector<std::string>& args,
                                      const std::string& initialDir)
{
   QStringList argList;
   BOOST_FOREACH(const std::string& arg, args)
   {
      argList.append(QString::fromStdString(arg));
   }

   QString exePath = QString::fromUtf8(
      desktop::options().executablePath().absolutePath().c_str());

   // temporarily restore the library path to the one we were launched with
   std::string ldPath = core::system::getenv("LD_LIBRARY_PATH");
   core::system::setenv("LD_LIBRARY_PATH",
      launchEnv_.value(QString::fromUtf8("LD_LIBRARY_PATH")).toStdString());

   // set environment variable indicating initial launch dir
   core::system::setenv(kRStudioInitialWorkingDir, initialDir);

   // start RStudio detached
   QProcess::startDetached(exePath, argList);

   // restore environment
   core::system::setenv("LD_LIBRARY_PATH", ldPath);
   core::system::unsetenv(kRStudioInitialWorkingDir);
}

} // namespace desktop
} // namespace rstudio
<commit_msg>modifier fixup no longer necessary on macOS<commit_after>/*
 * DesktopPosixApplicationLaunch.cpp
 *
 * Copyright (C) 2009-18 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#include "DesktopApplicationLaunch.hpp"
#include "DesktopPosixApplication.hpp"
#include "DesktopOptions.hpp"

#include <core/system/Environment.hpp>
#include <core/r_util/RUserData.hpp>

#include <boost/foreach.hpp>

#include <QKeyEvent>

namespace rstudio {
namespace desktop {

namespace {

PosixApplication* app()
{
   return qobject_cast<PosixApplication*>(qApp);
}

// helper for swapping Ctrl, Meta modifiers
// https://bugreports.qt.io/browse/QTBUG-51293
class MacEventFilter : public QObject
{
public:
   MacEventFilter(QObject* parent)
      : QObject(parent)
   {
   }

protected:
   bool eventFilter(QObject* pObject, QEvent* pEvent)
   {
      if (pEvent->type() == QEvent::KeyPress)
      {
         auto* pKeyEvent = static_cast<QKeyEvent*>(pEvent);
         auto modifiers = pKeyEvent->modifiers();

         // translate backtab to regular tab
         if (pKeyEvent->key() == Qt::Key_Backtab)
         {
            auto* pTabEvent = new QKeyEvent(
                     pKeyEvent->type(),
                     Qt::Key_Tab,
                     pKeyEvent->modifiers() | Qt::ShiftModifier);
            QCoreApplication::postEvent(pObject, pTabEvent);
            return true;
         }
      }

      return QObject::eventFilter(pObject, pEvent);
   }
};

} // anonymous namespace

ApplicationLaunch::ApplicationLaunch() :
    QWidget(nullptr),
    pMainWindow_(nullptr)
{
   connect(app(), SIGNAL(messageReceived(QString)),
           this, SIGNAL(openFileRequest(QString)));

   launchEnv_ = QProcessEnvironment::systemEnvironment();
}

void ApplicationLaunch::init(QString appName,
                             int& argc,
                             char* argv[],
                             boost::scoped_ptr<QApplication>* ppApp,
                             boost::scoped_ptr<ApplicationLaunch>* ppAppLaunch)
{
   // Immediately stuffed into scoped_ptr
   PosixApplication* pSingleApplication = new PosixApplication(appName,
                                                               argc,
                                                               argv);
   // create app launch instance
   pSingleApplication->setApplicationName(appName);
   ppApp->reset(pSingleApplication);

   ppAppLaunch->reset(new ApplicationLaunch());
   pSingleApplication->setAppLauncher(ppAppLaunch->get());

   // connect app open file signal to app launch
   connect(app(), SIGNAL(openFileRequest(QString)),
           ppAppLaunch->get(), SIGNAL(openFileRequest(QString)));

#ifdef Q_OS_MAC
   pSingleApplication->installEventFilter(new MacEventFilter(pSingleApplication));
#endif
}

void ApplicationLaunch::setActivationWindow(QWidget* pWindow)
{
   pMainWindow_ = pWindow;
   app()->setActivationWindow(pWindow, true);
}

void ApplicationLaunch::activateWindow()
{
   app()->activateWindow();
}

void ApplicationLaunch::attemptToRegisterPeer()
{
   // side-effect of is running is to try to register ourselves as a peer
   app()->isRunning();
}

bool ApplicationLaunch::sendMessage(QString filename)
{
   return app()->sendMessage(filename);
}

QString ApplicationLaunch::startupOpenFileRequest() const
{
   return app()->startupOpenFileRequest();
}

void ApplicationLaunch::launchRStudio(const std::vector<std::string>& args,
                                      const std::string& initialDir)
{
   QStringList argList;
   BOOST_FOREACH(const std::string& arg, args)
   {
      argList.append(QString::fromStdString(arg));
   }

   QString exePath = QString::fromUtf8(
      desktop::options().executablePath().absolutePath().c_str());

   // temporarily restore the library path to the one we were launched with
   std::string ldPath = core::system::getenv("LD_LIBRARY_PATH");
   core::system::setenv("LD_LIBRARY_PATH",
      launchEnv_.value(QString::fromUtf8("LD_LIBRARY_PATH")).toStdString());

   // set environment variable indicating initial launch dir
   core::system::setenv(kRStudioInitialWorkingDir, initialDir);

   // start RStudio detached
   QProcess::startDetached(exePath, argList);

   // restore environment
   core::system::setenv("LD_LIBRARY_PATH", ldPath);
   core::system::unsetenv(kRStudioInitialWorkingDir);
}

} // namespace desktop
} // namespace rstudio
<|endoftext|>


<commit_before>#include <iostream>

#include <algebra/infinite_vector.h>
#include <algebra/sparse_matrix.h>
#include <utils/array1d.h>
#include <utils/fixed_array1d.h>

#include <interval/ds_basis.h>

#include <interval/p_basis.h>
#include <interval/i_index.h>
#include <cube/cube_basis.h>

using namespace std;
using namespace WaveletTL;

int main()
{
  cout << "Testing wavelet bases on the cube..." << endl;

  //typedef DSBasis<3,3> Basis1D;
  typedef PBasis<3,3> Basis1D;

#if 1
  typedef CubeBasis<Basis1D,1> Basis;

  //primal boundary conditions
  FixedArray1D<int,2*1> bound_1_1D;
  bound_1_1D[0] = 2;
  bound_1_1D[1] = 1;

  //dual boundary conditions
  FixedArray1D<int,2*1> bound_1T_1D;
  bound_1T_1D[0] = 0;
  bound_1T_1D[1] = 0;

  //Basis basis(bound_1_1D, bound_1T_1D);
  Basis basis(bound_1_1D);
  //Basis basis;

  CubeIndex<Basis1D,1,Basis> index(&basis);
  for (int i = 0; i < 64; i++)
    {
      cout << index << endl;
      ++index;
    }

  typedef Basis1D::Index Index1D;

  Basis1D basis1D(bound_1_1D[0], bound_1_1D[1]);

  unsigned int i = 0;
  for (Index1D<Basis1D> lambda(first_generator<Basis1D>(&basis1D, basis1D.j0()));; ++lambda) {
    cout << "-----------------------------------------" << endl;
    cout << lambda << " number  = " << lambda.number() << endl;
    cout << " index  = " << IntervalIndex<Basis1D>(i, &basis1D) << endl;
    if (! (Index1D<Basis1D>(i, &basis1D) == lambda))
      abort();
    i++;
    if (lambda == last_wavelet<Basis1D>(&basis1D, basis1D.j0()+2)) break;
  }

  for (int j = basis1D.j0(); j < basis1D.j0()+5; j++ ) {
    if (j == basis1D.j0()) {
      cout << "number of first generator on coarstest level = " << first_generator_num<Basis1D>(&basis1D) << endl;
      cout << "number of last generator on coarstest level = " << last_generator_num<Basis1D>(&basis1D) << endl;
    }

    cout << "number of first wavelet on level " << j << " = " << first_wavelet_num<Basis1D>(&basis1D, j) << endl;
    cout << "number of last wavelet on level " << j << " = " << last_wavelet_num<Basis1D>(&basis1D, j) << endl;

  }

//   unsigned int i = 0;
//   for (CubeIndex<Basis1D,1> lambda(first_generator<Basis1D,1,Basis>(&basis, basis.j0()));; ++lambda) {
//     cout << "-----------------------------------------" << endl;
//     cout << lambda << " number  = " << lambda.number() << endl;
//     cout << " index  = " << CubeIndex<Basis1D,1>(i, &basis) << endl;
//      if (! (CubeIndex<Basis1D,1>(i, &basis) == lambda))
//       abort();
//     i++;
//     if (lambda == last_wavelet<Basis1D,1,Basis>(&basis, basis.j0()+2)) break;
//   }

#else

  //primal boundary conditions
  FixedArray1D<int,2*2> bound_1_2D;
  bound_1_2D[0] = 1;
  bound_1_2D[1] = 1;
  bound_1_2D[2] = 1;
  bound_1_2D[3] = 1;

  //dual boundary conditions
  FixedArray1D<int,2*2> bound_1T_2D;
  bound_1T_2D[0] = 0;
  bound_1T_2D[1] = 0;
  bound_1T_2D[2] = 0;
  bound_1T_2D[3] = 0;

  typedef CubeBasis<Basis1D,2> Basis2;
  //Basis2 basis2(bound_1_2D, bound_1T_2D);
  Basis2 basis2(bound_1_2D);
  //Basis2 basis2;

//   CubeIndex<Basis1D,2> index2(&basis2);
//   for (int i = 0; i < 255; i++) {
//       cout << index2 << endl;
//       ++index2;
//   }

  unsigned int i = 0;
  for (CubeIndex<Basis1D,2> lambda(first_generator<Basis1D,2,Basis2>(&basis2, basis2.j0()));; ++lambda) {
    cout << "-----------------------------------------" << endl;
    cout << lambda << " number  = " << lambda.number() << endl;
    cout << " index  = " << CubeIndex<Basis1D,2>(i, &basis2) << endl;
    if (! (CubeIndex<Basis1D,2>(i, &basis2) == lambda))
      abort();
    i++;
    if (lambda == last_wavelet<Basis1D,2,Basis2>(&basis2, basis2.j0())) break;
  }

  for (int j = basis2.j0(); j < basis2.j0()+5; j++ ) {
    if (j == basis2.j0()) {
      cout << "number of first generator on coarstest level = " << first_generator_num<Basis1D,2,Basis2>(&basis2) << endl;
      cout << "number of last generator on coarstest level = " << last_generator_num<Basis1D,2,Basis2>(&basis2) << endl;
    }

    cout << "number of first wavelet on level " << j << " = " << first_wavelet_num<Basis1D,2,Basis2>(&basis2, j) << endl;
    cout << "number of last wavelet on level " << j << " = " << last_wavelet_num<Basis1D,2,Basis2>(&basis2, j) << endl;

  }

#endif
}
<commit_msg>fixed a gcc4 complaint<commit_after>#include <iostream>

#include <algebra/infinite_vector.h>
#include <algebra/sparse_matrix.h>
#include <utils/array1d.h>
#include <utils/fixed_array1d.h>

#include <interval/ds_basis.h>

#include <interval/p_basis.h>
#include <interval/i_index.h>
#include <cube/cube_basis.h>

using namespace std;
using namespace WaveletTL;

int main()
{
  cout << "Testing wavelet bases on the cube..." << endl;

  //typedef DSBasis<3,3> Basis1D;
  typedef PBasis<3,3> Basis1D;

#if 1
  typedef CubeBasis<Basis1D,1> Basis;

  //primal boundary conditions
  FixedArray1D<int,2*1> bound_1_1D;
  bound_1_1D[0] = 2;
  bound_1_1D[1] = 1;

  //dual boundary conditions
  FixedArray1D<int,2*1> bound_1T_1D;
  bound_1T_1D[0] = 0;
  bound_1T_1D[1] = 0;

  //Basis basis(bound_1_1D, bound_1T_1D);
  Basis basis(bound_1_1D);
  //Basis basis;

  CubeIndex<Basis1D,1,Basis> index(&basis);
  for (int i = 0; i < 64; i++)
    {
      cout << index << endl;
      ++index;
    }

  typedef Basis1D::Index Index1D;

  Basis1D basis1D(bound_1_1D[0], bound_1_1D[1]);

  unsigned int i = 0;
  for (Index1D lambda(first_generator<Basis1D>(&basis1D, basis1D.j0()));; ++lambda) {
    cout << "-----------------------------------------" << endl;
    cout << lambda << " number  = " << lambda.number() << endl;
    cout << " index  = " << IntervalIndex<Basis1D>(i, &basis1D) << endl;
    if (! (Index1D(i, &basis1D) == lambda))
      abort();
    i++;
    if (lambda == last_wavelet<Basis1D>(&basis1D, basis1D.j0()+2)) break;
  }

  for (int j = basis1D.j0(); j < basis1D.j0()+5; j++ ) {
    if (j == basis1D.j0()) {
      cout << "number of first generator on coarstest level = " << first_generator_num<Basis1D>(&basis1D) << endl;
      cout << "number of last generator on coarstest level = " << last_generator_num<Basis1D>(&basis1D) << endl;
    }

    cout << "number of first wavelet on level " << j << " = " << first_wavelet_num<Basis1D>(&basis1D, j) << endl;
    cout << "number of last wavelet on level " << j << " = " << last_wavelet_num<Basis1D>(&basis1D, j) << endl;

  }

//   unsigned int i = 0;
//   for (CubeIndex<Basis1D,1> lambda(first_generator<Basis1D,1,Basis>(&basis, basis.j0()));; ++lambda) {
//     cout << "-----------------------------------------" << endl;
//     cout << lambda << " number  = " << lambda.number() << endl;
//     cout << " index  = " << CubeIndex<Basis1D,1>(i, &basis) << endl;
//      if (! (CubeIndex<Basis1D,1>(i, &basis) == lambda))
//       abort();
//     i++;
//     if (lambda == last_wavelet<Basis1D,1,Basis>(&basis, basis.j0()+2)) break;
//   }

#else

  //primal boundary conditions
  FixedArray1D<int,2*2> bound_1_2D;
  bound_1_2D[0] = 1;
  bound_1_2D[1] = 1;
  bound_1_2D[2] = 1;
  bound_1_2D[3] = 1;

  //dual boundary conditions
  FixedArray1D<int,2*2> bound_1T_2D;
  bound_1T_2D[0] = 0;
  bound_1T_2D[1] = 0;
  bound_1T_2D[2] = 0;
  bound_1T_2D[3] = 0;

  typedef CubeBasis<Basis1D,2> Basis2;
  //Basis2 basis2(bound_1_2D, bound_1T_2D);
  Basis2 basis2(bound_1_2D);
  //Basis2 basis2;

//   CubeIndex<Basis1D,2> index2(&basis2);
//   for (int i = 0; i < 255; i++) {
//       cout << index2 << endl;
//       ++index2;
//   }

  unsigned int i = 0;
  for (CubeIndex<Basis1D,2> lambda(first_generator<Basis1D,2,Basis2>(&basis2, basis2.j0()));; ++lambda) {
    cout << "-----------------------------------------" << endl;
    cout << lambda << " number  = " << lambda.number() << endl;
    cout << " index  = " << CubeIndex<Basis1D,2>(i, &basis2) << endl;
    if (! (CubeIndex<Basis1D,2>(i, &basis2) == lambda))
      abort();
    i++;
    if (lambda == last_wavelet<Basis1D,2,Basis2>(&basis2, basis2.j0())) break;
  }

  for (int j = basis2.j0(); j < basis2.j0()+5; j++ ) {
    if (j == basis2.j0()) {
      cout << "number of first generator on coarstest level = " << first_generator_num<Basis1D,2,Basis2>(&basis2) << endl;
      cout << "number of last generator on coarstest level = " << last_generator_num<Basis1D,2,Basis2>(&basis2) << endl;
    }

    cout << "number of first wavelet on level " << j << " = " << first_wavelet_num<Basis1D,2,Basis2>(&basis2, j) << endl;
    cout << "number of last wavelet on level " << j << " = " << last_wavelet_num<Basis1D,2,Basis2>(&basis2, j) << endl;

  }

#endif
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9c_mi_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include "p9c_mi_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr uint64_t literal_7 = 7;
constexpr uint64_t literal_1 = 1;
constexpr uint64_t literal_0x19 = 0x19;
constexpr uint64_t literal_0b0000000000001000000 = 0b0000000000001000000;
constexpr uint64_t literal_0b0000000000001000 = 0b0000000000001000;

fapi2::ReturnCode p9c_mi_scom(const fapi2::Target<fapi2::TARGET_TYPE_MI>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1)
{
    {
        uint64_t l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC = literal_1;
        uint64_t l_def_ENABLE_DYNAMIC_64_128B_READS = literal_1;
        uint64_t l_def_ENABLE_ECRESP = literal_1;
        uint64_t l_def_ENABLE_AMO_CACHING = literal_1;
        fapi2::buffer<uint64_t> l_scom_buffer;
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010810ull, l_scom_buffer ));

            l_scom_buffer.insert<46, 4, 60, uint64_t>(literal_7 );

            if (l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC)
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCPERF1_ENABLE_PF_DROP_CMDLIST_ON = 0x1;
                l_scom_buffer.insert<61, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCPERF1_ENABLE_PF_DROP_CMDLIST_ON );
            }

            if (l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC)
            {
                l_scom_buffer.insert<32, 7, 57, uint64_t>(literal_0x19 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x5010810ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010811ull, l_scom_buffer ));

            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_PERFMON_COMMAND_ON = 0x1;
            l_scom_buffer.insert<48, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_PERFMON_COMMAND_ON );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_EMERGENCY_THROTTLE_ON = 0x1;
            l_scom_buffer.insert<21, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_EMERGENCY_THROTTLE_ON );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_CHECKSTOP_COMMAND_ON = 0x1;
            l_scom_buffer.insert<22, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_CHECKSTOP_COMMAND_ON );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_TRACESTOP_COMMAND_ON = 0x1;
            l_scom_buffer.insert<23, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_TRACESTOP_COMMAND_ON );

            if (l_def_ENABLE_DYNAMIC_64_128B_READS)
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_ON = 0x1;
                l_scom_buffer.insert<9, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_ON );
            }

            if (l_def_ENABLE_ECRESP)
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_CENTAURP_ENABLE_ECRESP_ON = 0x1;
                l_scom_buffer.insert<7, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_CENTAURP_ENABLE_ECRESP_ON );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x5010811ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010812ull, l_scom_buffer ));

            l_scom_buffer.insert<33, 19, 45, uint64_t>(literal_0b0000000000001000000 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x5010812ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010813ull, l_scom_buffer ));

            if (l_def_ENABLE_AMO_CACHING)
            {
                l_scom_buffer.insert<24, 16, 48, uint64_t>(literal_0b0000000000001000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x5010813ull, l_scom_buffer));
        }

    };
fapi_try_exit:
    return fapi2::current_err;
}
<commit_msg>Updates for Cumulus dmi/mi/mc initfiles<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/initfiles/p9c_mi_scom.C $  */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2017,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include "p9c_mi_scom.H"
#include <stdint.h>
#include <stddef.h>
#include <fapi2.H>

using namespace fapi2;

constexpr uint64_t literal_7 = 7;
constexpr uint64_t literal_16 = 16;
constexpr uint64_t literal_8 = 8;
constexpr uint64_t literal_1 = 1;
constexpr uint64_t literal_0x19 = 0x19;
constexpr uint64_t literal_0 = 0;
constexpr uint64_t literal_0b0000000000001000000 = 0b0000000000001000000;
constexpr uint64_t literal_0b0000000000001000 = 0b0000000000001000;
constexpr uint64_t literal_0b01 = 0b01;
constexpr uint64_t literal_5 = 5;

fapi2::ReturnCode p9c_mi_scom(const fapi2::Target<fapi2::TARGET_TYPE_MI>& TGT0,
                              const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM>& TGT1)
{
    {
        uint64_t l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC = literal_1;
        uint64_t l_def_ENABLE_DYNAMIC_64_128B_READS = literal_0;
        uint64_t l_def_ENABLE_ECRESP = literal_1;
        uint64_t l_def_ENABLE_AMO_CACHING = literal_1;
        uint64_t l_def_ENABLE_MCU_TIMEOUTS = literal_1;
        fapi2::buffer<uint64_t> l_scom_buffer;
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010810ull, l_scom_buffer ));

            l_scom_buffer.insert<46, 4, 60, uint64_t>(literal_7 );
            l_scom_buffer.insert<50, 5, 59, uint64_t>(literal_16 );
            l_scom_buffer.insert<55, 6, 58, uint64_t>(literal_8 );

            if ((l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCPERF1_ENABLE_PF_DROP_CMDLIST_ON = 0x1;
                l_scom_buffer.insert<61, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCPERF1_ENABLE_PF_DROP_CMDLIST_ON );
            }

            if ((l_def_ENABLE_PREFETCH_DROP_PROMOTE_BASIC == literal_1))
            {
                l_scom_buffer.insert<32, 7, 57, uint64_t>(literal_0x19 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x5010810ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010811ull, l_scom_buffer ));

            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_PERFMON_COMMAND_OFF = 0x0;
            l_scom_buffer.insert<48, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_PERFMON_COMMAND_OFF );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_EMERGENCY_THROTTLE_ON = 0x1;
            l_scom_buffer.insert<21, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_EMERGENCY_THROTTLE_ON );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_CHECKSTOP_COMMAND_ON = 0x1;
            l_scom_buffer.insert<22, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_CHECKSTOP_COMMAND_ON );
            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_TRACESTOP_COMMAND_ON = 0x1;
            l_scom_buffer.insert<23, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_CENTAUR_TRACESTOP_COMMAND_ON );

            if ((l_def_ENABLE_DYNAMIC_64_128B_READS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_ON = 0x1;
                l_scom_buffer.insert<9, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_ON );
            }
            else if ((l_def_ENABLE_DYNAMIC_64_128B_READS == literal_0))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_OFF = 0x0;
                l_scom_buffer.insert<9, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ENABLE_64_128B_READ_OFF );
            }

            if ((l_def_ENABLE_ECRESP == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_CENTAURP_ENABLE_ECRESP_ON = 0x1;
                l_scom_buffer.insert<7, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_CENTAURP_ENABLE_ECRESP_ON );
            }

            constexpr auto l_MC01_PBI01_SCOMFIR_MCMODE0_ASYNC_MODE_ON = 0x1;
            l_scom_buffer.insert<6, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCMODE0_ASYNC_MODE_ON );
            FAPI_TRY(fapi2::putScom(TGT0, 0x5010811ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010812ull, l_scom_buffer ));

            l_scom_buffer.insert<33, 19, 45, uint64_t>(literal_0b0000000000001000000 );
            FAPI_TRY(fapi2::putScom(TGT0, 0x5010812ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x5010813ull, l_scom_buffer ));

            if ((l_def_ENABLE_AMO_CACHING == literal_1))
            {
                l_scom_buffer.insert<24, 16, 48, uint64_t>(literal_0b0000000000001000 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x5010813ull, l_scom_buffer));
        }
        {
            FAPI_TRY(fapi2::getScom( TGT0, 0x501081bull, l_scom_buffer ));

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_SELECT_PB_HANG_PULSE_ON = 0x1;
                l_scom_buffer.insert<0, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_SELECT_PB_HANG_PULSE_ON );
            }

            constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_SELECT_LOCAL_HANG_PULSE_OFF = 0x0;
            l_scom_buffer.insert<1, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_SELECT_LOCAL_HANG_PULSE_OFF );

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_NONMIRROR_HANG_ON = 0x1;
                l_scom_buffer.insert<32, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_NONMIRROR_HANG_ON );
            }

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_MIRROR_HANG_ON = 0x1;
                l_scom_buffer.insert<33, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_MIRROR_HANG_ON );
            }

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_APO_HANG_ON = 0x1;
                l_scom_buffer.insert<34, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_APO_HANG_ON );
            }

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                constexpr auto l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_CLIB_HANG_ON = 0x1;
                l_scom_buffer.insert<35, 1, 63, uint64_t>(l_MC01_PBI01_SCOMFIR_MCTO_ENABLE_CLIB_HANG_ON );
            }

            l_scom_buffer.insert<2, 2, 62, uint64_t>(literal_0b01 );

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                l_scom_buffer.insert<24, 8, 56, uint64_t>(literal_1 );
            }

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                l_scom_buffer.insert<5, 3, 61, uint64_t>(literal_7 );
            }

            if ((l_def_ENABLE_MCU_TIMEOUTS == literal_1))
            {
                l_scom_buffer.insert<37, 3, 61, uint64_t>(literal_5 );
            }

            FAPI_TRY(fapi2::putScom(TGT0, 0x501081bull, l_scom_buffer));
        }

    };
fapi_try_exit:
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>/***********************************************************************
filename:   FirstPersonHUD.cpp
created:    11/8/2012
author:     Lukas E Meindl
*************************************************************************/
/***************************************************************************
*   Copyright (C) 2004 - 2012 Paul D Turner & Thce CEGUI Development Team
*
*   Permission is hereby granted, free of charge, to any person obtaining
*   a copy of this software and associated documentation files (the
*   "Software"), to deal in the Software without restriction, including
*   without limitation the rights to use, copy, modify, merge, publish,
*   distribute, sublicense, and/or sell copies of the Software, and to
*   permit persons to whom the Software is furnished to do so, subject to
*   the following conditions:
*
*   The above copyright notice and this permission notice shall be
*   included in all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
*   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
*   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*   OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "FirstPersonHUD.h"

#include "CEGUI/CEGUI.h"

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace CEGUI;

struct GamePlate
{
    GamePlate(HUDDemo* hudDemo);
    ~GamePlate();

    void update(float timeSinceLastUpdate);
    int getPoints();

    CEGUI::Window* d_window;
    bool d_isComingFromRight;
    bool d_isDestroyed;
};

GamePlate::GamePlate(HUDDemo* hudDemo)
    : d_isDestroyed(false)
{
    d_window = hudDemo->spawnPlate();

    int randumNumber = rand() % 2;
    d_isComingFromRight = (randumNumber == 0 ? false : true);

    if(d_isComingFromRight)
    {
        d_window->setHorizontalAlignment(HA_RIGHT);
        d_window->setPosition(d_window->getPosition() + CEGUI::UVector2(cegui_reldim(0.2f), cegui_absdim(0.0f)));
    }
    else
        d_window->setPosition(d_window->getPosition() + CEGUI::UVector2(cegui_reldim(-0.2f), cegui_absdim(0.0f)));
}

GamePlate::~GamePlate()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
    winMgr.destroyWindow(d_window);
}

void GamePlate::update(float timeSinceLastUpdate)
{
    CEGUI::UVector2 positionOffset;

    if(d_isComingFromRight)
        positionOffset = CEGUI::UVector2(cegui_reldim(timeSinceLastUpdate * -0.11f), cegui_absdim(0.f));
    else
        positionOffset = CEGUI::UVector2(cegui_reldim(timeSinceLastUpdate * 0.11f), cegui_absdim(0.f));

    d_window->setPosition(d_window->getPosition() + positionOffset);

    const CEGUI::UVector2& position = d_window->getPosition();

    if(d_isComingFromRight)
    {
        if(position.d_x.d_scale < -1.2f)
            d_isDestroyed = true;
    }
    else
    {
        if(position.d_x.d_scale > 1.2f)
            d_isDestroyed = true;
    }
}

int GamePlate::getPoints()
{
    CEGUI::Window* window = d_window->getChild("ImageWindowObject");

    CEGUI::String objectImage = window->getProperty("Image");

    if(objectImage.compare(HUDDemo::s_imageNameBread) == 0)
        return 2;
    else if(objectImage.compare(HUDDemo::s_imageNamePoo) == 0)
        return -6;
    else if(objectImage.compare(HUDDemo::s_imageNameSteak) == 0)
        return -13;
    else if(objectImage.compare(HUDDemo::s_imageNamePrizza) == 0)
        return 3;
    else if(objectImage.compare(HUDDemo::s_imageNameVegPeople) == 0)
        return 1;
    else if(objectImage.compare(HUDDemo::s_imageNameVegFruits) == 0)
        return 88;

    return 0;
}

const CEGUI::String HUDDemo::s_imageNamePlate = "HUDDemo/Plate";
const CEGUI::String HUDDemo::s_imageNameBread = "HUDDemo/Bread";
const CEGUI::String HUDDemo::s_imageNamePoo = "HUDDemo/Poo";
const CEGUI::String HUDDemo::s_imageNamePrizza = "HUDDemo/Prizza";
const CEGUI::String HUDDemo::s_imageNameSteak = "HUDDemo/Steak";
const CEGUI::String HUDDemo::s_imageNameVegPeople = "HUDDemo/VegetablePeople";
const CEGUI::String HUDDemo::s_imageNameVegFruits = "HUDDemo/VegetablesAndFruits";

bool HUDDemo::initialise(CEGUI::GUIContext* guiContext)
{
    using namespace CEGUI;

    d_usedFiles = CEGUI::String(__FILE__);
    d_guiContext = guiContext;

    SchemeManager::getSingleton().createFromFile("HUDDemo.scheme");
    SchemeManager::getSingleton().createFromFile("Generic.scheme");
    SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme");

    FontManager::getSingleton().createFromFile("DejaVuSans-14.font");
    FontManager::getSingleton().createFromFile("Jura-13.font");

    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
    // Load the HUDDemo Layout
    d_root = winMgr.loadLayoutFromFile("HUDDemo.layout");

    CEGUI::Window* bg = winMgr.createWindow("Generic/Image");
    if(!ImageManager::getSingleton().isDefined("HUDBackground"))
        ImageManager::getSingleton().addFromImageFile("HUDBackground", "HUDBackground.jpg");
    bg->setProperty("Image", "HUDBackground");
    bg->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f)));
    bg->setAspectMode(CEGUI::AM_EXPAND);
    bg->setAspectRatio(1.5f);
    bg->setMousePassThroughEnabled(true);
    bg->addChild(d_root);

    d_guiContext->setRootWindow(bg);

    setupMouseCursor();

    srand(static_cast<unsigned int >(time(0)));

    d_score = 0;
    updateScoreWindow();

    return true;
}

/*************************************************************************
Cleans up resources allocated in the initialiseSample call.
*************************************************************************/
void HUDDemo::deinitialise()
{
    while(!d_gamePlates.empty())
    {
        GamePlate* curPlate = d_gamePlates.back();
        delete curPlate;

        d_gamePlates.pop_back();
    }
}

void HUDDemo::onEnteringSample()
{
    d_score = 0;
    updateScoreWindow();
}

void HUDDemo::update(float timeSinceLastUpdate)
{
    static float timeSinceLastSpawn(0.0f);

    timeSinceLastSpawn += timeSinceLastUpdate;

    updateMouseCursor();

    if(timeSinceLastSpawn> 1.2f)
    {
        d_gamePlates.push_back(new GamePlate(this));
        timeSinceLastSpawn -= 1.2f;
    }

    updatePlates(timeSinceLastUpdate);

    delayDestroyWindows();

}

void HUDDemo::setupMouseCursor()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    d_mouseCursorWnd = winMgr.createWindow("Generic/Image");
    d_mouseCursorWnd->setProperty("Image", "HUDDemo/Spoon");
    d_mouseCursorWnd->setAspectMode(CEGUI::AM_EXPAND);
    d_mouseCursorWnd->setAspectRatio(1.f);
    d_mouseCursorWnd->setSize(CEGUI::USize(cegui_absdim(0.0f), cegui_reldim(0.1f)));
    d_mouseCursorWnd->setAlwaysOnTop(true);
    d_mouseCursorWnd->setMousePassThroughEnabled(true);
    d_root->addChild(d_mouseCursorWnd);
}

void HUDDemo::updateMouseCursor()
{
    CEGUI::Vector2f position = d_guiContext->getMouseCursor().getPosition();

    // We want to position the image-window right top of the actual
    // cursor point so we add its height
    float absHeight = d_mouseCursorWnd->getPixelSize().d_height;
    position.d_y -= absHeight;

    d_mouseCursorWnd->setPosition(
        CEGUI::UVector2(
        cegui_absdim(position.d_x - 5.0f), cegui_absdim(position.d_y + 5.0f))
        );
}

CEGUI::Window* HUDDemo::spawnPlate()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    CEGUI::Window* plateRoot = winMgr.createWindow("DefaultWindow");
    plateRoot->setSize(CEGUI::USize(cegui_absdim(0.0f), cegui_reldim(0.16f)));
    plateRoot->setAspectMode(CEGUI::AM_EXPAND);
    plateRoot->setAspectRatio(1.0f);
    plateRoot->setRiseOnClickEnabled(false);
    plateRoot->setPixelAligned(false);
    plateRoot->subscribeEvent(CEGUI::Window::EventMouseClick, Event::Subscriber(&HUDDemo::handlePlateWindowClicked, this));
    d_root->addChild(plateRoot);

    CEGUI::Window* plateImgWnd = winMgr.createWindow("Generic/Image", "ImageWindowPlate");
    plateImgWnd->setProperty("Image", s_imageNamePlate);
    plateImgWnd->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_absdim(0.0f)));
    plateImgWnd->setAspectRatio(3.308f);
    plateImgWnd->setAspectMode(CEGUI::AM_EXPAND);
    plateImgWnd->setVerticalAlignment(CEGUI::VA_BOTTOM);
    plateImgWnd->setMousePassThroughEnabled(true);
    plateImgWnd->setPixelAligned(false);
    plateRoot->addChild(plateImgWnd);

    CEGUI::String image = getRandomGameImage();

    CEGUI::Window* plateTopping = winMgr.createWindow("Generic/Image", "ImageWindowObject");
    plateTopping->setProperty("Image", image);
    plateTopping->setSize(CEGUI::USize(cegui_reldim(0.88f), cegui_absdim(0.0f)));
    plateTopping->setAspectRatio(1.0f);
    plateTopping->setAspectMode(CEGUI::AM_EXPAND);
    plateTopping->setHorizontalAlignment(CEGUI::HA_CENTRE);
    plateTopping->setMousePassThroughEnabled(true);
    plateTopping->setPixelAligned(false);
    plateRoot->addChild(plateTopping);

    int randumNumber = rand() % 10000;
    float posY = randumNumber / 10000.0f;

    plateRoot->setPosition(CEGUI::UVector2(cegui_absdim(0.0f), cegui_reldim(0.8f * posY)));

    return plateRoot;
}

const CEGUI::String& HUDDemo::getRandomGameImage()
{
    int randumNumber = rand() % 100;

    if(randumNumber > 88)
        return s_imageNamePoo;
    else if(randumNumber > 72)
        return s_imageNamePrizza;
    else if(randumNumber > 55)
        return s_imageNameSteak;
    else if(randumNumber > 52)
        return s_imageNameVegFruits;
    else if(randumNumber > 25)
        return s_imageNameVegPeople;
    else if(randumNumber > 0)
        return s_imageNameBread;

    return s_imageNameBread;
}

void HUDDemo::updatePlates(float timeSinceLastUpdate)
{
    unsigned int vectorSize = d_gamePlates.size();

    for(unsigned int i = 0; i < vectorSize;)
    {
        GamePlate* currentPlate = d_gamePlates[i];

        //CEGUI bug: this shouldnt be necessary
        currentPlate->d_window->invalidate();

        currentPlate->update(timeSinceLastUpdate);
        if(currentPlate->d_isDestroyed)
        {
            delete currentPlate;
            d_gamePlates[i] = d_gamePlates.back();
            d_gamePlates.pop_back();
            vectorSize = d_gamePlates.size();
        }
        else
            ++i;
    }

}

void HUDDemo::updateScoreWindow()
{
    CEGUI::Window* scoreWnd = d_root->getChild("ScoreCounter");
    scoreWnd->setText(CEGUI::PropertyHelper<int>::toString(d_score));
}

bool HUDDemo::handlePlateWindowClicked(const CEGUI::EventArgs& args)
{
    const CEGUI::MouseEventArgs& mouseArgs = static_cast<const CEGUI::MouseEventArgs&>(args);

    for(unsigned int i = 0; i < d_gamePlates.size(); ++i)
    {
        GamePlate* gamePlate = d_gamePlates[i];

        if(gamePlate->d_window == mouseArgs.window)
        {
            int points = gamePlate->getPoints();
            d_score += points;
            updateScoreWindow();

            gamePlate->d_isDestroyed = true;
            createScorePopup(mouseArgs.position, points);
        }
    }

    return false;
}

void HUDDemo::createScorePopup(const CEGUI::Vector2<float>& mousePos, int points)
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    CEGUI::Window* popupWindow = winMgr.createWindow("HUDDemo/PopupLabel");
    d_root->addChild(popupWindow);
    popupWindow->setPosition(CEGUI::UVector2(cegui_absdim(mousePos.d_x), cegui_absdim(mousePos.d_y)));
    popupWindow->setText(CEGUI::PropertyHelper<int>::toString(points));
    popupWindow->setRiseOnClickEnabled(false);
    popupWindow->subscribeEvent(AnimationInstance::EventAnimationEnded, Event::Subscriber(&HUDDemo::handleScorePopupAnimationEnded, this));
    popupWindow->setFont("DejaVuSans-14");
    popupWindow->setPixelAligned(false);

    popupWindow->setPosition(popupWindow->getPosition() + CEGUI::UVector2(cegui_reldim(0.03f), cegui_reldim(-0.02f)));

    if(points < 0)
        popupWindow->setProperty("NormalTextColour", "FFDD0000");
    else
    {
        popupWindow->setText( "+" + popupWindow->getText());
        popupWindow->setProperty("NormalTextColour", "FF00CC00");
    }

    CEGUI::EventArgs args;
    popupWindow->fireEvent("StartAnimation", args);
}

bool HUDDemo::handleScorePopupAnimationEnded(const CEGUI::EventArgs& args)
{
    const CEGUI::AnimationEventArgs& animArgs = static_cast<const CEGUI::AnimationEventArgs&>(args);

    CEGUI::Window* window = static_cast<CEGUI::Window*>( animArgs.instance->getTarget());
    d_delayDestroyWindows.push_back(window);

    return false;
}

void HUDDemo::delayDestroyWindows()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    while(!d_delayDestroyWindows.empty())
    {
        CEGUI::Window* curWindow = d_delayDestroyWindows.back();
        winMgr.destroyWindow(curWindow);

        d_delayDestroyWindows.pop_back();
    }
}
/*************************************************************************
Define the module function that returns an instance of the sample
*************************************************************************/
extern "C" SAMPLE_EXPORT Sample& getSampleInstance()
{
    static HUDDemo sample;
    return sample;
}<commit_msg>FIX: Workaround for updating the HUDDemo while running<commit_after>/***********************************************************************
filename:   FirstPersonHUD.cpp
created:    11/8/2012
author:     Lukas E Meindl
*************************************************************************/
/***************************************************************************
*   Copyright (C) 2004 - 2012 Paul D Turner & Thce CEGUI Development Team
*
*   Permission is hereby granted, free of charge, to any person obtaining
*   a copy of this software and associated documentation files (the
*   "Software"), to deal in the Software without restriction, including
*   without limitation the rights to use, copy, modify, merge, publish,
*   distribute, sublicense, and/or sell copies of the Software, and to
*   permit persons to whom the Software is furnished to do so, subject to
*   the following conditions:
*
*   The above copyright notice and this permission notice shall be
*   included in all copies or substantial portions of the Software.
*
*   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
*   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
*   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
*   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*   OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "FirstPersonHUD.h"

#include "CEGUI/CEGUI.h"

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace CEGUI;

struct GamePlate
{
    GamePlate(HUDDemo* hudDemo);
    ~GamePlate();

    void update(float timeSinceLastUpdate);
    int getPoints();

    CEGUI::Window* d_window;
    bool d_isComingFromRight;
    bool d_isDestroyed;
};

GamePlate::GamePlate(HUDDemo* hudDemo)
    : d_isDestroyed(false)
{
    d_window = hudDemo->spawnPlate();

    int randumNumber = rand() % 2;
    d_isComingFromRight = (randumNumber == 0 ? false : true);

    if(d_isComingFromRight)
    {
        d_window->setHorizontalAlignment(HA_RIGHT);
        d_window->setPosition(d_window->getPosition() + CEGUI::UVector2(cegui_reldim(0.2f), cegui_absdim(0.0f)));
    }
    else
        d_window->setPosition(d_window->getPosition() + CEGUI::UVector2(cegui_reldim(-0.2f), cegui_absdim(0.0f)));
}

GamePlate::~GamePlate()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
    winMgr.destroyWindow(d_window);
}

void GamePlate::update(float timeSinceLastUpdate)
{
    CEGUI::UVector2 positionOffset;

    if(d_isComingFromRight)
        positionOffset = CEGUI::UVector2(cegui_reldim(timeSinceLastUpdate * -0.11f), cegui_absdim(0.f));
    else
        positionOffset = CEGUI::UVector2(cegui_reldim(timeSinceLastUpdate * 0.11f), cegui_absdim(0.f));

    d_window->setPosition(d_window->getPosition() + positionOffset);

    const CEGUI::UVector2& position = d_window->getPosition();

    if(d_isComingFromRight)
    {
        if(position.d_x.d_scale < -1.2f)
            d_isDestroyed = true;
    }
    else
    {
        if(position.d_x.d_scale > 1.2f)
            d_isDestroyed = true;
    }
}

int GamePlate::getPoints()
{
    CEGUI::Window* window = d_window->getChild("ImageWindowObject");

    CEGUI::String objectImage = window->getProperty("Image");

    if(objectImage.compare(HUDDemo::s_imageNameBread) == 0)
        return 2;
    else if(objectImage.compare(HUDDemo::s_imageNamePoo) == 0)
        return -6;
    else if(objectImage.compare(HUDDemo::s_imageNameSteak) == 0)
        return -13;
    else if(objectImage.compare(HUDDemo::s_imageNamePrizza) == 0)
        return 3;
    else if(objectImage.compare(HUDDemo::s_imageNameVegPeople) == 0)
        return 1;
    else if(objectImage.compare(HUDDemo::s_imageNameVegFruits) == 0)
        return 88;

    return 0;
}

const CEGUI::String HUDDemo::s_imageNamePlate = "HUDDemo/Plate";
const CEGUI::String HUDDemo::s_imageNameBread = "HUDDemo/Bread";
const CEGUI::String HUDDemo::s_imageNamePoo = "HUDDemo/Poo";
const CEGUI::String HUDDemo::s_imageNamePrizza = "HUDDemo/Prizza";
const CEGUI::String HUDDemo::s_imageNameSteak = "HUDDemo/Steak";
const CEGUI::String HUDDemo::s_imageNameVegPeople = "HUDDemo/VegetablePeople";
const CEGUI::String HUDDemo::s_imageNameVegFruits = "HUDDemo/VegetablesAndFruits";

bool HUDDemo::initialise(CEGUI::GUIContext* guiContext)
{
    using namespace CEGUI;

    d_usedFiles = CEGUI::String(__FILE__);
    d_guiContext = guiContext;

    SchemeManager::getSingleton().createFromFile("HUDDemo.scheme");
    SchemeManager::getSingleton().createFromFile("Generic.scheme");
    SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme");

    FontManager::getSingleton().createFromFile("DejaVuSans-14.font");
    FontManager::getSingleton().createFromFile("Jura-13.font");

    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
    // Load the HUDDemo Layout
    d_root = winMgr.loadLayoutFromFile("HUDDemo.layout");

    CEGUI::Window* bg = winMgr.createWindow("Generic/Image");
    if(!ImageManager::getSingleton().isDefined("HUDBackground"))
        ImageManager::getSingleton().addFromImageFile("HUDBackground", "HUDBackground.jpg");
    bg->setProperty("Image", "HUDBackground");
    bg->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f)));
    bg->setAspectMode(CEGUI::AM_EXPAND);
    bg->setAspectRatio(1.5f);
    bg->setMousePassThroughEnabled(true);
    bg->addChild(d_root);

    d_guiContext->setRootWindow(bg);

    setupMouseCursor();

    srand(static_cast<unsigned int >(time(0)));

    d_score = 0;
    updateScoreWindow();

    return true;
}

/*************************************************************************
Cleans up resources allocated in the initialiseSample call.
*************************************************************************/
void HUDDemo::deinitialise()
{
    while(!d_gamePlates.empty())
    {
        GamePlate* curPlate = d_gamePlates.back();
        delete curPlate;

        d_gamePlates.pop_back();
    }
}

void HUDDemo::onEnteringSample()
{
    d_score = 0;
    updateScoreWindow();
}

void HUDDemo::update(float timeSinceLastUpdate)
{
    static float timeSinceLastSpawn(0.0f);

    timeSinceLastSpawn += timeSinceLastUpdate;

    updateMouseCursor();

    if(timeSinceLastSpawn> 1.2f)
    {
        d_gamePlates.push_back(new GamePlate(this));
        timeSinceLastSpawn -= 1.2f;
    }

    updatePlates(timeSinceLastUpdate);

    delayDestroyWindows();

    d_guiContext->markAsDirty();
}

void HUDDemo::setupMouseCursor()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    d_mouseCursorWnd = winMgr.createWindow("Generic/Image");
    d_mouseCursorWnd->setProperty("Image", "HUDDemo/Spoon");
    d_mouseCursorWnd->setAspectMode(CEGUI::AM_EXPAND);
    d_mouseCursorWnd->setAspectRatio(1.f);
    d_mouseCursorWnd->setSize(CEGUI::USize(cegui_absdim(0.0f), cegui_reldim(0.1f)));
    d_mouseCursorWnd->setAlwaysOnTop(true);
    d_mouseCursorWnd->setMousePassThroughEnabled(true);
    d_root->addChild(d_mouseCursorWnd);
}

void HUDDemo::updateMouseCursor()
{
    CEGUI::Vector2f position = d_guiContext->getMouseCursor().getPosition();

    // We want to position the image-window right top of the actual
    // cursor point so we add its height
    float absHeight = d_mouseCursorWnd->getPixelSize().d_height;
    position.d_y -= absHeight;

    d_mouseCursorWnd->setPosition(
        CEGUI::UVector2(
        cegui_absdim(position.d_x - 5.0f), cegui_absdim(position.d_y + 5.0f))
        );
}

CEGUI::Window* HUDDemo::spawnPlate()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    CEGUI::Window* plateRoot = winMgr.createWindow("DefaultWindow");
    plateRoot->setSize(CEGUI::USize(cegui_absdim(0.0f), cegui_reldim(0.16f)));
    plateRoot->setAspectMode(CEGUI::AM_EXPAND);
    plateRoot->setAspectRatio(1.0f);
    plateRoot->setRiseOnClickEnabled(false);
    plateRoot->setPixelAligned(false);
    plateRoot->subscribeEvent(CEGUI::Window::EventMouseClick, Event::Subscriber(&HUDDemo::handlePlateWindowClicked, this));
    d_root->addChild(plateRoot);

    CEGUI::Window* plateImgWnd = winMgr.createWindow("Generic/Image", "ImageWindowPlate");
    plateImgWnd->setProperty("Image", s_imageNamePlate);
    plateImgWnd->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_absdim(0.0f)));
    plateImgWnd->setAspectRatio(3.308f);
    plateImgWnd->setAspectMode(CEGUI::AM_EXPAND);
    plateImgWnd->setVerticalAlignment(CEGUI::VA_BOTTOM);
    plateImgWnd->setMousePassThroughEnabled(true);
    plateImgWnd->setPixelAligned(false);
    plateRoot->addChild(plateImgWnd);

    CEGUI::String image = getRandomGameImage();

    CEGUI::Window* plateTopping = winMgr.createWindow("Generic/Image", "ImageWindowObject");
    plateTopping->setProperty("Image", image);
    plateTopping->setSize(CEGUI::USize(cegui_reldim(0.88f), cegui_absdim(0.0f)));
    plateTopping->setAspectRatio(1.0f);
    plateTopping->setAspectMode(CEGUI::AM_EXPAND);
    plateTopping->setHorizontalAlignment(CEGUI::HA_CENTRE);
    plateTopping->setMousePassThroughEnabled(true);
    plateTopping->setPixelAligned(false);
    plateRoot->addChild(plateTopping);

    int randumNumber = rand() % 10000;
    float posY = randumNumber / 10000.0f;

    plateRoot->setPosition(CEGUI::UVector2(cegui_absdim(0.0f), cegui_reldim(0.8f * posY)));

    return plateRoot;
}

const CEGUI::String& HUDDemo::getRandomGameImage()
{
    int randumNumber = rand() % 100;

    if(randumNumber > 88)
        return s_imageNamePoo;
    else if(randumNumber > 72)
        return s_imageNamePrizza;
    else if(randumNumber > 55)
        return s_imageNameSteak;
    else if(randumNumber > 52)
        return s_imageNameVegFruits;
    else if(randumNumber > 25)
        return s_imageNameVegPeople;
    else if(randumNumber > 0)
        return s_imageNameBread;

    return s_imageNameBread;
}

void HUDDemo::updatePlates(float timeSinceLastUpdate)
{
    unsigned int vectorSize = d_gamePlates.size();

    for(unsigned int i = 0; i < vectorSize;)
    {
        GamePlate* currentPlate = d_gamePlates[i];

        currentPlate->update(timeSinceLastUpdate);
        if(currentPlate->d_isDestroyed)
        {
            delete currentPlate;
            d_gamePlates[i] = d_gamePlates.back();
            d_gamePlates.pop_back();
            vectorSize = d_gamePlates.size();
        }
        else
            ++i;
    }

}

void HUDDemo::updateScoreWindow()
{
    CEGUI::Window* scoreWnd = d_root->getChild("ScoreCounter");
    scoreWnd->setText(CEGUI::PropertyHelper<int>::toString(d_score));
}

bool HUDDemo::handlePlateWindowClicked(const CEGUI::EventArgs& args)
{
    const CEGUI::MouseEventArgs& mouseArgs = static_cast<const CEGUI::MouseEventArgs&>(args);

    for(unsigned int i = 0; i < d_gamePlates.size(); ++i)
    {
        GamePlate* gamePlate = d_gamePlates[i];

        if(gamePlate->d_window == mouseArgs.window)
        {
            int points = gamePlate->getPoints();
            d_score += points;
            updateScoreWindow();

            gamePlate->d_isDestroyed = true;
            createScorePopup(mouseArgs.position, points);
        }
    }

    return false;
}

void HUDDemo::createScorePopup(const CEGUI::Vector2<float>& mousePos, int points)
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    CEGUI::Window* popupWindow = winMgr.createWindow("HUDDemo/PopupLabel");
    d_root->addChild(popupWindow);
    popupWindow->setPosition(CEGUI::UVector2(cegui_absdim(mousePos.d_x), cegui_absdim(mousePos.d_y)));
    popupWindow->setText(CEGUI::PropertyHelper<int>::toString(points));
    popupWindow->setRiseOnClickEnabled(false);
    popupWindow->subscribeEvent(AnimationInstance::EventAnimationEnded, Event::Subscriber(&HUDDemo::handleScorePopupAnimationEnded, this));
    popupWindow->setFont("DejaVuSans-14");
    popupWindow->setPixelAligned(false);

    popupWindow->setPosition(popupWindow->getPosition() + CEGUI::UVector2(cegui_reldim(0.03f), cegui_reldim(-0.02f)));

    if(points < 0)
        popupWindow->setProperty("NormalTextColour", "FFDD0000");
    else
    {
        popupWindow->setText( "+" + popupWindow->getText());
        popupWindow->setProperty("NormalTextColour", "FF00CC00");
    }

    CEGUI::EventArgs args;
    popupWindow->fireEvent("StartAnimation", args);
}

bool HUDDemo::handleScorePopupAnimationEnded(const CEGUI::EventArgs& args)
{
    const CEGUI::AnimationEventArgs& animArgs = static_cast<const CEGUI::AnimationEventArgs&>(args);

    CEGUI::Window* window = static_cast<CEGUI::Window*>( animArgs.instance->getTarget());
    d_delayDestroyWindows.push_back(window);

    return false;
}

void HUDDemo::delayDestroyWindows()
{
    CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();

    while(!d_delayDestroyWindows.empty())
    {
        CEGUI::Window* curWindow = d_delayDestroyWindows.back();
        winMgr.destroyWindow(curWindow);

        d_delayDestroyWindows.pop_back();
    }
}
/*************************************************************************
Define the module function that returns an instance of the sample
*************************************************************************/
extern "C" SAMPLE_EXPORT Sample& getSampleInstance()
{
    static HUDDemo sample;
    return sample;
}<|endoftext|>


<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

// Software Guide : BeginLatex
//
// There is some vector data sets widely available on the internet. These data
// sets can be huge, covering an entire country, with hundreds of thousands
// objects.
//
// Most of the time, you won't be interested in the whole area and would like
// to focuss only on the area corresponding to your satellite image.
//
//
// This example demonstrates the use of the
// \doxygen{otb}{VectorDataExtractROI}.
//
// Software Guide : EndLatex

#include "otbVectorData.h"
#include "otbVectorDataExtractROI.h"
#include "otbRemoteSensingRegion.h"

#include "otbVectorDataFileReader.h"
#include "otbVectorDataFileWriter.h"

#include "otbImage.h"
#include "otbImageFileReader.h"

int main( int argc, char* argv[] )
{
  if (argc < 4  )
  {
    std::cout << argv[0] <<" <input vector filename> <input image name> <output vector filename>  "  << std::endl;

    return EXIT_FAILURE;
  }

  const char * inVectorName = argv[1];
  const char * inImageName = argv[2];
  const char * outVectorName = argv[3];

  typedef double                                             Type;
  typedef otb::VectorData<>                                  VectorDataType;
  typedef otb::VectorDataExtractROI< VectorDataType >        FilterType;
  typedef otb::VectorDataFileReader<VectorDataType>          VectorDataFileReaderType;
  typedef otb::VectorDataFileWriter<VectorDataType>          VectorDataWriterType;

  typedef   otb::RemoteSensingRegion<Type>                    TypedRegion;

  typedef otb::Image<unsigned char, 2>                       ImageType;
  typedef otb::ImageFileReader<ImageType>                    ImageReaderType;
  ImageReaderType::Pointer imageReader = ImageReaderType::New();
  imageReader->SetFileName(inImageName);
  imageReader->UpdateOutputInformation();

  FilterType::Pointer               filter = FilterType::New();
  VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
  VectorDataWriterType::Pointer     writer = VectorDataWriterType::New();

  TypedRegion region;
  TypedRegion::SizeType                                     size;
  TypedRegion::IndexType                                    index;

  size[0]  = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]
      * imageReader->GetOutput()->GetSpacing()[0];
  size[1]  = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]
      * imageReader->GetOutput()->GetSpacing()[1];
  index[0] = imageReader->GetOutput()->GetOrigin()[0]
      - 0.5 * imageReader->GetOutput()->GetSpacing()[0];
  index[1] = imageReader->GetOutput()->GetOrigin()[1]
      - 0.5 * imageReader->GetOutput()->GetSpacing()[1];
  region.SetSize(size);
  region.SetOrigin(index);

  otb::ImageMetadataInterface::Pointer imageMetadataInterface = otb::ImageMetadataInterface::New();
  region.SetRegionProjection(imageMetadataInterface->GetProjectionRef(imageReader->GetOutput()->GetMetaDataDictionary()));

  region.SetKeywordList(imageReader->GetOutput()->GetImageKeywordlist());

  reader->SetFileName(inVectorName);

  filter->SetInput(reader->GetOutput());
  filter->SetRegion(region);

  writer->SetFileName(outVectorName);
  writer->SetInput(filter->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}
<commit_msg>DOC: finishing up example for VectorDataExtractROI<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

// Software Guide : BeginLatex
//
// There is some vector data sets widely available on the internet. These data
// sets can be huge, covering an entire country, with hundreds of thousands
// objects.
//
// Most of the time, you won't be interested in the whole area and would like
// to focuss only on the area corresponding to your satellite image.
//
// The \doxygen{otb}{VectorDataExtractROI} is able to extract the area corresponding
// to your satellite image, even if the image is still in sensor geometry (provided
// the sensor model is supported by OTB). Let's see how we can do that.
//
// This example demonstrates the use of the
// \doxygen{otb}{VectorDataExtractROI}.
//
// Software Guide : EndLatex

#include "otbVectorData.h"
#include "otbVectorDataExtractROI.h"
#include "otbRemoteSensingRegion.h"

#include "otbVectorDataFileReader.h"
#include "otbVectorDataFileWriter.h"

#include "otbImage.h"
#include "otbImageFileReader.h"

int main( int argc, char* argv[] )
{
  if (argc < 4  )
  {
    std::cout << argv[0] <<" <input vector filename> <input image name> <output vector filename>  "  << std::endl;

    return EXIT_FAILURE;
  }

  const char * inVectorName = argv[1];
  const char * inImageName = argv[2];
  const char * outVectorName = argv[3];

  typedef double                                             Type;
  typedef otb::VectorData<>                                  VectorDataType;

  typedef otb::VectorDataFileReader<VectorDataType>          VectorDataFileReaderType;
  typedef otb::VectorDataFileWriter<VectorDataType>          VectorDataWriterType;

  typedef   otb::RemoteSensingRegion<Type>                    TypedRegion;

  typedef otb::Image<unsigned char, 2>                       ImageType;
  typedef otb::ImageFileReader<ImageType>                    ImageReaderType;
  ImageReaderType::Pointer imageReader = ImageReaderType::New();
  imageReader->SetFileName(inImageName);
  imageReader->UpdateOutputInformation();

  // Software Guide : BeginLatex
  //
  // After the usual declaration (you can check the source file for the details),
  // we can declare the \doxygen{otb}{VectorDataExtractROI}:
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::VectorDataExtractROI< VectorDataType >        FilterType;
  FilterType::Pointer               filter = FilterType::New();
  // Software Guide : EndCodeSnippet

  // Software Guide : BeginLatex
  //
  // Then, we need to specify the region to extract. This region is a bit special as
  // it contains also information related to its reference system (cartographic projection
  // or sensor model projection). We retrieve all these information from the image
  // we gave as an input.
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  TypedRegion region;
  TypedRegion::SizeType                                     size;
  TypedRegion::IndexType                                    index;

  size[0]  = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[0]
      * imageReader->GetOutput()->GetSpacing()[0];
  size[1]  = imageReader->GetOutput()->GetLargestPossibleRegion().GetSize()[1]
      * imageReader->GetOutput()->GetSpacing()[1];
  index[0] = imageReader->GetOutput()->GetOrigin()[0]
      - 0.5 * imageReader->GetOutput()->GetSpacing()[0];
  index[1] = imageReader->GetOutput()->GetOrigin()[1]
      - 0.5 * imageReader->GetOutput()->GetSpacing()[1];
  region.SetSize(size);
  region.SetOrigin(index);

  otb::ImageMetadataInterface::Pointer imageMetadataInterface
      = otb::ImageMetadataInterface::New();
  region.SetRegionProjection(
            imageMetadataInterface->GetProjectionRef(
                    imageReader->GetOutput()->GetMetaDataDictionary()));

  region.SetKeywordList(imageReader->GetOutput()->GetImageKeywordlist());

  filter->SetRegion(region);
  // Software Guide : EndCodeSnippet

  VectorDataFileReaderType::Pointer reader = VectorDataFileReaderType::New();
  VectorDataWriterType::Pointer     writer = VectorDataWriterType::New();
  reader->SetFileName(inVectorName);
  writer->SetFileName(outVectorName);

  // Software Guide : BeginLatex
  //
  // And finally, we can plug the filter in the pipeline:
  //
  // Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  filter->SetInput(reader->GetOutput());
  writer->SetInput(filter->GetOutput());
  // Software Guide : EndCodeSnippet

  writer->Update();

  return EXIT_SUCCESS;
}
<|endoftext|>