<commit_before>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2009 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/ConnectionCapabilities>

#include "TelepathyQt4/future-internal.h"

#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Types>

namespace Tp
{

/**
 * \class ConnectionCapabilities
 * \ingroup clientconn
 * \headerfile TelepathyQt4/connection-capabilities.h <TelepathyQt4/ConnectionCapabilities>
 *
 * \brief The ConnectionCapabilities class provides an object representing the
 * capabilities of a Connection.
 */

/**
 * Construct a new ConnectionCapabilities object.
 */
ConnectionCapabilities::ConnectionCapabilities()
    : CapabilitiesBase(false)
{
}

/**
 * Construct a new ConnectionCapabilities object using the give \a classes.
 *
 * \param classes RequestableChannelClassList representing the capabilities of a
 *                Connection.
 */
ConnectionCapabilities::ConnectionCapabilities(const RequestableChannelClassList &classes)
    : CapabilitiesBase(classes, false)
{
}

/**
 * Class destructor.
 */
ConnectionCapabilities::~ConnectionCapabilities()
{
}

/**
 * Return true if named text chatrooms can be joined by providing a
 * chatroom identifier.
 *
 * If the protocol is such that chatrooms can be joined, but only via
 * a more elaborate D-Bus API than normal (because more information is needed),
 * then this method will return false.
 *
 * \return \c true if Account::ensureTextChatroom() can be expected to work.
 */
bool ConnectionCapabilities::textChatrooms() const
{
    QString channelType;
    uint targetHandleType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        if (!cls.fixedProperties.size() == 2) {
            continue;
        }

        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        targetHandleType = qdbus_cast<uint>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            targetHandleType == HandleTypeRoom) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference media calls is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceStreamedMediaCalls() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference media calls is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference media call
 * channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference media
 * calls with fewer than two (even zero) already established media calls.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceStreamedMediaCallsWithInvitees() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chats is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChats() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chats is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference text chat
 * channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference text
 * chats with fewer than two (even zero) already established text chats.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatsWithInvitees() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chat rooms is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatrooms() const
{
    QString channelType;
    uint targetHandleType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        targetHandleType = qdbus_cast<uint>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            targetHandleType == HandleTypeRoom &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chat rooms is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference text chat
 * room channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference text
 * chat rooms with fewer than two (even zero) already established text chat rooms.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatroomsWithInvitees() const
{
    QString channelType;
    uint targetHandleType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        targetHandleType = qdbus_cast<uint>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            targetHandleType == HandleTypeRoom &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) &&
            (cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")) ||
             cls.allowedProperties.contains(QLatin1String(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles")))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearch()
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH)) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel specifying a server is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearchWithSpecificServer() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH) &&
            cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Server"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel specifying a limit is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearchWithLimit() const
{
    QString channelType;
    RequestableChannelClassList classes = requestableChannelClasses();
    foreach (const RequestableChannelClass &cls, classes) {
        channelType = qdbus_cast<QString>(cls.fixedProperties.value(
                QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType")));
        if (channelType == QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH) &&
            cls.allowedProperties.contains(QLatin1String(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Limit"))) {
            return true;
        }
    }
    return false;
}

/**
 * \deprecated Use textChatrooms() instead.
 */
bool ConnectionCapabilities::supportsTextChatrooms() const
{
    return textChatrooms();
}

/**
 * \deprecated Use conferenceStreamedMediaCalls() or conferenceStreamedMediaCallsWithInvitees()
 * instead.
 */
bool ConnectionCapabilities::supportsConferenceMediaCalls(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceStreamedMediaCallsWithInvitees();
    }
    return conferenceStreamedMediaCalls();
}

/**
 * \deprecated Use conferenceTextChats() instead.
 */
bool ConnectionCapabilities::supportsConferenceTextChats(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceTextChatsWithInvitees();
    }
    return conferenceTextChats();
}

/**
 * \deprecated Use conferenceTextChatrooms() instead.
 */
bool ConnectionCapabilities::supportsConferenceTextChatrooms(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceTextChatroomsWithInvitees();
    }
    return conferenceTextChatrooms();
}

/**
 * \deprecated Use contactSearch() instead.
 */
bool ConnectionCapabilities::supportsContactSearch()
{
    return contactSearch();
}

/**
 * \deprecated Use contactSearchWithSpecificServer() instead.
 */
bool ConnectionCapabilities::supportsContactSearchWithSpecificServer() const
{
    return contactSearchWithSpecificServer();
}

/**
 * \deprecated Use contactSearchWithLimit() instead.
 */
bool ConnectionCapabilities::supportsContactSearchWithLimit() const
{
    return contactSearchWithLimit();
}

} // Tp
<commit_msg>ConnectionCapabilities: Use RequestableChannelClassSpecList.<commit_after>/*
 * This file is part of TelepathyQt4
 *
 * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
 * Copyright (C) 2009 Nokia Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <TelepathyQt4/ConnectionCapabilities>

#include "TelepathyQt4/future-internal.h"

#include <TelepathyQt4/Constants>
#include <TelepathyQt4/Types>

namespace Tp
{

/**
 * \class ConnectionCapabilities
 * \ingroup clientconn
 * \headerfile TelepathyQt4/connection-capabilities.h <TelepathyQt4/ConnectionCapabilities>
 *
 * \brief The ConnectionCapabilities class provides an object representing the
 * capabilities of a Connection.
 */

/**
 * Construct a new ConnectionCapabilities object.
 */
ConnectionCapabilities::ConnectionCapabilities()
    : CapabilitiesBase(false)
{
}

/**
 * Construct a new ConnectionCapabilities object using the give \a classes.
 *
 * \param classes RequestableChannelClassList representing the capabilities of a
 *                Connection.
 */
ConnectionCapabilities::ConnectionCapabilities(const RequestableChannelClassList &classes)
    : CapabilitiesBase(classes, false)
{
}

/**
 * Class destructor.
 */
ConnectionCapabilities::~ConnectionCapabilities()
{
}

/**
 * Return true if named text chatrooms can be joined by providing a
 * chatroom identifier.
 *
 * If the protocol is such that chatrooms can be joined, but only via
 * a more elaborate D-Bus API than normal (because more information is needed),
 * then this method will return false.
 *
 * \return \c true if Account::ensureTextChatroom() can be expected to work.
 */
bool ConnectionCapabilities::textChatrooms() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (!rccSpec.fixedPropertiesCount() == 2) {
            continue;
        }

        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            rccSpec.hasTargetHandleType(HandleTypeRoom)) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference media calls is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceStreamedMediaCalls() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference media calls is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference media call
 * channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference media
 * calls with fewer than two (even zero) already established media calls.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceStreamedMediaCallsWithInvitees() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chats is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChats() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chats is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference text chat
 * channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference text
 * chats with fewer than two (even zero) already established text chats.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatsWithInvitees() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chat rooms is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatrooms() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            rccSpec.hasTargetHandleType(HandleTypeRoom) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating conference text chat rooms is supported.
 *
 * This method will also check whether inviting new contacts when creating a conference text chat
 * room channel by providing additional members to initial invitees (as opposed to merging several
 * channels into one new conference channel) is supported.
 *
 * If providing additional members is supported, it is also possible to request conference text
 * chat rooms with fewer than two (even zero) already established text chat rooms.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::conferenceTextChatroomsWithInvitees() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) &&
            rccSpec.hasTargetHandleType(HandleTypeRoom) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels")) &&
            (rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles") ||
             rccSpec.hasAllowedProperty(TP_FUTURE_INTERFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeHandles"))) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearch()
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH)) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel specifying a server is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearchWithSpecificServer() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH) &&
            rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Server")) {
            return true;
        }
    }
    return false;
}

/**
 * Return whether creating a ContactSearch channel specifying a limit is supported.
 *
 * \return \c true if supported, \c false otherwise.
 */
bool ConnectionCapabilities::contactSearchWithLimit() const
{
    RequestableChannelClassSpecList rccSpecs = requestableChannelClassSpecList();
    foreach (const RequestableChannelClassSpec &rccSpec, rccSpecs) {
        if (rccSpec.hasChannelType(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH) &&
            rccSpec.hasAllowedProperty(TELEPATHY_INTERFACE_CHANNEL_TYPE_CONTACT_SEARCH ".Limit")) {
            return true;
        }
    }
    return false;
}

/**
 * \deprecated Use textChatrooms() instead.
 */
bool ConnectionCapabilities::supportsTextChatrooms() const
{
    return textChatrooms();
}

/**
 * \deprecated Use conferenceStreamedMediaCalls() or conferenceStreamedMediaCallsWithInvitees()
 * instead.
 */
bool ConnectionCapabilities::supportsConferenceMediaCalls(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceStreamedMediaCallsWithInvitees();
    }
    return conferenceStreamedMediaCalls();
}

/**
 * \deprecated Use conferenceTextChats() instead.
 */
bool ConnectionCapabilities::supportsConferenceTextChats(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceTextChatsWithInvitees();
    }
    return conferenceTextChats();
}

/**
 * \deprecated Use conferenceTextChatrooms() instead.
 */
bool ConnectionCapabilities::supportsConferenceTextChatrooms(bool withInitialInvitees) const
{
    if (withInitialInvitees) {
        return conferenceTextChatroomsWithInvitees();
    }
    return conferenceTextChatrooms();
}

/**
 * \deprecated Use contactSearch() instead.
 */
bool ConnectionCapabilities::supportsContactSearch()
{
    return contactSearch();
}

/**
 * \deprecated Use contactSearchWithSpecificServer() instead.
 */
bool ConnectionCapabilities::supportsContactSearchWithSpecificServer() const
{
    return contactSearchWithSpecificServer();
}

/**
 * \deprecated Use contactSearchWithLimit() instead.
 */
bool ConnectionCapabilities::supportsContactSearchWithLimit() const
{
    return contactSearchWithLimit();
}

} // Tp
<|endoftext|>


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

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkPointCastTest.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Insight Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.

=========================================================================*/
/**
 *
 *  This program illustrates the use of the utility class PointCast<>
 *
 */

#include "itkPoint.h"
#include <iostream>

//-------------------------
//
//   Main code
//
//-------------------------
int main()
{

  // Dimension & Type
  const     unsigned int    N = 3;

  //  Point Classes
  typedef    itk::Point<  double, N >    DoublePointType;
  typedef    itk::Point<  float , N >    FloatPointType;

  DoublePointType dp;
  dp[0] = 1.0;
  dp[1] = 1.7;
  dp[2] = 1.9;

  FloatPointType fp;
  fp[0] = 0.0;
  fp[1] = 0.0;
  fp[2] = 0.0;

  std::cout << "Initial values dp = ";
  std::cout << dp << std::endl;

  std::cout << "Initial values fp = ";
  std::cout << fp << std::endl;

  itk::PointCast( dp, fp );

  std::cout << "Final values fp = ";
  std::cout << fp << std::endl;

  for(unsigned int i=0; i<N; i++)
    {
    FloatPointType::ValueType val =
        static_cast< FloatPointType::ValueType >( dp[i] );
    if( val != fp[i] )
      {
        std::cout << "Test failed at component " << i << std::endl;
        return EXIT_FAILURE;
      }
    }

  std::cout << "Test PASSED ! " << std::endl;

  return EXIT_SUCCESS;
}

<commit_msg>ENH: Removed: the test is now incorporated in PointGeometryTest<commit_after><|endoftext|>


<commit_before>/*******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net
 *
 * 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 OR COPYRIGHT HOLDERS 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.
 ******************************************************************************/

/*!
 * @copyright   (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net
 * @brief       Test case XS::Atomic
 */

/* Disabled warnings for GoogleMock */
#ifdef __clang__
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic push
#if __clang_major__ >= 7
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#pragma clang diagnostic ignored "-Wmissing-noreturn"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wused-but-marked-unused"
#pragma clang diagnostic ignored "-Wdeprecated"
#endif

#include <GoogleMock/GoogleMock.h>

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#include <XS/Atomic.hpp>

using namespace testing;

/*******************************************************************************
 * Common definitions
 ******************************************************************************/

TEST( XS_Atomic_Trivial_Pointer, CTOR )
{
    XS::Atomic< const char * > a;

    ASSERT_TRUE( a == nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, CTOR_V )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( a, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, CCTOR )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ a1 };

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorAssign )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    a2 = a1;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorAssign_V )
{
    XS::Atomic< const char * > a;

    a = "hello, world";

    ASSERT_TRUE( strcmp( a, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorCast )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( static_cast< const char * >( a ), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Load )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( a.Load(), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Store )
{
    XS::Atomic< const char * > a;

    a.Store( "hello, world" );

    ASSERT_TRUE( strcmp( a.Load(), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Swap )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, universe" ) == 0 );

    swap( a1, a2 );

    ASSERT_TRUE( strcmp( a1, "hello, universe" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

/*******************************************************************************
 * Type specific
 ******************************************************************************/

TEST( XS_Atomic_Trivial_Pointer, PreIncrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, PreDecrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

    a2 = --a1;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );

}

TEST( XS_Atomic_Trivial_Pointer, PostIncrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = a1++;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, PostDecrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

    a2 = a1--;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

}

TEST( XS_Atomic_Trivial_Pointer, NegationOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_FALSE( !a1 );
    ASSERT_TRUE(  !a2 );
}

TEST( XS_Atomic_Trivial_Pointer, ANDOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };
    XS::Atomic< const char * > a3{ nullptr };
    XS::Atomic< const char * > a4{ nullptr };

    ASSERT_TRUE(  a1 && a2 );
    ASSERT_FALSE( a1 && a3 );
    ASSERT_FALSE( a3 && a1 );
    ASSERT_FALSE( a3 && a4 );
}

TEST( XS_Atomic_Trivial_Pointer, ANDOperator_V )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_TRUE(  a1 && "hello, universe" );
    ASSERT_FALSE( a1 && a2 );
    ASSERT_FALSE( a2 && a1 );
    ASSERT_FALSE( a2 && nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, InclusiveOROperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };
    XS::Atomic< const char * > a3{ nullptr };
    XS::Atomic< const char * > a4{ nullptr };

    ASSERT_TRUE(  a1 || a2 );
    ASSERT_TRUE(  a1 || a3 );
    ASSERT_TRUE(  a3 || a1 );
    ASSERT_FALSE( a3 || a4 );
}

TEST( XS_Atomic_Trivial_Pointer, InclusiveOROperator_V )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_TRUE(  a1 || "hello, universe" );
    ASSERT_TRUE(  a1 || a2 );
    ASSERT_TRUE(  a2 || a1 );
    ASSERT_FALSE( a2 || nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, EqualToOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, EqualToOperator_V )
{}

TEST( XS_Atomic_Trivial_Pointer, NotEqualToOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, NotEqualToOperator_V )
{}

TEST( XS_Atomic_Trivial_Pointer, LessThanOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, LessThanOperator_V )
{}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOperator_V )
{}

TEST( XS_Atomic_Trivial_Pointer, LessThanOrEqualToOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, LessThanOrEqualToOperator_V )
{}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOrEqualToOperator )
{}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOrEqualToOperator_V )
{}
<commit_msg>Unit tests.<commit_after>/*******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Jean-David Gadina - www.xs-labs.com / www.digidna.net
 *
 * 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 OR COPYRIGHT HOLDERS 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.
 ******************************************************************************/

/*!
 * @copyright   (c) 2015 - Jean-David Gadina - www.xs-labs.com / www.digidna.net
 * @brief       Test case XS::Atomic
 */

/* Disabled warnings for GoogleMock */
#ifdef __clang__
#pragma clang diagnostic ignored "-Wglobal-constructors"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic push
#if __clang_major__ >= 7
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#pragma clang diagnostic ignored "-Wmissing-noreturn"
#pragma clang diagnostic ignored "-Wpadded"
#pragma clang diagnostic ignored "-Wused-but-marked-unused"
#pragma clang diagnostic ignored "-Wdeprecated"
#endif

#include <GoogleMock/GoogleMock.h>

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#include <XS/Atomic.hpp>

using namespace testing;

/*******************************************************************************
 * Common definitions
 ******************************************************************************/

TEST( XS_Atomic_Trivial_Pointer, CTOR )
{
    XS::Atomic< const char * > a;

    ASSERT_TRUE( a == nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, CTOR_V )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( a, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, CCTOR )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ a1 };

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorAssign )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    a2 = a1;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorAssign_V )
{
    XS::Atomic< const char * > a;

    a = "hello, world";

    ASSERT_TRUE( strcmp( a, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, OperatorCast )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( static_cast< const char * >( a ), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Load )
{
    XS::Atomic< const char * > a{ "hello, world" };

    ASSERT_TRUE( strcmp( a.Load(), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Store )
{
    XS::Atomic< const char * > a;

    a.Store( "hello, world" );

    ASSERT_TRUE( strcmp( a.Load(), "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, Swap )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, universe" ) == 0 );

    swap( a1, a2 );

    ASSERT_TRUE( strcmp( a1, "hello, universe" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

/*******************************************************************************
 * Type specific
 ******************************************************************************/

TEST( XS_Atomic_Trivial_Pointer, PreIncrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, PreDecrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

    a2 = --a1;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );

}

TEST( XS_Atomic_Trivial_Pointer, PostIncrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = a1++;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "hello, world" ) == 0 );
}

TEST( XS_Atomic_Trivial_Pointer, PostDecrementOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );

    a2 = ++a1;

    ASSERT_TRUE( strcmp( a1, "ello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

    a2 = a1--;

    ASSERT_TRUE( strcmp( a1, "hello, world" ) == 0 );
    ASSERT_TRUE( strcmp( a2, "ello, world" ) == 0 );

}

TEST( XS_Atomic_Trivial_Pointer, NegationOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_FALSE( !a1 );
    ASSERT_TRUE(  !a2 );
}

TEST( XS_Atomic_Trivial_Pointer, ANDOperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };
    XS::Atomic< const char * > a3{ nullptr };
    XS::Atomic< const char * > a4{ nullptr };

    ASSERT_TRUE(  a1 && a2 );
    ASSERT_FALSE( a1 && a3 );
    ASSERT_FALSE( a3 && a1 );
    ASSERT_FALSE( a3 && a4 );
}

TEST( XS_Atomic_Trivial_Pointer, ANDOperator_V )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_TRUE(  a1 && "hello, universe" );
    ASSERT_FALSE( a1 && a2 );
    ASSERT_FALSE( a2 && a1 );
    ASSERT_FALSE( a2 && nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, InclusiveOROperator )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ "hello, universe" };
    XS::Atomic< const char * > a3{ nullptr };
    XS::Atomic< const char * > a4{ nullptr };

    ASSERT_TRUE(  a1 || a2 );
    ASSERT_TRUE(  a1 || a3 );
    ASSERT_TRUE(  a3 || a1 );
    ASSERT_FALSE( a3 || a4 );
}

TEST( XS_Atomic_Trivial_Pointer, InclusiveOROperator_V )
{
    XS::Atomic< const char * > a1{ "hello, world" };
    XS::Atomic< const char * > a2{ nullptr };

    ASSERT_TRUE(  a1 || "hello, universe" );
    ASSERT_TRUE(  a1 || a2 );
    ASSERT_TRUE(  a2 || a1 );
    ASSERT_FALSE( a2 || nullptr );
}

TEST( XS_Atomic_Trivial_Pointer, EqualToOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ "hello, universe" };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p1 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_TRUE(  a1 == a2 );
    ASSERT_FALSE( a1 == a3 );
}

TEST( XS_Atomic_Trivial_Pointer, EqualToOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ "hello, universe" };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_TRUE(  a1 == p1 );
    ASSERT_FALSE( a1 == p2 );
}

TEST( XS_Atomic_Trivial_Pointer, NotEqualToOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ "hello, universe" };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p1 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_FALSE( a1 != a2 );
    ASSERT_TRUE(  a1 != a3 );
}

TEST( XS_Atomic_Trivial_Pointer, NotEqualToOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ "hello, universe" };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_FALSE( a1 != p1 );
    ASSERT_TRUE(  a1 != p2 );
}

TEST( XS_Atomic_Trivial_Pointer, LessThanOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p1 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_FALSE( a1 < a2 );
    ASSERT_TRUE(  a1 < a3 );
}

TEST( XS_Atomic_Trivial_Pointer, LessThanOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_FALSE( a1 < p1 );
    ASSERT_TRUE(  a1 < p2 );
}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p1 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_FALSE( a1 > a2 );
    ASSERT_TRUE(  a3 > a1 );
}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_FALSE( a1 > p2 );
    ASSERT_TRUE(  a2 > p1 );
}

TEST( XS_Atomic_Trivial_Pointer, LessThanOrEqualToOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p1 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_TRUE(  a1 <= a2 );
    ASSERT_TRUE(  a1 <= a3 );
    ASSERT_FALSE( a3 <= a1 );
}

TEST( XS_Atomic_Trivial_Pointer, LessThanOrEqualToOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_TRUE(  a1 <= p1 );
    ASSERT_TRUE(  a1 <= p2 );
    ASSERT_FALSE( a2 <= p1 );
}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOrEqualToOperator )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };
    XS::Atomic< const char * > a3{ p2 };

    ASSERT_FALSE( a1 >= a2 );
    ASSERT_TRUE(  a2 >= a1 );
    ASSERT_TRUE(  a2 >= a3 );
}

TEST( XS_Atomic_Trivial_Pointer, GreaterThanOrEqualToOperator_V )
{
    const char               * p1{ "hello, world" };
    const char               * p2{ p1 + 1 };
    XS::Atomic< const char * > a1{ p1 };
    XS::Atomic< const char * > a2{ p2 };

    ASSERT_FALSE( a1 >= p2 );
    ASSERT_TRUE(  a2 >= p1 );
    ASSERT_TRUE(  a2 >= p2 );
}
<|endoftext|>


<commit_before>/*
 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
 * Copyright (C) 2009 Apple 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 Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"
#include "ScriptController.h"

#include "ChromiumBridge.h"
#include "CString.h"
#include "Document.h"
#include "DOMWindow.h"
#include "Event.h"
#include "EventListener.h"
#include "EventNames.h"
#include "Frame.h"
#include "Node.h"
#include "NotImplemented.h"
#include "npruntime_priv.h"
#include "NPV8Object.h"
#include "ScriptSourceCode.h"
#include "ScriptState.h"
#include "Widget.h"
#include "XSSAuditor.h"

#include "V8Binding.h"
#include "V8NPObject.h"
#include "V8Proxy.h"

namespace WebCore {

void ScriptController::setFlags(const char* string, int length)
{
    v8::V8::SetFlagsFromString(string, length);
}

Frame* ScriptController::retrieveFrameForEnteredContext()
{
    return V8Proxy::retrieveFrameForEnteredContext();
}

Frame* ScriptController::retrieveFrameForCurrentContext()
{
    return V8Proxy::retrieveFrameForCurrentContext();
}

bool ScriptController::isSafeScript(Frame* target)
{
    return V8Proxy::CanAccessFrame(target, true);
}

void ScriptController::gcProtectJSWrapper(void* domObject)
{
    V8Proxy::GCProtect(domObject);
}

void ScriptController::gcUnprotectJSWrapper(void* domObject)
{
    V8Proxy::GCUnprotect(domObject);
}

ScriptController::ScriptController(Frame* frame)
    : m_frame(frame)
    , m_sourceURL(0)
    , m_processingTimerCallback(false)
    , m_paused(false)
    , m_scriptState(new ScriptState(frame))
    , m_proxy(new V8Proxy(frame))
#if ENABLE(NETSCAPE_PLUGIN_API)
    , m_windowScriptNPObject(0)
#endif
    , m_XSSAuditor(new XSSAuditor(frame))
{
}

ScriptController::~ScriptController()
{
    m_proxy->disconnectFrame();
}

void ScriptController::clearScriptObjects()
{
    PluginObjectMap::iterator it = m_pluginObjects.begin();
    for (; it != m_pluginObjects.end(); ++it) {
        _NPN_UnregisterObject(it->second);
        NPN_ReleaseObject(it->second);
    }
    m_pluginObjects.clear();

#if ENABLE(NETSCAPE_PLUGIN_API)
    if (m_windowScriptNPObject) {
        // Call _NPN_DeallocateObject() instead of _NPN_ReleaseObject() so that we don't leak if a plugin fails to release the window
        // script object properly.
        // This shouldn't cause any problems for plugins since they should have already been stopped and destroyed at this point.
        _NPN_DeallocateObject(m_windowScriptNPObject);
        m_windowScriptNPObject = 0;
    }
#endif
}

void ScriptController::updateSecurityOrigin()
{
    m_proxy->updateSecurityOrigin();
}

void ScriptController::updatePlatformScriptObjects()
{
    notImplemented();
}

bool ScriptController::processingUserGesture() const
{
    Frame* activeFrame = V8Proxy::retrieveFrameForEnteredContext();
    // No script is running, so it must be run by users.
    if (!activeFrame)
        return true;

    V8Proxy* activeProxy = activeFrame->script()->proxy();

    v8::HandleScope handleScope;
    v8::Handle<v8::Context> context = V8Proxy::GetContext(activeFrame);
    // FIXME: find all cases context can be empty:
    //  1) JS is disabled;
    //  2) page is NULL;
    if (context.IsEmpty())
        return true;

    v8::Context::Scope scope(context);

    v8::Handle<v8::Object> global = context->Global();
    v8::Handle<v8::Value> jsEvent = global->Get(v8::String::NewSymbol("event"));
    Event* event = V8Proxy::ToNativeEvent(jsEvent);

    // Based on code from kjs_bindings.cpp.
    // Note: This is more liberal than Firefox's implementation.
    if (event) {
        const AtomicString& type = event->type();
        bool eventOk =
            // mouse events
            type == eventNames().clickEvent || type == eventNames().mousedownEvent || type == eventNames().mouseupEvent || type == eventNames().dblclickEvent
            // keyboard events
            || type == eventNames().keydownEvent || type == eventNames().keypressEvent || type == eventNames().keyupEvent
            // other accepted events
            || type == eventNames().selectEvent || type == eventNames().changeEvent || type == eventNames().focusEvent || type == eventNames().blurEvent || type == eventNames().submitEvent;

        if (eventOk)
            return true;
    } else if (activeProxy->inlineCode() && !activeProxy->timerCallback()) {
        // This is the  case -> we let it through.
        return true;
    }

    // This is the  case or a timer callback -> block it.
    return false;
}

void ScriptController::evaluateInNewContext(const Vector case or a timer callback -> block it.
    return false;
}

void ScriptController::evaluateInNewContext(const Vector


<commit_before><commit_msg>vulkan update<commit_after><|endoftext|>


<commit_before>
#include "OCCViewer_ViewModel.h"
#include "OCCViewer_ViewWindow.h"
#include "OCCViewer_VService.h"
#include "OCCViewer_ViewPort3d.h"

#include "SUIT_ViewWindow.h"
#include "SUIT_Desktop.h"
#include "SUIT_Session.h"

#include <qpainter.h>
#include <qapplication.h>
#include <qcolordialog.h>
#include <qpalette.h>
#include <qpopupmenu.h>

#include <AIS_Axis.hxx>
#include <AIS_Drawer.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>

#include <Geom_Axis2Placement.hxx>
#include <Prs3d_DatumAspect.hxx>
#include <Prs3d_LineAspect.hxx>

OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron )
: SUIT_ViewModel(),
myBgColor( Qt::black )
{
  // init CasCade viewers
  myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000.,
                                              V3d_XposYnegZpos, true, true );

  myV3dViewer->Init();

  myV3dCollector = OCCViewer_VService::Viewer3d( "", (short*) "Collector3d", "", 1000.,
                                                 V3d_XposYnegZpos, true, true );
  myV3dCollector->Init();

  // init selector
  myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector);

  // display isoline on planar faces (box for ex.)
  myAISContext->IsoOnPlane( true );

  clearViewAspects();

  /* create trihedron */
  if( DisplayTrihedron )
  {
    Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
    myTrihedron = new AIS_Trihedron(anAxis);
    myTrihedron->SetInfiniteState( Standard_True );

    Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
    //myTrihedron->SetColor( Col );
    myTrihedron->SetArrowColor( Col.Name() );
    myTrihedron->SetSize(100);
    Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
    if (drawer->HasDatumAspect()) {
        Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
        daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
        daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
        daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
    }

    myAISContext->Display(myTrihedron);
    myAISContext->Deactivate(myTrihedron);
  }

  // selection
  mySelectionEnabled = true;
  myMultiSelectionEnabled = true;
}

OCCViewer_Viewer::~OCCViewer_Viewer()
{
}

QColor OCCViewer_Viewer::backgroundColor() const
{
  return myBgColor;
}

void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
{
  if ( c.isValid() )
    myBgColor = c;
}

void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
{
  if ( view ) {
    view->initLayout();

    OCCViewer_ViewPort3d* vp3d = view->getViewPort();
    if ( vp3d )
      vp3d->setBackgroundColor( myBgColor );
  }
}

SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
{
  OCCViewer_ViewWindow* view = new OCCViewer_ViewWindow(theDesktop, this);
  initView( view );
  return view;
}

//*********************************************************************
void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
{
  SUIT_ViewModel::setViewManager(theViewManager);
  if (theViewManager) {
    connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));

    connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));

    connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
  }
}

//*********************************************************************
void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
}

//*********************************************************************
void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  if (!mySelectionEnabled) return;
  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;

  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
  myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView->getViewPort()->getView());
}

//*********************************************************************
void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  if (!mySelectionEnabled) return;
  if (theEvent->button() != Qt::LeftButton) return;
  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;

  myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
  bool aHasShift = (theEvent->state() & Qt::ShiftButton);

  if (myStartPnt == myEndPnt)
  {
    if (aHasShift && myMultiSelectionEnabled)
      myAISContext->ShiftSelect();
    else
      myAISContext->Select();
  }
  else
  {
    if (aHasShift && myMultiSelectionEnabled)
      myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
                                myEndPnt.x(), myEndPnt.y(),
                                aView->getViewPort()->getView(), Standard_False );
    else
      myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
                           myEndPnt.x(), myEndPnt.y(),
                           aView->getViewPort()->getView(), Standard_False );

    int Nb = myAISContext->NbSelected();
    if( Nb>1 && !myMultiSelectionEnabled )
    {
        myAISContext->InitSelected();
        Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
        if( !anOwner.IsNull() )
        {
            myAISContext->ClearSelected( Standard_False );
            myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
        }
    }

    myAISContext->UpdateCurrentViewer();
  }
  emit selectionChanged();
}

//*********************************************************************
void OCCViewer_Viewer::enableSelection(bool isEnabled)
{
  mySelectionEnabled = isEnabled;
  //!! To be done for view windows
}

//*********************************************************************
void OCCViewer_Viewer::enableMultiselection(bool isEnable)
{
  myMultiSelectionEnabled = isEnable;
  //!! To be done for view windows
}

//*********************************************************************
void OCCViewer_Viewer::contextMenuPopup(QPopupMenu* thePopup)
{
  thePopup->insertItem( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
  thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );

  thePopup->insertSeparator();

  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView && !aView->getToolBar()->isVisible() )
    thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
}

void OCCViewer_Viewer::onDumpView()
{
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView )
    aView->onDumpView();
}

//*********************************************************************
void OCCViewer_Viewer::onChangeBgColor()
{
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if( !aView )
    return;
  OCCViewer_ViewPort3d* aViewPort3d = aView->getViewPort();
  if( !aViewPort3d )
    return;
  QColor aColorActive = aViewPort3d->backgroundColor();

  QColor selColor = QColorDialog::getColor( aColorActive, aView);
  if ( selColor.isValid() )
    aViewPort3d->setBackgroundColor(selColor);
}

//*********************************************************************
void OCCViewer_Viewer::onShowToolbar() {
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView )
    aView->getToolBar()->show();
}

//*********************************************************************
void OCCViewer_Viewer::update()
{
  if (!myV3dViewer.IsNull())
    myV3dViewer->Update();
}

//*********************************************************************
void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
{
  theList.Clear();
  for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
    theList.Append(myAISContext->SelectedInteractive());
}

//*********************************************************************
void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
{
  AIS_ListIteratorOfListOfInteractive aIt;
  for (aIt.Initialize(theList); aIt.More(); aIt.Next())
    myAISContext->SetSelected(aIt.Value(), false);
  myAISContext->UpdateCurrentViewer();
}

//*********************************************************************
void OCCViewer_Viewer::performSelectionChanged()
{
    emit selectionChanged();
}

//****************************************************************

void OCCViewer_Viewer::onClearViewAspects()
{
    clearViewAspects();
}

//****************************************************************

void OCCViewer_Viewer::clearViewAspects()
{
	myViewAspects.clear();
}

//****************************************************************

const viewAspectList& OCCViewer_Viewer::getViewAspects()
{
	return myViewAspects;
}

//****************************************************************

void OCCViewer_Viewer::appendViewAspect( const viewAspect& aParams )
{
	myViewAspects.append( aParams );
}

//****************************************************************

void OCCViewer_Viewer::updateViewAspects( const viewAspectList& aViewList )
{
	myViewAspects = aViewList;
}

bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
                                  bool hilight, bool update )
{
  bool isInLocal = myAISContext->HasOpenedContext();
  if( !obj.IsNull() )
    if( !isInLocal )
    {
      if ( hilight && !myAISContext->IsSelected( obj ) )
        myAISContext->AddOrRemoveCurrentObject( obj, false );
      else if ( !hilight && myAISContext->IsSelected( obj ) )
        myAISContext->AddOrRemoveCurrentObject( obj, false );
    }

  if ( update )
    myV3dViewer->Redraw();

  return false;
}

bool OCCViewer_Viewer::unHighlightAll( bool updateviewer )
{
  if ( myAISContext->HasOpenedContext() )
    myAISContext->ClearSelected( updateviewer );
  else
    myAISContext->ClearCurrents( updateviewer );
  return false;
}

bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
                                   bool onlyInViewer )
{
  AIS_ListOfInteractive List;
  myAISContext->DisplayedObjects(List);

  if( !onlyInViewer )
  {
    AIS_ListOfInteractive List1;
    myAISContext->ObjectsInCollector(List1);
    List.Append(List1);
  }

  AIS_ListIteratorOfListOfInteractive ite(List);
  for ( ; ite.More(); ite.Next() )
    if( ite.Value()==obj )
      return true;

  return false;
}

bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
{
  return myAISContext->IsDisplayed( obj );
}

void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
                                 const QColor& color,
                                 bool update )
{
  if( !obj.IsNull() )
  {
    Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
                                               color.green() / 255.,
                                               color.blue() / 255.,
                                               Quantity_TOC_RGB );
    obj->SetColor( CSFColor );
  }

  if( update )
    myV3dViewer->Update();
}

void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
                                             int mode, bool update )
{
  myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, true );
  if( update )
    myV3dViewer->Update();
}

void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
                                        float trans, bool update )
{
  myAISContext->SetTransparency( obj, trans, false );
  myAISContext->Redisplay( obj, Standard_False, Standard_True );
  if( update )
    myV3dViewer->Update();
}

//****************************************************************
void OCCViewer_Viewer::toggleTrihedron()
{
  setTrihedronShown( !isTrihedronVisible() );
}

bool OCCViewer_Viewer::isTrihedronVisible() const
{
  return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
}

void OCCViewer_Viewer::setTrihedronShown( const bool on )
{
  if ( myTrihedron.IsNull() )
    return;

  if ( on )
    myAISContext->Display( myTrihedron );
  else
    myAISContext->Erase( myTrihedron );
}

int OCCViewer_Viewer::trihedronSize() const
{
  int sz = 0;
  if ( !myTrihedron.IsNull() )
    sz = (int)myTrihedron->Size();
  return sz;
}

void OCCViewer_Viewer::setTrihedronSize( const int sz )
{
  if ( !myTrihedron.IsNull() )
    myTrihedron->SetSize( sz );
}

void OCCViewer_Viewer::setIsos( const int u, const int v )
{
  Handle(AIS_InteractiveContext) ic = getAISContext();
  if ( ic.IsNull() )
  return;

  ic->SetIsoNumber( u, AIS_TOI_IsoU );
  ic->SetIsoNumber( u, AIS_TOI_IsoV );
}

void OCCViewer_Viewer::isos( int& u, int& v ) const
{
  Handle(AIS_InteractiveContext) ic = getAISContext();
  if ( !ic.IsNull() )
  {
    u = ic->IsoNumber( AIS_TOI_IsoU );
    v = ic->IsoNumber( AIS_TOI_IsoV );
  }
}
<commit_msg>Fix for problem: numbers of isolines functionality work incorrect.<commit_after>
#include "OCCViewer_ViewModel.h"
#include "OCCViewer_ViewWindow.h"
#include "OCCViewer_VService.h"
#include "OCCViewer_ViewPort3d.h"

#include "SUIT_ViewWindow.h"
#include "SUIT_Desktop.h"
#include "SUIT_Session.h"

#include <qpainter.h>
#include <qapplication.h>
#include <qcolordialog.h>
#include <qpalette.h>
#include <qpopupmenu.h>

#include <AIS_Axis.hxx>
#include <AIS_Drawer.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>

#include <Geom_Axis2Placement.hxx>
#include <Prs3d_DatumAspect.hxx>
#include <Prs3d_LineAspect.hxx>

OCCViewer_Viewer::OCCViewer_Viewer( bool DisplayTrihedron )
: SUIT_ViewModel(),
myBgColor( Qt::black )
{
  // init CasCade viewers
  myV3dViewer = OCCViewer_VService::Viewer3d( "", (short*) "Viewer3d", "", 1000.,
                                              V3d_XposYnegZpos, true, true );

  myV3dViewer->Init();

  myV3dCollector = OCCViewer_VService::Viewer3d( "", (short*) "Collector3d", "", 1000.,
                                                 V3d_XposYnegZpos, true, true );
  myV3dCollector->Init();

  // init selector
  myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector);

  // display isoline on planar faces (box for ex.)
  myAISContext->IsoOnPlane( true );

  clearViewAspects();

  /* create trihedron */
  if( DisplayTrihedron )
  {
    Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
    myTrihedron = new AIS_Trihedron(anAxis);
    myTrihedron->SetInfiniteState( Standard_True );

    Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
    //myTrihedron->SetColor( Col );
    myTrihedron->SetArrowColor( Col.Name() );
    myTrihedron->SetSize(100);
    Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
    if (drawer->HasDatumAspect()) {
        Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
        daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
        daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
        daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
    }

    myAISContext->Display(myTrihedron);
    myAISContext->Deactivate(myTrihedron);
  }

  // selection
  mySelectionEnabled = true;
  myMultiSelectionEnabled = true;
}

OCCViewer_Viewer::~OCCViewer_Viewer()
{
}

QColor OCCViewer_Viewer::backgroundColor() const
{
  return myBgColor;
}

void OCCViewer_Viewer::setBackgroundColor( const QColor& c )
{
  if ( c.isValid() )
    myBgColor = c;
}

void OCCViewer_Viewer::initView( OCCViewer_ViewWindow* view )
{
  if ( view ) {
    view->initLayout();

    OCCViewer_ViewPort3d* vp3d = view->getViewPort();
    if ( vp3d )
      vp3d->setBackgroundColor( myBgColor );
  }
}

SUIT_ViewWindow* OCCViewer_Viewer::createView( SUIT_Desktop* theDesktop )
{
  OCCViewer_ViewWindow* view = new OCCViewer_ViewWindow(theDesktop, this);
  initView( view );
  return view;
}

//*********************************************************************
void OCCViewer_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
{
  SUIT_ViewModel::setViewManager(theViewManager);
  if (theViewManager) {
    connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));

    connect(theViewManager, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));

    connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
            this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
  }
}

//*********************************************************************
void OCCViewer_Viewer::onMousePress(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  myStartPnt.setX(theEvent->x()); myStartPnt.setY(theEvent->y());
}

//*********************************************************************
void OCCViewer_Viewer::onMouseMove(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  if (!mySelectionEnabled) return;
  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;

  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
  myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView->getViewPort()->getView());
}

//*********************************************************************
void OCCViewer_Viewer::onMouseRelease(SUIT_ViewWindow* theWindow, QMouseEvent* theEvent)
{
  if (!mySelectionEnabled) return;
  if (theEvent->button() != Qt::LeftButton) return;
  if (!theWindow->inherits("OCCViewer_ViewWindow")) return;

  myEndPnt.setX(theEvent->x()); myEndPnt.setY(theEvent->y());
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*) theWindow;
  bool aHasShift = (theEvent->state() & Qt::ShiftButton);

  if (myStartPnt == myEndPnt)
  {
    if (aHasShift && myMultiSelectionEnabled)
      myAISContext->ShiftSelect();
    else
      myAISContext->Select();
  }
  else
  {
    if (aHasShift && myMultiSelectionEnabled)
      myAISContext->ShiftSelect(myStartPnt.x(), myStartPnt.y(),
                                myEndPnt.x(), myEndPnt.y(),
                                aView->getViewPort()->getView(), Standard_False );
    else
      myAISContext->Select(myStartPnt.x(), myStartPnt.y(),
                           myEndPnt.x(), myEndPnt.y(),
                           aView->getViewPort()->getView(), Standard_False );

    int Nb = myAISContext->NbSelected();
    if( Nb>1 && !myMultiSelectionEnabled )
    {
        myAISContext->InitSelected();
        Handle( SelectMgr_EntityOwner ) anOwner = myAISContext->SelectedOwner();
        if( !anOwner.IsNull() )
        {
            myAISContext->ClearSelected( Standard_False );
            myAISContext->AddOrRemoveSelected( anOwner, Standard_False );
        }
    }

    myAISContext->UpdateCurrentViewer();
  }
  emit selectionChanged();
}

//*********************************************************************
void OCCViewer_Viewer::enableSelection(bool isEnabled)
{
  mySelectionEnabled = isEnabled;
  //!! To be done for view windows
}

//*********************************************************************
void OCCViewer_Viewer::enableMultiselection(bool isEnable)
{
  myMultiSelectionEnabled = isEnable;
  //!! To be done for view windows
}

//*********************************************************************
void OCCViewer_Viewer::contextMenuPopup(QPopupMenu* thePopup)
{
  thePopup->insertItem( tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
  thePopup->insertItem( tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );

  thePopup->insertSeparator();

  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView && !aView->getToolBar()->isVisible() )
    thePopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
}

void OCCViewer_Viewer::onDumpView()
{
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView )
    aView->onDumpView();
}

//*********************************************************************
void OCCViewer_Viewer::onChangeBgColor()
{
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if( !aView )
    return;
  OCCViewer_ViewPort3d* aViewPort3d = aView->getViewPort();
  if( !aViewPort3d )
    return;
  QColor aColorActive = aViewPort3d->backgroundColor();

  QColor selColor = QColorDialog::getColor( aColorActive, aView);
  if ( selColor.isValid() )
    aViewPort3d->setBackgroundColor(selColor);
}

//*********************************************************************
void OCCViewer_Viewer::onShowToolbar() {
  OCCViewer_ViewWindow* aView = (OCCViewer_ViewWindow*)(myViewManager->getActiveView());
  if ( aView )
    aView->getToolBar()->show();
}

//*********************************************************************
void OCCViewer_Viewer::update()
{
  if (!myV3dViewer.IsNull())
    myV3dViewer->Update();
}

//*********************************************************************
void OCCViewer_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
{
  theList.Clear();
  for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
    theList.Append(myAISContext->SelectedInteractive());
}

//*********************************************************************
void OCCViewer_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
{
  AIS_ListIteratorOfListOfInteractive aIt;
  for (aIt.Initialize(theList); aIt.More(); aIt.Next())
    myAISContext->SetSelected(aIt.Value(), false);
  myAISContext->UpdateCurrentViewer();
}

//*********************************************************************
void OCCViewer_Viewer::performSelectionChanged()
{
    emit selectionChanged();
}

//****************************************************************

void OCCViewer_Viewer::onClearViewAspects()
{
    clearViewAspects();
}

//****************************************************************

void OCCViewer_Viewer::clearViewAspects()
{
	myViewAspects.clear();
}

//****************************************************************

const viewAspectList& OCCViewer_Viewer::getViewAspects()
{
	return myViewAspects;
}

//****************************************************************

void OCCViewer_Viewer::appendViewAspect( const viewAspect& aParams )
{
	myViewAspects.append( aParams );
}

//****************************************************************

void OCCViewer_Viewer::updateViewAspects( const viewAspectList& aViewList )
{
	myViewAspects = aViewList;
}

bool OCCViewer_Viewer::highlight( const Handle(AIS_InteractiveObject)& obj,
                                  bool hilight, bool update )
{
  bool isInLocal = myAISContext->HasOpenedContext();
  if( !obj.IsNull() )
    if( !isInLocal )
    {
      if ( hilight && !myAISContext->IsSelected( obj ) )
        myAISContext->AddOrRemoveCurrentObject( obj, false );
      else if ( !hilight && myAISContext->IsSelected( obj ) )
        myAISContext->AddOrRemoveCurrentObject( obj, false );
    }

  if ( update )
    myV3dViewer->Redraw();

  return false;
}

bool OCCViewer_Viewer::unHighlightAll( bool updateviewer )
{
  if ( myAISContext->HasOpenedContext() )
    myAISContext->ClearSelected( updateviewer );
  else
    myAISContext->ClearCurrents( updateviewer );
  return false;
}

bool OCCViewer_Viewer::isInViewer( const Handle(AIS_InteractiveObject)& obj,
                                   bool onlyInViewer )
{
  AIS_ListOfInteractive List;
  myAISContext->DisplayedObjects(List);

  if( !onlyInViewer )
  {
    AIS_ListOfInteractive List1;
    myAISContext->ObjectsInCollector(List1);
    List.Append(List1);
  }

  AIS_ListIteratorOfListOfInteractive ite(List);
  for ( ; ite.More(); ite.Next() )
    if( ite.Value()==obj )
      return true;

  return false;
}

bool OCCViewer_Viewer::isVisible( const Handle(AIS_InteractiveObject)& obj )
{
  return myAISContext->IsDisplayed( obj );
}

void OCCViewer_Viewer::setColor( const Handle(AIS_InteractiveObject)& obj,
                                 const QColor& color,
                                 bool update )
{
  if( !obj.IsNull() )
  {
    Quantity_Color CSFColor = Quantity_Color ( color.red() / 255.,
                                               color.green() / 255.,
                                               color.blue() / 255.,
                                               Quantity_TOC_RGB );
    obj->SetColor( CSFColor );
  }

  if( update )
    myV3dViewer->Update();
}

void OCCViewer_Viewer::switchRepresentation( const Handle(AIS_InteractiveObject)& obj,
                                             int mode, bool update )
{
  myAISContext->SetDisplayMode( obj, (Standard_Integer)mode, true );
  if( update )
    myV3dViewer->Update();
}

void OCCViewer_Viewer::setTransparency( const Handle(AIS_InteractiveObject)& obj,
                                        float trans, bool update )
{
  myAISContext->SetTransparency( obj, trans, false );
  myAISContext->Redisplay( obj, Standard_False, Standard_True );
  if( update )
    myV3dViewer->Update();
}

//****************************************************************
void OCCViewer_Viewer::toggleTrihedron()
{
  setTrihedronShown( !isTrihedronVisible() );
}

bool OCCViewer_Viewer::isTrihedronVisible() const
{
  return !myTrihedron.IsNull() && !myAISContext.IsNull() && myAISContext->IsDisplayed( myTrihedron );
}

void OCCViewer_Viewer::setTrihedronShown( const bool on )
{
  if ( myTrihedron.IsNull() )
    return;

  if ( on )
    myAISContext->Display( myTrihedron );
  else
    myAISContext->Erase( myTrihedron );
}

int OCCViewer_Viewer::trihedronSize() const
{
  int sz = 0;
  if ( !myTrihedron.IsNull() )
    sz = (int)myTrihedron->Size();
  return sz;
}

void OCCViewer_Viewer::setTrihedronSize( const int sz )
{
  if ( !myTrihedron.IsNull() )
    myTrihedron->SetSize( sz );
}

void OCCViewer_Viewer::setIsos( const int u, const int v )
{
  Handle(AIS_InteractiveContext) ic = getAISContext();
  if ( ic.IsNull() )
  return;

  ic->SetIsoNumber( u, AIS_TOI_IsoU );
  ic->SetIsoNumber( v, AIS_TOI_IsoV );
}

void OCCViewer_Viewer::isos( int& u, int& v ) const
{
  Handle(AIS_InteractiveContext) ic = getAISContext();
  if ( !ic.IsNull() )
  {
    u = ic->IsoNumber( AIS_TOI_IsoU );
    v = ic->IsoNumber( AIS_TOI_IsoV );
  }
}
<|endoftext|>


<commit_before>AliAnalysisTaskStrVsMult *AddTaskStrVsMult(UInt_t triggerMask = AliVEvent::kINT7, TString suffix = "")
{
  // analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskStrangenessVsMultiplicity", "No analysis manager to connect to.");
    return NULL;
  }
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTaskStrangenessVsMultiplicity", "This task requires an input event handler");
    return NULL;
  }

  // Create the task and add it to the manager
  TString tskname = Form("StrVsMult_Task_%s", suffix.Data());
  AliAnalysisTaskStrVsMult *mytask = new AliAnalysisTaskStrVsMult(tskname);
  mytask->SelectCollisionCandidates(triggerMask);
  mgr->AddTask(mytask);

  // output file name
  TString outputFileName = AliAnalysisManager::GetCommonFileName();
  outputFileName += ":PWGLF_StrVsMult";
  printf("Set OutputFileName : \n %s\n", outputFileName.Data() );

  //output containers
  AliAnalysisDataContainer *coutput_0, *coutput_1, *coutput_2, *coutput_3, *coutput_4, *coutput_5, *coutput_6, *coutput_7;
  coutput_0 = mgr->CreateContainer(Form("chists_eve_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_1 = mgr->CreateContainer(Form("chists_K0S_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_2 = mgr->CreateContainer(Form("chists_Lam_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_3 = mgr->CreateContainer(Form("chists_ALam_%s", suffix.Data()),TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_4 = mgr->CreateContainer(Form("chists_Xim_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_5 = mgr->CreateContainer(Form("chists_Xip_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_6 = mgr->CreateContainer(Form("chists_Omm_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_7 = mgr->CreateContainer(Form("chists_Omp_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );

  //connecting input and output
  mgr->ConnectInput (mytask, 0, mgr->GetCommonInputContainer());
  mgr->ConnectOutput(mytask, 1, coutput_0);
  mgr->ConnectOutput(mytask, 2, coutput_1);
  mgr->ConnectOutput(mytask, 3, coutput_2);
  mgr->ConnectOutput(mytask, 4, coutput_3);
  mgr->ConnectOutput(mytask, 5, coutput_4);
  mgr->ConnectOutput(mytask, 6, coutput_5);
  mgr->ConnectOutput(mytask, 7, coutput_6);
  mgr->ConnectOutput(mytask, 8, coutput_7);

  return mytask;

}
<commit_msg>Remove trigger selection from AddTask<commit_after>AliAnalysisTaskStrVsMult *AddTaskStrVsMult(TString suffix = "")
{
  // analysis manager
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    ::Error("AddTaskStrangenessVsMultiplicity", "No analysis manager to connect to.");
    return NULL;
  }
  if (!mgr->GetInputEventHandler()) {
    ::Error("AddTaskStrangenessVsMultiplicity", "This task requires an input event handler");
    return NULL;
  }

  // Create the task and add it to the manager
  TString tskname = Form("StrVsMult_Task_%s", suffix.Data());
  AliAnalysisTaskStrVsMult *mytask = new AliAnalysisTaskStrVsMult(tskname);
  mgr->AddTask(mytask);

  // output file name
  TString outputFileName = AliAnalysisManager::GetCommonFileName();
  outputFileName += ":PWGLF_StrVsMult";
  printf("Set OutputFileName : \n %s\n", outputFileName.Data() );

  //output containers
  AliAnalysisDataContainer *coutput_0, *coutput_1, *coutput_2, *coutput_3, *coutput_4, *coutput_5, *coutput_6, *coutput_7;
  coutput_0 = mgr->CreateContainer(Form("chists_eve_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_1 = mgr->CreateContainer(Form("chists_K0S_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_2 = mgr->CreateContainer(Form("chists_Lam_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_3 = mgr->CreateContainer(Form("chists_ALam_%s", suffix.Data()),TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_4 = mgr->CreateContainer(Form("chists_Xim_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_5 = mgr->CreateContainer(Form("chists_Xip_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_6 = mgr->CreateContainer(Form("chists_Omm_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );
  coutput_7 = mgr->CreateContainer(Form("chists_Omp_%s", suffix.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, outputFileName );

  //connecting input and output
  mgr->ConnectInput (mytask, 0, mgr->GetCommonInputContainer());
  mgr->ConnectOutput(mytask, 1, coutput_0);
  mgr->ConnectOutput(mytask, 2, coutput_1);
  mgr->ConnectOutput(mytask, 3, coutput_2);
  mgr->ConnectOutput(mytask, 4, coutput_3);
  mgr->ConnectOutput(mytask, 5, coutput_4);
  mgr->ConnectOutput(mytask, 6, coutput_5);
  mgr->ConnectOutput(mytask, 7, coutput_6);
  mgr->ConnectOutput(mytask, 8, coutput_7);

  return mytask;

}
<|endoftext|>


<commit_before>#include "KEngine/Core/StateMachine.hpp"

#include "KEngine/Log/Log.hpp"

#include <algorithm>

namespace ke
{

    void StateMachine::update(const ke::Time & elapsedTime)
    {
        assert(this->startState);
        assert(this->endState);

        // the state machine has not started or has been reset.
        if (!currentState)
        {
            this->currentState = this->startState;
			this->currentState->onEnter();
        }

        this->status = Status::Running;
        this->currentState->update(elapsedTime);

        // current state requested exit.
        if (this->isCurrentStateExitRequested)
        {
            this->isCurrentStateExitRequested = false;
            auto stateExitCode = this->currentStateExitCode;
            this->currentStateExitCode = -1;

            this->currentState->onExit();

            // we reset the state machine if the state requesting exit is the end state.
            if (this->currentState == this->endState)
            {
                this->status = Status::Finished;
                this->currentState = nullptr;
                return;
            }

            auto exitingStateType = this->currentState->getType();

            // no state transition from the current state.
            // implicitly transition directly to the end state.
            auto stateTransitionSrcStateType_it = this->stateTransitionMap.find(exitingStateType);
            if (stateTransitionSrcStateType_it == this->stateTransitionMap.end())
            {
#if defined(KE_DEBUG)
                ke::Log::instance()->warn("No transition from state of type {}. " \
                    "Implicitly transitioning directly to end state of type {}.",
                    this->currentState->getName(), this->endState->getName());
#endif
                this->currentState = this->endState;
                this->currentState->onEnter();
                return;
            }

            // state transition(s) available for current state but no mapping for given exit code.
            // implicitly transition directly to the end state.
            auto & exitCodeToDestStateMap = (*stateTransitionSrcStateType_it).second;
            auto stateTransitionSrcStateExitCode_it = exitCodeToDestStateMap.find(stateExitCode);
            if (stateTransitionSrcStateExitCode_it == exitCodeToDestStateMap.end())
            {
#if defined(KE_DEBUG)
                ke::Log::instance()->warn("No transition from state of type {} for exit code {}. " \
                    "Implicitly transitioning directly to end state of type {}.",
                    this->currentState->getName(), stateExitCode, this->endState->getName());
#endif
                this->currentState = this->endState;
                this->currentState->onEnter();
                return;
            }

            // mapping is available. transition to target state.
            auto destState = (*stateTransitionSrcStateExitCode_it).second;
            this->currentState = destState;
            this->currentState->onEnter();
        }
    }

    void StateMachine::finishState(IState * state, int stateExitCode)
    {
        assert(this->currentState == state);
		assert(this->startState);
		assert(this->endState);

        this->isCurrentStateExitRequested = true;
        this->currentStateExitCode = stateExitCode;
    }

    void StateMachine::addState(StateSptr state)
    {
		assert(state);
		assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
		for (auto existingState : this->states)
		{
			if (existingState->getType() == state->getType())
			{
				ke::Log::instance()->error("A start state instance of {} already exists in this state machine.", state->getName());
			}
		}
#endif
        this->states.insert(state);
    }

    void StateMachine::addStartState(StateSptr state)
    {
		assert(state);
		assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
		for (auto existingState : this->states)
		{
			if (existingState->getType() == state->getType())
			{
				ke::Log::instance()->error("A state instance of {} already exists in this state machine.", state->getName());
			}
		}
#endif
        this->states.insert(state);
		this->startState = state.get();
    }

    void StateMachine::addEndState(StateSptr state)
    {
		assert(state);
		assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
		for (auto existingState : this->states)
		{
			if (existingState->getType() == state->getType())
			{
				ke::Log::instance()->error("An end state instance of {} already exists in this state machine.", state->getName());
			}
		}
#endif
        this->states.insert(state);
		this->endState = state.get();
    }

    bool StateMachine::addStateTransition(StateMachineStateType exitStateType, StateMachineStateExitCodeType exitStateExitCode, StateMachineStateType startStateType)
    {
		auto it_exitState = std::find_if(this->states.cbegin(), this->states.cend(),
								[exitStateType](ke::IStateMachine::StateSptr state) { return state->getType() == exitStateType; });
		if (it_exitState == this->states.cend())
		{
#if defined(KE_DEBUG)
			ke::Log::instance()->warn("The state machine does not contain a state of type {0:#x} ", exitStateExitCode);
#endif
			return false;
		}
		auto it_startState = std::find_if(this->states.cbegin(), this->states.cend(),
								[startStateType](ke::IStateMachine::StateSptr state) { return state->getType() == startStateType; });
		if (it_startState == this->states.cend())
		{
#if defined(KE_DEBUG)
			ke::Log::instance()->warn("The state machine does not contain a state of type {0:#x} ", startStateType);
#endif
			return false;
		}
		stateTransitionMap[exitStateExitCode][exitStateExitCode] = (*it_startState).get();
        return true;
    }

	IStateMachine::IState * StateMachine::getCurrentState()
	{
		return this->currentState;
	}

}<commit_msg>fix whitespace<commit_after>#include "KEngine/Core/StateMachine.hpp"

#include "KEngine/Log/Log.hpp"

#include <algorithm>

namespace ke
{

    void StateMachine::update(const ke::Time & elapsedTime)
    {
        assert(this->startState);
        assert(this->endState);

        // the state machine has not started or has been reset.
        if (!currentState)
        {
            this->currentState = this->startState;
            this->currentState->onEnter();
        }

        this->status = Status::Running;
        this->currentState->update(elapsedTime);

        // current state requested exit.
        if (this->isCurrentStateExitRequested)
        {
            this->isCurrentStateExitRequested = false;
            auto stateExitCode = this->currentStateExitCode;
            this->currentStateExitCode = -1;

            this->currentState->onExit();

            // we reset the state machine if the state requesting exit is the end state.
            if (this->currentState == this->endState)
            {
                this->status = Status::Finished;
                this->currentState = nullptr;
                return;
            }

            auto exitingStateType = this->currentState->getType();

            // no state transition from the current state.
            // implicitly transition directly to the end state.
            auto stateTransitionSrcStateType_it = this->stateTransitionMap.find(exitingStateType);
            if (stateTransitionSrcStateType_it == this->stateTransitionMap.end())
            {
#if defined(KE_DEBUG)
                ke::Log::instance()->warn("No transition from state of type {}. " \
                    "Implicitly transitioning directly to end state of type {}.",
                    this->currentState->getName(), this->endState->getName());
#endif
                this->currentState = this->endState;
                this->currentState->onEnter();
                return;
            }

            // state transition(s) available for current state but no mapping for given exit code.
            // implicitly transition directly to the end state.
            auto & exitCodeToDestStateMap = (*stateTransitionSrcStateType_it).second;
            auto stateTransitionSrcStateExitCode_it = exitCodeToDestStateMap.find(stateExitCode);
            if (stateTransitionSrcStateExitCode_it == exitCodeToDestStateMap.end())
            {
#if defined(KE_DEBUG)
                ke::Log::instance()->warn("No transition from state of type {} for exit code {}. " \
                    "Implicitly transitioning directly to end state of type {}.",
                    this->currentState->getName(), stateExitCode, this->endState->getName());
#endif
                this->currentState = this->endState;
                this->currentState->onEnter();
                return;
            }

            // mapping is available. transition to target state.
            auto destState = (*stateTransitionSrcStateExitCode_it).second;
            this->currentState = destState;
            this->currentState->onEnter();
        }
    }

    void StateMachine::finishState(IState * state, int stateExitCode)
    {
        assert(this->currentState == state);
        assert(this->startState);
        assert(this->endState);

        this->isCurrentStateExitRequested = true;
        this->currentStateExitCode = stateExitCode;
    }

    void StateMachine::addState(StateSptr state)
    {
        assert(state);
        assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
        for (auto existingState : this->states)
        {
            if (existingState->getType() == state->getType())
            {
                ke::Log::instance()->error("A start state instance of {} already exists in this state machine.", state->getName());
            }
        }
#endif
        this->states.insert(state);
    }

    void StateMachine::addStartState(StateSptr state)
    {
        assert(state);
        assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
        for (auto existingState : this->states)
        {
            if (existingState->getType() == state->getType())
            {
                ke::Log::instance()->error("A state instance of {} already exists in this state machine.", state->getName());
            }
        }
#endif
        this->states.insert(state);
        this->startState = state.get();
    }

    void StateMachine::addEndState(StateSptr state)
    {
        assert(state);
        assert(state->getType() != ke::INVALID_STATE_MACHINE_STATE_TYPE);
#if defined(KE_DEBUG)
        for (auto existingState : this->states)
        {
            if (existingState->getType() == state->getType())
            {
                ke::Log::instance()->error("An end state instance of {} already exists in this state machine.", state->getName());
            }
        }
#endif
        this->states.insert(state);
        this->endState = state.get();
    }

    bool StateMachine::addStateTransition(StateMachineStateType exitStateType, StateMachineStateExitCodeType exitStateExitCode, StateMachineStateType startStateType)
    {
        auto it_exitState = std::find_if(this->states.cbegin(), this->states.cend(),
                                [exitStateType](ke::IStateMachine::StateSptr state) { return state->getType() == exitStateType; });
        if (it_exitState == this->states.cend())
        {
#if defined(KE_DEBUG)
            ke::Log::instance()->warn("The state machine does not contain a state of type {0:#x} ", exitStateExitCode);
#endif
            return false;
        }
        auto it_startState = std::find_if(this->states.cbegin(), this->states.cend(),
                                [startStateType](ke::IStateMachine::StateSptr state) { return state->getType() == startStateType; });
        if (it_startState == this->states.cend())
        {
#if defined(KE_DEBUG)
            ke::Log::instance()->warn("The state machine does not contain a state of type {0:#x} ", startStateType);
#endif
            return false;
        }
        stateTransitionMap[exitStateExitCode][exitStateExitCode] = (*it_startState).get();
        return true;
    }

    IStateMachine::IState * StateMachine::getCurrentState()
    {
        return this->currentState;
    }

}<|endoftext|>