<commit_before>#pragma once

//#define BOOST_RESULT_OF_USE_DECLTYPE
#include <type_traits>
#include <array>

#ifdef NDEBUG
#define BOOST_DISABLE_ASSERTS
#endif

#include <boost/multi_array.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/iterator_facade.hpp>

#include "tuple_tools.hpp"

namespace gftools {

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_base;

template <typename ValueType, size_t N>
struct container;

template<typename ContainerType, size_t M = ContainerType::N_>
using container_view = container_base<typename ContainerType::value_type, ContainerType::N_, typename ContainerType::boost_t::template array_view<M>::type>;

template <typename ValueType, size_t N>
using container_ref = container_base<ValueType, N, boost::multi_array_ref<ValueType,N>>;

namespace extra {
template <typename, bool View=false> struct container_traits;

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_traits<container_base<ValueType,N,BoostContainerType>,false>
{
    typedef BoostContainerType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef container_base<ValueType,N-1,boost_under_type> type;
    typedef container_base<ValueType,N-1,boost_under_type> ref_type;
};

template <typename ValueType, typename BoostContainerType>
struct container_traits<container_base<ValueType,1,BoostContainerType>,false>
{
    typedef BoostContainerType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef ValueType type;
    typedef ValueType& ref_type;
};

template <typename ValueType, size_t N, typename BoostViewType>
struct container_traits<container_base<ValueType,N,BoostViewType>,true>
{
    typedef BoostViewType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef ValueType type;
    typedef ValueType& ref_type;
};

}; // end of namespace extra

// ================================================================== //

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_base
{
    constexpr static size_t N_ = N;
    constexpr static bool is_view_ = (N != BoostContainerType::dimensionality);

    typedef ValueType value_type;
    typedef typename extra::container_traits<container_base, is_view_>::type under_type;
    typedef typename extra::container_traits<container_base, is_view_>::ref_type under_ref_type;
    typedef typename extra::container_traits<container_base, is_view_>::boost_under_type boost_under_type;

    typedef BoostContainerType boost_t;
    typedef Eigen::Array<ValueType, Eigen::Dynamic, 1> EigenArray;
    typedef Eigen::Map<EigenArray> EigenMap;
    typedef Eigen::Matrix<ValueType,Eigen::Dynamic, Eigen::Dynamic> MatrixType;
    typedef Eigen::Matrix<ValueType,Eigen::Dynamic, 1> VectorType;

    typedef std::function<under_type(boost_under_type)> action_type;
    typedef boost::transform_iterator<action_type,typename boost_t::iterator> iterator;
    typedef boost::transform_iterator<action_type,typename boost_t::iterator> const_iterator;

    container_base(const boost_t &in):storage_(in){};
    /** Copy constructor. */
    container_base(const container_base<ValueType,N,boost_t> &rhs):storage_(rhs.storage_){};
    template <typename BT2>
        container_base(const container_base<ValueType,N,BT2> &rhs):storage_(rhs.boost_container_()){};
    template <typename BT2>
        container_base& operator=(const container_base<ValueType,N,BT2> &rhs){storage_ = rhs.boost_container_(); return (*this);};
    container_base& operator=(const container_base<ValueType,N,boost_t> &rhs){storage_ = rhs.storage_; return (*this);};
    /** Move constructor. */
    container_base(container_base<ValueType,N,boost_t> &&rhs):storage_(std::forward<boost_t>(rhs.storage_)){ }
    container_base& operator=(container_base<ValueType,N,boost_t> &&rhs){std::swap(storage_,rhs.storage_); return (*this);};
    void swap(container_base& rhs) {std::swap(storage_,rhs.storage_);}

    /** Access operators. */
    auto operator[](size_t i) -> under_ref_type { return under_ref_type(storage_[i]); }
    auto operator[](size_t i) const -> under_ref_type const { return under_ref_type(storage_[i]); }

    boost_t& boost_container_() const {return storage_; }
    ValueType& operator()(std::array<size_t, N> indices){return storage_(indices);}
    const ValueType& operator() (std::array<size_t, N> indices) const {return storage_(indices);}

    container_base<ValueType,1,boost::multi_array_ref<ValueType,1>> flatten();
// TODO : put views

    template <size_t N2 = N, typename DT = boost_t>
    using Is2d = typename std::enable_if<N2==2,DT>::type;
    /** Return operators. */
    template<size_t N2 = N, typename U = Is2d<N2>>
    container_base<ValueType,N,boost_t>& operator=(MatrixType rhs);
    template<size_t N2 = N, typename U = Is2d<N2>>
    MatrixType as_matrix() const;
    /** Return a diagonal matrix, corresponding to the object */
    MatrixType as_diagonal_matrix() const;
    /** Return a vector, corresponding to the object. */
    VectorType as_vector() const;

    /** Conjugate. */
    //container<ValueType,N>&& conj();
    template<typename T=ValueType> typename std::enable_if< std::is_same<T, complex_type>::value, container<ValueType,N>>::type conj() const;
    template<typename T=ValueType> typename std::enable_if<!std::is_same<T, complex_type>::value, container<ValueType,N>>::type conj() const;
    //typename std::enable_if<!std::is_convertible<ValueType, complex_type>::value, container<ValueType,N>&&>::type conj_d();
    //container<ValueType,N>&& conj();
    /** Sum of all values in the container. */
    ValueType sum() const;
    ValueType* data() { return storage_.origin(); }
    int size() const;
    std::array<size_t,N> shape() const;
    template <typename V2, typename DT>
    double diff(const container_base<V2,N,DT>& r) const
        { return std::sqrt(std::abs( ((*this)*(*this).conj()).sum() + (r*r.conj()).sum() - ((*this)*r.conj()).sum() - ((*this).conj()*r).sum())); }

    /** Make the object streamable. */
    template <typename V1, size_t M, typename B>
    friend std::ostream& operator<<(std::ostream& lhs, const container_base<V1, M, B> &in);

    /** Begin iterator. */
    const_iterator begin() const;
    /** End iterator. */
    const_iterator end() const;

    /** Mathematical operators. */
    template <typename T>
        typename std::enable_if<std::is_convertible<T,ValueType>::value,container_base&>::type operator=(T rhs);// { Base(*this) = rhs; return (*this);}

    template <typename T>
    using BaseRefIfContainer = typename std::enable_if<T::N_>=1, container_base<ValueType,N,boost_t>&>::type;
    template <typename T>
    using ContainerIfContainer = typename std::enable_if<T::N_>=1, container<ValueType,N>>::type;
    template <typename T>
    using BaseRefIfValue = typename std::enable_if<std::is_convertible<T,ValueType>::value, container_base<ValueType,N,boost_t>&>::type;
    template <typename T>
    using ContainerIfValue = typename std::enable_if<std::is_convertible<T,ValueType>::value, container<ValueType,N>>::type;

    template <typename R>
        BaseRefIfContainer<R> operator+=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator+(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator+=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator+(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator-=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator-(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator-=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator-(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator*=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator*(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator*=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator*(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator/=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator/(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator/=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator/(const R2& rhs) const;

    friend container<ValueType,N> operator* (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs*lhs;};
    friend container<ValueType,N> operator+ (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs+lhs;};
    friend container<ValueType,N> operator- (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs*(-1.0)+lhs;};
    friend container<ValueType,N> operator/ (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {container<ValueType,N> out(rhs); out=lhs; return out/rhs;};

    class ex_wrong_index : public std::exception { virtual const char* what() const throw(){return "Index out of bounds";}};

//-----------------------------//
    protected:
    friend struct container<ValueType,N>;

    mutable boost_t storage_;
};

template <typename ValueType, size_t N>
struct container : container_base<ValueType,N,typename boost::multi_array<ValueType, N>> {
    typedef boost::multi_array<ValueType, N> boost_t;
    typedef container_base<ValueType,N,boost_t> Base;
    using Base::storage_;
    typedef typename Base::MatrixType MatrixType;

    template <typename T>
    using IsNotContainer = typename std::enable_if<!(T::N_>=1)>::type;

    container(std::array<int,N> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(shape)) {};
    explicit container(std::array<size_t,N> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(shape)) {};
    container(std::initializer_list<int> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(shape)) {};

    template <typename CT>
        container(container_base<ValueType,N,CT> in) : container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(in.storage_) {};

    template<typename ...ShapeArgs,
        typename = typename std::enable_if<sizeof...(ShapeArgs) == N
               && (std::is_same<std::tuple<ShapeArgs...>, typename tuple_tools::repeater<int,N>::tuple_type>::value // Arguments have to be strictly ints
               || std::is_same<std::tuple<ShapeArgs...>, typename tuple_tools::repeater<size_t,N>::tuple_type>::value) // or size_t
        ,int>::type>
        container(ShapeArgs...in):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(std::array<int,N>({{in...}}))) {
            static_assert(sizeof...(in) == N,"arg mismatch");
        };

    template<size_t N2 = N, typename U = typename std::enable_if<N2==2, bool>>
        container<ValueType,N> (MatrixType rhs);
    using Base::operator+=;
    using Base::operator-=;
    using Base::operator*=;
    using Base::operator/=;
    //using Base::operator=;
    template <typename T> typename std::enable_if<std::is_convertible<T,ValueType>::value,container&>::type operator=(T rhs) {
        typename std::add_lvalue_reference<Base>::type(*this) = rhs; return (*this);}
};

}; // end of namespace gftools

#include "container.hxx"
<commit_msg>better initialization of container<commit_after>#pragma once

//#define BOOST_RESULT_OF_USE_DECLTYPE
#include <type_traits>
#include <array>

#ifdef NDEBUG
#define BOOST_DISABLE_ASSERTS
#endif

#include <boost/multi_array.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/iterator/iterator_facade.hpp>

#include "tuple_tools.hpp"

namespace gftools {

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_base;

template <typename ValueType, size_t N>
struct container;

template<typename ContainerType, size_t M = ContainerType::N_>
using container_view = container_base<typename ContainerType::value_type, ContainerType::N_, typename ContainerType::boost_t::template array_view<M>::type>;

template <typename ValueType, size_t N>
using container_ref = container_base<ValueType, N, boost::multi_array_ref<ValueType,N>>;

namespace extra {
template <typename, bool View=false> struct container_traits;

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_traits<container_base<ValueType,N,BoostContainerType>,false>
{
    typedef BoostContainerType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef container_base<ValueType,N-1,boost_under_type> type;
    typedef container_base<ValueType,N-1,boost_under_type> ref_type;
};

template <typename ValueType, typename BoostContainerType>
struct container_traits<container_base<ValueType,1,BoostContainerType>,false>
{
    typedef BoostContainerType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef ValueType type;
    typedef ValueType& ref_type;
};

template <typename ValueType, size_t N, typename BoostViewType>
struct container_traits<container_base<ValueType,N,BoostViewType>,true>
{
    typedef BoostViewType boost_t;
    typedef typename boost_t::reference boost_under_type;
    typedef ValueType type;
    typedef ValueType& ref_type;
};

}; // end of namespace extra

// ================================================================== //

template <typename ValueType, size_t N, typename BoostContainerType>
struct container_base
{
    constexpr static size_t N_ = N;
    constexpr static bool is_view_ = (N != BoostContainerType::dimensionality);

    typedef ValueType value_type;
    typedef typename extra::container_traits<container_base, is_view_>::type under_type;
    typedef typename extra::container_traits<container_base, is_view_>::ref_type under_ref_type;
    typedef typename extra::container_traits<container_base, is_view_>::boost_under_type boost_under_type;

    typedef BoostContainerType boost_t;
    typedef Eigen::Array<ValueType, Eigen::Dynamic, 1> EigenArray;
    typedef Eigen::Map<EigenArray> EigenMap;
    typedef Eigen::Matrix<ValueType,Eigen::Dynamic, Eigen::Dynamic> MatrixType;
    typedef Eigen::Matrix<ValueType,Eigen::Dynamic, 1> VectorType;

    typedef std::function<under_type(boost_under_type)> action_type;
    typedef boost::transform_iterator<action_type,typename boost_t::iterator> iterator;
    typedef boost::transform_iterator<action_type,typename boost_t::iterator> const_iterator;

    container_base(const boost_t &in):storage_(in){};
    /** Copy constructor. */
    container_base(const container_base<ValueType,N,boost_t> &rhs):storage_(rhs.storage_){};
    template <typename BT2>
        container_base(const container_base<ValueType,N,BT2> &rhs):storage_(rhs.boost_container_()){};
    template <typename BT2>
        container_base& operator=(const container_base<ValueType,N,BT2> &rhs){storage_ = rhs.boost_container_(); return (*this);};
    container_base& operator=(const container_base<ValueType,N,boost_t> &rhs){storage_ = rhs.storage_; return (*this);};
    /** Move constructor. */
    container_base(container_base<ValueType,N,boost_t> &&rhs):storage_(std::forward<boost_t>(rhs.storage_)){ }
    container_base& operator=(container_base<ValueType,N,boost_t> &&rhs){std::swap(storage_,rhs.storage_); return (*this);};
    void swap(container_base& rhs) {std::swap(storage_,rhs.storage_);}

    /** Access operators. */
    auto operator[](size_t i) -> under_ref_type { return under_ref_type(storage_[i]); }
    auto operator[](size_t i) const -> under_ref_type const { return under_ref_type(storage_[i]); }

    boost_t& boost_container_() const {return storage_; }
    ValueType& operator()(std::array<size_t, N> indices){return storage_(indices);}
    const ValueType& operator() (std::array<size_t, N> indices) const {return storage_(indices);}

    container_base<ValueType,1,boost::multi_array_ref<ValueType,1>> flatten();
// TODO : put views

    template <size_t N2 = N, typename DT = boost_t>
    using Is2d = typename std::enable_if<N2==2,DT>::type;
    /** Return operators. */
    template<size_t N2 = N, typename U = Is2d<N2>>
    container_base<ValueType,N,boost_t>& operator=(MatrixType rhs);
    template<size_t N2 = N, typename U = Is2d<N2>>
    MatrixType as_matrix() const;
    /** Return a diagonal matrix, corresponding to the object */
    MatrixType as_diagonal_matrix() const;
    /** Return a vector, corresponding to the object. */
    VectorType as_vector() const;

    /** Conjugate. */
    //container<ValueType,N>&& conj();
    template<typename T=ValueType> typename std::enable_if< std::is_same<T, complex_type>::value, container<ValueType,N>>::type conj() const;
    template<typename T=ValueType> typename std::enable_if<!std::is_same<T, complex_type>::value, container<ValueType,N>>::type conj() const;
    //typename std::enable_if<!std::is_convertible<ValueType, complex_type>::value, container<ValueType,N>&&>::type conj_d();
    //container<ValueType,N>&& conj();
    /** Sum of all values in the container. */
    ValueType sum() const;
    ValueType* data() { return storage_.origin(); }
    int size() const;
    std::array<size_t,N> shape() const;
    template <typename V2, typename DT>
    double diff(const container_base<V2,N,DT>& r) const
        { return std::sqrt(std::abs( ((*this)*(*this).conj()).sum() + (r*r.conj()).sum() - ((*this)*r.conj()).sum() - ((*this).conj()*r).sum())); }

    /** Make the object streamable. */
    template <typename V1, size_t M, typename B>
    friend std::ostream& operator<<(std::ostream& lhs, const container_base<V1, M, B> &in);

    /** Begin iterator. */
    const_iterator begin() const;
    /** End iterator. */
    const_iterator end() const;

    /** Mathematical operators. */
    template <typename T>
        typename std::enable_if<std::is_convertible<T,ValueType>::value,container_base&>::type operator=(T rhs);// { Base(*this) = rhs; return (*this);}

    template <typename T>
    using BaseRefIfContainer = typename std::enable_if<T::N_>=1, container_base<ValueType,N,boost_t>&>::type;
    template <typename T>
    using ContainerIfContainer = typename std::enable_if<T::N_>=1, container<ValueType,N>>::type;
    template <typename T>
    using BaseRefIfValue = typename std::enable_if<std::is_convertible<T,ValueType>::value, container_base<ValueType,N,boost_t>&>::type;
    template <typename T>
    using ContainerIfValue = typename std::enable_if<std::is_convertible<T,ValueType>::value, container<ValueType,N>>::type;

    template <typename R>
        BaseRefIfContainer<R> operator+=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator+(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator+=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator+(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator-=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator-(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator-=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator-(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator*=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator*(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator*=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator*(const R2& rhs) const;

    template <typename R>
        BaseRefIfContainer<R> operator/=(const R &rhs);
    template <typename R>
        ContainerIfContainer<R> operator/(const R &rhs) const;
    template <typename R2>
        BaseRefIfValue<R2> operator/=(const R2& rhs);
    template <typename R2>
        ContainerIfValue<R2> operator/(const R2& rhs) const;

    friend container<ValueType,N> operator* (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs*lhs;};
    friend container<ValueType,N> operator+ (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs+lhs;};
    friend container<ValueType,N> operator- (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {return rhs*(-1.0)+lhs;};
    friend container<ValueType,N> operator/ (const ValueType & lhs, const container_base<ValueType,N,boost_t> & rhs) {container<ValueType,N> out(rhs); out=lhs; return out/rhs;};

    class ex_wrong_index : public std::exception { virtual const char* what() const throw(){return "Index out of bounds";}};

//-----------------------------//
    protected:
    friend struct container<ValueType,N>;

    mutable boost_t storage_;
};

template <typename ValueType, size_t N>
struct container : container_base<ValueType,N,typename boost::multi_array<ValueType, N>> {
    typedef boost::multi_array<ValueType, N> boost_t;
    typedef container_base<ValueType,N,boost_t> Base;
    using Base::storage_;
    typedef typename Base::MatrixType MatrixType;

    template <typename T>
    using IsNotContainer = typename std::enable_if<!(T::N_>=1)>::type;

    container(std::array<int,N> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(shape)) {};
    explicit container(std::array<size_t,N> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(shape)) {};
    container(std::initializer_list<int> shape):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(std::array<int, N>(shape))) {};

    template <typename CT>
        container(container_base<ValueType,N,CT> in) : container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(in.storage_) {};

    template<typename ...ShapeArgs,
        typename = typename std::enable_if<sizeof...(ShapeArgs) == N
               && (std::is_same<std::tuple<ShapeArgs...>, typename tuple_tools::repeater<int,N>::tuple_type>::value // Arguments have to be strictly ints
               || std::is_same<std::tuple<ShapeArgs...>, typename tuple_tools::repeater<size_t,N>::tuple_type>::value) // or size_t
        ,int>::type>
        container(ShapeArgs...in):container_base<ValueType,N,typename boost::multi_array<ValueType, N>>(boost::multi_array<ValueType, N>(std::array<int,N>({{in...}}))) {
            static_assert(sizeof...(in) == N,"arg mismatch");
        };

    template<size_t N2 = N, typename U = typename std::enable_if<N2==2, bool>>
        container<ValueType,N> (MatrixType rhs);
    using Base::operator+=;
    using Base::operator-=;
    using Base::operator*=;
    using Base::operator/=;
    //using Base::operator=;
    template <typename T> typename std::enable_if<std::is_convertible<T,ValueType>::value,container&>::type operator=(T rhs) {
        typename std::add_lvalue_reference<Base>::type(*this) = rhs; return (*this);}
};

}; // end of namespace gftools

#include "container.hxx"
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of meegotouch-controlpanelsoundsettingsapplet.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "alerttonebrowser.h"
#include "alerttonedefaults.h"
#include "alerttoneappletmaps.h"
#include "trackerconnection.h"
#include "drilldownitem.h"

#include <QtTracker/Tracker>
#include <QGraphicsLinearLayout>

#ifdef HAVE_CONTENT_MANAGER
#include <SelectSingleContentItemPage.h>
#endif

#include <MList>
#include <MListFilter>
#include <MApplication>
#include <MApplicationPage>
#include <MApplicationWindow>
#include <MWindow>
#include <MAction>
#include <MTextEdit>
#include <MButton>
#include <MWidgetAction>
#include <MImageWidget>
#include <MContentItem>

//#define DEBUG
#define WARNING
#include "../debug.h"

static const int filterEditorPosition = 2;

class MCustomContentItem: public MContentItem
{
public:
    MCustomContentItem (MContentItem::ContentItemStyle itemStyle=MContentItem::IconAndTwoTextLabels, QGraphicsItem *parent=0)
    :MContentItem(itemStyle,parent),fullPath("") {}

    QString fullPath;
};

/******************************************************************************
 * AlertToneBrowser implementation.
 */
AlertToneBrowser::AlertToneBrowser(AlertTone *tone, QGraphicsWidget *parent):
    AlertToneToplevel (parent),
    m_tone (tone),
    m_defaults (0),
    m_preview (0),
    m_MusicBrowser (0),
    m_DoneButton (0),
    m_CancelButton (0)
{
    /*
     * FIXME: Why do we need to set the title?
     */
    setProperty ("title", AlertToneAppletMaps::mapToUiString (m_tone->key ()));

    createContent();
}

AlertToneBrowser::~AlertToneBrowser()
{
    SYS_DEBUG ("");
    stopPlayingSound ();
}

void
AlertToneBrowser::createContent()
{
    m_MainLayout = new QGraphicsLinearLayout (Qt::Vertical);
    m_MainLayout->setContentsMargins (0., 0., 0., 0.);
    m_MainLayout->setSpacing (0.);
    setLayout (m_MainLayout);

#ifdef HAVE_CONTENT_MANAGER
    // "Pick from My Music"
    m_my_music = new DrillDownItem;
    m_my_music->setLayoutPosition (M::VerticalTopPosition);
    m_my_music->imageWidget()->setImage("icon-l-music");
    m_my_music->setObjectName("MContentItem_pickFromMyMusic");
    m_MainLayout->addItem (m_my_music);
    connect (m_my_music, SIGNAL (clicked ()), SLOT (launchMusicBrowser ()));
#endif

    // "Get more from Ovi store"
    m_ovi_store = new DrillDownItem;
    m_ovi_store->setLayoutPosition (M::VerticalBottomPosition);
    m_ovi_store->imageWidget()->setImage("icon-m-common-ovi");
    m_ovi_store->setObjectName("MContentItem_getMoreFromOviStore");
    m_MainLayout->addItem (m_ovi_store);
    connect (m_ovi_store, SIGNAL (clicked ()), SLOT (launchOviStore ()));

    /*
     * The list with the available sound files.
     */
    m_defaults = new AlertToneDefaults(m_tone, 0);
    m_defaults->filtering()->setEnabled (true);
    m_defaults->filtering()->setFilterMode (
            MListFilter::FilterAsBeginningOfLine);
    m_LiveFilterEditor = m_defaults->filtering()->editor();
    m_MainLayout->addItem(m_defaults);
    connect (m_defaults, SIGNAL (displayEntered ()),
             SLOT (defaultsDisplayEntered ()));

    // We need this stretch to keep the widgets growing in size when too much
    // lines are filtered out from the list.
    m_MainLayout->addStretch ();

    retranslateUi();

    m_defaults->selectAndScroll (m_tone->fileName(), m_tone->niceName());

    connect (m_LiveFilterEditor, SIGNAL(textChanged()),
            this, SLOT(textChanged ()));

    connect(m_defaults, SIGNAL(defaultItemClicked(const QString &)),
            this, SLOT(defaultItemClicked(const QString &)));
}

void
AlertToneBrowser::defaultsDisplayEntered()
{
    SYS_DEBUG ("");

    /*
     * A fix for the NB#198788 - Live filtering text editor loses focus in
     * this scenario
     */
    if (!m_LiveFilterEditor || !m_LiveFilterEditor->isOnDisplay())
        m_defaults->setFocus();
}

void
AlertToneBrowser::retranslateUi()
{
#ifdef HAVE_CONTENT_MANAGER
    m_my_music->setProperty ("title", qtTrId("qtn_sond_pick_music"));
#endif
    m_ovi_store->setProperty("title", qtTrId("qtn_sond_store"));

    if (m_DoneButton)
        //% "Done"
        m_DoneButton->setText (qtTrId("qtn_comm_command_done"));

    if (m_CancelButton)
        //% "Cancel"
        m_CancelButton->setText (qtTrId("qtn_comm_cancel"));
}

void
AlertToneBrowser::cancel()
{
    SYS_DEBUG ("");
    m_defaults->toneChanged ();
    emit closePage();
}

void
AlertToneBrowser::accept()
{
    SYS_DEBUG ("");
    if (!currSelectedFile.isEmpty())
        m_tone->set(currSelectedFile);

    emit closePage();
}

void
AlertToneBrowser::launchMusicBrowser()
{
#ifdef HAVE_CONTENT_MANAGER
    SYS_DEBUG ("launching content picker...");

    if (! m_MusicBrowser)
    {
        m_MusicBrowser = new SelectSingleContentItemPage (
                QString (),
                QStringList () <<
                  "http://www.tracker-project.org/temp/nmm#MusicPiece",
                m_tone->trackerId ());

        m_MusicBrowser->setObjectName (
                "SelectSingleContentItemPage_musicBrowser");
        connect (m_MusicBrowser, SIGNAL (backButtonClicked ()),
                 SLOT (browserBackButtonClicked ()));
        connect (m_MusicBrowser, SIGNAL (contentItemSelected (const QString&)),
                 SLOT (selectingMusicItem (const QString&)));
    }

    m_MusicBrowser->appear ();
#endif
}

void
AlertToneBrowser::launchOviStore()
{
    QString cmdline = "webwidgetrunner /usr/share/webwidgets/applications/d34177b1c241ea44cb132005b63ee6527c9f6040-wrt-widget.desktop -widgetparameter ringtones " /* + m_tone->key() */ + QString("&");
    qDebug() << "AlertToneBrowser(" << m_tone->key() << ")::launchOviStore:" << cmdline;
    system(cmdline.toUtf8().constData());
}

static QString
trackerIdToFilename(const QString &trackerId)
{
    const QString query = "select ?u where { <" + trackerId + "> nie:url ?u }";

    QVector<QStringList> result = ::tracker()->rawSparqlQuery(query);

    SYS_DEBUG ("*** query         = %s", SYS_STR(query));
    SYS_DEBUG ("*** result.size() = %d", result.size());
    for (int Nix = 0; Nix < result.size() ; Nix++) {
        for (int Nix1 = 0 ; Nix1 < result[Nix].size() ; Nix1++) {
            QUrl url(result[Nix][Nix1]);
            SYS_DEBUG ("*** result[%d][%d] = %s",
                    Nix, Nix1, SYS_STR(result[Nix][Nix1]));
            if (url.isValid() && url.scheme() == "file")
                return QUrl::fromPercentEncoding(url.path().toUtf8());
        }
    }

    return QString("");
}

/*
 * NOTE: This method will not start the playing of the sound file any more.
 */
void
AlertToneBrowser::setAlertTone (
        const QString &fname,
        bool           setGui)
{
    SYS_DEBUG ("*** fname  = %s", SYS_STR(fname));
    SYS_DEBUG ("*** setGui = %s", SYS_BOOL(setGui));

    currSelectedFile = fname;

    if (setGui) {
        /*
         * The nice name is most probably already in the cache. If not the model
         * will do receive a signal.
         * FIXME: how could we test this? Do we need to teszt what happens when
         * this item is not cached yet?
         */
        m_defaults->selectAndScroll (fname,
                TrackerConnection::instance()->niceNameFromFileName(fname));
    }
}

/*!
 * This slot is called when the text in the live filtering text editor has been
 * changed.
 */
void
AlertToneBrowser::textChanged ()
{
    bool     visible;
    QString  text;

    visible = m_LiveFilterEditor->isOnDisplay();
    if (!m_MainLayout)
        return;

    text = m_LiveFilterEditor->text();

    if (visible && text.isEmpty()) {
         /*
          * Removing the filter editor from the layout.
          */
        m_defaults->setFocus();
        m_LiveFilterEditor->setVisible (false);
        m_MainLayout->removeItem (m_LiveFilterEditor);
    } else if (!visible && !text.isEmpty()) {
        /*
         * Adding the filter editor widget to the layout.
         */
        m_MainLayout->insertItem (filterEditorPosition, m_LiveFilterEditor);
        m_LiveFilterEditor->setVisible (true);
        m_LiveFilterEditor->setFocus();
    }

    m_MainLayout->invalidate ();
    m_defaults->setFilterText (m_LiveFilterEditor->text());
    update ();
}

/*
 * This method will start the playback of a given file. If the player is already
 * playing the very same file the playback will be started.
 */
void
AlertToneBrowser::startPlayingSound (
        const QString &filename)
{
    bool playingTheSame = m_preview && m_preview->fname() == filename;

    SYS_DEBUG ("playingTheSame = %s", SYS_BOOL(playingTheSame));
    /*
     * If we are already playing the same sound we stop the playback. This is
     * coming from the UI specification: "Second tap of the item will stop the
     * preview while the sound is playing.
     */
    if (playingTheSame) {
        delete m_preview;
    } else {
        if (m_preview)
            delete m_preview;
        m_preview = new AlertTonePreview(filename);
    }
}

/*
 * This method will stop the playback unconditionaly.
 */
void
AlertToneBrowser::stopPlayingSound ()
{
    if (m_preview)
        delete m_preview;
}

/*
 * This slot is activated when the user clicks on a sound file in the default
 * sound list.
 */
void
AlertToneBrowser::defaultItemClicked (
        const QString &filename)
{
    SYS_DEBUG ("*** filename = %s", SYS_STR(filename));
    // We don't need to set the UI, this signal came from the UI already.
    setAlertTone (filename, false);
    startPlayingSound (filename);
}

/*
 * This slot is activated when the browser back button is clicked. Stopping the
 * playback will fix NB#199653 - Music preview doesn't stop when leaving from
 * "Select from My music" view.
 *
 * FIXME: Maybe watching the back button signal is not robus enough, the
 * playback will not be stopped when some other method is used to page back...
 */
void
AlertToneBrowser::browserBackButtonClicked ()
{
    SYS_DEBUG ("");
    stopPlayingSound ();
#ifdef HAVE_CONTENT_MANAGER
    m_MusicBrowser->dismiss ();
#endif
}

/*
 * This slot is activated when the user selects one item from the content
 * picker.
 */
void
AlertToneBrowser::selectingMusicItem (
        const QString &item)
{
    QString fname = trackerIdToFilename(item);

    if (fname.isEmpty()) {
        SYS_WARNING ("TrackerID '%s' is not valid.", SYS_STR(item));
        stopPlayingSound ();
        return;
    }

    SYS_DEBUG ("*** trackerID = %s", SYS_STR(item));
    SYS_DEBUG ("*** fname     = %s", SYS_STR(fname));

    setAlertTone(fname, true);
    startPlayingSound (fname);
}

/*
 * This virtual method is called when the MApplicationPage for the widget is
 * already there, so we can initialize it.
 */
void
AlertToneBrowser::polishEvent ()
{
    QGraphicsWidget  *parent;
    MApplicationPage *page = 0;
    MWidgetAction    *widgetAction;

    SYS_DEBUG ("");
    /*
     * Just a protection about double adding the actions.
     */
    if (m_DoneButton)
        return;

    MWindow *win = MApplication::activeWindow ();
    if (win) {
        connect (win, SIGNAL(displayExited()),
                this, SLOT(stopPlayingSound()));
        connect (win, SIGNAL(switcherEntered()),
                this, SLOT(stopPlayingSound()));
    }

    /*
     * We need to find the MApplicationPage among our parents.
     */
    parent = parentWidget();
    while (parent) {
        page = qobject_cast <MApplicationPage *>(parent);
        if (page)
            break;
        parent = parent->parentWidget();
    }

    if (!page)
        return;

    /**************************************************************************
     * Hiding the home button and the escape button from the page.
     */
    page->setComponentsDisplayMode (
            MApplicationPage::EscapeButton,
            MApplicationPageModel::Hide);
    page->setComponentsDisplayMode (
            MApplicationPage::HomeButton,
            MApplicationPageModel::Hide);

    /**************************************************************************
     * Creating the 'done' button and adding it to the page.
     */
    //% "Done"
    m_DoneButton = new MButton (qtTrId("qtn_comm_command_done"), this);
    m_DoneButton->setViewType ("toolbar");
    m_DoneButton->setStyleName ("ToolBarLabelOnlyCommonButton");
    widgetAction = new MWidgetAction (this);
    widgetAction->setLocation (MAction::ToolBarLocation);
    widgetAction->setWidget (m_DoneButton);
    page->addAction (widgetAction);
    connect (m_DoneButton, SIGNAL (clicked ()), SLOT (accept ()));

    /**************************************************************************
     * Creating the 'cancel' button and adding it to the page.
     */
    //% "Cancel"
    m_CancelButton = new MButton (qtTrId("qtn_comm_cancel"), this);
    m_CancelButton->setViewType ("toolbar");
    m_CancelButton->setStyleName ("ToolBarLabelOnlyCommonButton");
    widgetAction = new MWidgetAction (this);
    widgetAction->setLocation (MAction::ToolBarLocation);
    widgetAction->setWidget (m_CancelButton);
    page->addAction (widgetAction);
    connect (m_CancelButton, SIGNAL (clicked ()), SLOT (cancel ()));
}

<commit_msg>Fixes: fix the crash issue in a proper why (to not to cause other problems)<commit_after>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of meegotouch-controlpanelsoundsettingsapplet.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "alerttonebrowser.h"
#include "alerttonedefaults.h"
#include "alerttoneappletmaps.h"
#include "trackerconnection.h"
#include "drilldownitem.h"

#include <QtTracker/Tracker>
#include <QGraphicsLinearLayout>

#ifdef HAVE_CONTENT_MANAGER
#include <SelectSingleContentItemPage.h>
#endif

#include <MList>
#include <MListFilter>
#include <MApplication>
#include <MApplicationPage>
#include <MApplicationWindow>
#include <MWindow>
#include <MAction>
#include <MTextEdit>
#include <MButton>
#include <MWidgetAction>
#include <MImageWidget>
#include <MContentItem>

//#define DEBUG
#define WARNING
#include "../debug.h"

static const int filterEditorPosition = 2;

class MCustomContentItem: public MContentItem
{
public:
    MCustomContentItem (MContentItem::ContentItemStyle itemStyle=MContentItem::IconAndTwoTextLabels, QGraphicsItem *parent=0)
    :MContentItem(itemStyle,parent),fullPath("") {}

    QString fullPath;
};

/******************************************************************************
 * AlertToneBrowser implementation.
 */
AlertToneBrowser::AlertToneBrowser(AlertTone *tone, QGraphicsWidget *parent):
    AlertToneToplevel (parent),
    m_tone (tone),
    m_defaults (0),
    m_preview (0),
    m_MusicBrowser (0),
    m_DoneButton (0),
    m_CancelButton (0)
{
    /*
     * FIXME: Why do we need to set the title?
     */
    setProperty ("title", AlertToneAppletMaps::mapToUiString (m_tone->key ()));

    createContent();
}

AlertToneBrowser::~AlertToneBrowser()
{
    SYS_DEBUG ("");
    stopPlayingSound ();
}

void
AlertToneBrowser::createContent()
{
    m_MainLayout = new QGraphicsLinearLayout (Qt::Vertical);
    m_MainLayout->setContentsMargins (0., 0., 0., 0.);
    m_MainLayout->setSpacing (0.);
    setLayout (m_MainLayout);

#ifdef HAVE_CONTENT_MANAGER
    // "Pick from My Music"
    m_my_music = new DrillDownItem;
    m_my_music->setLayoutPosition (M::VerticalTopPosition);
    m_my_music->imageWidget()->setImage("icon-l-music");
    m_my_music->setObjectName("MContentItem_pickFromMyMusic");
    m_MainLayout->addItem (m_my_music);
    connect (m_my_music, SIGNAL (clicked ()), SLOT (launchMusicBrowser ()));
#endif

    // "Get more from Ovi store"
    m_ovi_store = new DrillDownItem;
    m_ovi_store->setLayoutPosition (M::VerticalBottomPosition);
    m_ovi_store->imageWidget()->setImage("icon-m-common-ovi");
    m_ovi_store->setObjectName("MContentItem_getMoreFromOviStore");
    m_MainLayout->addItem (m_ovi_store);
    connect (m_ovi_store, SIGNAL (clicked ()), SLOT (launchOviStore ()));

    /*
     * The list with the available sound files.
     */
    m_defaults = new AlertToneDefaults(m_tone, 0);
    m_defaults->filtering()->setEnabled (true);
    m_defaults->filtering()->setFilterMode (
            MListFilter::FilterAsBeginningOfLine);
    m_LiveFilterEditor = m_defaults->filtering()->editor();
    m_MainLayout->addItem(m_defaults);
    connect (m_defaults, SIGNAL (displayEntered ()),
             SLOT (defaultsDisplayEntered ()));

    // We need this stretch to keep the widgets growing in size when too much
    // lines are filtered out from the list.
    m_MainLayout->addStretch ();

    retranslateUi();

    m_defaults->selectAndScroll (m_tone->fileName(), m_tone->niceName());

    connect (m_LiveFilterEditor, SIGNAL(textChanged()),
            this, SLOT(textChanged ()));

    connect(m_defaults, SIGNAL(defaultItemClicked(const QString &)),
            this, SLOT(defaultItemClicked(const QString &)));
}

void
AlertToneBrowser::defaultsDisplayEntered()
{
    SYS_DEBUG ("");

    /*
     * A fix for the NB#198788 - Live filtering text editor loses focus in
     * this scenario
     */
    if (!m_LiveFilterEditor || !m_LiveFilterEditor->isOnDisplay())
        m_defaults->setFocus();
}

void
AlertToneBrowser::retranslateUi()
{
#ifdef HAVE_CONTENT_MANAGER
    m_my_music->setProperty ("title", qtTrId("qtn_sond_pick_music"));
#endif
    m_ovi_store->setProperty("title", qtTrId("qtn_sond_store"));

    if (m_DoneButton)
        //% "Done"
        m_DoneButton->setText (qtTrId("qtn_comm_command_done"));

    if (m_CancelButton)
        //% "Cancel"
        m_CancelButton->setText (qtTrId("qtn_comm_cancel"));
}

void
AlertToneBrowser::cancel()
{
    SYS_DEBUG ("");
    m_defaults->toneChanged ();
    emit closePage();
}

void
AlertToneBrowser::accept()
{
    SYS_DEBUG ("");
    if (!currSelectedFile.isEmpty())
        m_tone->set(currSelectedFile);

    emit closePage();
}

void
AlertToneBrowser::launchMusicBrowser()
{
#ifdef HAVE_CONTENT_MANAGER
    SYS_DEBUG ("launching content picker...");

    if (! m_MusicBrowser)
    {
        m_MusicBrowser = new SelectSingleContentItemPage (
                QString (),
                QStringList () <<
                  "http://www.tracker-project.org/temp/nmm#MusicPiece",
                m_tone->trackerId ());

        m_MusicBrowser->setObjectName (
                "SelectSingleContentItemPage_musicBrowser");
        connect (m_MusicBrowser, SIGNAL (backButtonClicked ()),
                 SLOT (browserBackButtonClicked ()));
        connect (m_MusicBrowser, SIGNAL (contentItemSelected (const QString&)),
                 SLOT (selectingMusicItem (const QString&)));
    }

    m_MusicBrowser->appear (MSceneWindow::DestroyWhenDismissed);
#endif
}

void
AlertToneBrowser::launchOviStore()
{
    QString cmdline = "webwidgetrunner /usr/share/webwidgets/applications/d34177b1c241ea44cb132005b63ee6527c9f6040-wrt-widget.desktop -widgetparameter ringtones " /* + m_tone->key() */ + QString("&");
    qDebug() << "AlertToneBrowser(" << m_tone->key() << ")::launchOviStore:" << cmdline;
    system(cmdline.toUtf8().constData());
}

static QString
trackerIdToFilename(const QString &trackerId)
{
    const QString query = "select ?u where { <" + trackerId + "> nie:url ?u }";

    QVector<QStringList> result = ::tracker()->rawSparqlQuery(query);

    SYS_DEBUG ("*** query         = %s", SYS_STR(query));
    SYS_DEBUG ("*** result.size() = %d", result.size());
    for (int Nix = 0; Nix < result.size() ; Nix++) {
        for (int Nix1 = 0 ; Nix1 < result[Nix].size() ; Nix1++) {
            QUrl url(result[Nix][Nix1]);
            SYS_DEBUG ("*** result[%d][%d] = %s",
                    Nix, Nix1, SYS_STR(result[Nix][Nix1]));
            if (url.isValid() && url.scheme() == "file")
                return QUrl::fromPercentEncoding(url.path().toUtf8());
        }
    }

    return QString("");
}

/*
 * NOTE: This method will not start the playing of the sound file any more.
 */
void
AlertToneBrowser::setAlertTone (
        const QString &fname,
        bool           setGui)
{
    SYS_DEBUG ("*** fname  = %s", SYS_STR(fname));
    SYS_DEBUG ("*** setGui = %s", SYS_BOOL(setGui));

    currSelectedFile = fname;

    if (setGui) {
        /*
         * The nice name is most probably already in the cache. If not the model
         * will do receive a signal.
         * FIXME: how could we test this? Do we need to teszt what happens when
         * this item is not cached yet?
         */
        m_defaults->selectAndScroll (fname,
                TrackerConnection::instance()->niceNameFromFileName(fname));
    }
}

/*!
 * This slot is called when the text in the live filtering text editor has been
 * changed.
 */
void
AlertToneBrowser::textChanged ()
{
    bool     visible;
    QString  text;

    visible = m_LiveFilterEditor->isOnDisplay();
    if (!m_MainLayout)
        return;

    text = m_LiveFilterEditor->text();

    if (visible && text.isEmpty()) {
         /*
          * Removing the filter editor from the layout.
          */
        m_defaults->setFocus();
        m_LiveFilterEditor->setVisible (false);
        m_MainLayout->removeItem (m_LiveFilterEditor);
    } else if (!visible && !text.isEmpty()) {
        /*
         * Adding the filter editor widget to the layout.
         */
        m_MainLayout->insertItem (filterEditorPosition, m_LiveFilterEditor);
        m_LiveFilterEditor->setVisible (true);
        m_LiveFilterEditor->setFocus();
    }

    m_MainLayout->invalidate ();
    m_defaults->setFilterText (m_LiveFilterEditor->text());
    update ();
}

/*
 * This method will start the playback of a given file. If the player is already
 * playing the very same file the playback will be started.
 */
void
AlertToneBrowser::startPlayingSound (
        const QString &filename)
{
    bool playingTheSame = m_preview && m_preview->fname() == filename;

    SYS_DEBUG ("playingTheSame = %s", SYS_BOOL(playingTheSame));
    /*
     * If we are already playing the same sound we stop the playback. This is
     * coming from the UI specification: "Second tap of the item will stop the
     * preview while the sound is playing.
     */
    if (playingTheSame) {
        delete m_preview;
    } else {
        if (m_preview)
            delete m_preview;
        m_preview = new AlertTonePreview(filename);
    }
}

/*
 * This method will stop the playback unconditionaly.
 */
void
AlertToneBrowser::stopPlayingSound ()
{
    if (m_preview)
        delete m_preview;
}

/*
 * This slot is activated when the user clicks on a sound file in the default
 * sound list.
 */
void
AlertToneBrowser::defaultItemClicked (
        const QString &filename)
{
    SYS_DEBUG ("*** filename = %s", SYS_STR(filename));
    // We don't need to set the UI, this signal came from the UI already.
    setAlertTone (filename, false);
    startPlayingSound (filename);
}

/*
 * This slot is activated when the browser back button is clicked. Stopping the
 * playback will fix NB#199653 - Music preview doesn't stop when leaving from
 * "Select from My music" view.
 *
 * FIXME: Maybe watching the back button signal is not robus enough, the
 * playback will not be stopped when some other method is used to page back...
 */
void
AlertToneBrowser::browserBackButtonClicked ()
{
    SYS_DEBUG ("");
    stopPlayingSound ();
#ifdef HAVE_CONTENT_MANAGER
    m_MusicBrowser->dismiss ();
    m_MusicBrowser = 0;
#endif
}

/*
 * This slot is activated when the user selects one item from the content
 * picker.
 */
void
AlertToneBrowser::selectingMusicItem (
        const QString &item)
{
    QString fname = trackerIdToFilename(item);

    if (fname.isEmpty()) {
        SYS_WARNING ("TrackerID '%s' is not valid.", SYS_STR(item));
        stopPlayingSound ();
        return;
    }

    SYS_DEBUG ("*** trackerID = %s", SYS_STR(item));
    SYS_DEBUG ("*** fname     = %s", SYS_STR(fname));

    setAlertTone(fname, true);
    startPlayingSound (fname);
}

/*
 * This virtual method is called when the MApplicationPage for the widget is
 * already there, so we can initialize it.
 */
void
AlertToneBrowser::polishEvent ()
{
    QGraphicsWidget  *parent;
    MApplicationPage *page = 0;
    MWidgetAction    *widgetAction;

    SYS_DEBUG ("");
    /*
     * Just a protection about double adding the actions.
     */
    if (m_DoneButton)
        return;

    MWindow *win = MApplication::activeWindow ();
    if (win) {
        connect (win, SIGNAL(displayExited()),
                this, SLOT(stopPlayingSound()));
        connect (win, SIGNAL(switcherEntered()),
                this, SLOT(stopPlayingSound()));
    }

    /*
     * We need to find the MApplicationPage among our parents.
     */
    parent = parentWidget();
    while (parent) {
        page = qobject_cast <MApplicationPage *>(parent);
        if (page)
            break;
        parent = parent->parentWidget();
    }

    if (!page)
        return;

    /**************************************************************************
     * Hiding the home button and the escape button from the page.
     */
    page->setComponentsDisplayMode (
            MApplicationPage::EscapeButton,
            MApplicationPageModel::Hide);
    page->setComponentsDisplayMode (
            MApplicationPage::HomeButton,
            MApplicationPageModel::Hide);

    /**************************************************************************
     * Creating the 'done' button and adding it to the page.
     */
    //% "Done"
    m_DoneButton = new MButton (qtTrId("qtn_comm_command_done"), this);
    m_DoneButton->setViewType ("toolbar");
    m_DoneButton->setStyleName ("ToolBarLabelOnlyCommonButton");
    widgetAction = new MWidgetAction (this);
    widgetAction->setLocation (MAction::ToolBarLocation);
    widgetAction->setWidget (m_DoneButton);
    page->addAction (widgetAction);
    connect (m_DoneButton, SIGNAL (clicked ()), SLOT (accept ()));

    /**************************************************************************
     * Creating the 'cancel' button and adding it to the page.
     */
    //% "Cancel"
    m_CancelButton = new MButton (qtTrId("qtn_comm_cancel"), this);
    m_CancelButton->setViewType ("toolbar");
    m_CancelButton->setStyleName ("ToolBarLabelOnlyCommonButton");
    widgetAction = new MWidgetAction (this);
    widgetAction->setLocation (MAction::ToolBarLocation);
    widgetAction->setWidget (m_CancelButton);
    page->addAction (widgetAction);
    connect (m_CancelButton, SIGNAL (clicked ()), SLOT (cancel ()));
}

<|endoftext|>


<commit_before>
/***************************************************************************
                   jabberaccountwidget.h  -  Account widget for Jabber
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002-2003 by Till Gerken <till@tantalo.net>
                           Based on code by Olivier Goffart <ogoffart@tiscalinet.be>
    email                : kopete-devel@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kdebug.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <kmessagebox.h>
#include <klocale.h>

#include "jabbereditaccountwidget.h"

JabberEditAccountWidget::JabberEditAccountWidget (JabberProtocol * proto, JabberAccount * ident, QWidget * parent, const char *name)
						: DlgJabberEditAccountWidget (parent, name), KopeteEditAccountWidget (ident)
{
	m_protocol = proto;

	connect (mID, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mPass, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mResource, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mServer, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mPort, SIGNAL (valueChanged (int)), this, SLOT (configChanged ()));

	connect (mAutoConnect, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (chkUseSSL, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (chkRemPass, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));

	// Chat TAB
	connect (cmbAuth, SIGNAL (activated (int)), this, SLOT (configChanged ()));

	connect (cbProxyType, SIGNAL (activated (int)), this, SLOT (configChanged ()));
	connect (leProxyName, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (spbProxyPort, SIGNAL (valueChanged (int)), this, SLOT (configChanged ()));

	connect (cbProxyAuth, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (leProxyUser, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (leProxyPass, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));

	connect (mID, SIGNAL (textChanged (const QString &)), this, SLOT (setJIDValidation ()));
	connect (mServer, SIGNAL (textChanged (const QString &)), this, SLOT (setJIDValidation ()));

	connect (btnRegister, SIGNAL (clicked ()), this, SLOT (registerClicked ()));
	connect (chkUseSSL, SIGNAL (toggled (bool)), this, SLOT (sslToggled (bool)));

	if (account())
	{
		this->reopen ();
	}
}

JabberEditAccountWidget::~JabberEditAccountWidget ()
{
}

void JabberEditAccountWidget::reopen ()
{

	// FIXME: this is temporary until Kopete supports accound ID changes!
	mID->setDisabled(true);

	mID->setText (account()->accountId ());
	mPass->setText (account()->password ());
	mResource->setText (account()->pluginData (m_protocol, "Resource"));
	mServer->setText (account()->pluginData (m_protocol, "Server"));

	if (account()->pluginData (m_protocol, "UseSSL") == "true")
		chkUseSSL->setChecked (true);

	mPort->setValue (account()->pluginData (m_protocol, "Port").toInt ());

	if (account()->pluginData (m_protocol, "RemPass") == "true")
		chkRemPass->setChecked (true);

	QString auth = account()->pluginData (m_protocol, "AuthType");

	cmbAuth->setCurrentItem (0);

	if (auth == QString ("plain"))
		cmbAuth->setCurrentItem (1);

	QString proxyType = account()->pluginData (m_protocol, "ProxyType");

	cbProxyType->setCurrentItem (0);
	if (proxyType == QString ("HTTPS"))
		cbProxyType->setCurrentItem (1);
	else if (proxyType == QString ("SOCKS4"))
		cbProxyType->setCurrentItem (2);
	else if (proxyType == QString ("SOCKS5"))
		cbProxyType->setCurrentItem (3);

	leProxyName->setText (account()->pluginData (m_protocol, "ProxyName"));
	spbProxyPort->setValue (account()->pluginData (m_protocol, "ProxyPort").toInt ());
	cbProxyAuth->setChecked (account()->pluginData (m_protocol, "ProxyAuth") == QString::fromLatin1 ("true"));
	leProxyUser->setText (account()->pluginData (m_protocol, "ProxyUser"));
	leProxyPass->setText (account()->pluginData (m_protocol, "ProxyPass"));
	mAutoConnect->setChecked (account()->autoLogin());

	revalidateJID = false;

}

KopeteAccount *JabberEditAccountWidget::apply ()
{
	kdDebug (14180) << "JabberEditAccount::apply()" << endl;

	if(revalidateJID)
		validateJID();

	if (!account())
	{
		setAccount(new JabberAccount (m_protocol, mID->text ()));
	}

	if(account()->isConnected())
	{
		KMessageBox::information(this,
					i18n("The changes you just made will take effect next time you log in with Jabber."),
					i18n("Jabber Changes During Online Jabber Session"));
	}

	this->writeConfig ();

	return account();
}

void JabberEditAccountWidget::writeConfig ()
{

	// FIXME: The call below represents a flaw in the current Kopete API.
	// Once the API is cleaned up, this will most likely require a change.
	//account()->setAccountId(mID->text());

	account()->setPluginData (m_protocol, "Server", mServer->text ());
	account()->setPluginData (m_protocol, "Resource", mResource->text ());
	account()->setPluginData (m_protocol, "Port", QString::number (mPort->value ()));

	if (chkUseSSL->isChecked ())
		account()->setPluginData (m_protocol, "UseSSL", "true");
	else
		account()->setPluginData (m_protocol, "UseSSL", "false");

	if (chkRemPass->isChecked ())
	{
		account()->setPluginData (m_protocol, "RemPass", "true");
		account()->setPassword (mPass->text ());
	}
	else
	{
		account()->setPluginData (m_protocol, "RemPass", "false");
		account()->setPassword (NULL);
	}

	account()->setAutoLogin(mAutoConnect->isChecked());

	switch (cmbAuth->currentItem ())
	{
	case 0:
		account()->setPluginData (m_protocol, "AuthType", "digest");
		break;
	case 1:
		account()->setPluginData (m_protocol, "AuthType", "plain");
		break;
	default:					// this case should never happen, just
		// implemented for safety
		account()->setPluginData (m_protocol, "AuthType", "digest");
		break;
	}

	switch (cbProxyType->currentItem ())
	{
	case 0:
		account()->setPluginData (m_protocol, "ProxyType", "None");
		break;
	case 1:
		account()->setPluginData (m_protocol, "ProxyType", "HTTPS");
		break;
	case 2:
		account()->setPluginData (m_protocol, "ProxyType", "SOCKS4");
		break;
	case 3:
		account()->setPluginData (m_protocol, "ProxyType", "SOCKS5");
		break;
	default:					// this case should never happen, just
		// implemented for safety
		account()->setPluginData (m_protocol, "ProxyType", "None");
		break;
	}

	account()->setPluginData (m_protocol, "ProxyName", leProxyName->text ());
	account()->setPluginData (m_protocol, "ProxyPort", QString::number (spbProxyPort->value ()));

	if (cbProxyAuth->isChecked ())
		account()->setPluginData (m_protocol, "ProxyAuth", "true");
	else
		account()->setPluginData (m_protocol, "ProxyAuth", "false");

	account()->setPluginData (m_protocol, "ProxyUser", leProxyUser->text ());
	account()->setPluginData (m_protocol, "ProxyPass", leProxyPass->text ());
	//config->sync();
	settings_changed = false;
}

bool JabberEditAccountWidget::validateData ()
{

	if(!mID->text().contains('@'))
	{
		KMessageBox::sorry(this, i18n("The Jabber ID you have chosen is invalid. "
							"Please make sure it is in the form user@jabber.org."),
							i18n("Invalid Jabber ID"));

		return false;
	}

	return true;
}

void JabberEditAccountWidget::validateJID ()
{
	QString server = mID->text().section('@', 1);

	if(mServer->text().isEmpty())
	{
		// the user didn't specify a server, automatically choose one
		mServer->setText(server);
	}
	else
	{
		if(mServer->text() != server)
		{
			// the user has chosen a different server than his JID
			// suggests, display a warning
			int result = KMessageBox::warningYesNo (this, i18n("You have chosen a different Jabber server than your Jabber "
													"ID suggests. Do you want me to change your server setting? Selecting \"Yes\" "
													"will change your Jabber server to \"%1\" as indicated by your Jabber ID. "
													"Selecting \"No\" leave your current settings.").arg(server),
													i18n("Are you sure about your server name?"));

			if(result == KMessageBox::Yes)
				mServer->setText(server);
		}
	}

}

void JabberEditAccountWidget::configChanged ()
{
	settings_changed = true;
}

void JabberEditAccountWidget::setJIDValidation ()
{

	if(account ()->pluginData(m_protocol, "Server") == mServer->text ())
		revalidateJID = false;
	else
		revalidateJID = true;

}

void JabberEditAccountWidget::registerClicked ()
{

	if(!validateData())
		return;

	if (!account())
	{
		setAccount(new JabberAccount (m_protocol, mID->text ()));
	}

	this->writeConfig ();

	static_cast < JabberAccount * >(account())->registerUser ();

}

void JabberEditAccountWidget::sslToggled (bool value)
{
	if (value && (mPort->value() == 5222))
		mPort->stepUp ();
	else
		if(!value && (mPort->value() == 5223))
			mPort->stepDown ();
}

#include "jabbereditaccountwidget.moc"

// vim: set noet ts=4 sts=4 sw=4:
<commit_msg>Fix crash introduced by last commit here. Crash occured when creating a new account and account() would return a NULL pointer. CCMAIL: kopete-devel@kde.org<commit_after>
/***************************************************************************
                   jabberaccountwidget.h  -  Account widget for Jabber
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002-2003 by Till Gerken <till@tantalo.net>
                           Based on code by Olivier Goffart <ogoffart@tiscalinet.be>
    email                : kopete-devel@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kdebug.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <kmessagebox.h>
#include <klocale.h>

#include "jabbereditaccountwidget.h"

JabberEditAccountWidget::JabberEditAccountWidget (JabberProtocol * proto, JabberAccount * ident, QWidget * parent, const char *name)
						: DlgJabberEditAccountWidget (parent, name), KopeteEditAccountWidget (ident)
{
	m_protocol = proto;

	connect (mID, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mPass, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mResource, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mServer, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (mPort, SIGNAL (valueChanged (int)), this, SLOT (configChanged ()));

	connect (mAutoConnect, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (chkUseSSL, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (chkRemPass, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));

	// Chat TAB
	connect (cmbAuth, SIGNAL (activated (int)), this, SLOT (configChanged ()));

	connect (cbProxyType, SIGNAL (activated (int)), this, SLOT (configChanged ()));
	connect (leProxyName, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (spbProxyPort, SIGNAL (valueChanged (int)), this, SLOT (configChanged ()));

	connect (cbProxyAuth, SIGNAL (toggled (bool)), this, SLOT (configChanged ()));
	connect (leProxyUser, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));
	connect (leProxyPass, SIGNAL (textChanged (const QString &)), this, SLOT (configChanged ()));

	connect (mID, SIGNAL (textChanged (const QString &)), this, SLOT (setJIDValidation ()));
	connect (mServer, SIGNAL (textChanged (const QString &)), this, SLOT (setJIDValidation ()));

	connect (btnRegister, SIGNAL (clicked ()), this, SLOT (registerClicked ()));
	connect (chkUseSSL, SIGNAL (toggled (bool)), this, SLOT (sslToggled (bool)));

	if (account())
	{
		this->reopen ();
	}
}

JabberEditAccountWidget::~JabberEditAccountWidget ()
{
}

void JabberEditAccountWidget::reopen ()
{

	// FIXME: this is temporary until Kopete supports accound ID changes!
	mID->setDisabled(true);

	mID->setText (account()->accountId ());
	mPass->setText (account()->password ());
	mResource->setText (account()->pluginData (m_protocol, "Resource"));
	mServer->setText (account()->pluginData (m_protocol, "Server"));

	if (account()->pluginData (m_protocol, "UseSSL") == "true")
		chkUseSSL->setChecked (true);

	mPort->setValue (account()->pluginData (m_protocol, "Port").toInt ());

	if (account()->pluginData (m_protocol, "RemPass") == "true")
		chkRemPass->setChecked (true);

	QString auth = account()->pluginData (m_protocol, "AuthType");

	cmbAuth->setCurrentItem (0);

	if (auth == QString ("plain"))
		cmbAuth->setCurrentItem (1);

	QString proxyType = account()->pluginData (m_protocol, "ProxyType");

	cbProxyType->setCurrentItem (0);
	if (proxyType == QString ("HTTPS"))
		cbProxyType->setCurrentItem (1);
	else if (proxyType == QString ("SOCKS4"))
		cbProxyType->setCurrentItem (2);
	else if (proxyType == QString ("SOCKS5"))
		cbProxyType->setCurrentItem (3);

	leProxyName->setText (account()->pluginData (m_protocol, "ProxyName"));
	spbProxyPort->setValue (account()->pluginData (m_protocol, "ProxyPort").toInt ());
	cbProxyAuth->setChecked (account()->pluginData (m_protocol, "ProxyAuth") == QString::fromLatin1 ("true"));
	leProxyUser->setText (account()->pluginData (m_protocol, "ProxyUser"));
	leProxyPass->setText (account()->pluginData (m_protocol, "ProxyPass"));
	mAutoConnect->setChecked (account()->autoLogin());

	revalidateJID = false;

}

KopeteAccount *JabberEditAccountWidget::apply ()
{
	kdDebug (14180) << "JabberEditAccount::apply()" << endl;

	if(revalidateJID)
		validateJID();

	if (!account())
	{
		setAccount(new JabberAccount (m_protocol, mID->text ()));
	}

	if(account()->isConnected())
	{
		KMessageBox::information(this,
					i18n("The changes you just made will take effect next time you log in with Jabber."),
					i18n("Jabber Changes During Online Jabber Session"));
	}

	this->writeConfig ();

	return account();
}

void JabberEditAccountWidget::writeConfig ()
{

	// FIXME: The call below represents a flaw in the current Kopete API.
	// Once the API is cleaned up, this will most likely require a change.
	//account()->setAccountId(mID->text());

	account()->setPluginData (m_protocol, "Server", mServer->text ());
	account()->setPluginData (m_protocol, "Resource", mResource->text ());
	account()->setPluginData (m_protocol, "Port", QString::number (mPort->value ()));

	if (chkUseSSL->isChecked ())
		account()->setPluginData (m_protocol, "UseSSL", "true");
	else
		account()->setPluginData (m_protocol, "UseSSL", "false");

	if (chkRemPass->isChecked ())
	{
		account()->setPluginData (m_protocol, "RemPass", "true");
		account()->setPassword (mPass->text ());
	}
	else
	{
		account()->setPluginData (m_protocol, "RemPass", "false");
		account()->setPassword (NULL);
	}

	account()->setAutoLogin(mAutoConnect->isChecked());

	switch (cmbAuth->currentItem ())
	{
	case 0:
		account()->setPluginData (m_protocol, "AuthType", "digest");
		break;
	case 1:
		account()->setPluginData (m_protocol, "AuthType", "plain");
		break;
	default:					// this case should never happen, just
		// implemented for safety
		account()->setPluginData (m_protocol, "AuthType", "digest");
		break;
	}

	switch (cbProxyType->currentItem ())
	{
	case 0:
		account()->setPluginData (m_protocol, "ProxyType", "None");
		break;
	case 1:
		account()->setPluginData (m_protocol, "ProxyType", "HTTPS");
		break;
	case 2:
		account()->setPluginData (m_protocol, "ProxyType", "SOCKS4");
		break;
	case 3:
		account()->setPluginData (m_protocol, "ProxyType", "SOCKS5");
		break;
	default:					// this case should never happen, just
		// implemented for safety
		account()->setPluginData (m_protocol, "ProxyType", "None");
		break;
	}

	account()->setPluginData (m_protocol, "ProxyName", leProxyName->text ());
	account()->setPluginData (m_protocol, "ProxyPort", QString::number (spbProxyPort->value ()));

	if (cbProxyAuth->isChecked ())
		account()->setPluginData (m_protocol, "ProxyAuth", "true");
	else
		account()->setPluginData (m_protocol, "ProxyAuth", "false");

	account()->setPluginData (m_protocol, "ProxyUser", leProxyUser->text ());
	account()->setPluginData (m_protocol, "ProxyPass", leProxyPass->text ());
	//config->sync();
	settings_changed = false;
}

bool JabberEditAccountWidget::validateData ()
{

	if(!mID->text().contains('@'))
	{
		KMessageBox::sorry(this, i18n("The Jabber ID you have chosen is invalid. "
							"Please make sure it is in the form user@jabber.org."),
							i18n("Invalid Jabber ID"));

		return false;
	}

	return true;
}

void JabberEditAccountWidget::validateJID ()
{
	QString server = mID->text().section('@', 1);

	if(mServer->text().isEmpty())
	{
		// the user didn't specify a server, automatically choose one
		mServer->setText(server);
	}
	else
	{
		if(mServer->text() != server)
		{
			// the user has chosen a different server than his JID
			// suggests, display a warning
			int result = KMessageBox::warningYesNo (this, i18n("You have chosen a different Jabber server than your Jabber "
													"ID suggests. Do you want me to change your server setting? Selecting \"Yes\" "
													"will change your Jabber server to \"%1\" as indicated by your Jabber ID. "
													"Selecting \"No\" leave your current settings.").arg(server),
													i18n("Are you sure about your server name?"));

			if(result == KMessageBox::Yes)
				mServer->setText(server);
		}
	}

}

void JabberEditAccountWidget::configChanged ()
{
	settings_changed = true;
}

void JabberEditAccountWidget::setJIDValidation ()
{

	revalidateJID = true;

	if((account() != 0L) && (account ()->pluginData(m_protocol, "Server") == mServer->text ()))
		revalidateJID = false;

}

void JabberEditAccountWidget::registerClicked ()
{

	if(!validateData())
		return;

	if (!account())
	{
		setAccount(new JabberAccount (m_protocol, mID->text ()));
	}

	this->writeConfig ();

	static_cast < JabberAccount * >(account())->registerUser ();

}

void JabberEditAccountWidget::sslToggled (bool value)
{
	if (value && (mPort->value() == 5222))
		mPort->stepUp ();
	else
		if(!value && (mPort->value() == 5223))
			mPort->stepDown ();
}

#include "jabbereditaccountwidget.moc"

// vim: set noet ts=4 sts=4 sw=4:
<|endoftext|>


<commit_before>#include "argument.h"
#include "argument_p.h"
#include "value.h"

phpcxx::Argument::Argument(const char* argName)
    : d_ptr(new ArgumentPrivate(argName, IS_UNDEF, nullptr, false, false, false))
{
}

phpcxx::Argument::Argument(const char* argName, phpcxx::ArgumentType type, bool allowNull, bool byRef, bool isVariadic)
    : d_ptr(new ArgumentPrivate(argName, static_cast<int>(type), nullptr, allowNull, byRef, isVariadic))
{
}

phpcxx::Argument::Argument(const char* argName, const char* className, bool allowNull, bool byRef, bool isVariadic)
    : d_ptr(new ArgumentPrivate(argName, IS_OBJECT, className, allowNull, byRef, isVariadic))
{
}

phpcxx::Argument::Argument(const struct _zend_internal_arg_info& other)
    : d_ptr(new ArgumentPrivate(other))
{
}

phpcxx::Argument::Argument(phpcxx::Argument&& other) noexcept
    : d_ptr(std::move(other.d_ptr))
{
}

phpcxx::Argument::~Argument()
{
}

const char* phpcxx::Argument::name() const
{
    return this->d_ptr->m_arginfo.name;
}

const char* phpcxx::Argument::className() const
{
    return this->d_ptr->m_arginfo.class_name;
}

phpcxx::ArgumentType phpcxx::Argument::type() const
{
    return static_cast<phpcxx::ArgumentType>(this->d_ptr->m_arginfo.type_hint);
}

bool phpcxx::Argument::canBeNull() const
{
    return this->d_ptr->m_arginfo.allow_null;
}

bool phpcxx::Argument::isPassedByReference() const
{
    return this->d_ptr->m_arginfo.pass_by_reference;
}

bool phpcxx::Argument::isVariadic() const
{
    return this->d_ptr->m_arginfo.is_variadic;
}

phpcxx::Argument&& phpcxx::Argument::setType(phpcxx::ArgumentType type)
{
    this->d_ptr->m_arginfo.type_hint = static_cast<zend_uchar>(type);
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setClass(const char* name)
{
    this->d_ptr->m_arginfo.type_hint  = IS_OBJECT;
    this->d_ptr->m_arginfo.class_name = name;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setNullable(bool v)
{
    this->d_ptr->m_arginfo.allow_null = v;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setByRef(bool v)
{
    this->d_ptr->m_arginfo.pass_by_reference = v;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setVariadic(bool v)
{
    this->d_ptr->m_arginfo.is_variadic = v;
    return std::move(*this);
}

const struct _zend_internal_arg_info& phpcxx::Argument::get() const
{
    return this->d_ptr->m_arginfo;
}

std::ostream& phpcxx::operator<<(std::ostream& os, const Argument& obj)
{
    os
        << "[Argument: name=" << obj.name()
        << ", type=" << Value::typeToString(static_cast<Type>(obj.type()))
        << ", nullable=" << obj.canBeNull()
        << ", byref=" << obj.isPassedByReference()
        << ", variadic=" << obj.isVariadic()
        << "]" << std::endl;
    ;

    return os;
}
<commit_msg>IS_TRUE/IS_FALSE should be mapped to phpcxx::ArgumentType::Bool<commit_after>#include "argument.h"
#include "argument_p.h"
#include "value.h"

phpcxx::Argument::Argument(const char* argName)
    : d_ptr(new ArgumentPrivate(argName, IS_UNDEF, nullptr, false, false, false))
{
}

phpcxx::Argument::Argument(const char* argName, phpcxx::ArgumentType type, bool allowNull, bool byRef, bool isVariadic)
    : d_ptr(new ArgumentPrivate(argName, static_cast<int>(type), nullptr, allowNull, byRef, isVariadic))
{
}

phpcxx::Argument::Argument(const char* argName, const char* className, bool allowNull, bool byRef, bool isVariadic)
    : d_ptr(new ArgumentPrivate(argName, IS_OBJECT, className, allowNull, byRef, isVariadic))
{
}

phpcxx::Argument::Argument(const struct _zend_internal_arg_info& other)
    : d_ptr(new ArgumentPrivate(other))
{
}

phpcxx::Argument::Argument(phpcxx::Argument&& other) noexcept
    : d_ptr(std::move(other.d_ptr))
{
}

phpcxx::Argument::~Argument()
{
}

const char* phpcxx::Argument::name() const
{
    return this->d_ptr->m_arginfo.name;
}

const char* phpcxx::Argument::className() const
{
    return this->d_ptr->m_arginfo.class_name;
}

phpcxx::ArgumentType phpcxx::Argument::type() const
{
    int type_hint = this->d_ptr->m_arginfo.type_hint;
    if (IS_TRUE == type_hint || IS_FALSE == type_hint) {
        return phpcxx::ArgumentType::Bool;
    }

    return static_cast<phpcxx::ArgumentType>(type_hint);
}

bool phpcxx::Argument::canBeNull() const
{
    return this->d_ptr->m_arginfo.allow_null;
}

bool phpcxx::Argument::isPassedByReference() const
{
    return this->d_ptr->m_arginfo.pass_by_reference;
}

bool phpcxx::Argument::isVariadic() const
{
    return this->d_ptr->m_arginfo.is_variadic;
}

phpcxx::Argument&& phpcxx::Argument::setType(phpcxx::ArgumentType type)
{
    this->d_ptr->m_arginfo.type_hint = static_cast<zend_uchar>(type);
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setClass(const char* name)
{
    this->d_ptr->m_arginfo.type_hint  = IS_OBJECT;
    this->d_ptr->m_arginfo.class_name = name;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setNullable(bool v)
{
    this->d_ptr->m_arginfo.allow_null = v;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setByRef(bool v)
{
    this->d_ptr->m_arginfo.pass_by_reference = v;
    return std::move(*this);
}

phpcxx::Argument&& phpcxx::Argument::setVariadic(bool v)
{
    this->d_ptr->m_arginfo.is_variadic = v;
    return std::move(*this);
}

const struct _zend_internal_arg_info& phpcxx::Argument::get() const
{
    return this->d_ptr->m_arginfo;
}

std::ostream& phpcxx::operator<<(std::ostream& os, const Argument& obj)
{
    os
        << "[Argument: name=" << obj.name()
        << ", type=" << Value::typeToString(static_cast<Type>(obj.type()))
        << ", nullable=" << obj.canBeNull()
        << ", byref=" << obj.isPassedByReference()
        << ", variadic=" << obj.isVariadic()
        << "]" << std::endl;
    ;

    return os;
}
<|endoftext|>


<commit_before>#include "bloomierFilter.h"

BloomierFilter::BloomierFilter(size_t pM, size_t pK, size_t pQ){
	mM = pM;;
	mK = pK;
	mQ = pQ;
	mBitVectorSize = ceil(pQ / static_cast<float>(CHAR_BIT));
	mBloomierHash = new BloomierHash(pM, pK, mBitVectorSize);
	mOrderAndMatchFinder = new OrderAndMatchFinder(pM, pK, mBloomierHash);
	mTable = new bloomierTable(pM);
	mValueTable = new vvsize_t_p(pM);
	for (size_t i = 0; i < pM; ++i) {
		(*mTable)[i] = new bitVector(mBitVectorSize, 0);
		(*mValueTable)[i] = new vsize_t();
	}

    mEncoder = new Encoder(mBitVectorSize);
	mPiIndex = 0;
}

BloomierFilter::~BloomierFilter(){

}
void BloomierFilter::check() {
	std::cout << __LINE__ << std::endl;
	size_t sumTable = 0;
	for(size_t i = 0; i < mTable->size(); ++i) {
        try {
		  sumTable += (*mTable)[i]->size();
        } catch(int e) {
            std::cout << "i: " << i << std::endl;
        }
	}
	std::cout << __LINE__ << std::endl;
	size_t sumValueTable = 0;
	for(size_t i = 0; i < mValueTable->size(); ++i) {
		sumValueTable += (*mValueTable)[i]->size();
	}
	std::cout << "sumTable: "  << sumTable << std::endl;
	std::cout << "sumValueTable: "  << sumValueTable << std::endl;

	std::cout << __LINE__ << std::endl;

}
bloomierTable* BloomierFilter::getTable() {
	return mTable;
}

void BloomierFilter::setTable(bloomierTable* pTable) {
    if (mTable != NULL) {
        for (size_t i = 0; i < mTable->size(); ++i) {
            delete (*mTable)[i];
        }
        delete mTable;
    }
	mTable = pTable;
}

vvsize_t_p* BloomierFilter::getValueTable() {
	return mValueTable;
}
void BloomierFilter::setValueTable(vvsize_t_p* pTable) {
	mValueTable = pTable;
}

void BloomierFilter::xorOperation(bitVector* pValue, bitVector* pMask, vsize_t* pNeighbors) {
	this->xorBitVector(pValue, pMask);

	for (auto it = pNeighbors->begin(); it != pNeighbors->end(); ++it) {
		if (*it < mTable->size()) {
			this->xorBitVector(pValue, (*mTable)[(*it)]);
		}
	}
}
vsize_t* BloomierFilter::get(size_t pKey) {
    // std::cout << __LINE__ << std::endl;
	vsize_t* neighbors = mBloomierHash->getKNeighbors(pKey);
	bitVector* mask = mBloomierHash->getMask(pKey);
	bitVector* valueToGet = new bitVector(mBitVectorSize, 0);
	this->xorOperation(valueToGet, mask, neighbors);
    // std::cout << __LINE__ << std::endl;

	size_t h = mEncoder->decode(valueToGet);
    // std::cout << __LINE__ << std::endl;

	if (h < neighbors->size()) {
    // std::cout << __LINE__ << std::endl;

		size_t L = (*neighbors)[h];
    // std::cout << __LINE__ << std::endl;

		if (L < mValueTable->size()) {
    // std::cout << __LINE__ << std::endl;

			return (*mValueTable)[L];
		}
	}
    // std::cout << __LINE__ << std::endl;

	return new vsize_t();
}
bool BloomierFilter::set(size_t pKey, size_t pValue) {
	vsize_t* neighbors = mBloomierHash->getKNeighbors(pKey);
	bitVector* mask = mBloomierHash->getMask(pKey);
	bitVector* valueToGet = new bitVector(mBitVectorSize, 0);
	this->xorOperation(valueToGet, mask, neighbors);
	size_t h = mEncoder->decode(valueToGet);
	if (h < neighbors->size()) {
		size_t L = (*neighbors)[h];
		if (L < mValueTable->size()) {
			vsize_t* v = ((*mValueTable)[L]);
			v->push_back(pValue);
			return true;
		}
	} else {
		vsize_t* keys = new vsize_t (1, pKey);
		vvsize_t_p* values = new vvsize_t_p (1);
		(*values)[0] = new vsize_t(1, pValue);
		this->create(keys, values, mPiIndex);
		return true;
	}
	return false;
}

void BloomierFilter::create(vsize_t* pKeys, vvsize_t_p* pValues, size_t piIndex) {
	mOrderAndMatchFinder->find(pKeys);
    vsize_t* piVector = mOrderAndMatchFinder->getPiVector();
	vsize_t* tauVector = mOrderAndMatchFinder->getTauVector();
	for (size_t i = piIndex; i < piVector->size(); ++i) {
		vsize_t* neighbors = mBloomierHash->getKNeighbors((*pKeys)[i]);
		bitVector* mask = mBloomierHash->getMask((*pKeys)[i]);
		size_t l = (*tauVector)[i];
		size_t L = (*neighbors)[l];

		bitVector* encodeValue = mEncoder->encode(l);
		this->xorBitVector((*mTable)[L], encodeValue);
		this->xorBitVector((*mTable)[L], mask);
		for (size_t j = 0; j < neighbors->size(); ++j) {
			if (j != l) {
				this->xorBitVector((*mTable)[L], (*mTable)[(*neighbors)[j]]);
			}
		}
        for (size_t j = 0; j < (*pValues)[i-piIndex]->size(); ++j) {
            (*mValueTable)[L]->push_back((*pValues)[i-piIndex]->operator[](j));
        }
	}
	mPiIndex += pKeys->size();
}

void BloomierFilter::xorBitVector(bitVector* pResult, bitVector* pInput) {
	size_t length = std::min(pResult->size(), pInput->size());
	for (size_t i = 0; i < length; ++i) {
		(*pResult)[i] = (*pResult)[i] ^ (*pInput)[i];
	}
}<commit_msg>inserted deletion of pointers<commit_after>#include "bloomierFilter.h"

BloomierFilter::BloomierFilter(size_t pM, size_t pK, size_t pQ){
	mM = pM;;
	mK = pK;
	mQ = pQ;
	mBitVectorSize = ceil(pQ / static_cast<float>(CHAR_BIT));
	mBloomierHash = new BloomierHash(pM, pK, mBitVectorSize);
	mOrderAndMatchFinder = new OrderAndMatchFinder(pM, pK, mBloomierHash);
	mTable = new bloomierTable(pM);
	mValueTable = new vvsize_t_p(pM);
	for (size_t i = 0; i < pM; ++i) {
		(*mTable)[i] = new bitVector(mBitVectorSize, 0);
		(*mValueTable)[i] = new vsize_t();
	}

    mEncoder = new Encoder(mBitVectorSize);
	mPiIndex = 0;
}

BloomierFilter::~BloomierFilter(){

}
void BloomierFilter::check() {
	std::cout << __LINE__ << std::endl;
	size_t sumTable = 0;
	for(size_t i = 0; i < mTable->size(); ++i) {
        try {
		  sumTable += (*mTable)[i]->size();
        } catch(int e) {
            std::cout << "i: " << i << std::endl;
        }
	}
	std::cout << __LINE__ << std::endl;
	size_t sumValueTable = 0;
	for(size_t i = 0; i < mValueTable->size(); ++i) {
		sumValueTable += (*mValueTable)[i]->size();
	}
	std::cout << "sumTable: "  << sumTable << std::endl;
	std::cout << "sumValueTable: "  << sumValueTable << std::endl;

	std::cout << __LINE__ << std::endl;

}
bloomierTable* BloomierFilter::getTable() {
	return mTable;
}

void BloomierFilter::setTable(bloomierTable* pTable) {
    if (mTable != NULL) {
        for (size_t i = 0; i < mTable->size(); ++i) {
            delete (*mTable)[i];
        }
        delete mTable;
    }
	mTable = pTable;
}

vvsize_t_p* BloomierFilter::getValueTable() {
	return mValueTable;
}
void BloomierFilter::setValueTable(vvsize_t_p* pTable) {
	mValueTable = pTable;
}

void BloomierFilter::xorOperation(bitVector* pValue, bitVector* pMask, vsize_t* pNeighbors) {
	this->xorBitVector(pValue, pMask);

	for (auto it = pNeighbors->begin(); it != pNeighbors->end(); ++it) {
		if (*it < mTable->size()) {
			this->xorBitVector(pValue, (*mTable)[(*it)]);
		}
	}
}
vsize_t* BloomierFilter::get(size_t pKey) {
    // std::cout << __LINE__ << std::endl;
	vsize_t* neighbors = mBloomierHash->getKNeighbors(pKey);
	bitVector* mask = mBloomierHash->getMask(pKey);
	bitVector* valueToGet = new bitVector(mBitVectorSize, 0);
	this->xorOperation(valueToGet, mask, neighbors);

	size_t h = mEncoder->decode(valueToGet);
	if (h < neighbors->size()) {
		size_t L = (*neighbors)[h];
		if (L < mValueTable->size()) {
            delete neighbors;
			delete mask;
			delete valueToGet;
			return (*mValueTable)[L];
		}
	}
    delete neighbors;
	delete mask;
	delete valueToGet;
	return new vsize_t();
}
bool BloomierFilter::set(size_t pKey, size_t pValue) {
	vsize_t* neighbors = mBloomierHash->getKNeighbors(pKey);
	bitVector* mask = mBloomierHash->getMask(pKey);
	bitVector* valueToGet = new bitVector(mBitVectorSize, 0);
	this->xorOperation(valueToGet, mask, neighbors);
	size_t h = mEncoder->decode(valueToGet);

	delete mask;
	delete valueToGet;
	if (h < neighbors->size()) {
		size_t L = (*neighbors)[h];
		delete neighbors;
		if (L < mValueTable->size()) {
			vsize_t* v = ((*mValueTable)[L]);
			v->push_back(pValue);
			return true;
		}
	} else {
		delete neighbors;
		vsize_t* keys = new vsize_t (1, pKey);
		vvsize_t_p* values = new vvsize_t_p (1);
		(*values)[0] = new vsize_t(1, pValue);
		this->create(keys, values, mPiIndex);
		return true;
	}
	return false;
}

void BloomierFilter::create(vsize_t* pKeys, vvsize_t_p* pValues, size_t piIndex) {
	mOrderAndMatchFinder->find(pKeys);
    vsize_t* piVector = mOrderAndMatchFinder->getPiVector();
	vsize_t* tauVector = mOrderAndMatchFinder->getTauVector();
	for (size_t i = piIndex; i < piVector->size(); ++i) {
		vsize_t* neighbors = mBloomierHash->getKNeighbors((*pKeys)[i]);
		bitVector* mask = mBloomierHash->getMask((*pKeys)[i]);
		size_t l = (*tauVector)[i];
		size_t L = (*neighbors)[l];

		bitVector* encodeValue = mEncoder->encode(l);
		this->xorBitVector((*mTable)[L], encodeValue);
		this->xorBitVector((*mTable)[L], mask);
		for (size_t j = 0; j < neighbors->size(); ++j) {
			if (j != l) {
				this->xorBitVector((*mTable)[L], (*mTable)[(*neighbors)[j]]);
			}
		}
        for (size_t j = 0; j < (*pValues)[i-piIndex]->size(); ++j) {
            (*mValueTable)[L]->push_back((*pValues)[i-piIndex]->operator[](j));
        }
		delete neighbors;
		delete mask;
		delete encodeValue;
	}
	mPiIndex += pKeys->size();
	delete pKeys;
	for (size_t i = 0; i < pValues->size(); ++i) {
		delete (*pValues)[i];
	}
	delete pValues;
	// delete piVector;
	// delete tauVector;

}

void BloomierFilter::xorBitVector(bitVector* pResult, bitVector* pInput) {
	size_t length = std::min(pResult->size(), pInput->size());
	for (size_t i = 0; i < length; ++i) {
		(*pResult)[i] = (*pResult)[i] ^ (*pInput)[i];
	}
}<|endoftext|>


<commit_before>// Static scheduling demo - mapper part.
//
// Copyright (C) Braam Research, 2016.

#include <stdarg.h>

#include "legion.h"
#include "realm.h"
#include "legion_types.h"
#include "default_mapper.h"
#include "id.h"

#include "bandwidth-latency-support.h"

using namespace Realm;
using namespace Legion;
using namespace Legion::Mapping;
using namespace LegionRuntime::Accessor;

LegionRuntime::Logger::Category log_logging("logging");

void node_log(char*fmt, ...) {
    va_list vl;
    char buf[1024];
    va_start(vl, fmt);
    vsprintf(buf, fmt, vl);
    log_logging.print("%s", buf);
} /* node_log */

class BandwidthLatencyMapper : public DefaultMapper {
public:
  BandwidthLatencyMapper(MapperRuntime *rt, Machine machine, Processor local,
                         const char *mapper_name = NULL)
    : DefaultMapper(rt, machine, local, mapper_name)
  {
    fprintf(stderr, "logging level %d\n", log_logging.get_level());
  }
public:
  virtual Processor default_policy_select_initial_processor(
                                    MapperContext ctx, const Task &task);
private:
  bool equal_to(std::string& a, char*b) {
    return a == std::string(b);
  }
  // compute CPU index for a task from task's ID.
  Processor task_cpu(const Task &task, Processor old_proc) {
    std::set<Processor> all_procs;
    machine.get_all_processors(all_procs);
    std::string taskname(task.get_task_name());
    if (taskname == "receive_change") {
      for (std::set<Processor>::const_iterator it = all_procs.begin();
            it != all_procs.end(); it++) {
        log_logging.print("considering cpu %llx.\n",it->id);
        Realm::ID cpuid(*it);
        if (it->kind() == Processor::LOC_PROC && cpuid.node() == 1) { // selecting second node.
            return (*it);
        }
      }
    }
    return old_proc;
  }
};

Processor BandwidthLatencyMapper::default_policy_select_initial_processor(
                                    MapperContext ctx, const Task &task)
{
  return task_cpu(task, local_proc);
}

static void create_mappers(Machine machine, HighLevelRuntime *runtime, const std::set<Processor> &local_procs)
{
  for (std::set<Processor>::const_iterator it = local_procs.begin();
        it != local_procs.end(); it++)
  {
    runtime->replace_default_mapper(new BandwidthLatencyMapper(runtime->get_mapper_runtime(), machine, *it, "Bandwidth Latency Mapper"), *it);
  }
}

void register_mappers()
{
  HighLevelRuntime::set_registration_callback(create_mappers);
}

/* return (runtime instance initialization) relative time in microseconds (good enough for our benchmark) */
long current_time_microseconds() {
  return Clock::current_time_in_microseconds();
} /* current_time_microseconds */

<commit_msg>Fixing building issues<commit_after>// Static scheduling demo - mapper part.
//
// Copyright (C) Braam Research, 2016.

#include <stdarg.h>

#include "legion.h"
#include "realm.h"
#include "legion_types.h"
#include "default_mapper.h"
#include "id.h"

#include "bandwidth-latency-support.h"

using namespace Realm;
using namespace Legion;
using namespace Legion::Mapping;
using namespace LegionRuntime::Accessor;

LegionRuntime::Logger::Category log_logging("logging");

void node_log(char*fmt, ...) {
    va_list vl;
    char buf[1024];
    va_start(vl, fmt);
    vsprintf(buf, fmt, vl);
    log_logging.print("%s", buf);
} /* node_log */

class BandwidthLatencyMapper : public DefaultMapper {
public:
  BandwidthLatencyMapper(MapperRuntime *rt, Machine machine, Processor local,
                         const char *mapper_name = NULL)
    : DefaultMapper(rt, machine, local, mapper_name)
  {
    fprintf(stderr, "logging level %d\n", log_logging.get_level());
  }
public:
  virtual Processor default_policy_select_initial_processor(
                                    MapperContext ctx, const Task &task);
private:
  bool equal_to(std::string& a, char*b) {
    return a == std::string(b);
  }
  // compute CPU index for a task from task's ID.
  Processor task_cpu(const Task &task, Processor old_proc) {
    std::set<Processor> all_procs;
    machine.get_all_processors(all_procs);
    std::string taskname(task.get_task_name());
    if (taskname == "receive_change") {
      for (std::set<Processor>::const_iterator it = all_procs.begin();
            it != all_procs.end(); it++) {
        log_logging.print("considering cpu %llx.\n",it->id);
        Realm::ID cpuid(*it);
        if (cpuid.is_processor() && cpuid.proc.owner_node == 1) { // selecting second node.
            return (*it);
        }
      }
    }
    return old_proc;
  }
};

Processor BandwidthLatencyMapper::default_policy_select_initial_processor(
                                    MapperContext ctx, const Task &task)
{
  return task_cpu(task, local_proc);
}

static void create_mappers(Machine machine, HighLevelRuntime *runtime, const std::set<Processor> &local_procs)
{
  for (std::set<Processor>::const_iterator it = local_procs.begin();
        it != local_procs.end(); it++)
  {
    runtime->replace_default_mapper(new BandwidthLatencyMapper(runtime->get_mapper_runtime(), machine, *it, "Bandwidth Latency Mapper"), *it);
  }
}

void register_mappers()
{
  HighLevelRuntime::set_registration_callback(create_mappers);
}

/* return (runtime instance initialization) relative time in microseconds (good enough for our benchmark) */
long current_time_microseconds() {
  return Clock::current_time_in_microseconds();
} /* current_time_microseconds */

<|endoftext|>


<commit_before>AliAnalysisTask *AddTask_jditzel_DoubleHypNucTree(UInt_t triggerMask = (AliVEvent::kAny), Bool_t pidch = kFALSE) {
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddTask_jditzel_DoubleHypNucTreeAOD", "No analysis manager found.");
    return 0;
  }
  if (!mgr->GetInputEventHandler()) {
    return 0x0;
  }

  AliAnalysisTaskDoubleHypNucTree *task = new AliAnalysisTaskDoubleHypNucTree("jditzelTaskDoubleHypNucTree");
  if(!task) return 0x0;

  task->SetTriggerMask(triggerMask);
  task->SelectPIDcheckOnly(pidch);

  //Data Containers
  AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("histograms", TList::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput2 = mgr->CreateContainer("fTree", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput3 = mgr->CreateContainer("fTreeD", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput4 = mgr->CreateContainer("fTreeKF", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput5 = mgr->CreateContainer("fTreeGen", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput6 = mgr->CreateContainer("gTree", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput7 = mgr->CreateContainer("gTreeD", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput8 = mgr->CreateContainer("gTreeKF", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput9 = mgr->CreateContainer("gTreeGen", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  mgr->ConnectInput(task, 0, cinput);
  mgr->ConnectOutput(task, 1, coutput1);
  mgr->ConnectOutput(task, 2, coutput2);
  mgr->ConnectOutput(task, 3, coutput3);
  mgr->ConnectOutput(task, 4, coutput4);
  mgr->ConnectOutput(task, 5, coutput5);
  mgr->ConnectOutput(task, 6, coutput6);
  mgr->ConnectOutput(task, 7, coutput7);
  mgr->ConnectOutput(task, 8, coutput8);
  mgr->ConnectOutput(task, 9, coutput9);
  return task;
}
<commit_msg>Update AddTask_jditzel_DoubleHypNucTree.C<commit_after>AliAnalysisTask *AddTask_jditzel_DoubleHypNucTree(UInt_t triggerMask = (AliVEvent::kAny), Bool_t pidch = kFALSE) {
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) {
    Error("AddTask_jditzel_DoubleHypNucTree", "No analysis manager found.");
    return 0;
  }
  if (!mgr->GetInputEventHandler()) {
    return 0x0;
  }

  AliAnalysisTaskDoubleHypNucTree *task = new AliAnalysisTaskDoubleHypNucTree("jditzelTaskDoubleHypNucTree");
  if(!task) return 0x0;

  task->SetTriggerMask(triggerMask);
  task->SelectPIDcheckOnly(pidch);

  //Data Containers
  AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("histograms", TList::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput2 = mgr->CreateContainer("fTree", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput3 = mgr->CreateContainer("fTreeD", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput4 = mgr->CreateContainer("fTreeKF", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput5 = mgr->CreateContainer("fTreeGen", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput6 = mgr->CreateContainer("gTree", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput7 = mgr->CreateContainer("gTreeD", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput8 = mgr->CreateContainer("gTreeKF", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  AliAnalysisDataContainer *coutput9 = mgr->CreateContainer("gTreeGen", TTree::Class(),AliAnalysisManager::kOutputContainer,mgr->GetCommonFileName());
  mgr->ConnectInput(task, 0, cinput);
  mgr->ConnectOutput(task, 1, coutput1);
  mgr->ConnectOutput(task, 2, coutput2);
  mgr->ConnectOutput(task, 3, coutput3);
  mgr->ConnectOutput(task, 4, coutput4);
  mgr->ConnectOutput(task, 5, coutput5);
  mgr->ConnectOutput(task, 6, coutput6);
  mgr->ConnectOutput(task, 7, coutput7);
  mgr->ConnectOutput(task, 8, coutput8);
  mgr->ConnectOutput(task, 9, coutput9);
  return task;
}
<|endoftext|>