<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ScatterChartTypeTemplate.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 01:24:41 $
 *
 *  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 CHART_SCATTERCHARTTYPETEMPLATE_HXX
#define CHART_SCATTERCHARTTYPETEMPLATE_HXX

#include "ChartTypeTemplate.hxx"
#include "OPropertySet.hxx"
#include "MutexContainer.hxx"

#ifndef _COMPHELPER_UNO3_HXX_
#include <comphelper/uno3.hxx>
#endif

#ifndef _COM_SUN_STAR_CHART2_STACKMODE_HPP_
#include <com/sun/star/chart2/StackMode.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_CURVESTYLE_HPP_
#include <com/sun/star/chart2/CurveStyle.hpp>
#endif

namespace chart
{

class ScatterChartTypeTemplate :
        public helper::MutexContainer,
        public ChartTypeTemplate,
        public ::property::OPropertySet
{
public:
    explicit ScatterChartTypeTemplate(
        ::com::sun::star::uno::Reference<
            ::com::sun::star::uno::XComponentContext > const & xContext,
        const ::rtl::OUString & rServiceName,
        ::com::sun::star::chart2::CurveStyle eCurveStyle,
        bool bSymbols,
        bool bHasLines = true,
        sal_Int32 nDim = 2 );
    virtual ~ScatterChartTypeTemplate();

    /// XServiceInfo declarations
    APPHELPER_XSERVICEINFO_DECL()

    /// merge XInterface implementations
     DECLARE_XINTERFACE()
    /// merge XTypeProvider implementations
     DECLARE_XTYPEPROVIDER()

protected:
    // ____ OPropertySet ____
    virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const
        throw(::com::sun::star::beans::UnknownPropertyException);
    virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();

    // ____ XPropertySet ____
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL
        getPropertySetInfo()
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XChartTypeTemplate ____
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL
        createDiagram( const ::com::sun::star::uno::Sequence<
                           ::com::sun::star::uno::Reference<
                               ::com::sun::star::chart2::XDataSeries > >& aSeriesSeq )
        throw (::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL matchesTemplate(
        const ::com::sun::star::uno::Reference<
            ::com::sun::star::chart2::XDiagram >& xDiagram )
        throw (::com::sun::star::uno::RuntimeException);

    // ____ ChartTypeTemplate ____
    virtual sal_Int32 getDimension() const;
    virtual ::com::sun::star::uno::Reference<
        ::com::sun::star::chart2::XChartType > getDefaultChartType()
        throw (::com::sun::star::uno::RuntimeException);

private:
    ::com::sun::star::chart2::CurveStyle
                       m_eCurveStyle;
    bool               m_bHasSymbols;
    bool               m_bHasLines;
    sal_Int32          m_nDim;
};

} //  namespace chart

// CHART_SCATTERCHARTTYPETEMPLATE_HXX
#endif
<commit_msg>INTEGRATION: CWS chart2mst3 (1.4.4); FILE MERGED 2007/03/26 14:20:42 iha 1.4.4.17: #i75590# copy some aspects from old charttype during creation of new 2005/10/07 12:06:06 bm 1.4.4.16: RESYNC: (1.4-1.5); FILE MERGED 2005/07/15 16:07:22 bm 1.4.4.15: keep more old objects on chart type changes 2005/07/14 14:59:03 bm 1.4.4.14: overload supportsCategories 2005/05/09 09:51:27 bm 1.4.4.13: moved parts of API to data namespace 2004/09/15 17:32:07 bm 1.4.4.12: API simplification 2004/06/29 12:26:35 bm 1.4.4.11: XChartTypeTemplate changes 2004/05/27 17:27:13 bm 1.4.4.10: +getChartTypeForNewSeries at XChartTypeTemplate 2004/05/07 15:34:37 bm 1.4.4.9: applyStyle works for single series now 2004/04/20 19:21:35 iha 1.4.4.8: make curve style an adabtable property 2004/04/01 10:53:12 bm 1.4.4.7: XChartType: may return a coordinate system now 2004/03/24 19:05:25 bm 1.4.4.6: XChartTypeTemplate changed: matchesTemplate may modify the template s properties if bAdaptProperties is true 2004/03/22 15:27:08 iha 1.4.4.5: added parameter SwapXAndYAxis for horizontal bar chart to method createCoordinateSystems 2004/03/19 14:32:59 bm 1.4.4.4: XDataSource now contains XLabeledDataSources 2004/03/02 16:40:44 bm 1.4.4.3: allow creating more than one coordinate system 2004/02/20 17:43:58 iha 1.4.4.2: integrate categories at ScaleData 2004/02/13 16:51:45 bm 1.4.4.1: join from changes on branch bm_post_chart01<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ScatterChartTypeTemplate.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: vg $ $Date: 2007-05-22 18:52:14 $
 *
 *  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 CHART_SCATTERCHARTTYPETEMPLATE_HXX
#define CHART_SCATTERCHARTTYPETEMPLATE_HXX

#include "ChartTypeTemplate.hxx"
#include "OPropertySet.hxx"
#include "MutexContainer.hxx"

#ifndef _COMPHELPER_UNO3_HXX_
#include <comphelper/uno3.hxx>
#endif

#ifndef _COM_SUN_STAR_CHART2_CURVESTYLE_HPP_
#include <com/sun/star/chart2/CurveStyle.hpp>
#endif

namespace chart
{

class ScatterChartTypeTemplate :
        public MutexContainer,
        public ChartTypeTemplate,
        public ::property::OPropertySet
{
public:
    explicit ScatterChartTypeTemplate(
        ::com::sun::star::uno::Reference<
            ::com::sun::star::uno::XComponentContext > const & xContext,
        const ::rtl::OUString & rServiceName,
        bool bSymbols,
        bool bHasLines = true,
        sal_Int32 nDim = 2 );
    virtual ~ScatterChartTypeTemplate();

    /// XServiceInfo declarations
    APPHELPER_XSERVICEINFO_DECL()

    /// merge XInterface implementations
     DECLARE_XINTERFACE()
    /// merge XTypeProvider implementations
     DECLARE_XTYPEPROVIDER()

protected:
    // ____ OPropertySet ____
    virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const
        throw(::com::sun::star::beans::UnknownPropertyException);
    virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();

    // ____ XPropertySet ____
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL
        getPropertySetInfo()
        throw (::com::sun::star::uno::RuntimeException);

    // ____ XChartTypeTemplate ____
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableCreationParameterNames()
        throw (::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL matchesTemplate(
        const ::com::sun::star::uno::Reference<
            ::com::sun::star::chart2::XDiagram >& xDiagram,
        sal_Bool bAdaptProperties )
        throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL
        getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence<
            ::com::sun::star::uno::Reference<
                ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes )
        throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter()
        throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL applyStyle(
        const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries,
        ::sal_Int32 nChartTypeGroupIndex,
        ::sal_Int32 nSeriesIndex,
        ::sal_Int32 nSeriesCount )
        throw (::com::sun::star::uno::RuntimeException);

    // ____ ChartTypeTemplate ____
    virtual sal_Int32 getDimension() const;

    virtual bool supportsCategories() const;

private:
    bool               m_bHasSymbols;
    bool               m_bHasLines;
    sal_Int32          m_nDim;
};

} //  namespace chart

// CHART_SCATTERCHARTTYPETEMPLATE_HXX
#endif
<|endoftext|>


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

#include "boost/python.hpp"

#include "GafferBindings/UndoContextBinding.h"
#include "Gaffer/UndoContext.h"
#include "Gaffer/ScriptNode.h"

using namespace boost::python;
using namespace GafferBindings;
using namespace Gaffer;

namespace GafferBindings
{

void bindUndoContext()
{
	scope s = class_<UndoContext, boost::noncopyable>( "_UndoContext", init<ScriptNodePtr>() )
		.def( init<ScriptNodePtr, UndoContext::State>() )
		.def( init<ScriptNodePtr, UndoContext::State, const std::string &>() )
	;

	enum_<UndoContext::State>( "State" )
		.value( "Invalid", UndoContext::Invalid )
		.value( "Enabled", UndoContext::Enabled )
		.value( "Disabled", UndoContext::Disabled )
	;
}

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

#include "boost/python.hpp"

#include "IECorePython/ScopedGILRelease.h"

#include "Gaffer/UndoContext.h"
#include "Gaffer/ScriptNode.h"

#include "GafferBindings/UndoContextBinding.h"

using namespace boost::python;
using namespace GafferBindings;
using namespace Gaffer;

namespace
{

typedef boost::shared_ptr<UndoContext> UndoContextPtr;

void deleter( UndoContext *undoContext )
{
	// The destructor for the undo context may trigger a dirty
	// propagation, and observers of plugDirtiedSignal() may
	// well invoke a compute. We need to release the GIL so that
	// if that compute is multithreaded, those threads can acquire
	// the GIL for python based nodes and expressions.
	IECorePython::ScopedGILRelease gilRelease;
	delete undoContext;
}

UndoContextPtr construct( ScriptNodePtr script, UndoContext::State state, const char *mergeGroup )
{
	return UndoContextPtr( new UndoContext( script, state, mergeGroup ), deleter );
}

} // namespace

namespace GafferBindings
{

void bindUndoContext()
{
	class_<UndoContext, UndoContextPtr, boost::noncopyable> cls( "_UndoContext", no_init );

	// Must bind enum before constructor, because we need to
	// use an enum value for a default value.
	scope s( cls );
	enum_<UndoContext::State>( "State" )
		.value( "Invalid", UndoContext::Invalid )
		.value( "Enabled", UndoContext::Enabled )
		.value( "Disabled", UndoContext::Disabled )
	;

	cls.def(
		"__init__",
		make_constructor(
			construct,
			default_call_policies(),
			(
				boost::python::arg_( "script" ),
				boost::python::arg_( "state" ) = UndoContext::Enabled,
				boost::python::arg_( "mergeGroup" ) = ""
			)
		)
	);
}

} // namespace GafferBindings
<|endoftext|>


<commit_before>#include <QApplication>
#include <QSettings>
#include <QIcon>

#include <QDebug>

#include "appcontroller.h"
#include "appwindow.h"
#include "secondarywindow.h"
#include "widgets/librarywidget.h"
#include "widgets/secondary/loginwidget.h"
#include "widgets/secondary/settingswidget.h"

#include "ui_secondarywindow.h"

AppController::AppController(QObject* parent)
    : QObject(parent)
    , settingsWindow(NULL)
    , loginWithApiKey(false)
{
    setupSettings();
    api = new ItchioApi(this, settings->apiUrl());

    setupTrayIcon();
    setupAppWindow();

    if (settings->autoLogin() && settings->hasValidApiKey()) {
        api->loginWithApiKey(settings->apiKey(), [this](bool success, QString err) {
            if (success) {
                onLogin();
            } else {
                onAutoLoginFailure(err);
            }
        });

        loginWithApiKey = true;
    } else {
        setupLogin();
    }

    settingsWindow = new SecondaryWindow(new SettingsWidget(this), this, false);

}

void AppController::setupSettings()
{
    settingsFile = QCoreApplication::applicationDirPath() + "/itchio.ini";
    settings = new AppSettings(settingsFile, QSettings::IniFormat, this);
}

void AppController::quit()
{
    appWindow->hideWindow();
    trayIcon->hide();

    settings->enableStartMaximized(appWindow->isMaximized);
    settings->setWindowGeometry(appWindow->saveGeometry());
    settings->setWindowOldSize(appWindow->oldSize);
    settings->setWindowOldPosition(appWindow->oldPosition);

    if (settings->autoLogin()) {
        settings->setApiKey(api->userKey);
        settings->setUsername(api->userName);
    }
    else{
        settings->setApiKey("");
        settings->setUsername("");
    }

    QCoreApplication::exit();
}

void AppController::showSettings()
{
    settingsWindow->show();
    settingsWindow->activateWindow();
}

void AppController::trayIconDoubleClick(QSystemTrayIcon::ActivationReason reason)
{
    if (reason == QSystemTrayIcon::DoubleClick && !appWindow->isVisible()) {
        appWindow->showWindow();
    }
}

void AppController::setupTrayIcon()
{
    trayIcon = new QSystemTrayIcon(this);

    trayIcon->setIcon(QIcon(":/images/images/itchio-icon-16.png"));
    trayIcon->show();
}

void AppController::setupTrayIconMenu(bool beforeLogin)
{
    trayIconMenu = new QMenu();
    trayIcon->setContextMenu(trayIconMenu);

    if (!beforeLogin) {
        QAction* actionSettings = new QAction("Settings", this);
        trayIconMenu->addAction(actionSettings);
        connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));

        trayIconMenu->addSeparator();
    }

    QAction* actionQuit = new QAction("Quit", this);
    trayIconMenu->addAction(actionQuit);
    connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));

    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(trayIconDoubleClick(QSystemTrayIcon::ActivationReason)));
}

void AppController::showTrayIconNotification(TrayNotifications::Notifications notification, QString data)
{
    if (settings->showTrayNotifications()) {
        if((notification == TrayNotifications::LIBRARY_UPDATE &&
            settings->showLibraryUpdateNotifications()) ||
                (notification == TrayNotifications::DOWNLOAD_FINISHED &&
                 settings->showDownloadFinishedNotifications()) ||
                (notification == TrayNotifications::GAME_UPDATE_AVAILABLE &&
                 settings->showGameUpdateAvailableNotifications())){

            trayIcon->showMessage(TrayNotifications::toString(notification),
                                  data, QSystemTrayIcon::NoIcon, 5000);
        }

    }
}

void AppController::setupLogin()
{
    settings->setApiKey("");
    api->userKey = "";

    setupTrayIconMenu(true);

    loginWindow = new SecondaryWindow(new LoginWidget(qobject_cast<QWidget*>(this), this), this, true);
    loginWindow->show();
}

void AppController::setupAppWindow()
{
    appWindow = new AppWindow(this);
}

void AppController::onLogin()
{
    setupTrayIconMenu();

    if (!loginWithApiKey) {
        loginWindow->deleteLater();
        loginWindow->close();
    }

    appWindow->setupLibrary();
}

void AppController::onAutoLoginFailure(QString)
{
    setupLogin();
}
<commit_msg>Window geometry settings will not be saved if app closed on login.<commit_after>#include <QApplication>
#include <QSettings>
#include <QIcon>

#include <QDebug>

#include "appcontroller.h"
#include "appwindow.h"
#include "secondarywindow.h"
#include "widgets/librarywidget.h"
#include "widgets/secondary/loginwidget.h"
#include "widgets/secondary/settingswidget.h"

#include "ui_secondarywindow.h"

AppController::AppController(QObject* parent)
    : QObject(parent)
    , settingsWindow(NULL)
    , loginWithApiKey(false)
{
    setupSettings();
    api = new ItchioApi(this, settings->apiUrl());

    setupTrayIcon();
    setupAppWindow();

    if (settings->autoLogin() && settings->hasValidApiKey()) {
        api->loginWithApiKey(settings->apiKey(), [this](bool success, QString err) {
            if (success) {
                onLogin();
            } else {
                onAutoLoginFailure(err);
            }
        });

        loginWithApiKey = true;
    } else {
        setupLogin();
    }

    settingsWindow = new SecondaryWindow(new SettingsWidget(this), this, false);

}

void AppController::setupSettings()
{
    settingsFile = QCoreApplication::applicationDirPath() + "/itchio.ini";
    settings = new AppSettings(settingsFile, QSettings::IniFormat, this);
}

void AppController::quit()
{
    appWindow->hideWindow();
    trayIcon->hide();

    if(api->userName != ""){
        settings->enableStartMaximized(appWindow->isMaximized);
        settings->setWindowGeometry(appWindow->saveGeometry());
        settings->setWindowOldSize(appWindow->oldSize);
        settings->setWindowOldPosition(appWindow->oldPosition);
    }

    if (settings->autoLogin()) {
        settings->setApiKey(api->userKey);
        settings->setUsername(api->userName);
    }
    else{
        settings->setApiKey("");
        settings->setUsername("");
    }

    QCoreApplication::exit();
}

void AppController::showSettings()
{
    settingsWindow->show();
    settingsWindow->activateWindow();
}

void AppController::trayIconDoubleClick(QSystemTrayIcon::ActivationReason reason)
{
    if (reason == QSystemTrayIcon::DoubleClick && !appWindow->isVisible()) {
        appWindow->showWindow();
    }
}

void AppController::setupTrayIcon()
{
    trayIcon = new QSystemTrayIcon(this);

    trayIcon->setIcon(QIcon(":/images/images/itchio-icon-16.png"));
    trayIcon->show();
}

void AppController::setupTrayIconMenu(bool beforeLogin)
{
    trayIconMenu = new QMenu();
    trayIcon->setContextMenu(trayIconMenu);

    if (!beforeLogin) {
        QAction* actionSettings = new QAction("Settings", this);
        trayIconMenu->addAction(actionSettings);
        connect(actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));

        trayIconMenu->addSeparator();
    }

    QAction* actionQuit = new QAction("Quit", this);
    trayIconMenu->addAction(actionQuit);
    connect(actionQuit, SIGNAL(triggered()), this, SLOT(quit()));

    connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(trayIconDoubleClick(QSystemTrayIcon::ActivationReason)));
}

void AppController::showTrayIconNotification(TrayNotifications::Notifications notification, QString data)
{
    if (settings->showTrayNotifications()) {
        if((notification == TrayNotifications::LIBRARY_UPDATE &&
            settings->showLibraryUpdateNotifications()) ||
                (notification == TrayNotifications::DOWNLOAD_FINISHED &&
                 settings->showDownloadFinishedNotifications()) ||
                (notification == TrayNotifications::GAME_UPDATE_AVAILABLE &&
                 settings->showGameUpdateAvailableNotifications())){

            trayIcon->showMessage(TrayNotifications::toString(notification),
                                  data, QSystemTrayIcon::NoIcon, 5000);
        }

    }
}

void AppController::setupLogin()
{
    settings->setApiKey("");
    api->userKey = "";

    setupTrayIconMenu(true);

    loginWindow = new SecondaryWindow(new LoginWidget(qobject_cast<QWidget*>(this), this), this, true);
    loginWindow->show();
}

void AppController::setupAppWindow()
{
    appWindow = new AppWindow(this);
}

void AppController::onLogin()
{
    setupTrayIconMenu();

    if (!loginWithApiKey) {
        loginWindow->deleteLater();
        loginWindow->close();
    }

    appWindow->setupLibrary();
}

void AppController::onAutoLoginFailure(QString)
{
    setupLogin();
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: valuenodeaccess.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: jb $ $Date: 2002-03-28 08:47:03 $
 *
 *  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 CONFIGMGR_VALUENODEACCESS_HXX
#define CONFIGMGR_VALUENODEACCESS_HXX

#ifndef CONFIGMGR_NODEACCESS_HXX
#include "nodeaccess.hxx"
#endif

namespace configmgr
{
// -----------------------------------------------------------------------------
    namespace data
    {
    // -------------------------------------------------------------------------
        class ValueNodeAccess
        {
        public:
            typedef NodeAccess::Name        Name;
            typedef NodeAccess::Attributes  Attributes;
            typedef ValueNodeAddress                    NodeAddressType;
            typedef ValueNodeAddress::AddressType       AddressType;
            typedef ValueNodeAddress::DataType const    DataType;
            typedef DataType * NodePointerType;

            ValueNodeAccess(Accessor const& _aAccessor, NodeAddressType const& _aNodeRef)
            : m_aAccessor(_aAccessor)
            , m_pData(_aNodeRef.m_pData)
            {}

            ValueNodeAccess(Accessor const& _aAccessor, NodePointerType _pNode)
            : m_aAccessor(_aAccessor)
            , m_pData(check(_aAccessor,_pNode))
            {}

            explicit
            ValueNodeAccess(NodeAccess const & _aNode)
            : m_aAccessor(_aNode.accessor())
            , m_pData(check(_aNode))
            {
            }

            static bool isInstance(NodeAccess const & _aNode)
            {
                return check(_aNode) != NULL;
            }

            bool isValid() const { return m_pData != NULL; }

            Name getName() const;
            Attributes getAttributes() const;

            bool isEmpty()     const { return data().isEmpty(); }

            bool isNull()      const { return data().isNull(); }
            bool isDefault()   const;
            bool isLocalized() const;

            bool hasUsableDefault()   const { return data().hasUsableDefault(); }

            uno::Type   getValueType()  const { return data().getValueType(); }
            uno::Any    getValue()      const;
            uno::Any    getUserValue()      const;
            uno::Any    getDefaultValue()   const;

            static void setValue(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode, uno::Any const& _aValue);
            static void setToDefault(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode);
            static void changeDefault(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode, uno::Any const& _aValue);

            NodeAddressType address()   const { return NodeAddressType(m_pData); }
            Accessor        accessor()  const { return m_aAccessor; }

            DataType& data() const { return *static_cast<NodePointerType>(m_aAccessor.validate(m_pData)); }

            operator NodeAccess() const { return NodeAccess(m_aAccessor,NodeAddress(m_pData)); }
        private:
            static AddressType check(Accessor const& _acc, NodePointerType _p) { return _acc.address(_p); }
            static AddressType check(NodeAccess const& _aNodeData);

            Accessor    m_aAccessor;
            AddressType m_pData;
        };

        ValueNodeAddress toValueNodeAddress(memory::Accessor const & _aAccess, NodeAddress const & _aNodeAddr);
        ValueNodeAddress toValueNodeAddress(memory::UpdateAccessor & _aAccess, NodeAddress const & _aNodeAddr);
    // -------------------------------------------------------------------------

        inline
        NodeAccess::Name ValueNodeAccess::getName() const
        { return NodeAccess::wrapName( data().info.getName(m_aAccessor) ); }

        inline
        NodeAccess::Attributes ValueNodeAccess::getAttributes() const
        { return data().info.getAttributes(); }

        inline
        bool ValueNodeAccess::isDefault()   const
        { return data().info.isDefault(); }

        inline
        bool ValueNodeAccess::isLocalized()   const
        { return data().info.isLocalized(); }

        inline
        uno::Any    ValueNodeAccess::getValue()      const
        { return data().getValue(m_aAccessor); }

        inline
        uno::Any    ValueNodeAccess::getUserValue()    const
        { return data().getUserValue(m_aAccessor); }

        inline
        uno::Any    ValueNodeAccess::getDefaultValue()    const
        { return data().getDefaultValue(m_aAccessor); }

    // -------------------------------------------------------------------------
    }
// -----------------------------------------------------------------------------
} // namespace configmgr

#endif // CONFIGMGR_VALUENODEACCESS_HXX

<commit_msg>INTEGRATION: CWS cfg01 (1.2.24); FILE MERGED 2003/03/13 15:28:15 jb 1.2.24.2: #108154# Use NodeAccessRef to avoid copying Accessor objects 2003/02/28 16:33:18 ssmith 1.2.24.1: #107403# #107403# adding support for mandatory flag and changing dynamic properties semantics<commit_after>/*************************************************************************
 *
 *  $RCSfile: valuenodeaccess.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-01 13:35:21 $
 *
 *  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 CONFIGMGR_VALUENODEACCESS_HXX
#define CONFIGMGR_VALUENODEACCESS_HXX

#ifndef CONFIGMGR_NODEACCESS_HXX
#include "nodeaccess.hxx"
#endif

namespace configmgr
{
// -----------------------------------------------------------------------------
    namespace data
    {
    // -------------------------------------------------------------------------
        class ValueNodeAccess
        {
        public:
            typedef NodeAccess::Name        Name;
            typedef NodeAccess::Attributes  Attributes;
            typedef ValueNodeAddress                    NodeAddressType;
            typedef ValueNodeAddress::AddressType       AddressType;
            typedef ValueNodeAddress::DataType const    DataType;
            typedef DataType * NodePointerType;

            ValueNodeAccess(Accessor const& _aAccessor, NodeAddressType const& _aNodeRef)
            : m_aAccessor(_aAccessor)
            , m_pData(_aNodeRef.m_pData)
            {}

            ValueNodeAccess(Accessor const& _aAccessor, NodePointerType _pNode)
            : m_aAccessor(_aAccessor)
            , m_pData(check(_aAccessor,_pNode))
            {}

            explicit
            ValueNodeAccess(NodeAccess const & _aNode)
            : m_aAccessor(_aNode.accessor())
            , m_pData(check(_aNode))
            {
            }

            explicit
            ValueNodeAccess(NodeAccessRef const & _aNode)
            : m_aAccessor(_aNode.accessor())
            , m_pData(check(_aNode))
            {
            }

            static bool isInstance(NodeAccessRef const & _aNode)
            {
                return check(_aNode) != NULL;
            }

            bool isValid() const { return m_pData != NULL; }

            Name getName() const;
            Attributes getAttributes() const;

            bool isEmpty()     const { return data().isEmpty(); }

            bool isNull()      const { return data().isNull(); }
            bool isDefault()   const;
            bool isLocalized() const;

            bool hasUsableDefault()   const { return data().hasUsableDefault(); }

            uno::Type   getValueType()  const { return data().getValueType(); }
            uno::Any    getValue()      const;
            uno::Any    getUserValue()      const;
            uno::Any    getDefaultValue()   const;

            static void setValue(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode, uno::Any const& _aValue);
            static void setToDefault(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode);
            static void changeDefault(memory::UpdateAccessor & _aUpdater, NodeAddressType _aValueNode, uno::Any const& _aValue);

            NodeAddressType address()   const { return NodeAddressType(m_pData); }
            Accessor const& accessor()  const { return m_aAccessor; }

            DataType& data() const { return *static_cast<NodePointerType>(m_aAccessor.validate(m_pData)); }

            operator NodeAccessRef() const { return NodeAccessRef(&m_aAccessor,NodeAddress(m_pData)); }
        private:
            static AddressType check(Accessor const& _acc, NodePointerType _p) { return _acc.address(_p); }
            static AddressType check(NodeAccessRef const& _aNodeData);

            Accessor    m_aAccessor;
            AddressType m_pData;
        };

        ValueNodeAddress toValueNodeAddress(memory::Accessor const & _aAccess, NodeAddress const & _aNodeAddr);
        ValueNodeAddress toValueNodeAddress(memory::UpdateAccessor & _aAccess, NodeAddress const & _aNodeAddr);
    // -------------------------------------------------------------------------

        inline
        NodeAccess::Name ValueNodeAccess::getName() const
        { return NodeAccess::wrapName( data().info.getName(m_aAccessor) ); }

        inline
        NodeAccess::Attributes ValueNodeAccess::getAttributes() const
        { return sharable::node(data()).getAttributes(); }

        inline
        bool ValueNodeAccess::isDefault()   const
        { return data().info.isDefault(); }

        inline
        bool ValueNodeAccess::isLocalized()   const
        { return data().info.isLocalized(); }

        inline
        uno::Any    ValueNodeAccess::getValue()      const
        { return data().getValue(m_aAccessor); }

        inline
        uno::Any    ValueNodeAccess::getUserValue()    const
        { return data().getUserValue(m_aAccessor); }

        inline
        uno::Any    ValueNodeAccess::getDefaultValue()    const
        { return data().getDefaultValue(m_aAccessor); }

    // -------------------------------------------------------------------------
    }
// -----------------------------------------------------------------------------
} // namespace configmgr

#endif // CONFIGMGR_VALUENODEACCESS_HXX

<|endoftext|>


<commit_before>/*
 * D3Q27Lattice.cpp
 *
 *  Created on: Jul 10, 2017
 *      Author: sblair
 */
#include "D3Q27Lattice.h"
#include <cstdlib>

D3Q27Lattice::D3Q27Lattice(const int Nx, const int Ny, const int Nz):
Lattice(Nx,Ny,Nz),
ex{0,1,-1,0,0,0,0,1,1,-1,-1,1,1,-1,-1,0,0,0,0,1,1,1,1,-1,-1,-1,-1},
ey{0,0,0,1,-1,0,0,1,-1,1,-1,0,0,0,0,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1},
ez{0,0,0,0,0,1,-1,0,0,0,0,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1},
w{8./27.,2./27.,2./27.,2./27.,2./27.,2./27.,2./27.,
    1./54.,1./54.,1./54.,1./54.,1./54.,1./54.,
    1./54.,1./54.,1./54.,1./54.,1./54.,1./54.,
    1./216.,1./216.,1./216.,1./216.,
    1./216.,1./216.,1./216.,1./216.},
bbSpd{0,2,1,4,3,6,5,10,9,8,7,14,13,12,11,18,17,16,15,26,25,24,23,22,21,20,19},
Qflat{-1./3.,0,0,0,-1./3.,0,0,0,-1./3., // 0
	  2./3.,0,0,0,-1./3.,0,0,0,-1./3.,  // 1
	  -1./3.,0,0,0,2./3.,0,0,0,-1./3.,// 2
	  -1./3.,0,0,0,-1./3.,0,0,0,2./3.,// 3
	  2./3.,1,0,1,2./3.,0,0,0,-1./3.,// 4
	  2./3.,-1,0,-1,2./3.,0,0,0,-1./3.,// 5
	  2./3.,0,1,0,-1./3.,0,1,0,2./3.,// 6
	  2./3.,0,-1,0,-1./3.,0,-1,0,2./3.,// 7
	  -1./3.,0,0,0,2./3.,1,0,1,2./3.,//8
	  -1./3.,0,0,0,2./3.,-1,0,-1,2./3.,//9
	  2./3.,1,1,1,2./3.,1,1,1,2./3.,//10
	  2./3.,1,-1,1,2./3.,-1,-1,-1,2./3.,//11
	  2./3.,-1,1,-1,2./3.,-1,1,-1,2./3.,//12
	  2./3.,-1,-1,-1,2./3.,1,-1,1,2./3.,//13
	  2./3.,0,0,0,-1./3.,0,0,0,-1./3.,//14
	  -1./3.,0,0,0,2./3.,0,0,0,-1./3.,//15
	  -1./3.,0,0,0,-1./3.,0,0,0,2./3.,//16
	  2./3.,1,0,1,2./3.,0,0,0,-1./3.,//17
	  2./3.,-1,0,-1,2./3.,0,0,0,-1./3.,//18
	  2./3.,0,1,0,-1./3.,0,1,0,2./3.,//19
	  2./3.,0,-1,0,-1./3.,0,-1,0,2./3.,//20
	  -1./3.,0,0,0,2./3.,1,0,1,2./3.,//21
	  -1./3.,0,0,0,2./3.,-1,0,-1,2./3.,//22
	  2./3.,1,1,1,2./3.,1,1,1,2./3.,//23
	  2./3.,1,-1,1,2./3.,-1,-1,-1,2./3.,//24
	  2./3.,-1,1,-1,2./3.,-1,1,-1,2./3.,//25
	  2./3.,-1,-1,-1,2./3.,1,-1,1,2./3.}//26
{
	// direct base-class pointers to lattice variables
	setNumSpd(numSpd);
	setEx(ex);
	setEy(ey);
	setEz(ez);
	setW(w);
	setBBspd(bbSpd);
	setQflat(Qflat);

}

D3Q27Lattice::~D3Q27Lattice()
{

}

void D3Q27Lattice::set_inlet_bc_micro(LBM_DataHandler& f)
{
	int sp[9]={5,11,13,15,17,19,21,23,25};
	int bbSp[9]={6,14,12,18,16,26,24,22,20};
	int numBB = 9;
	for(int s=0;s<numBB;s++)
	{
		f.f[sp[s]]=f.fEq[sp[s]]+f.f[bbSp[s]]-f.fEq[bbSp[s]];
	}
}

void D3Q27Lattice::set_inlet_bc_macro(LBM_DataHandler& f)
{
	f.uz = f.u_bc;
	f.ux = 0; f.uy = 0.;
	f.rho = (1./(1. - f.uz))*(2.*(f.f[6]+f.f[14]+f.f[12]+
			f.f[18]+f.f[16]+f.f[26]+f.f[24]+f.f[22]+f.f[20])+
			(f.f[0]+f.f[1]+f.f[2]+f.f[3]+f.f[4]+
					f.f[7]+f.f[8]+f.f[9]+f.f[10]));
}

void D3Q27Lattice::set_outlet_bc_micro(LBM_DataHandler& f)
{
	int sp[9]={6,14,12,18,16,26,24,22,202};
	int bbSp[9]={5,11,13,15,17,19,21,23,25};
	int numBB = 9;
	for(int s=0;s<numBB;s++)
	{
		f.f[sp[s]]=f.fEq[sp[s]]+f.f[bbSp[s]]-f.fEq[bbSp[s]];
	}
}

void D3Q27Lattice::set_outlet_bc_macro(LBM_DataHandler& f)
{
	f.rho = f.rho_bc;
	f.uz = -1. + (1./f.rho)*(2.*
			(f.f[5]+f.f[11]+f.f[13]+f.f[15]+f.f[17]+f.f[19]+
					f.f[21]+f.f[23]+f.f[25])+
					(f.f[0]+f.f[1]+f.f[2]+f.f[3]+f.f[4]+
							f.f[7]+f.f[8]+f.f[9]+f.f[10]));
}

<commit_msg>fixed bug in D3Q27 re-ordering implementation<commit_after>/*
 * D3Q27Lattice.cpp
 *
 *  Created on: Jul 10, 2017
 *      Author: sblair
 */
#include "D3Q27Lattice.h"
#include <cstdlib>

D3Q27Lattice::D3Q27Lattice(const int Nx, const int Ny, const int Nz):
Lattice(Nx,Ny,Nz),
ex{0,1,-1,0,0,0,0,1,1,-1,-1,1,1,-1,-1,0,0,0,0,1,1,1,1,-1,-1,-1,-1},
ey{0,0,0,1,-1,0,0,1,-1,1,-1,0,0,0,0,1,1,-1,-1,1,1,-1,-1,1,1,-1,-1},
ez{0,0,0,0,0,1,-1,0,0,0,0,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1},
w{8./27.,2./27.,2./27.,2./27.,2./27.,2./27.,2./27.,
    1./54.,1./54.,1./54.,1./54.,1./54.,1./54.,
    1./54.,1./54.,1./54.,1./54.,1./54.,1./54.,
    1./216.,1./216.,1./216.,1./216.,
    1./216.,1./216.,1./216.,1./216.},
bbSpd{0,2,1,4,3,6,5,10,9,8,7,14,13,12,11,18,17,16,15,26,25,24,23,22,21,20,19},
Qflat{-1./3.,0,0,0,-1./3.,0,0,0,-1./3., // 0
	  2./3.,0,0,0,-1./3.,0,0,0,-1./3.,  // 1
	  -1./3.,0,0,0,2./3.,0,0,0,-1./3.,// 2
	  -1./3.,0,0,0,-1./3.,0,0,0,2./3.,// 3
	  2./3.,1,0,1,2./3.,0,0,0,-1./3.,// 4
	  2./3.,-1,0,-1,2./3.,0,0,0,-1./3.,// 5
	  2./3.,0,1,0,-1./3.,0,1,0,2./3.,// 6
	  2./3.,0,-1,0,-1./3.,0,-1,0,2./3.,// 7
	  -1./3.,0,0,0,2./3.,1,0,1,2./3.,//8
	  -1./3.,0,0,0,2./3.,-1,0,-1,2./3.,//9
	  2./3.,1,1,1,2./3.,1,1,1,2./3.,//10
	  2./3.,1,-1,1,2./3.,-1,-1,-1,2./3.,//11
	  2./3.,-1,1,-1,2./3.,-1,1,-1,2./3.,//12
	  2./3.,-1,-1,-1,2./3.,1,-1,1,2./3.,//13
	  2./3.,0,0,0,-1./3.,0,0,0,-1./3.,//14
	  -1./3.,0,0,0,2./3.,0,0,0,-1./3.,//15
	  -1./3.,0,0,0,-1./3.,0,0,0,2./3.,//16
	  2./3.,1,0,1,2./3.,0,0,0,-1./3.,//17
	  2./3.,-1,0,-1,2./3.,0,0,0,-1./3.,//18
	  2./3.,0,1,0,-1./3.,0,1,0,2./3.,//19
	  2./3.,0,-1,0,-1./3.,0,-1,0,2./3.,//20
	  -1./3.,0,0,0,2./3.,1,0,1,2./3.,//21
	  -1./3.,0,0,0,2./3.,-1,0,-1,2./3.,//22
	  2./3.,1,1,1,2./3.,1,1,1,2./3.,//23
	  2./3.,1,-1,1,2./3.,-1,-1,-1,2./3.,//24
	  2./3.,-1,1,-1,2./3.,-1,1,-1,2./3.,//25
	  2./3.,-1,-1,-1,2./3.,1,-1,1,2./3.}//26
{
	// direct base-class pointers to lattice variables
	setNumSpd(numSpd);
	setEx(ex);
	setEy(ey);
	setEz(ez);
	setW(w);
	setBBspd(bbSpd);
	setQflat(Qflat);

}

D3Q27Lattice::~D3Q27Lattice()
{

}

void D3Q27Lattice::set_inlet_bc_micro(LBM_DataHandler& f)
{
	int sp[9]={5,11,13,15,17,19,21,23,25};
	int bbSp[9]={6,14,12,18,16,26,24,22,20};
	int numBB = 9;
	for(int s=0;s<numBB;s++)
	{
		f.f[sp[s]]=f.fEq[sp[s]]+f.f[bbSp[s]]-f.fEq[bbSp[s]];
	}
}

void D3Q27Lattice::set_inlet_bc_macro(LBM_DataHandler& f)
{
	f.uz = f.u_bc;
	f.ux = 0; f.uy = 0.;
	f.rho = (1./(1. - f.uz))*(2.*(f.f[6]+f.f[14]+f.f[12]+
			f.f[18]+f.f[16]+f.f[26]+f.f[24]+f.f[22]+f.f[20])+
			(f.f[0]+f.f[1]+f.f[2]+f.f[3]+f.f[4]+
					f.f[7]+f.f[8]+f.f[9]+f.f[10]));
}

void D3Q27Lattice::set_outlet_bc_micro(LBM_DataHandler& f)
{
	int sp[9]={6,14,12,18,16,26,24,22,20};
	int bbSp[9]={5,11,13,15,17,19,21,23,25};
	int numBB = 9;
	for(int s=0;s<numBB;s++)
	{
		f.f[sp[s]]=f.fEq[sp[s]]+f.f[bbSp[s]]-f.fEq[bbSp[s]];
	}
}

void D3Q27Lattice::set_outlet_bc_macro(LBM_DataHandler& f)
{
	f.rho = f.rho_bc;
	f.uz = -1. + (1./f.rho)*(2.*
			(f.f[5]+f.f[11]+f.f[13]+f.f[15]+f.f[17]+f.f[19]+
					f.f[21]+f.f[23]+f.f[25])+
					(f.f[0]+f.f[1]+f.f[2]+f.f[3]+f.f[4]+
							f.f[7]+f.f[8]+f.f[9]+f.f[10]));
}

<|endoftext|>


<commit_before><commit_msg>some nicer error outputs<commit_after><|endoftext|>


<commit_before>/***************************************************************
 *
 * Copyright (C) 1990-2011, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 *
 * 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.
 *
 ***************************************************************/

#include "condor_common.h"
#include "startd_cron_job_mgr.h"
#include "startd_cron_job.h"
#include "condor_config.h"
#include "startd.h"

// Basic constructor
StartdCronJobMgr::StartdCronJobMgr( void )
		: CronJobMgr( ),
		  m_shutting_down( false ),
		  m_auto_publish( CAP_NEVER )
{
}

// Basic destructor
StartdCronJobMgr::~StartdCronJobMgr( void )
{
	dprintf( D_FULLDEBUG, "StartdCronJobMgr: Bye\n" );
}

int
StartdCronJobMgr::Initialize( const char *name )
{
	int status;

	SetName( name, name, "_cron" );

	char *cron_name = param( "STARTD_CRON_NAME" );
	if ( NULL != cron_name ) {
		dprintf( D_ALWAYS,
				 "WARNING: The use of STARTD_CRON_NAME to 'name' your "
				 "Startd's Daemon ClassAd Hook Manager is not longer supported "
				 "and will be removed in a future release of Condor." );
		name = cron_name;
		SetName( name, name );
	}

	status = CronJobMgr::Initialize( name );
	if ( NULL != cron_name ) {
		free( cron_name );
	}

	ParamAutoPublish( );
	return status;
}

int
StartdCronJobMgr::Reconfig( void )
{
	ParamAutoPublish();
	return CronJobMgr::HandleReconfig();
}

void
StartdCronJobMgr::ParamAutoPublish( void )
{
	m_auto_publish = CAP_NEVER;  // always default to never if not set
	char* tmp = param("STARTD_CRON_AUTOPUBLISH");
	if( tmp ) {
		m_auto_publish = getCronAutoPublishNum(tmp);
		if( m_auto_publish == CAP_ERROR ) {
			dprintf( D_ALWAYS, "StartdCronJobMgr::Reconfig(): "
					 "invalid value for STARTD_CRON_AUTOPUBLISH: \"%s\" "
					 "using default value of NEVER\n", tmp );
			m_auto_publish = CAP_NEVER;
		} else {
			dprintf( D_FULLDEBUG, "StartdCronJobMgr::Reconfig(): "
					 "STARTD_CRON_AUTOPUBLISH set to \"%s\"\n", tmp );
		}
		free( tmp );
		tmp = NULL;
	}
}

// Perform shutdown
int
StartdCronJobMgr::Shutdown( bool force )
{
	dprintf( D_FULLDEBUG, "StartdCronJobMgr: Shutting down\n" );
	m_shutting_down = true;
	return KillAll( force );
}

// Check shutdown
bool
StartdCronJobMgr::ShutdownOk( void )
{
	bool	idle = IsAllIdle( );

	// dprintf( D_ALWAYS, "ShutdownOk: %s\n", idle ? "Idle" : "Busy" );
	return idle;
}

StartdCronJobParams *
StartdCronJobMgr::CreateJobParams( const char *job_name )
{
	return new StartdCronJobParams( job_name, *this );
}

StartdCronJob *
StartdCronJobMgr::CreateJob( CronJobParams *job_params )
{
	const char * jobName = job_params->GetName();

	dprintf( D_FULLDEBUG,
			 "*** Creating Startd Cron job '%s'***\n",
			 jobName );
	StartdCronJobParams *params =
		dynamic_cast<StartdCronJobParams *>( job_params );
	ASSERT( params );

	char * metricString = params->Lookup( "METRICS" );
	if( metricString != NULL && metricString[0] != '\0' ) {
		StringList pairs( metricString );
		for( char * pair = pairs.first(); pair != NULL; pair = pairs.next() ) {
			StringList tn( pair, ":" );
			char * metricType = tn.first();
			char * attributeName = tn.next();
			if(! params->addMetric( metricType, attributeName )) {
				dprintf( 	D_ALWAYS, "Unknown metric type '%s' for attribute "
							"'%s' in monitor '%s', ignoring.\n", metricType,
							attributeName, jobName );
			} else {
				dprintf(	D_FULLDEBUG, "Added %s as %s metric for %s job\n",
							attributeName, metricType, jobName );
			}
		}

		free( metricString );
	}

	return new StartdCronJob( params, *this );
}

// Should we start a job?
bool
StartdCronJobMgr::ShouldStartJob( const CronJob &job ) const
{
	if ( m_shutting_down ) {
		return false;
	}

	// Don't start *any* new jobs during benchmarks
	if ( bench_job_mgr && bench_job_mgr->NumActiveBenchmarks() ) {
		return false;
	}

	return CronJobMgr::ShouldStartJob( job );
}

// Should we allow a benchmark to run?
bool
StartdCronJobMgr::ShouldStartBenchmarks( void ) const
{
	dprintf( D_FULLDEBUG,
			 "ShouldStartBenchmarks: load=%.2f max=%.2f\n",
			 GetCurJobLoad(), GetMaxJobLoad() );
	return ( GetCurJobLoad() < GetMaxJobLoad() );
}

// Job is started
bool
StartdCronJobMgr::JobStarted( const CronJob &job )
{
	return CronJobMgr::JobStarted( job );
}

// Job exitted
bool
StartdCronJobMgr::JobExited( const CronJob &job )
{
	bool status = CronJobMgr::JobExited( job );
	if ( m_shutting_down &&  IsAllIdle() ) {
		startd_check_free();
	}
	if ( bench_job_mgr ) {
		bench_job_mgr->ScheduleAllJobs();
	}
	return status;
}
<commit_msg>Fix minor memory leak in startd cron #6345<commit_after>/***************************************************************
 *
 * Copyright (C) 1990-2011, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 *
 * 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.
 *
 ***************************************************************/

#include "condor_common.h"
#include "startd_cron_job_mgr.h"
#include "startd_cron_job.h"
#include "condor_config.h"
#include "startd.h"

// Basic constructor
StartdCronJobMgr::StartdCronJobMgr( void )
		: CronJobMgr( ),
		  m_shutting_down( false ),
		  m_auto_publish( CAP_NEVER )
{
}

// Basic destructor
StartdCronJobMgr::~StartdCronJobMgr( void )
{
	dprintf( D_FULLDEBUG, "StartdCronJobMgr: Bye\n" );
}

int
StartdCronJobMgr::Initialize( const char *name )
{
	int status;

	SetName( name, name, "_cron" );

	char *cron_name = param( "STARTD_CRON_NAME" );
	if ( NULL != cron_name ) {
		dprintf( D_ALWAYS,
				 "WARNING: The use of STARTD_CRON_NAME to 'name' your "
				 "Startd's Daemon ClassAd Hook Manager is not longer supported "
				 "and will be removed in a future release of Condor." );
		name = cron_name;
		SetName( name, name );
	}

	status = CronJobMgr::Initialize( name );
	if ( NULL != cron_name ) {
		free( cron_name );
	}

	ParamAutoPublish( );
	return status;
}

int
StartdCronJobMgr::Reconfig( void )
{
	ParamAutoPublish();
	return CronJobMgr::HandleReconfig();
}

void
StartdCronJobMgr::ParamAutoPublish( void )
{
	m_auto_publish = CAP_NEVER;  // always default to never if not set
	char* tmp = param("STARTD_CRON_AUTOPUBLISH");
	if( tmp ) {
		m_auto_publish = getCronAutoPublishNum(tmp);
		if( m_auto_publish == CAP_ERROR ) {
			dprintf( D_ALWAYS, "StartdCronJobMgr::Reconfig(): "
					 "invalid value for STARTD_CRON_AUTOPUBLISH: \"%s\" "
					 "using default value of NEVER\n", tmp );
			m_auto_publish = CAP_NEVER;
		} else {
			dprintf( D_FULLDEBUG, "StartdCronJobMgr::Reconfig(): "
					 "STARTD_CRON_AUTOPUBLISH set to \"%s\"\n", tmp );
		}
		free( tmp );
		tmp = NULL;
	}
}

// Perform shutdown
int
StartdCronJobMgr::Shutdown( bool force )
{
	dprintf( D_FULLDEBUG, "StartdCronJobMgr: Shutting down\n" );
	m_shutting_down = true;
	return KillAll( force );
}

// Check shutdown
bool
StartdCronJobMgr::ShutdownOk( void )
{
	bool	idle = IsAllIdle( );

	// dprintf( D_ALWAYS, "ShutdownOk: %s\n", idle ? "Idle" : "Busy" );
	return idle;
}

StartdCronJobParams *
StartdCronJobMgr::CreateJobParams( const char *job_name )
{
	return new StartdCronJobParams( job_name, *this );
}

StartdCronJob *
StartdCronJobMgr::CreateJob( CronJobParams *job_params )
{
	const char * jobName = job_params->GetName();

	dprintf( D_FULLDEBUG,
			 "*** Creating Startd Cron job '%s'***\n",
			 jobName );
	StartdCronJobParams *params =
		dynamic_cast<StartdCronJobParams *>( job_params );
	ASSERT( params );

	char * metricString = params->Lookup( "METRICS" );
	if( metricString != NULL && metricString[0] != '\0' ) {
		StringList pairs( metricString );
		for( char * pair = pairs.first(); pair != NULL; pair = pairs.next() ) {
			StringList tn( pair, ":" );
			char * metricType = tn.first();
			char * attributeName = tn.next();
			if(! params->addMetric( metricType, attributeName )) {
				dprintf( 	D_ALWAYS, "Unknown metric type '%s' for attribute "
							"'%s' in monitor '%s', ignoring.\n", metricType,
							attributeName, jobName );
			} else {
				dprintf(	D_FULLDEBUG, "Added %s as %s metric for %s job\n",
							attributeName, metricType, jobName );
			}
		}
	}
	if (metricString) free( metricString );

	return new StartdCronJob( params, *this );
}

// Should we start a job?
bool
StartdCronJobMgr::ShouldStartJob( const CronJob &job ) const
{
	if ( m_shutting_down ) {
		return false;
	}

	// Don't start *any* new jobs during benchmarks
	if ( bench_job_mgr && bench_job_mgr->NumActiveBenchmarks() ) {
		return false;
	}

	return CronJobMgr::ShouldStartJob( job );
}

// Should we allow a benchmark to run?
bool
StartdCronJobMgr::ShouldStartBenchmarks( void ) const
{
	dprintf( D_FULLDEBUG,
			 "ShouldStartBenchmarks: load=%.2f max=%.2f\n",
			 GetCurJobLoad(), GetMaxJobLoad() );
	return ( GetCurJobLoad() < GetMaxJobLoad() );
}

// Job is started
bool
StartdCronJobMgr::JobStarted( const CronJob &job )
{
	return CronJobMgr::JobStarted( job );
}

// Job exitted
bool
StartdCronJobMgr::JobExited( const CronJob &job )
{
	bool status = CronJobMgr::JobExited( job );
	if ( m_shutting_down &&  IsAllIdle() ) {
		startd_check_free();
	}
	if ( bench_job_mgr ) {
		bench_job_mgr->ScheduleAllJobs();
	}
	return status;
}
<|endoftext|>


<commit_before>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>     // Include RealSense Cross Platform API
#include "example.hpp"              // Include short list of convenience functions for rendering

#include <map>
#include <vector>

int main(int argc, char * argv[]) try
{
    // Create a simple OpenGL window for rendering:
    window app(1280, 960, "CPP Multi-Camera Example");

    rs2::context                          ctx;        // Create librealsense context for managing devices

    std::map<std::string, rs2::colorizer> colorizers; // Declare map from device serial number to colorizer (utility class to convert depth data RGB colorspace)

    std::vector<rs2::pipeline>            pipelines;

    // Start a streaming pipe per each connected device
    for (auto&& dev : ctx.query_devices())
    {
        rs2::pipeline pipe(ctx);
        rs2::config cfg;
        cfg.enable_device(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));
        pipe.start(cfg);
        pipelines.emplace_back(pipe);
        // Map from each device's serial number to a different colorizer
        colorizers[dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER)] = rs2::colorizer();
    }

    // We'll keep track of the last frame of each stream available to make the presentation persistent
    std::map<int, rs2::frame> render_frames;

    // Main app loop
    while (app)
    {
        // Collect the new frames from all the connected devices
        std::vector<rs2::frame> new_frames;
        for (auto &&pipe : pipelines)
        {
            rs2::frameset fs;
            if (pipe.poll_for_frames(&fs))
            {
                for (const rs2::frame& f : fs)
                    new_frames.emplace_back(f);
            }
        }

        // Convert the newly-arrived frames to render-friendly format
        for (const auto& frame : new_frames)
        {
            // Get the serial number of the current frame's device
            auto serial = rs2::sensor_from_frame(frame)->get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
            // Apply the colorizer of the matching device and store the colorized frame
            render_frames[frame.get_profile().unique_id()] = colorizers[serial].process(frame);
        }

        // Present all the collected frames with openGl mosaic
        app.show(render_frames);
    }

    return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch (const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}
<commit_msg>Fix rs-multicam with T265<commit_after>// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>     // Include RealSense Cross Platform API
#include "example.hpp"              // Include short list of convenience functions for rendering

#include <map>
#include <vector>

int main(int argc, char * argv[]) try
{
    // Create a simple OpenGL window for rendering:
    window app(1280, 960, "CPP Multi-Camera Example");

    rs2::context                          ctx;        // Create librealsense context for managing devices

    std::map<std::string, rs2::colorizer> colorizers; // Declare map from device serial number to colorizer (utility class to convert depth data RGB colorspace)

    std::vector<rs2::pipeline>            pipelines;

    // Capture serial numbers before opening streaming
    std::vector<std::string>              serials;
    for (auto&& dev : ctx.query_devices())
        serials.push_back(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));

    // Start a streaming pipe per each connected device
    for (auto&& serial : serials)
    {
        rs2::pipeline pipe(ctx);
        rs2::config cfg;
        cfg.enable_device(serial);
        pipe.start(cfg);
        pipelines.emplace_back(pipe);
        // Map from each device's serial number to a different colorizer
        colorizers[serial] = rs2::colorizer();
    }

    // We'll keep track of the last frame of each stream available to make the presentation persistent
    std::map<int, rs2::frame> render_frames;

    // Main app loop
    while (app)
    {
        // Collect the new frames from all the connected devices
        std::vector<rs2::frame> new_frames;
        for (auto &&pipe : pipelines)
        {
            rs2::frameset fs;
            if (pipe.poll_for_frames(&fs))
            {
                for (const rs2::frame& f : fs)
                    new_frames.emplace_back(f);
            }
        }

        // Convert the newly-arrived frames to render-friendly format
        for (const auto& frame : new_frames)
        {
            // Get the serial number of the current frame's device
            auto serial = rs2::sensor_from_frame(frame)->get_info(RS2_CAMERA_INFO_SERIAL_NUMBER);
            // Apply the colorizer of the matching device and store the colorized frame
            render_frames[frame.get_profile().unique_id()] = colorizers[serial].process(frame);
        }

        // Present all the collected frames with openGl mosaic
        app.show(render_frames);
    }

    return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch (const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}
<|endoftext|>


<commit_before>#include "vfreebusy.h"

namespace ical {
namespace components {

const std::string VFreeBusy::NAME = "VFREEBUSY";

void VFreeBusy::print(std::ostream &out) const {

}

VFreeBusy VFreeBusy::parse(const core::WithPos<core::GenericComponent> &generic,
                           core::UniqueIdRegistry &uidRegistry)
{
    return {};
}

} // namespace components
} // namespace ical

<commit_msg>basic freebusy component parsing<commit_after>#include "vfreebusy.h"

namespace ical {
namespace components {

const std::string VFreeBusy::NAME = "VFREEBUSY";

void VFreeBusy::print(std::ostream &out) const {
    out << "BEGIN:" << NAME << "\r\n";
    for(auto &i : dtStampProp) i.print(out);
    for(auto &i : uidProp) i.print(out);
    for(auto &i : contactProp) i.print(out);
    for(auto &i : dtStartProp) i.print(out);
    for(auto &i : dtendProp) i.print(out);
    for(auto &i : organizerProp) i.print(out);
    for(auto &i : urlProp) i.print(out);
    for(auto &i : attendeeProps) i.print(out);
    for(auto &i : commentProps) i.print(out);
    for(auto &i : freebusyProps) i.print(out);
    out << "END:" << NAME << "\r\n";
}

VFreeBusy VFreeBusy::parse(const core::WithPos<core::GenericComponent> &generic,
                           core::UniqueIdRegistry &uidRegistry)
{
    if(generic->getName().value() != NAME)
        throw ParserException(generic.pos() , "invalid name in " + NAME + " component");

    VFreeBusy freebusy;

    /* Storing properties */
    for(const core::WithPos<core::GenericProperty> &i : generic->getProperties()) {
        if(i->getName().value() == properties::DTStamp::NAME) {
            freebusy.dtStampProp.push_back(properties::DTStamp::parse(i));
        } else if(i->getName().value() == properties::Uid::NAME) {
            freebusy.uidProp.push_back(properties::Uid::parse(i));
        } else if(i->getName().value() == properties::Contact::NAME) {
            freebusy.contactProp.push_back(properties::Contact::parse(i));
        } else if(i->getName().value() == properties::DTStart::NAME) {
            freebusy.dtStartProp.push_back(properties::DTStart::parse(i));
        } else if(i->getName().value() == properties::DTEnd::NAME) {
            freebusy.dtendProp.push_back(properties::DTEnd::parse(i));
        } else if(i->getName().value() == properties::Organizer::NAME) {
            freebusy.organizerProp.push_back(properties::Organizer::parse(i));
        } else if(i->getName().value() == properties::Url::NAME) {
            freebusy.urlProp.push_back(properties::Url::parse(i));
        } else if(i->getName().value() == properties::Attendee::NAME) {
            freebusy.attendeeProps.push_back(properties::Attendee::parse(i));
        } else if(i->getName().value() == properties::Comment::NAME) {
            freebusy.commentProps.push_back(properties::Comment::parse(i));
        } else if(i->getName().value() == properties::Freebusy::NAME) {
            freebusy.freebusyProps.push_back(properties::Freebusy::parse(i));
        } else {
            throw ParserException(i.pos() , "invalid property in " + NAME + " component");
        }
    }

    /** Properties sanity checking **/
    /* Required properties check */
    if(freebusy.dtStampProp.size() != 1)
        throw ParserException(generic.pos() , properties::DTStamp::NAME + " is required once in " + NAME + " component");
    if(freebusy.uidProp.size() != 1)
        throw ParserException(generic.pos() , properties::Uid::NAME + " is required once in " + NAME + " component");
    /* OPTIONAL properties max ONCE check */
    if(freebusy.contactProp.size() > 1)
        throw ParserException(generic.pos() , properties::Contact::NAME + " property can't occurr multiple times");
    if(freebusy.dtStartProp.size() > 1)
        throw ParserException(generic.pos() , properties::DTStart::NAME + " property can't occurr multiple times");
    if(freebusy.dtendProp.size() > 1)
        throw ParserException(generic.pos() , properties::DTEnd::NAME + " property can't occurr multiple times");
    if(freebusy.organizerProp.size() > 1)
        throw ParserException(generic.pos() , properties::Organizer::NAME + " property can't occurr multiple times");
    if(freebusy.urlProp.size() > 1)
        throw ParserException(generic.pos() , properties::Url::NAME + " property can't occurr multiple times");

    if (!uidRegistry.registerId(freebusy.uidProp[0].getValue())) {
        throw ParserException(generic.pos() , "The value of the " + properties::Uid::NAME + " property must be globally unique");
    }

    return freebusy;

}

} // namespace components
} // namespace ical

<|endoftext|>


<commit_before>#include <iostream>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include "vec3.h"
#include "ray.h"

using namespace std;

// I need to grok this. I have no idea what it does.
vec3 color(const ray& r) {
  vec3 unit_direction = unit_vector(r.direction());
  // Scale the unit vector down such that 1.0 = BLue, and 0.0 = White
  // Originaly such that -1.0 = White and 1.0 = Blue
  float t = 0.5*(unit_direction.y + 1.0);
  return (1.0f-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0);
}

int main(int argc, char** argv) {
  if (argc != 2) {
    cout << "Incorrect number of arguments\nUsage: run.out output_file.png" << endl;
    return 1;
  }

  const unsigned int width = 200;
  const unsigned int height = 100;
  const unsigned char channels = 3;
  unsigned int index;

  unsigned char* data = new unsigned char[width * height * channels];

  /*
   * Because I'm going from top to bottom, left to right, I am using the
   * following screen schema.
   * ------------------------------
   * |-2, -1, -1        2, -1, -1 |
   * |                            |
   * |           0, 0, 0          |
   * |                            |
   * |-2, 1, -1          2, 1, -1 |
   * ------------------------------
   */

  vec3 lower_left_corner(-2.0, 1.0, -1.0);
  vec3 horizontal(4.0, 0.0, 0.0);
  vec3 vertical(0.0, -2.0, 0.0);
  vec3 origin(0.0, 0.0, 0.0);

  for (unsigned int y = 0; y < height; y++) {
    for (unsigned int x = 0; x < width; x++) {

      index = (y * width * channels) + (x * channels);

      float u = (float) x / (float) width;
      float v = (float) y / (float) height;

      ray r(origin, lower_left_corner + u * horizontal + v * vertical);
      vec3 col = color(r);

      data[index]     = col.x * 255; // Red channel
      data[index + 1] = col.y * 255; // Green channel
      data[index + 2] = col.z * 255; // Blue channel
    }
  }

  stbi_write_png(argv[1], width, height, channels, data, width * channels);

  delete[] data;

  return 0;
}
<commit_msg>Updated to use bottom left as origin. This will make calculations for the rest of the book easier<commit_after>#include <iostream>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include "vec3.h"
#include "ray.h"

using namespace std;

// I need to grok this. I have no idea what it does.
vec3 color(const ray& r) {
  vec3 unit_direction = unit_vector(r.direction());
  // Scale the unit vector down such that 1.0 = BLue, and 0.0 = White
  // Originaly such that -1.0 = White and 1.0 = Blue
  float t = 0.5*(unit_direction.y + 1.0);
  return (1.0f-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0);
}

int main(int argc, char** argv) {
  if (argc != 2) {
    cout << "Incorrect number of arguments\nUsage: run.out output_file.png" << endl;
    return 1;
  }

  const int width = 200;
  const int height = 100;
  const unsigned char channels = 3;
  int index;

  unsigned char* data = new unsigned char[width * height * channels];

  vec3 lower_left_corner(-2.0, -1.0, -1.0);
  vec3 horizontal(4.0, 0.0, 0.0);
  vec3 vertical(0.0, 2.0, 0.0);
  vec3 origin(0.0, 0.0, 0.0);

  for (int y = height - 1; y >= 0; y--) {
    for (int x = 0; x < width; x++) {

      // Calculate the index using top left as origin
      index = (y * width * channels) + (x * channels);
      // Flip it to use bottom left as origin
      index = (width * height * channels) - index;

      float u = (float) x / (float) width;
      float v = (float) y / (float) height;

      ray r(origin, lower_left_corner + u * horizontal + v * vertical);
      vec3 col = color(r);

      data[index]     = col.x * 255; // Red channel
      data[index + 1] = col.y * 255; // Green channel
      data[index + 2] = col.z * 255; // Blue channel
    }
  }

  stbi_write_png(argv[1], width, height, channels, data, width * channels);

  delete[] data;

  return 0;
}
<|endoftext|>


<commit_before>// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "public/fpdf_doc.h"

#include <memory>
#include <vector>

#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
#include "core/fpdfapi/include/cpdf_modulemgr.h"
#include "core/fpdfdoc/include/fpdf_doc.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"

#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
#endif  // PDF_ENABLE_XFA

class CPDF_TestDocument : public CPDF_Document {
 public:
  CPDF_TestDocument() : CPDF_Document(nullptr) {}

  void SetRoot(CPDF_Dictionary* root) { m_pRootDict = root; }
  CPDF_IndirectObjectHolder* GetHolder() { return this; }
};

#ifdef PDF_ENABLE_XFA
class CPDF_TestXFADocument : public CPDFXFA_Document {
 public:
  CPDF_TestXFADocument()
      : CPDFXFA_Document(new CPDF_TestDocument(), CPDFXFA_App::GetInstance()) {}

  void SetRoot(CPDF_Dictionary* root) {
    reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root);
  }

  CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); }
};
using CPDF_TestPdfDocument = CPDF_TestXFADocument;
#else   // PDF_ENABLE_XFA
using CPDF_TestPdfDocument = CPDF_TestDocument;
#endif  // PDF_ENABLE_XFA

class PDFDocTest : public testing::Test {
 public:
  struct DictObjInfo {
    uint32_t num;
    CPDF_Dictionary* obj;
  };

  void SetUp() override {
    // We don't need page module or render module, but
    // initialize them to keep the code sane.
    CPDF_ModuleMgr::Create();
    CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
    module_mgr->InitPageModule();

    m_pDoc.reset(new CPDF_TestPdfDocument());
    m_pIndirectObjs = m_pDoc->GetHolder();
    // Setup the root directory.
    m_pRootObj.reset(new CPDF_Dictionary());
    m_pDoc->SetRoot(m_pRootObj.get());
  }

  std::vector<DictObjInfo> CreateDictObjs(int num) {
    std::vector<DictObjInfo> info;
    for (int i = 0; i < num; ++i) {
      // Objects created will be released by the document.
      CPDF_Dictionary* obj(new CPDF_Dictionary());
      m_pIndirectObjs->AddIndirectObject(obj);
      info.push_back({obj->GetObjNum(), obj});
    }
    return info;
  }

 protected:
  std::unique_ptr<CPDF_TestPdfDocument> m_pDoc;
  CPDF_IndirectObjectHolder* m_pIndirectObjs;
  std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> m_pRootObj;
};

TEST_F(PDFDocTest, FindBookmark) {
  {
    // No bookmark information.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    title = GetFPDFWideString(L"Preface");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Empty bookmark tree.
    m_pRootObj->SetAt("Outlines", new CPDF_Dictionary());
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    title = GetFPDFWideString(L"Preface");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Check on a regular bookmark tree.
    auto bookmarks = CreateDictObjs(3);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[2].obj->SetAt(
        "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with partial match only.
    title = GetFPDFWideString(L"Chapter");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title match is case insensitive.
    title = GetFPDFWideString(L"cHaPter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Circular bookmarks in depth.
    auto bookmarks = CreateDictObjs(3);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[2].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Circular bookmarks in breadth.
    auto bookmarks = CreateDictObjs(4);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[2].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num));

    bookmarks[3].obj->SetAt("Title", new CPDF_String(L"Chapter 3"));
    bookmarks[3].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[3].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 8");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
}
<commit_msg>PDFDocTest should TearDown() properly.<commit_after>// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "public/fpdf_doc.h"

#include <memory>
#include <vector>

#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
#include "core/fpdfapi/include/cpdf_modulemgr.h"
#include "core/fpdfdoc/include/fpdf_doc.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"

#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_app.h"
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
#endif  // PDF_ENABLE_XFA

class CPDF_TestDocument : public CPDF_Document {
 public:
  CPDF_TestDocument() : CPDF_Document(nullptr) {}

  void SetRoot(CPDF_Dictionary* root) { m_pRootDict = root; }
  CPDF_IndirectObjectHolder* GetHolder() { return this; }
};

#ifdef PDF_ENABLE_XFA
class CPDF_TestXFADocument : public CPDFXFA_Document {
 public:
  CPDF_TestXFADocument()
      : CPDFXFA_Document(new CPDF_TestDocument(), CPDFXFA_App::GetInstance()) {}

  void SetRoot(CPDF_Dictionary* root) {
    reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root);
  }

  CPDF_IndirectObjectHolder* GetHolder() { return GetPDFDoc(); }
};
using CPDF_TestPdfDocument = CPDF_TestXFADocument;
#else   // PDF_ENABLE_XFA
using CPDF_TestPdfDocument = CPDF_TestDocument;
#endif  // PDF_ENABLE_XFA

class PDFDocTest : public testing::Test {
 public:
  struct DictObjInfo {
    uint32_t num;
    CPDF_Dictionary* obj;
  };

  void SetUp() override {
    // We don't need page module or render module, but
    // initialize them to keep the code sane.
    CPDF_ModuleMgr::Create();
    CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get();
    module_mgr->InitPageModule();

    m_pDoc.reset(new CPDF_TestPdfDocument());
    m_pIndirectObjs = m_pDoc->GetHolder();
    // Setup the root directory.
    m_pRootObj.reset(new CPDF_Dictionary());
    m_pDoc->SetRoot(m_pRootObj.get());
  }

  void TearDown() override {
    m_pRootObj.reset();
    m_pIndirectObjs = nullptr;
    m_pDoc.reset();
    CPDF_ModuleMgr::Destroy();
  }

  std::vector<DictObjInfo> CreateDictObjs(int num) {
    std::vector<DictObjInfo> info;
    for (int i = 0; i < num; ++i) {
      // Objects created will be released by the document.
      CPDF_Dictionary* obj(new CPDF_Dictionary());
      m_pIndirectObjs->AddIndirectObject(obj);
      info.push_back({obj->GetObjNum(), obj});
    }
    return info;
  }

 protected:
  std::unique_ptr<CPDF_TestPdfDocument> m_pDoc;
  CPDF_IndirectObjectHolder* m_pIndirectObjs;
  std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> m_pRootObj;
};

TEST_F(PDFDocTest, FindBookmark) {
  {
    // No bookmark information.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    title = GetFPDFWideString(L"Preface");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Empty bookmark tree.
    m_pRootObj->SetAt("Outlines", new CPDF_Dictionary());
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    title = GetFPDFWideString(L"Preface");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Check on a regular bookmark tree.
    auto bookmarks = CreateDictObjs(3);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[2].obj->SetAt(
        "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with partial match only.
    title = GetFPDFWideString(L"Chapter");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title match is case insensitive.
    title = GetFPDFWideString(L"cHaPter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Circular bookmarks in depth.
    auto bookmarks = CreateDictObjs(3);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[2].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 2");
    EXPECT_EQ(bookmarks[2].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
  {
    // Circular bookmarks in breadth.
    auto bookmarks = CreateDictObjs(4);

    bookmarks[1].obj->SetAt("Title", new CPDF_String(L"Chapter 1"));
    bookmarks[1].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[1].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    bookmarks[2].obj->SetAt("Title", new CPDF_String(L"Chapter 2"));
    bookmarks[2].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[2].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num));

    bookmarks[3].obj->SetAt("Title", new CPDF_String(L"Chapter 3"));
    bookmarks[3].obj->SetAt(
        "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
    bookmarks[3].obj->SetAt(
        "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));

    bookmarks[0].obj->SetAt("Type", new CPDF_Name("Outlines"));
    bookmarks[0].obj->SetAt("Count", new CPDF_Number(2));
    bookmarks[0].obj->SetAt(
        "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
    bookmarks[0].obj->SetAt(
        "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));

    m_pRootObj->SetAt("Outlines",
                      new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));

    // Title with no match.
    std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
        GetFPDFWideString(L"Chapter 8");
    EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));

    // Title with a match.
    title = GetFPDFWideString(L"Chapter 3");
    EXPECT_EQ(bookmarks[3].obj, FPDFBookmark_Find(m_pDoc.get(), title.get()));
  }
}
<|endoftext|>