<commit_before>// Time:  O(n)
// Space: O(1)

/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
// Morris Traversal.
class Solution {
    /**
     * @param root: The root of binary tree.
     * @return: Inorder in vector which contains node values.
     */
public:
    vector<int> inorderTraversal(TreeNode *root) {
        vector<int> res;
        TreeNode *prev = nullptr;
        TreeNode *curr = root;
        while (curr) {
            if (!curr->left) {
                res.emplace_back(curr->val);
                prev = curr;
                curr = curr->right;
            } else {
                TreeNode *node = curr->left;
                while (node->right && node->right != curr) {
                    node = node->right;
                }
                if (!node->right) {
                    node->right = curr;
                    curr = curr->left;
                } else {
                    res.emplace_back(curr->val);
                    prev = curr;
                    node->right = nullptr;
                    curr = curr->right;
                }
            }
        }
        return res;
    }
};

// Time:  O(n)
// Space: O(h)
// Stack solution.
class Solution2 {
    /**
     * @param root: The root of binary tree.
     * @return: Inorder in vector which contains node values.
     */
public:
    vector<int> inorderTraversal(TreeNode *root) {
        vector<int> res;
        stack<pair<TreeNode *, bool>> s;
        s.emplace(root, false);
        bool visited;
        while (!s.empty()) {
            tie(root, visited) = s.top();
            s.pop();
            if (root == nullptr) {
                continue;
            }
            if (visited) {
                res.emplace_back(root->val);
            } else {
                s.emplace(root->right, false);
                s.emplace(root, true);
                s.emplace(root->left, false);
            }
        }
        return res;
    }
};
<commit_msg>Update binary-tree-inorder-traversal.cpp<commit_after>// Time:  O(n)
// Space: O(1)

/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
// Morris Traversal.
class Solution {
    /**
     * @param root: The root of binary tree.
     * @return: Inorder in vector which contains node values.
     */
public:
    vector<int> inorderTraversal(TreeNode *root) {
        vector<int> res;
        TreeNode *prev = nullptr;
        TreeNode *curr = root;
        while (curr) {
            if (!curr->left) {
                res.emplace_back(curr->val);
                prev = curr;
                curr = curr->right;
            } else {
                TreeNode *node = curr->left;
                while (node->right && node->right != curr) {
                    node = node->right;
                }
                if (!node->right) {
                    node->right = curr;
                    curr = curr->left;
                } else {
                    res.emplace_back(curr->val);
                    prev = curr;
                    node->right = nullptr;
                    curr = curr->right;
                }
            }
        }
        return res;
    }
};

// Time:  O(n)
// Space: O(h)
// Stack solution.
class Solution2 {
    /**
     * @param root: The root of binary tree.
     * @return: Inorder in vector which contains node values.
     */
public:
    vector<int> inorderTraversal(TreeNode *root) {
        vector<int> res;
        stack<pair<TreeNode *, bool>> s;
        s.emplace(root, false);
        while (!s.empty()) {
            bool visited;
            tie(root, visited) = s.top();
            s.pop();
            if (root == nullptr) {
                continue;
            }
            if (visited) {
                res.emplace_back(root->val);
            } else {
                s.emplace(root->right, false);
                s.emplace(root, true);
                s.emplace(root->left, false);
            }
        }
        return res;
    }
};
<|endoftext|>


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

#ifndef SC_HDRCONT_HXX
#define SC_HDRCONT_HXX

#ifndef _WINDOW_HXX //autogen
#include <vcl/window.hxx>
#endif
#ifndef _SELENG_HXX //autogen
#include <vcl/seleng.hxx>
#endif

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

#define HDR_HORIZONTAL      0
#define HDR_VERTICAL        1

#define HDR_SIZE_OPTIMUM    0xFFFF

                                    // Groesse des Sliders
#define HDR_SLIDERSIZE      2

class ScHeaderControl : public Window
{
private:
    SelectionEngine*    pSelEngine;
    Font                aNormFont;
    Font                aBoldFont;
    BOOL                bBoldSet;

    USHORT          nFlags;
    BOOL            bVertical;              // Vertikal = Zeilenheader

    long            nWidth;
    long            nSmallWidth;
    long            nBigWidth;

    USHORT          nSize;

    USHORT          nMarkStart;
    USHORT          nMarkEnd;
    BOOL            bMarkRange;

    BOOL            bDragging;              // Groessen aendern
    USHORT          nDragNo;
    long            nDragStart;
    long            nDragPos;
    BOOL            bDragMoved;

    BOOL            bIgnoreMove;

    long            GetScrPos( USHORT nEntryNo );
    USHORT          GetMousePos( const MouseEvent& rMEvt, BOOL& rBorder );

    void            ShowDragHelp();

    void            DoPaint( USHORT nStart, USHORT nEnd );

protected:
                    //  von Window ueberladen

    virtual void    Paint( const Rectangle& rRect );

    virtual void    MouseMove( const MouseEvent& rMEvt );
    virtual void    MouseButtonUp( const MouseEvent& rMEvt );
    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
    virtual void    Tracking( const TrackingEvent& rTEvt );

    virtual void    RequestHelp( const HelpEvent& rHEvt );

                    //  neue Methoden

    virtual USHORT  GetPos() = 0;                               // aktuelle Position (Scrolling)
    virtual USHORT  GetEntrySize( USHORT nEntryNo ) = 0;        // Breite / Hoehe (Pixel)
    virtual String  GetEntryText( USHORT nEntryNo ) = 0;

    virtual USHORT  GetHiddenCount( USHORT nEntryNo );
    virtual BOOL    IsLayoutRTL();
    virtual BOOL    IsMirrored();

    virtual void    SetEntrySize( USHORT nPos, USHORT nNewWidth ) = 0;
    virtual void    HideEntries( USHORT nStart, USHORT nEnd ) = 0;

    virtual void    SetMarking( BOOL bSet );
    virtual void    SelectWindow();
    virtual BOOL    IsDisabled();
    virtual BOOL    ResizeAllowed();
    virtual String  GetDragHelp( long nVal );

    virtual void    DrawInvert( long nDragPos );
    virtual void    Command( const CommandEvent& rCEvt );

public:
            ScHeaderControl( Window* pParent, SelectionEngine* pSelectionEngine,
                                USHORT nNewSize, USHORT nNewFlags );
            ~ScHeaderControl();

    void    SetIgnoreMove(BOOL bSet)            { bIgnoreMove = bSet; }

    void    StopMarking();

    void    SetMark( BOOL bNewSet, USHORT nNewStart, USHORT nNewEnd );

    long    GetWidth() const                    { return nWidth; }
    long    GetSmallWidth() const               { return nSmallWidth; }
    long    GetBigWidth() const                 { return nBigWidth; }
    void    SetWidth( long nNew );
};

#endif

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

#ifndef SC_HDRCONT_HXX
#define SC_HDRCONT_HXX

#ifndef _WINDOW_HXX //autogen
#include <vcl/window.hxx>
#endif
#ifndef _SELENG_HXX //autogen
#include <vcl/seleng.hxx>
#endif
#ifndef SC_ADDRESS_HXX
#include "address.hxx"
#endif

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

#define HDR_HORIZONTAL      0
#define HDR_VERTICAL        1

#define HDR_SIZE_OPTIMUM    0xFFFF

                                    // Groesse des Sliders
#define HDR_SLIDERSIZE      2

class ScHeaderControl : public Window
{
private:
    SelectionEngine*    pSelEngine;
    Font                aNormFont;
    Font                aBoldFont;
    BOOL                bBoldSet;

    USHORT          nFlags;
    BOOL            bVertical;              // Vertikal = Zeilenheader

    long            nWidth;
    long            nSmallWidth;
    long            nBigWidth;

    SCCOLROW        nSize;

    SCCOLROW        nMarkStart;
    SCCOLROW        nMarkEnd;
    BOOL            bMarkRange;

    BOOL            bDragging;              // Groessen aendern
    SCCOLROW        nDragNo;
    long            nDragStart;
    long            nDragPos;
    BOOL            bDragMoved;

    BOOL            bIgnoreMove;

    long            GetScrPos( SCCOLROW nEntryNo );
    SCCOLROW        GetMousePos( const MouseEvent& rMEvt, BOOL& rBorder );

    void            ShowDragHelp();

    void            DoPaint( SCCOLROW nStart, SCCOLROW nEnd );

protected:
                    //  von Window ueberladen

    virtual void    Paint( const Rectangle& rRect );

    virtual void    MouseMove( const MouseEvent& rMEvt );
    virtual void    MouseButtonUp( const MouseEvent& rMEvt );
    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
    virtual void    Tracking( const TrackingEvent& rTEvt );

    virtual void    RequestHelp( const HelpEvent& rHEvt );

                    //  neue Methoden

    virtual SCCOLROW    GetPos() = 0;                               // aktuelle Position (Scrolling)
    virtual USHORT  GetEntrySize( SCCOLROW nEntryNo ) = 0;      // Breite / Hoehe (Pixel)
    virtual String  GetEntryText( SCCOLROW nEntryNo ) = 0;

    virtual SCCOLROW GetHiddenCount( SCCOLROW nEntryNo );
    virtual BOOL    IsLayoutRTL();
    virtual BOOL    IsMirrored();

    virtual void    SetEntrySize( SCCOLROW nPos, USHORT nNewWidth ) = 0;
    virtual void    HideEntries( SCCOLROW nStart, SCCOLROW nEnd ) = 0;

    virtual void    SetMarking( BOOL bSet );
    virtual void    SelectWindow();
    virtual BOOL    IsDisabled();
    virtual BOOL    ResizeAllowed();
    virtual String  GetDragHelp( long nVal );

    virtual void    DrawInvert( long nDragPos );
    virtual void    Command( const CommandEvent& rCEvt );

public:
            ScHeaderControl( Window* pParent, SelectionEngine* pSelectionEngine,
                                SCCOLROW nNewSize, USHORT nNewFlags );
            ~ScHeaderControl();

    void    SetIgnoreMove(BOOL bSet)            { bIgnoreMove = bSet; }

    void    StopMarking();

    void    SetMark( BOOL bNewSet, SCCOLROW nNewStart, SCCOLROW nNewEnd );

    long    GetWidth() const                    { return nWidth; }
    long    GetSmallWidth() const               { return nSmallWidth; }
    long    GetBigWidth() const                 { return nBigWidth; }
    void    SetWidth( long nNew );
};

#endif

<|endoftext|>


<commit_before>#include "kclinput.h"

#include "kclinputevent.h"
#include "kclthread.h"

#include <KDebug>
#include <QApplication>
#include <QFile>
#include <QMessageBox>
#include <QMouseEvent>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x)  ((x)%BITS_PER_LONG)
#define BIT(x)  (1UL<<OFF(x))
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)

KCLInput::KCLInput(const QString& devicePath, QObject * parent)
    : QObject(parent)
{
    m_error = false;
    m_enable = true;
    m_absMove  = false;
    m_relMove = false;
    m_lastAbsAxis = 0;
    m_lastRelAxis = 0;
    m_msgError = QString();
    m_devicePath = devicePath;
    m_deviceName = "no name";
    readInformation();
    inputListener = new KCLThread(m_devicePath, this);
}

KCLInput::~KCLInput()
{
    setDisable();
    delete inputListener;
    kDebug() << "Closed device :" << deviceName();
}

bool KCLInput::event(QEvent * evt)
{

    KCLInputEvent * event = (KCLInputEvent*)evt;
    emit eventSent(event);

    switch (event->type()) {
    case KCL::Key:

        if (event->value() == 1) { // if click
            m_buttons.append(event->code());
            emit buttonPressed(event->code());
              emit pressed();
        }

        if (event->value() == 0) { //if release
            m_buttons.removeOne(event->code());
            emit buttonReleased(event->code());
        }
        return true;
        break;

    case KCL::RelativeAxis:
        emit moved();
        m_relMove = true;
        m_lastRelAxis = event->code();
        m_relAxis[event->code()] = event->value();
        emit relAxisChanged(event->code(), event->value());
        return true;
        break;

    case KCL::AbsoluAxis:
        emit moved();
        m_absMove = true;
        m_lastAbsAxis = event->code();
        m_absAxis[event->code()] = event->value();
        emit absAxisChanged(event->code(), event->value());
        return true;
        break;

    default:break;
    }
    return QObject::event(evt);
}

void KCLInput::readInformation()
{
    if (!QFile::exists(m_devicePath)) {
        kDebug() << "m_devicePath does not exist";
        m_error = true;
        m_msgError += "device url does not exist \n";
        return;
    }

    int m_fd = -1;
    if ((m_fd = open(m_devicePath.toUtf8(), O_RDONLY)) < 0) {
        kDebug() << "Could not open device" << m_devicePath;
        m_error = true;
        m_msgError += "could not open the device \n";
        return;
    }

    if (ioctl(m_fd, EVIOCGID, &m_device_info)) {
        kDebug() << "Could not retrieve information of device" << m_devicePath;
        m_msgError += "could not retrieve information of device\n";
        m_error = true;
        return;
    }

    char name[256] = "Unknown";
    if (ioctl(m_fd, EVIOCGNAME(sizeof(name)), name) < 0) {
        kDebug() << "could not retrieve name of device" << m_devicePath;
        //        m_msgError += "cannot retrieve name of device\n";
        //        m_error = true;
    }

    m_deviceName = QString(name);

    unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
    int abs[5];
    memset(bit, 0, sizeof(bit));
    ioctl(m_fd, EVIOCGBIT(0, EV_MAX), bit[0]);

    m_buttonCapabilities.clear();
    m_absAxisInfos.clear();

    for (int i = 0; i < EV_MAX; i++) {
        if (test_bit(i, bit[0])) {
            if (!i) {
                continue;
            }

            ioctl(m_fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
            for (int j = 0; j < KEY_MAX; j++) {
                if (test_bit(j, bit[i])) {
                    if (i == EV_KEY) {
                        m_buttonCapabilities.append(j);
                    }

                    if (i == EV_REL) {
                        m_relAxisCapabilities.append(j);
                    }

                    if (i == EV_ABS) {
                        ioctl(m_fd, EVIOCGABS(j), abs);
                        AbsVal cabs(0, 0, 0, 0);
                        for (int k = 0; k < 5; k++) {
                            if ((k < 3) || abs[k]) {
                                switch (k) {
                                case 0:
                                    cabs.value = abs[k];
                                    break;
                                case 1:
                                    cabs.min = abs[k];
                                    break;
                                case 2:
                                    cabs.max = abs[k];
                                    break;
                                case 3:
                                    cabs.fuzz = abs[k];
                                    break;
                                case 4:
                                    cabs.flat = abs[k];
                                    break;
                                }
                            }
                        }
                        m_absAxisCapabilities.append(j);
                        m_absAxisInfos[j] = cabs;
                    }
                }
            }
        }
    }

    //===============Find Force feedback ?? ===============

    close(m_fd);

    m_deviceType = KCL::Unknown;

    if (m_buttonCapabilities.contains(BTN_STYLUS)) {
        m_deviceType  = KCL::Tablet;
    }

    if (m_buttonCapabilities.contains(BTN_STYLUS)
        || m_buttonCapabilities.contains(ABS_PRESSURE)) {
        m_deviceType  = KCL::Mouse;
    }

    if (m_buttonCapabilities.contains(BTN_TRIGGER)) {
        m_deviceType  = KCL::Joystick;
    }

    if (m_buttonCapabilities.contains(BTN_MOUSE)) {
        m_deviceType  = KCL::Mouse;
    }

    if (m_buttonCapabilities.contains(KEY_ESC)) {
        m_deviceType  = KCL::KeyBoard;
    }
}

void KCLInput::setEnable()
{
    m_enable = true;
    if (!error()) {
        inputListener = new KCLThread(m_devicePath, this);
        inputListener->start();
    }
}

void KCLInput::setDisable()
{
    m_enable = false;
    m_buttons.clear();
    m_relAxis.clear();
    m_absAxis.clear();
    m_relMove = false;
    m_absMove = false;
    inputListener->terminate();
}
<commit_msg>fix a leak regarding kclthread handling<commit_after>#include "kclinput.h"

#include "kclinputevent.h"
#include "kclthread.h"

#include <KDebug>
#include <QApplication>
#include <QFile>
#include <QMessageBox>
#include <QMouseEvent>

#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x)  ((x)%BITS_PER_LONG)
#define BIT(x)  (1UL<<OFF(x))
#define LONG(x) ((x)/BITS_PER_LONG)
#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)

KCLInput::KCLInput(const QString& devicePath, QObject * parent)
    : QObject(parent)
{
    m_error = false;
    m_enable = true;
    m_absMove  = false;
    m_relMove = false;
    m_lastAbsAxis = 0;
    m_lastRelAxis = 0;
    m_msgError = QString();
    m_devicePath = devicePath;
    m_deviceName = "no name";
    readInformation();
    inputListener = NULL;
}

KCLInput::~KCLInput()
{
    setDisable();
    kDebug() << "Closed device :" << deviceName();
}

bool KCLInput::event(QEvent * evt)
{

    KCLInputEvent * event = (KCLInputEvent*)evt;
    emit eventSent(event);

    switch (event->type()) {
    case KCL::Key:

        if (event->value() == 1) { // if click
            m_buttons.append(event->code());
            emit buttonPressed(event->code());
              emit pressed();
        }

        if (event->value() == 0) { //if release
            m_buttons.removeOne(event->code());
            emit buttonReleased(event->code());
        }
        return true;
        break;

    case KCL::RelativeAxis:
        emit moved();
        m_relMove = true;
        m_lastRelAxis = event->code();
        m_relAxis[event->code()] = event->value();
        emit relAxisChanged(event->code(), event->value());
        return true;
        break;

    case KCL::AbsoluAxis:
        emit moved();
        m_absMove = true;
        m_lastAbsAxis = event->code();
        m_absAxis[event->code()] = event->value();
        emit absAxisChanged(event->code(), event->value());
        return true;
        break;

    default:break;
    }
    return QObject::event(evt);
}

void KCLInput::readInformation()
{
    if (!QFile::exists(m_devicePath)) {
        kDebug() << "m_devicePath does not exist";
        m_error = true;
        m_msgError += "device url does not exist \n";
        return;
    }

    int m_fd = -1;
    if ((m_fd = open(m_devicePath.toUtf8(), O_RDONLY)) < 0) {
        kDebug() << "Could not open device" << m_devicePath;
        m_error = true;
        m_msgError += "could not open the device \n";
        return;
    }

    if (ioctl(m_fd, EVIOCGID, &m_device_info)) {
        kDebug() << "Could not retrieve information of device" << m_devicePath;
        m_msgError += "could not retrieve information of device\n";
        m_error = true;
        return;
    }

    char name[256] = "Unknown";
    if (ioctl(m_fd, EVIOCGNAME(sizeof(name)), name) < 0) {
        kDebug() << "could not retrieve name of device" << m_devicePath;
        //        m_msgError += "cannot retrieve name of device\n";
        //        m_error = true;
    }

    m_deviceName = QString(name);

    unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
    int abs[5];
    memset(bit, 0, sizeof(bit));
    ioctl(m_fd, EVIOCGBIT(0, EV_MAX), bit[0]);

    m_buttonCapabilities.clear();
    m_absAxisInfos.clear();

    for (int i = 0; i < EV_MAX; i++) {
        if (test_bit(i, bit[0])) {
            if (!i) {
                continue;
            }

            ioctl(m_fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
            for (int j = 0; j < KEY_MAX; j++) {
                if (test_bit(j, bit[i])) {
                    if (i == EV_KEY) {
                        m_buttonCapabilities.append(j);
                    }

                    if (i == EV_REL) {
                        m_relAxisCapabilities.append(j);
                    }

                    if (i == EV_ABS) {
                        ioctl(m_fd, EVIOCGABS(j), abs);
                        AbsVal cabs(0, 0, 0, 0);
                        for (int k = 0; k < 5; k++) {
                            if ((k < 3) || abs[k]) {
                                switch (k) {
                                case 0:
                                    cabs.value = abs[k];
                                    break;
                                case 1:
                                    cabs.min = abs[k];
                                    break;
                                case 2:
                                    cabs.max = abs[k];
                                    break;
                                case 3:
                                    cabs.fuzz = abs[k];
                                    break;
                                case 4:
                                    cabs.flat = abs[k];
                                    break;
                                }
                            }
                        }
                        m_absAxisCapabilities.append(j);
                        m_absAxisInfos[j] = cabs;
                    }
                }
            }
        }
    }

    //===============Find Force feedback ?? ===============

    close(m_fd);

    m_deviceType = KCL::Unknown;

    if (m_buttonCapabilities.contains(BTN_STYLUS)) {
        m_deviceType  = KCL::Tablet;
    }

    if (m_buttonCapabilities.contains(BTN_STYLUS)
        || m_buttonCapabilities.contains(ABS_PRESSURE)) {
        m_deviceType  = KCL::Mouse;
    }

    if (m_buttonCapabilities.contains(BTN_TRIGGER)) {
        m_deviceType  = KCL::Joystick;
    }

    if (m_buttonCapabilities.contains(BTN_MOUSE)) {
        m_deviceType  = KCL::Mouse;
    }

    if (m_buttonCapabilities.contains(KEY_ESC)) {
        m_deviceType  = KCL::KeyBoard;
    }
}

void KCLInput::setEnable()
{
    setDisable();
    m_enable = true;
    if (!error()) {
        inputListener = new KCLThread(m_devicePath, this);
        inputListener->start();
    }
}

void KCLInput::setDisable()
{
    m_enable = false;
    m_buttons.clear();
    m_relAxis.clear();
    m_absAxis.clear();
    m_relMove = false;
    m_absMove = false;
    if (inputListener) {
        inputListener->terminate();
        delete inputListener;
    }
}
<|endoftext|>


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

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

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

#define _BIGINT_HXX
#define _CACHESTR_HXX
#define _CONFIG_HXX
#define _CURSOR_HXX
#define _CTRLTOOL_HXX
#define _DLGCFG_HXX
#define _DYNARR_HXX
#define _EXTATTR_HXX
#define _FILDLG_HXX
#define _FONTDLG_HXX
#define _FRM3D_HXX
#define _INTRO_HXX
#define _ISETBWR_HXX
#define _NO_SVRTF_PARSER_HXX
#define _MACRODLG_HXX
#define _MODALDLG_HXX
#define _MOREBUTTON_HXX
#define _OUTLINER_HXX
#define _PASSWD_HXX
#define _PRNDLG_HXX
//#define _POLY_HXX
#define _PVRWIN_HXX
#define _QUEUE_HXX
#define _RULER_HXX
#define _SCRWIN_HXX
#define _SETBRW_HXX
#define _STACK_HXX
//#define _STATUS_HXX ***
#define _STDMENU_HXX
#define _TABBAR_HXX
//#define _VCBRW_HXX
#define _VCTRLS_HXX
//#define _VCSBX_HXX
#define _VCONT_HXX
#define _VDRWOBJ_HXX

//sfx
#define _SFXAPPWIN_HXX
#define _SFXCTRLITEM
#define _SFXDISPATCH_HXX
#define _SFXFILEDLG_HXX
#define _SFXIMGMGR_HXX
#define _SFXIPFRM_HXX
#define _SFX_MACRO_HXX
#define _SFXMULTISEL_HXX
#define _SFX_MINFITEM_HXX

//sfxcore.hxx
//#define _SFXINIMGR_HXX ***
//#define _SFXCFGITEM_HXX
//#define _SFX_PRINTER_HXX
#define _SFXGENLINK_HXX
#define _SFXHINTPOST_HXX
#define _SFXDOCINF_HXX
#define _SFXLINKHDL_HXX
//#define _SFX_PROGRESS_HXX

//sfxsh.hxx
//#define _SFX_SHELL_HXX
//#define _SFXAPP_HXX
//#define _SFXDISPATCH_HXX
//#define _SFXMSG_HXX ***
//#define _SFXOBJFACE_HXX ***
//#define _SFXREQUEST_HXX
#define _SFXMACRO_HXX

// SFX
//#define _SFXAPPWIN_HXX ***
#define _SFX_SAVEOPT_HXX
//#define _SFX_CHILDWIN_HXX
//#define _SFXCTRLITEM_HXX
#define _SFXPRNMON_HXX
#define _INTRO_HXX
#define _SFXMSGDESCR_HXX
#define _SFXMSGPOOL_HXX
#define _SFXFILEDLG_HXX
#define _PASSWD_HXX
#define _SFXTBXCTRL_HXX
#define _SFXSTBITEM_HXX
#define _SFXMNUITEM_HXX
#define _SFXIMGMGR_HXX
#define _SFXTBXMGR_HXX
#define _SFXSTBMGR_HXX
#define _SFX_MINFITEM_HXX
#define _SFXEVENT_HXX

//sfxdoc.hxx
//#define _SFX_OBJSH_HXX
//#define _SFX_CLIENTSH_HXX
//#define _SFXDOCINF_HXX
//#define _SFX_OBJFAC_HXX
#define _SFX_DOCFILT_HXX
//#define _SFXDOCFILE_HXX ***
//define _VIEWFAC_HXX
//#define _SFXVIEWFRM_HXX
//#define _SFXVIEWSH_HXX
//#define _MDIFRM_HXX ***
#define _SFX_IPFRM_HXX
//#define _SFX_INTERNO_HXX

//sfxdlg.hxx
//#define _SFXTABDLG_HXX
//#define _BASEDLGS_HXX ***
#define _SFX_DINFDLG_HXX
#define _SFXDINFEDT_HXX
#define _SFX_MGETEMPL_HXX
#define _SFX_TPLPITEM_HXX
//#define _SFX_STYLEDLG_HXX
#define _NEWSTYLE_HXX
//#define _SFXDOCTEMPL_HXX ***
//#define _SFXDOCTDLG_HXX ***
//#define _SFX_TEMPLDLG_HXX ***
//#define _SFXNEW_HXX ***
#define _SFXDOCMAN_HXX
//#define _SFXDOCKWIN_HXX

//sfxitems.hxx
#define _SFX_WHMAP_HXX
#define _ARGS_HXX
//#define _SFXPOOLITEM_HXX
//#define _SFXINTITEM_HXX
//#define _SFXENUMITEM_HXX
#define _SFXFLAGITEM_HXX
//#define _SFXSTRITEM_HXX
#define _SFXPTITEM_HXX
#define _SFXRECTITEM_HXX
//#define _SFXITEMPOOL_HXX
//#define _SFXITEMSET_HXX
#define _SFXITEMITER_HXX
#define _SFX_WHITER_HXX
#define _SFXPOOLCACH_HXX
//#define _AEITEM_HXX
#define _SFXRNGITEM_HXX
//#define _SFXSLSTITM_HXX
//#define _SFXSTYLE_HXX

//xout.hxx
//#define _XENUM_HXX
//#define _XPOLY_HXX
//#define _XATTR_HXX
//#define _XOUTX_HXX
//#define _XPOOL_HXX
//#define _XTABLE_HXX

//svdraw.hxx
#define _SDR_NOITEMS
#define _SDR_NOTOUCH
#define _SDR_NOTRANSFORM
//#define _SDR_NOOBJECTS
//#define _SDR_NOVIEWS

#define _SFXBASIC_HXX
#define _SFX_DOCFILE_HXX
#define _SFX_DOCFILT_HXX
#define _SFX_DOCINF_HXX
#define _SFX_DOCSH_HXX
#define _SFX_TEMPLDLG_HXX
#define _SFXSTBMGR_HXX
#define _SFXTBXMGR_HXX
#define _SFXIMGMGR_HXX
#define _SFXMNUITEM_HXX
#define _SFXMNUMGR_HXX
#define _SFXSTBITEM_HXX
#define _SFXTBXCTRL_HXX
#define _SFXFILEDLG_HXX
#define _SFXREQUEST_HXX
#define _SFXOBJFACE_HXX
#define _SFXMSGPOOL_HXX
#define _SFXMSGDESCR_HXX
#define _SFXMSG_HXX
#define _SFX_PRNMON_HXX

//si
#define _SI_NOSBXCONTROLS
#define _SI_NOCONTROL
//#define SI_NOITEMS
//#define SI_NODRW
//#define SI_NOOTHERFORMS
#define _SIDLL_HXX
//#define _VCSBX_HXX
//#define _VCBRW_HXX

//#define _SVDATTR_HXX      <--- der wars
#define _SVDXOUT_HXX
#define _SVDEC_HXX
//#define _SVDIO_HXX
//#define _SVDLAYER_HXX
//#define _SVDRAG_HXX
#define _SVINCVW_HXX
#define _SV_MULTISEL_HXX
#define _SVRTV_HXX
#define _SVTABBX_HXX

#define _SVX_DAILDLL_HXX
#define _SVX_HYPHEN_HXX
#define _SVX_IMPGRF_HXX
#define _SVX_OPTITEMS_HXX
#define _SVX_OPTGERL_HXX
#define _SVX_OPTSAVE_HXX
#define _SVX_OPTSPELL_HXX
#define _SVX_OPTPATH_HXX
#define _SVX_OPTLINGU_HXX
#define _SVX_RULER_HXX
#define _SVX_RULRITEM_HXX
#define _SVX_SPLWRAP_HXX
#define _SVX_SPLDLG_HXX
#define _SVX_THESDLG_HXX

// INCLUDE ---------------------------------------------------------------

#include <sfx2/childwin.hxx>
#include <sfx2/objsh.hxx>

#include "document.hxx"
#include "viewdata.hxx"
#include "drawview.hxx"
#include "drawpage.hxx"
#include "drwlayer.hxx"

// STATIC DATA -----------------------------------------------------------

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

void ActivateOlk( ScViewData* pViewData )
{
    // Browser fuer Virtual Controls fuellen
    //  VC's und den Browser dazu gibts nicht mehr...

    //  GetSbxForm gibt's nicht mehr, muss auch nichts mehr angemeldet werden
}

void DeActivateOlk( ScViewData* pViewData )
{
    // Browser fuer Virtual Controls fuellen
    //  VC's und den Browser dazu gibts nicht mehr...

    //  GetSbxForm gibt's nicht mehr, muss auch nichts mehr angemeldet werden
}

<commit_msg>INTEGRATION: CWS ooo19126 (1.4.798); FILE MERGED 2005/09/05 15:09:34 rt 1.4.798.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: olkact.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 23:01:20 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifdef PCH
#include "ui_pch.hxx"
#endif

#pragma hdrstop

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

#define _BIGINT_HXX
#define _CACHESTR_HXX
#define _CONFIG_HXX
#define _CURSOR_HXX
#define _CTRLTOOL_HXX
#define _DLGCFG_HXX
#define _DYNARR_HXX
#define _EXTATTR_HXX
#define _FILDLG_HXX
#define _FONTDLG_HXX
#define _FRM3D_HXX
#define _INTRO_HXX
#define _ISETBWR_HXX
#define _NO_SVRTF_PARSER_HXX
#define _MACRODLG_HXX
#define _MODALDLG_HXX
#define _MOREBUTTON_HXX
#define _OUTLINER_HXX
#define _PASSWD_HXX
#define _PRNDLG_HXX
//#define _POLY_HXX
#define _PVRWIN_HXX
#define _QUEUE_HXX
#define _RULER_HXX
#define _SCRWIN_HXX
#define _SETBRW_HXX
#define _STACK_HXX
//#define _STATUS_HXX ***
#define _STDMENU_HXX
#define _TABBAR_HXX
//#define _VCBRW_HXX
#define _VCTRLS_HXX
//#define _VCSBX_HXX
#define _VCONT_HXX
#define _VDRWOBJ_HXX

//sfx
#define _SFXAPPWIN_HXX
#define _SFXCTRLITEM
#define _SFXDISPATCH_HXX
#define _SFXFILEDLG_HXX
#define _SFXIMGMGR_HXX
#define _SFXIPFRM_HXX
#define _SFX_MACRO_HXX
#define _SFXMULTISEL_HXX
#define _SFX_MINFITEM_HXX

//sfxcore.hxx
//#define _SFXINIMGR_HXX ***
//#define _SFXCFGITEM_HXX
//#define _SFX_PRINTER_HXX
#define _SFXGENLINK_HXX
#define _SFXHINTPOST_HXX
#define _SFXDOCINF_HXX
#define _SFXLINKHDL_HXX
//#define _SFX_PROGRESS_HXX

//sfxsh.hxx
//#define _SFX_SHELL_HXX
//#define _SFXAPP_HXX
//#define _SFXDISPATCH_HXX
//#define _SFXMSG_HXX ***
//#define _SFXOBJFACE_HXX ***
//#define _SFXREQUEST_HXX
#define _SFXMACRO_HXX

// SFX
//#define _SFXAPPWIN_HXX ***
#define _SFX_SAVEOPT_HXX
//#define _SFX_CHILDWIN_HXX
//#define _SFXCTRLITEM_HXX
#define _SFXPRNMON_HXX
#define _INTRO_HXX
#define _SFXMSGDESCR_HXX
#define _SFXMSGPOOL_HXX
#define _SFXFILEDLG_HXX
#define _PASSWD_HXX
#define _SFXTBXCTRL_HXX
#define _SFXSTBITEM_HXX
#define _SFXMNUITEM_HXX
#define _SFXIMGMGR_HXX
#define _SFXTBXMGR_HXX
#define _SFXSTBMGR_HXX
#define _SFX_MINFITEM_HXX
#define _SFXEVENT_HXX

//sfxdoc.hxx
//#define _SFX_OBJSH_HXX
//#define _SFX_CLIENTSH_HXX
//#define _SFXDOCINF_HXX
//#define _SFX_OBJFAC_HXX
#define _SFX_DOCFILT_HXX
//#define _SFXDOCFILE_HXX ***
//define _VIEWFAC_HXX
//#define _SFXVIEWFRM_HXX
//#define _SFXVIEWSH_HXX
//#define _MDIFRM_HXX ***
#define _SFX_IPFRM_HXX
//#define _SFX_INTERNO_HXX

//sfxdlg.hxx
//#define _SFXTABDLG_HXX
//#define _BASEDLGS_HXX ***
#define _SFX_DINFDLG_HXX
#define _SFXDINFEDT_HXX
#define _SFX_MGETEMPL_HXX
#define _SFX_TPLPITEM_HXX
//#define _SFX_STYLEDLG_HXX
#define _NEWSTYLE_HXX
//#define _SFXDOCTEMPL_HXX ***
//#define _SFXDOCTDLG_HXX ***
//#define _SFX_TEMPLDLG_HXX ***
//#define _SFXNEW_HXX ***
#define _SFXDOCMAN_HXX
//#define _SFXDOCKWIN_HXX

//sfxitems.hxx
#define _SFX_WHMAP_HXX
#define _ARGS_HXX
//#define _SFXPOOLITEM_HXX
//#define _SFXINTITEM_HXX
//#define _SFXENUMITEM_HXX
#define _SFXFLAGITEM_HXX
//#define _SFXSTRITEM_HXX
#define _SFXPTITEM_HXX
#define _SFXRECTITEM_HXX
//#define _SFXITEMPOOL_HXX
//#define _SFXITEMSET_HXX
#define _SFXITEMITER_HXX
#define _SFX_WHITER_HXX
#define _SFXPOOLCACH_HXX
//#define _AEITEM_HXX
#define _SFXRNGITEM_HXX
//#define _SFXSLSTITM_HXX
//#define _SFXSTYLE_HXX

//xout.hxx
//#define _XENUM_HXX
//#define _XPOLY_HXX
//#define _XATTR_HXX
//#define _XOUTX_HXX
//#define _XPOOL_HXX
//#define _XTABLE_HXX

//svdraw.hxx
#define _SDR_NOITEMS
#define _SDR_NOTOUCH
#define _SDR_NOTRANSFORM
//#define _SDR_NOOBJECTS
//#define _SDR_NOVIEWS

#define _SFXBASIC_HXX
#define _SFX_DOCFILE_HXX
#define _SFX_DOCFILT_HXX
#define _SFX_DOCINF_HXX
#define _SFX_DOCSH_HXX
#define _SFX_TEMPLDLG_HXX
#define _SFXSTBMGR_HXX
#define _SFXTBXMGR_HXX
#define _SFXIMGMGR_HXX
#define _SFXMNUITEM_HXX
#define _SFXMNUMGR_HXX
#define _SFXSTBITEM_HXX
#define _SFXTBXCTRL_HXX
#define _SFXFILEDLG_HXX
#define _SFXREQUEST_HXX
#define _SFXOBJFACE_HXX
#define _SFXMSGPOOL_HXX
#define _SFXMSGDESCR_HXX
#define _SFXMSG_HXX
#define _SFX_PRNMON_HXX

//si
#define _SI_NOSBXCONTROLS
#define _SI_NOCONTROL
//#define SI_NOITEMS
//#define SI_NODRW
//#define SI_NOOTHERFORMS
#define _SIDLL_HXX
//#define _VCSBX_HXX
//#define _VCBRW_HXX

//#define _SVDATTR_HXX      <--- der wars
#define _SVDXOUT_HXX
#define _SVDEC_HXX
//#define _SVDIO_HXX
//#define _SVDLAYER_HXX
//#define _SVDRAG_HXX
#define _SVINCVW_HXX
#define _SV_MULTISEL_HXX
#define _SVRTV_HXX
#define _SVTABBX_HXX

#define _SVX_DAILDLL_HXX
#define _SVX_HYPHEN_HXX
#define _SVX_IMPGRF_HXX
#define _SVX_OPTITEMS_HXX
#define _SVX_OPTGERL_HXX
#define _SVX_OPTSAVE_HXX
#define _SVX_OPTSPELL_HXX
#define _SVX_OPTPATH_HXX
#define _SVX_OPTLINGU_HXX
#define _SVX_RULER_HXX
#define _SVX_RULRITEM_HXX
#define _SVX_SPLWRAP_HXX
#define _SVX_SPLDLG_HXX
#define _SVX_THESDLG_HXX

// INCLUDE ---------------------------------------------------------------

#include <sfx2/childwin.hxx>
#include <sfx2/objsh.hxx>

#include "document.hxx"
#include "viewdata.hxx"
#include "drawview.hxx"
#include "drawpage.hxx"
#include "drwlayer.hxx"

// STATIC DATA -----------------------------------------------------------

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

void ActivateOlk( ScViewData* pViewData )
{
    // Browser fuer Virtual Controls fuellen
    //  VC's und den Browser dazu gibts nicht mehr...

    //  GetSbxForm gibt's nicht mehr, muss auch nichts mehr angemeldet werden
}

void DeActivateOlk( ScViewData* pViewData )
{
    // Browser fuer Virtual Controls fuellen
    //  VC's und den Browser dazu gibts nicht mehr...

    //  GetSbxForm gibt's nicht mehr, muss auch nichts mehr angemeldet werden
}

<|endoftext|>


<commit_before>#include "application.h"

#include <QtQml>
#include <QScreen>
#include <QKeyEvent>
#include <QQuickView>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>
#include <QFontDatabase>
#include <QFile>
#include <QWeakPointer>

#include "imageprovider.h"

#include "quick/enums.h"
#include "quick/models.h"
#include "quick/quicktrackinfo.h"
#include "quick/quickmosaicgenerator.h"
#include "quick/quickfactory.h"
#include "quick/quickartistsynopsis.h"
#include "quick/quickglobalstatemachine.h"

#include "../../appkey.c"

namespace sp = Spotinetta;

namespace {
// This global is unfortunately necessary for the Qt Quick models
// to retrieve the current session
QWeakPointer<Spotinetta::Session> g_session;
}

namespace Sonetta {

Application::Application(QObject * parent)
    :   QObject(parent),
      m_view(new QQuickView),
      m_ui(new UIStateCoordinator),
      m_output(new AudioOutput),
      m_settings(new Settings),
      m_exiting(false)
{
    createSession();

    m_player.reset(new Player(m_session, m_output));
    m_search.reset(new SearchEngine(m_session.constCast<const sp::Session>(), m_settings));
    m_collection.reset(new LibraryCollection(m_session.constCast<const sp::Session>(), this));

    connect(m_session.data(), &sp::Session::loggedOut, this, &Application::onLogout);
    connect(m_session.data(), &sp::Session::log, [] (const QString &msg) { qDebug() << msg; });

    connect(m_settings.data(), &Settings::mouseEnabledChanged, this, &Application::updateCursor);

    m_view->installEventFilter(this);
}

Application::~Application()
{
    // Manually reset view here to make sure it's deleted
    // before any of the others (Player, SearchEngine etc.)
    m_view.reset();
}

bool Application::initialize()
{
    registerQmlTypes();

    // Enable mouse
    m_settings->setMouseEnabled(true);

    if (m_session->error() == sp::Error::Ok)
    {
        m_navigation.initialize(m_settings->lircDelay());

        setupQuickEnvironment();
        showUi();
        return true;
    }
    else
    {
        const QByteArray error = sp::errorMessage(m_session->error()).toUtf8();
        qFatal("Session creation failed. Error: %s", error.constData());
        return false;
    }
}

void Application::onExit()
{
    if (!m_exiting)
    {
        m_exiting = true;
        if (m_session->connectionState() == sp::Session::ConnectionState::LoggedIn
                || m_session->connectionState() == sp::Session::ConnectionState::Offline)
        {
            m_session->logout();
        }
        else
        {
            // Skip session logout
            onLogout();
        }
    }
}

void Application::onLogout()
{
    if (m_exiting)
    {
        QCoreApplication::quit();
    }
}

void Application::updateCursor()
{
    if (m_view.isNull())
        return;

    if (m_settings->mouseEnabled())
    {
        m_view->unsetCursor();
    }
    else
    {
        m_view->setCursor(QCursor(Qt::BlankCursor));
    }
}

ObjectSharedPointer<sp::Session> Application::session()
{
    return ObjectSharedPointer<sp::Session>(g_session.toStrongRef());
}

bool Application::eventFilter(QObject * obj, QEvent * e)
{
    Q_UNUSED(obj);
    Q_ASSERT(obj == m_view.data());

    switch (e->type())
    {
    case QEvent::Close:
        onExit();
        return true;
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseMove:
    case QEvent::MouseTrackingChange:
        if (!m_settings->mouseEnabled())
            return true;
    default:
        return false;
    }
}

void Application::registerQmlTypes()
{
    Navigation::registerTypes();

    qmlRegisterType<QuickPlaylistContainerModel>("Sonetta", 0, 1, "PlaylistContainerModel");
    qmlRegisterType<QuickPlaylistModel>("Sonetta", 0, 1, "PlaylistModel");
    qmlRegisterType<QuickAlbumModel>("Sonetta", 0, 1, "AlbumModel");
    qmlRegisterType<QuickTrackInfo>("Sonetta", 0, 1, "TrackInfo");
    qmlRegisterType<QuickMosaicGenerator>("Sonetta", 0, 1, "MosaicGenerator");
    qmlRegisterType<QuickArtistSynopsis>("Sonetta", 0, 1, "ArtistSynopsis");

    qmlRegisterUncreatableType<Spotinetta::Session>("Sonetta", 0, 1, "Session", "Cannot instantiate Session.");
    qmlRegisterSingletonType<QuickFactory>("Sonetta", 0, 1, "Factory", &quickFactorySingletonProvider);

    // Enums
    qmlRegisterUncreatableType<AlbumEnums>("Sonetta", 0, 1, "Album", "Cannot instantiate Album.");
    qmlRegisterUncreatableType<TrackEnums>("Sonetta", 0, 1, "Track", "Cannot instantiate Track.");

    // State machine
    qmlRegisterType<QuickGlobalStateTransition>("Sonetta.Utilities", 0, 1, "GlobalStateTransition");
    qmlRegisterSingletonType<QuickGlobalStateMachine>("Sonetta.Utilities", 0, 1, "GlobalStateMachine",
                             [] (QQmlEngine *, QJSEngine *) -> QObject * { return new QuickGlobalStateMachine; });
}

void Application::setupQuickEnvironment()
{
    connect(m_view->engine(), &QQmlEngine::quit, this, &Application::onExit);

    const QString applicationDir = QCoreApplication::applicationDirPath();

    ImageProvider * provider = new ImageProvider(m_session.constCast<const sp::Session>(), m_view.data());
    m_view->engine()->addImageProvider(QLatin1String("sp"), provider);

    m_view->engine()->addImportPath(applicationDir + QStringLiteral("/quick"));
    m_view->engine()->addPluginPath(applicationDir + QStringLiteral("/quick"));
    m_view->engine()->addPluginPath(applicationDir + QStringLiteral("/plugins"));

    m_view->engine()->rootContext()->setContextProperty("player", m_player.data());
    m_view->engine()->rootContext()->setContextProperty("ui", m_ui.data());
    m_view->engine()->rootContext()->setContextProperty("session", m_session.data());
    m_view->engine()->rootContext()->setContextProperty("search", m_search.data());
    m_view->engine()->rootContext()->setContextProperty("library", m_collection.data());
    m_view->engine()->addImportPath(applicationDir + QStringLiteral("/modules/"));
    m_view->setSource(QUrl::fromLocalFile(applicationDir + QStringLiteral("/interfaces/default/main.qml")));
    m_view->setResizeMode(QQuickView::SizeRootObjectToView);
}

void Application::showUi()
{
    updateCursor();

    // Center view
    QScreen * screen = m_view->screen();
    QPoint screenCenter = screen->availableGeometry().center();
    QPoint windowCenter = m_view->geometry().center();
    m_view->setPosition(screenCenter - windowCenter);
    m_view->showFullScreen();
    //m_view->showNormal();
}

void Application::loadFonts()
{
    qDebug() << "Loading supplied applications fonts...";

    QDir fontDir (QCoreApplication::applicationDirPath() + "/fonts");
    if (fontDir.exists())
    {
        QStringList paths = fontDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
        for (const QString & path : paths)
        {
            QFile file(fontDir.absoluteFilePath(path));
            if (file.open(QIODevice::ReadOnly))
            {
                QByteArray data = file.readAll();
                int id = QFontDatabase::addApplicationFontFromData(data);
                qDebug() << "Loaded font families:" << QFontDatabase::applicationFontFamilies(id);
            }
            else
            {
                qDebug() << "Failed to open font file " << path;
            }
        }
    }

    qDebug() << "Font loading complete.";
}

void Application::createSession()
{
    sp::SessionConfig config;
    config.applicationKey = sp::ApplicationKey(g_appkey, g_appkey_size);
    config.userAgent = "sonetta";
    config.audioOutput = m_output;

    config.settingsLocation = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/libspotify";
    config.cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/libspotify";

    // Create directories if they don't exist
    QDir dir;
    dir.mkpath(config.settingsLocation);
    dir.mkpath(config.cacheLocation);

    m_session.reset(new sp::Session(config));

    // See comment above declaration for rationale
    g_session = m_session;
}

}
<commit_msg>Possible minor fix for crash at shutdown<commit_after>#include "application.h"

#include <QtQml>
#include <QScreen>
#include <QKeyEvent>
#include <QQuickView>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>
#include <QFontDatabase>
#include <QFile>
#include <QWeakPointer>

#include "imageprovider.h"

#include "quick/enums.h"
#include "quick/models.h"
#include "quick/quicktrackinfo.h"
#include "quick/quickmosaicgenerator.h"
#include "quick/quickfactory.h"
#include "quick/quickartistsynopsis.h"
#include "quick/quickglobalstatemachine.h"

#include "../../appkey.c"

namespace sp = Spotinetta;

namespace {
// This global is unfortunately necessary for the Qt Quick models
// to retrieve the current session
QWeakPointer<Spotinetta::Session> g_session;
}

namespace Sonetta {

Application::Application(QObject * parent)
    :   QObject(parent),
      m_view(new QQuickView),
      m_ui(new UIStateCoordinator),
      m_output(new AudioOutput),
      m_settings(new Settings),
      m_exiting(false)
{
    createSession();

    m_player.reset(new Player(m_session, m_output));
    m_search.reset(new SearchEngine(m_session.constCast<const sp::Session>(), m_settings));
    m_collection.reset(new LibraryCollection(m_session.constCast<const sp::Session>()));

    connect(m_session.data(), &sp::Session::loggedOut, this, &Application::onLogout);
    connect(m_session.data(), &sp::Session::log, [] (const QString &msg) { qDebug() << msg; });

    connect(m_settings.data(), &Settings::mouseEnabledChanged, this, &Application::updateCursor);

    m_view->installEventFilter(this);
}

Application::~Application()
{
    // Manually reset view here to make sure it's deleted
    // before any of the others (Player, SearchEngine etc.)
    m_view.reset();
}

bool Application::initialize()
{
    registerQmlTypes();

    // Enable mouse
    m_settings->setMouseEnabled(true);

    if (m_session->error() == sp::Error::Ok)
    {
        m_navigation.initialize(m_settings->lircDelay());

        setupQuickEnvironment();
        showUi();
        return true;
    }
    else
    {
        const QByteArray error = sp::errorMessage(m_session->error()).toUtf8();
        qFatal("Session creation failed. Error: %s", error.constData());
        return false;
    }
}

void Application::onExit()
{
    if (!m_exiting)
    {
        m_exiting = true;
        if (m_session->connectionState() == sp::Session::ConnectionState::LoggedIn
                || m_session->connectionState() == sp::Session::ConnectionState::Offline)
        {
            m_session->logout();
        }
        else
        {
            // Skip session logout
            onLogout();
        }
    }
}

void Application::onLogout()
{
    if (m_exiting)
    {
        QCoreApplication::quit();
    }
}

void Application::updateCursor()
{
    if (m_view.isNull())
        return;

    if (m_settings->mouseEnabled())
    {
        m_view->unsetCursor();
    }
    else
    {
        m_view->setCursor(QCursor(Qt::BlankCursor));
    }
}

ObjectSharedPointer<sp::Session> Application::session()
{
    return ObjectSharedPointer<sp::Session>(g_session.toStrongRef());
}

bool Application::eventFilter(QObject * obj, QEvent * e)
{
    Q_UNUSED(obj);
    Q_ASSERT(obj == m_view.data());

    switch (e->type())
    {
    case QEvent::Close:
        onExit();
        return true;
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseMove:
    case QEvent::MouseTrackingChange:
        if (!m_settings->mouseEnabled())
            return true;
    default:
        return false;
    }
}

void Application::registerQmlTypes()
{
    Navigation::registerTypes();

    qmlRegisterType<QuickPlaylistContainerModel>("Sonetta", 0, 1, "PlaylistContainerModel");
    qmlRegisterType<QuickPlaylistModel>("Sonetta", 0, 1, "PlaylistModel");
    qmlRegisterType<QuickAlbumModel>("Sonetta", 0, 1, "AlbumModel");
    qmlRegisterType<QuickTrackInfo>("Sonetta", 0, 1, "TrackInfo");
    qmlRegisterType<QuickMosaicGenerator>("Sonetta", 0, 1, "MosaicGenerator");
    qmlRegisterType<QuickArtistSynopsis>("Sonetta", 0, 1, "ArtistSynopsis");

    qmlRegisterUncreatableType<Spotinetta::Session>("Sonetta", 0, 1, "Session", "Cannot instantiate Session.");
    qmlRegisterSingletonType<QuickFactory>("Sonetta", 0, 1, "Factory", &quickFactorySingletonProvider);

    // Enums
    qmlRegisterUncreatableType<AlbumEnums>("Sonetta", 0, 1, "Album", "Cannot instantiate Album.");
    qmlRegisterUncreatableType<TrackEnums>("Sonetta", 0, 1, "Track", "Cannot instantiate Track.");

    // State machine
    qmlRegisterType<QuickGlobalStateTransition>("Sonetta.Utilities", 0, 1, "GlobalStateTransition");
    qmlRegisterSingletonType<QuickGlobalStateMachine>("Sonetta.Utilities", 0, 1, "GlobalStateMachine",
                             [] (QQmlEngine *, QJSEngine *) -> QObject * { return new QuickGlobalStateMachine; });
}

void Application::setupQuickEnvironment()
{
    connect(m_view->engine(), &QQmlEngine::quit, this, &Application::onExit);

    const QString applicationDir = QCoreApplication::applicationDirPath();

    ImageProvider * provider = new ImageProvider(m_session.constCast<const sp::Session>(), m_view.data());
    m_view->engine()->addImageProvider(QLatin1String("sp"), provider);

    m_view->engine()->addImportPath(applicationDir + QStringLiteral("/quick"));
    m_view->engine()->addPluginPath(applicationDir + QStringLiteral("/quick"));
    m_view->engine()->addPluginPath(applicationDir + QStringLiteral("/plugins"));

    m_view->engine()->rootContext()->setContextProperty("player", m_player.data());
    m_view->engine()->rootContext()->setContextProperty("ui", m_ui.data());
    m_view->engine()->rootContext()->setContextProperty("session", m_session.data());
    m_view->engine()->rootContext()->setContextProperty("search", m_search.data());
    m_view->engine()->rootContext()->setContextProperty("library", m_collection.data());
    m_view->engine()->addImportPath(applicationDir + QStringLiteral("/modules/"));
    m_view->setSource(QUrl::fromLocalFile(applicationDir + QStringLiteral("/interfaces/default/main.qml")));
    m_view->setResizeMode(QQuickView::SizeRootObjectToView);
}

void Application::showUi()
{
    updateCursor();

    // Center view
    QScreen * screen = m_view->screen();
    QPoint screenCenter = screen->availableGeometry().center();
    QPoint windowCenter = m_view->geometry().center();
    m_view->setPosition(screenCenter - windowCenter);
    m_view->showFullScreen();
    //m_view->showNormal();
}

void Application::loadFonts()
{
    qDebug() << "Loading supplied applications fonts...";

    QDir fontDir (QCoreApplication::applicationDirPath() + "/fonts");
    if (fontDir.exists())
    {
        QStringList paths = fontDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
        for (const QString & path : paths)
        {
            QFile file(fontDir.absoluteFilePath(path));
            if (file.open(QIODevice::ReadOnly))
            {
                QByteArray data = file.readAll();
                int id = QFontDatabase::addApplicationFontFromData(data);
                qDebug() << "Loaded font families:" << QFontDatabase::applicationFontFamilies(id);
            }
            else
            {
                qDebug() << "Failed to open font file " << path;
            }
        }
    }

    qDebug() << "Font loading complete.";
}

void Application::createSession()
{
    sp::SessionConfig config;
    config.applicationKey = sp::ApplicationKey(g_appkey, g_appkey_size);
    config.userAgent = "sonetta";
    config.audioOutput = m_output;

    config.settingsLocation = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/libspotify";
    config.cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/libspotify";

    // Create directories if they don't exist
    QDir dir;
    dir.mkpath(config.settingsLocation);
    dir.mkpath(config.cacheLocation);

    m_session.reset(new sp::Session(config));

    // See comment above declaration for rationale
    g_session = m_session;
}

}
<|endoftext|>


<commit_before>#include <Eigen/Dense>
#include <iostream> // must go before other things because R defines a "length" macro
#include <nimble/RcppUtils.h>
#include "nimble/RcppNimbleUtils.h"
//#include <nimble/ModelClassUtils.h>
//#include <nimble/accessorClasses.h>
#include <nimble/nimbleGraph.h>
#include <nimble/EigenTypedefs.h>
#include <nimble/dists.h>

#include <R_ext/Rdynload.h>

#define FUN(name, numArgs) \
  {#name, (DL_FUNC) &name, numArgs}

#define CFUN(name, numArgs) \
  {"R_"#name, (DL_FUNC) &name, numArgs}

R_CallMethodDef CallEntries[] = {
  // {"getModelValuesPtrFromModel", (DL_FUNC) &getModelValuesPtrFromModel, 1},
// FUN(setNodeModelPtr, 3),
// FUN(getAvailableNames, 1),
// FUN(getMVElement, 2),
// FUN(setMVElement, 3),
// FUN(resizeManyModelVarAccessor, 2),
// FUN(resizeManyModelValuesAccessor, 2),
// FUN(getModelObjectPtr, 2),
 // FUN(getModelValuesMemberElement, 2),
 // FUN(getNRow, 1),
 //FUN(addBlankModelValueRows, 2),
 //FUN(copyModelValuesElements, 4),
 FUN(C_dwish_chol, 5),
 FUN(C_rwish_chol, 3),
 FUN(C_ddirch, 3),
 FUN(C_rdirch, 1),
 FUN(C_dmulti, 4),
 FUN(C_rmulti, 2),
 FUN(C_dcat, 3),
 FUN(C_rcat, 2),
 FUN(C_dt_nonstandard, 5),
 FUN(C_rt_nonstandard, 4),
 FUN(C_dmnorm_chol, 5),
 FUN(C_rmnorm_chol, 3),
 FUN(C_dinterval, 4),
 FUN(C_rinterval, 3),

 // FUN(makeNumericList, 3),
//   The following 4 conflict with names of R functions. So we prefix them with a R_
 //CFUN(setPtrVectorOfPtrs, 3),
 //CFUN(setOnePtrVectorOfPtrs, 3),
 //CFUN(setDoublePtrFromSinglePtr, 2),
// CFUN(setSinglePtrFromSinglePtr, 2),
// FUN(newModelValues, 1),

 //These don't register well since they are overloaded
// FUN(SEXP_2_double, 3),
 // FUN(double_2_SEXP, 2),
 // FUN(SEXP_2_bool, 3),
 // FUN(bool_2_SEXP, 2),
 // FUN(SEXP_2_int, 3),
 // FUN(int_2_SEXP, 2),
 // FUN(SEXP_2_string, 2),
 // FUN(SEXP_2_stringVector, 2),
 // FUN(string_2_SEXP, 1),
 // FUN(stringVector_2_SEXP, 1)
 FUN(fastMatrixInsert, 4),
 FUN(matrix2ListDouble, 5),
 FUN(matrix2ListInt, 5),
 // FUN(rankSample, 4),
 FUN(parseVar, 1),

 FUN(setGraph, 6),
 FUN(anyStochDependencies, 1),
 FUN(anyStochParents, 1),
 FUN(getDependencies, 4),

 {NULL, NULL, 0}
};

/* Arrange to register the routines so that they can be checked and also accessed by
   their equivalent name as an R symbol, e.g. .Call(setNodeModelPtr, ....)
 */
extern "C"
void
R_init_nimble(DllInfo *dll)
{
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
}

<commit_msg>add R_useDynamicSymbols<commit_after>#include <Eigen/Dense>
#include <iostream> // must go before other things because R defines a "length" macro
#include <nimble/RcppUtils.h>
#include "nimble/RcppNimbleUtils.h"
//#include <nimble/ModelClassUtils.h>
//#include <nimble/accessorClasses.h>
#include <nimble/nimbleGraph.h>
#include <nimble/EigenTypedefs.h>
#include <nimble/dists.h>

#include <R_ext/Rdynload.h>

#define FUN(name, numArgs) \
  {#name, (DL_FUNC) &name, numArgs}

#define CFUN(name, numArgs) \
  {"R_"#name, (DL_FUNC) &name, numArgs}

R_CallMethodDef CallEntries[] = {
  // {"getModelValuesPtrFromModel", (DL_FUNC) &getModelValuesPtrFromModel, 1},
// FUN(setNodeModelPtr, 3),
// FUN(getAvailableNames, 1),
// FUN(getMVElement, 2),
// FUN(setMVElement, 3),
// FUN(resizeManyModelVarAccessor, 2),
// FUN(resizeManyModelValuesAccessor, 2),
// FUN(getModelObjectPtr, 2),
 // FUN(getModelValuesMemberElement, 2),
 // FUN(getNRow, 1),
 //FUN(addBlankModelValueRows, 2),
 //FUN(copyModelValuesElements, 4),
 FUN(C_dwish_chol, 5),
 FUN(C_rwish_chol, 3),
 FUN(C_ddirch, 3),
 FUN(C_rdirch, 1),
 FUN(C_dmulti, 4),
 FUN(C_rmulti, 2),
 FUN(C_dcat, 3),
 FUN(C_rcat, 2),
 FUN(C_dt_nonstandard, 5),
 FUN(C_rt_nonstandard, 4),
 FUN(C_dmnorm_chol, 5),
 FUN(C_rmnorm_chol, 3),
 FUN(C_dinterval, 4),
 FUN(C_rinterval, 3),

 // FUN(makeNumericList, 3),
//   The following 4 conflict with names of R functions. So we prefix them with a R_
 //CFUN(setPtrVectorOfPtrs, 3),
 //CFUN(setOnePtrVectorOfPtrs, 3),
 //CFUN(setDoublePtrFromSinglePtr, 2),
// CFUN(setSinglePtrFromSinglePtr, 2),
// FUN(newModelValues, 1),

 //These don't register well since they are overloaded
// FUN(SEXP_2_double, 3),
 // FUN(double_2_SEXP, 2),
 // FUN(SEXP_2_bool, 3),
 // FUN(bool_2_SEXP, 2),
 // FUN(SEXP_2_int, 3),
 // FUN(int_2_SEXP, 2),
 // FUN(SEXP_2_string, 2),
 // FUN(SEXP_2_stringVector, 2),
 // FUN(string_2_SEXP, 1),
 // FUN(stringVector_2_SEXP, 1)
 FUN(fastMatrixInsert, 4),
 FUN(matrix2ListDouble, 5),
 FUN(matrix2ListInt, 5),
 // FUN(rankSample, 4),
 FUN(parseVar, 1),

 FUN(setGraph, 6),
 FUN(anyStochDependencies, 1),
 FUN(anyStochParents, 1),
 FUN(getDependencies, 4),

 {NULL, NULL, 0}
};

/* Arrange to register the routines so that they can be checked and also accessed by
   their equivalent name as an R symbol, e.g. .Call(setNodeModelPtr, ....)
 */
extern "C"
void
R_init_nimble(DllInfo *dll)
{
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}

<|endoftext|>


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

#ifndef CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
#include <connectivity/dbmetadata.hxx>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif

/** === begin UNO includes === **/
#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#endif
/** === end UNO includes === **/

#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif

//........................................................................
namespace dbtools
{
//........................................................................

    /** === begin UNO using === **/
    using ::com::sun::star::uno::Reference;
    using ::com::sun::star::sdbc::XConnection;
    using ::com::sun::star::sdbc::XConnection;
    using ::com::sun::star::sdbc::XDatabaseMetaData;
    using ::com::sun::star::lang::IllegalArgumentException;
    using ::com::sun::star::uno::Exception;
    /** === end UNO using === **/

    //====================================================================
    //= DatabaseMetaData_Impl
    //====================================================================
    struct DatabaseMetaData_Impl
    {
        Reference< XConnection >        xConnection;
        Reference< XDatabaseMetaData >  xConnectionMetaData;
    };

    //--------------------------------------------------------------------
    namespace
    {
        static void lcl_construct( DatabaseMetaData_Impl& _metaDataImpl, const Reference< XConnection >& _connection )
        {
            _metaDataImpl.xConnection = _connection;
            if ( !_metaDataImpl.xConnection.is() )
                return;

            _metaDataImpl.xConnectionMetaData = _connection->getMetaData();
            if ( !_metaDataImpl.xConnectionMetaData.is() )
                throw IllegalArgumentException();
        }

        static void lcl_checkConnected( DatabaseMetaData_Impl& _metaDataImpl )
        {
            if ( !_metaDataImpl.xConnection.is() )
                throwSQLException( "not connected", SQL_CONNECTION_DOES_NOT_EXIST, NULL );
        }
    }

    //====================================================================
    //= DatabaseMetaData
    //====================================================================
    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData()
        :m_pImpl( new DatabaseMetaData_Impl )
    {
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData( const Reference< XConnection >& _connection )
        :m_pImpl( new DatabaseMetaData_Impl )
    {
        lcl_construct( *m_pImpl, _connection );
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData( const DatabaseMetaData& _copyFrom )
        :m_pImpl( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) )
    {
    }

    //--------------------------------------------------------------------
    DatabaseMetaData& DatabaseMetaData::operator=( const DatabaseMetaData& _copyFrom )
    {
        if ( this == &_copyFrom )
            return *this;

        m_pImpl.reset( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) );
        return *this;
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::~DatabaseMetaData()
    {
    }

    //--------------------------------------------------------------------
    bool DatabaseMetaData::isConnected() const
    {
        return m_pImpl->xConnection.is();
    }

    //--------------------------------------------------------------------
    bool SAL_CALL DatabaseMetaData::supportsSubqueriesInFrom() const
    {
        lcl_checkConnected( *m_pImpl );

        bool supportsSubQueries = false;
        try
        {
            sal_Int32 maxTablesInselect = m_pImpl->xConnectionMetaData->getMaxTablesInSelect();
            supportsSubQueries = ( maxTablesInselect > 1 ) || ( maxTablesInselect == 0 );
            // TODO: is there a better way to determine this? The above is not really true. More precise,
            // it's a *very* generous heuristics ...
        }
        catch( const Exception& )
        {
            DBG_UNHANDLED_EXCEPTION();
        }
        return supportsSubQueries;
    }

//........................................................................
} // namespace dbtools
//........................................................................

<commit_msg>INTEGRATION: CWS dba204b (1.2.2); FILE MERGED 2006/07/17 08:06:34 fs 1.2.2.1: #i67260# +restrictIdentifiersToSQL92<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dbmetadata.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2006-07-26 07:21:25 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
#include <connectivity/dbmetadata.hxx>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif

/** === begin UNO includes === **/
#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
#include <com/sun/star/container/XChild.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
/** === end UNO includes === **/

#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif

//........................................................................
namespace dbtools
{
//........................................................................

    /** === begin UNO using === **/
    using ::com::sun::star::uno::Reference;
    using ::com::sun::star::sdbc::XConnection;
    using ::com::sun::star::sdbc::XConnection;
    using ::com::sun::star::sdbc::XDatabaseMetaData;
    using ::com::sun::star::lang::IllegalArgumentException;
    using ::com::sun::star::uno::Exception;
    using ::com::sun::star::uno::Any;
    using ::com::sun::star::container::XChild;
    using ::com::sun::star::uno::UNO_QUERY_THROW;
    using ::com::sun::star::beans::XPropertySet;
    using ::com::sun::star::uno::Sequence;
    using ::com::sun::star::beans::PropertyValue;
    /** === end UNO using === **/

    //====================================================================
    //= DatabaseMetaData_Impl
    //====================================================================
    struct DatabaseMetaData_Impl
    {
        Reference< XConnection >        xConnection;
        Reference< XDatabaseMetaData >  xConnectionMetaData;
    };

    //--------------------------------------------------------------------
    namespace
    {
        static void lcl_construct( DatabaseMetaData_Impl& _metaDataImpl, const Reference< XConnection >& _connection )
        {
            _metaDataImpl.xConnection = _connection;
            if ( !_metaDataImpl.xConnection.is() )
                return;

            _metaDataImpl.xConnectionMetaData = _connection->getMetaData();
            if ( !_metaDataImpl.xConnectionMetaData.is() )
                throw IllegalArgumentException();
        }

        static void lcl_checkConnected( DatabaseMetaData_Impl& _metaDataImpl )
        {
            if ( !_metaDataImpl.xConnection.is() )
                throwSQLException( "not connected", SQL_CONNECTION_DOES_NOT_EXIST, NULL );
        }

        static bool lcl_getDataSourceSetting( const sal_Char* _asciiName, const DatabaseMetaData_Impl& _metaData, Any& _out_setting )
        {
            try
            {
                Reference< XChild > connectionAsChild( _metaData.xConnection, UNO_QUERY_THROW );
                Reference< XPropertySet > dataSource( connectionAsChild->getParent(), UNO_QUERY_THROW );

                Sequence< PropertyValue > dataSourceSettings;
                OSL_VERIFY( dataSource->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Info" ) ) ) >>= dataSourceSettings );

                const PropertyValue* setting( dataSourceSettings.getConstArray() );
                const PropertyValue* settingEnd( setting + dataSourceSettings.getLength() );
                for ( ; setting != settingEnd; ++setting )
                {
                    if ( setting->Name.equalsAscii( _asciiName ) )
                    {
                        _out_setting = setting->Value;
                        return true;
                    }
                }
            }
            catch( const Exception& )
            {
                DBG_UNHANDLED_EXCEPTION();
            }
            return false;
        }
    }

    //====================================================================
    //= DatabaseMetaData
    //====================================================================
    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData()
        :m_pImpl( new DatabaseMetaData_Impl )
    {
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData( const Reference< XConnection >& _connection )
        :m_pImpl( new DatabaseMetaData_Impl )
    {
        lcl_construct( *m_pImpl, _connection );
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::DatabaseMetaData( const DatabaseMetaData& _copyFrom )
        :m_pImpl( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) )
    {
    }

    //--------------------------------------------------------------------
    DatabaseMetaData& DatabaseMetaData::operator=( const DatabaseMetaData& _copyFrom )
    {
        if ( this == &_copyFrom )
            return *this;

        m_pImpl.reset( new DatabaseMetaData_Impl( *_copyFrom.m_pImpl ) );
        return *this;
    }

    //--------------------------------------------------------------------
    DatabaseMetaData::~DatabaseMetaData()
    {
    }

    //--------------------------------------------------------------------
    bool DatabaseMetaData::isConnected() const
    {
        return m_pImpl->xConnection.is();
    }

    //--------------------------------------------------------------------
    bool SAL_CALL DatabaseMetaData::supportsSubqueriesInFrom() const
    {
        lcl_checkConnected( *m_pImpl );

        bool supportsSubQueries = false;
        try
        {
            sal_Int32 maxTablesInselect = m_pImpl->xConnectionMetaData->getMaxTablesInSelect();
            supportsSubQueries = ( maxTablesInselect > 1 ) || ( maxTablesInselect == 0 );
            // TODO: is there a better way to determine this? The above is not really true. More precise,
            // it's a *very* generous heuristics ...
        }
        catch( const Exception& )
        {
            DBG_UNHANDLED_EXCEPTION();
        }
        return supportsSubQueries;
    }

    //--------------------------------------------------------------------
    bool SAL_CALL DatabaseMetaData::restrictIdentifiersToSQL92() const
    {
        bool restrict( false );
        Any setting;
        if ( lcl_getDataSourceSetting( "EnableSQL92Check", *m_pImpl, setting ) )
            OSL_VERIFY( setting >>= restrict );
        return restrict;
    }

//........................................................................
} // namespace dbtools
//........................................................................

<|endoftext|>


<commit_before>/*
 * File:   Sphere.cpp
 * Author: Benedikt Vogler
 *
 * Created on 4. Juli 2014, 19:25
 */

#include "Sphere.hpp"

std::pair<bool, Ray> Sphere::intersect(Ray const& ray) const {
    glm::vec3 l = ray.origin - center;
    float a = glm::dot(ray.direction, ray.direction);
    float b = 2.0f*(glm::dot(l,ray.direction));
    float c = glm::dot(l,l) - radius*radius;

    float det = b*b-4.0f*a*c;
    if (det>=0.0f) {//wenn es min. eine Lösung gibt
        float t1 = (-b-sqrt(det))/(2.0f*a);
        float t2 = (-b+sqrt(det))/(2.0f*a);

        if (t1 < t2){//nimm Punkt, welcher näher dran ist
            if (t1<0)
                return std::make_pair(false, Ray());//keine Lösung
            else
                return std::make_pair(true, Ray(l-(ray.origin+ray.direction*t1)));//use t1
        } else{
            if (t2<0)
                return std::make_pair(false, Ray());//keine Lösung
            else
                return std::make_pair(true, Ray(l-(ray.origin+ray.direction*t2)));//use t2
        }
    } else
        return std::make_pair(false, Ray());//keine Lösung
}<commit_msg>returns hopefully the normal #9<commit_after>/*
 * File:   Sphere.cpp
 * Author: Benedikt Vogler
 *
 * Created on 4. Juli 2014, 19:25
 */

#include "Sphere.hpp"
#include <glm/glm.hpp>

std::pair<bool, Ray> Sphere::intersect(Ray const& ray) const {
    glm::vec3 l = ray.origin - center;
    float a = glm::dot(ray.direction, ray.direction);
    float b = 2.0f*(glm::dot(l,ray.direction));
    float c = glm::dot(l,l) - radius*radius;

    float det = b*b-4.0f*a*c;
    if (det>=0.0f) {//wenn es min. eine Lösung gibt
        float t1 = (-b-sqrt(det))/(2.0f*a);
        float t2 = (-b+sqrt(det))/(2.0f*a);

        if (t1 < t2){//nimm Punkt, welcher näher dran ist
            if (t1<0)
                return std::make_pair(false, Ray());//keine Lösung
            else{
                auto p =l-(ray.origin+ray.direction*t1);
                return std::make_pair(true, Ray(p,glm::normalize(center-p)));//use t1
            }
        } else{
            if (t2<0)
                return std::make_pair(false, Ray());//keine Lösung
            else{
                auto p =l-(ray.origin+ray.direction*t2);
                return std::make_pair(true, Ray(p,glm::normalize(center-p)));//use t2
            }

        }
    } else
        return std::make_pair(false, Ray());//keine Lösung
}<|endoftext|>


<commit_before>#include "types.h"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"

static wq *wq_;
static wq *wqcrit_;

void*
xallocwork(unsigned long nbytes)
{
  return kmalloc(nbytes, "xallocwork");
}

void
xfreework(void* ptr, unsigned long nbytes)
{
  kmfree(ptr, nbytes);
}

size_t
wq_size(void)
{
  return sizeof(wq);
}

int
wq_push(work *w)
{
  return wq_->push(w, mycpuid());
}

void
wqcrit_trywork(void)
{
  while (wqcrit_->trywork(false))
    ;
}

int
wqcrit_push(work *w, int c)
{
  return wqcrit_->push(w, c);
}

int
wq_trywork(void)
{
  return wqcrit_->trywork(false) || wq_->trywork(true);
}

void
wq_dump(void)
{
  return wq_->dump();
}

void
initwq(void)
{
  wq_ = new wq();
  wqcrit_ = new wq();
  if (wq_ == nullptr || wqcrit_ == nullptr)
    panic("initwq");
}
<commit_msg>Assert if work queues are used too early<commit_after>#include "types.h"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"

static wq *wq_;
static wq *wqcrit_;

void*
xallocwork(unsigned long nbytes)
{
  return kmalloc(nbytes, "xallocwork");
}

void
xfreework(void* ptr, unsigned long nbytes)
{
  kmfree(ptr, nbytes);
}

size_t
wq_size(void)
{
  return sizeof(wq);
}

int
wq_push(work *w)
{
  assert(wq_);
  return wq_->push(w, mycpuid());
}

void
wqcrit_trywork(void)
{
  assert(wqcrit_);
  while (wqcrit_->trywork(false))
    ;
}

int
wqcrit_push(work *w, int c)
{
  assert(wqcrit_);
  return wqcrit_->push(w, c);
}

int
wq_trywork(void)
{
  assert(wq_ && wqcrit_);
  return wqcrit_->trywork(false) || wq_->trywork(true);
}

void
wq_dump(void)
{
  if (wq_)
    return wq_->dump();
}

void
initwq(void)
{
  wq_ = new wq();
  wqcrit_ = new wq();
  if (wq_ == nullptr || wqcrit_ == nullptr)
    panic("initwq");
}
<|endoftext|>


<commit_before>/*
 * ====================================================================
 * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library (in the file LGPL.txt); if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA  02110-1301  USA
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://rapidsvn.tigris.org/.
 * ====================================================================
 */

// subversion api
#include "svn_path.h"

// apr api
#include "apr_file_io.h"

// svncpp
#include "svnqt/path.hpp"
#include "svnqt/pool.hpp"
#include "svnqt/url.hpp"
#include "svnqt/svnqt_defines.hpp"

namespace svn
{
  Path::Path (const char * path)
  {
    init(QString::FROMUTF8(path));
  }

  Path::Path (const QString & path)
  {
    init (path);
  }

  Path::Path (const Path & path)
    : m_path(path.m_path)
  {
  }

  void
  Path::init (const QString& path)
  {
    Pool pool;

    if (path.isEmpty()) {
      m_path = "";
    } else {
      const char * int_path = svn_path_internal_style (path.TOUTF8(), pool.pool () );
      if (Url::isValid(path) ) {
        if (!svn_path_is_uri_safe(int_path)) {
            int_path = svn_path_uri_encode(int_path,pool);
        }
      }
      m_path = QString::FROMUTF8(int_path);
    }
  }

  const QString &
  Path::path () const
  {
    return m_path;
  }

  Path::operator const QString&()const
  {
    return m_path;
  }

  QString Path::prettyPath()const
  {
    if (!Url::isValid(m_path)) {
        return m_path;
    }
    Pool pool;
    const char * int_path = svn_path_uri_decode(m_path.TOUTF8(), pool.pool () );
    return QString::FROMUTF8(int_path);
  }

  const QByteArray
  Path::cstr() const
  {
    return m_path.TOUTF8();
  }

  Path&
  Path::operator=(const Path & path)
  {
    if (this == &path)
      return *this;
    m_path = path.path();
    return *this;
  }

  bool
  Path::isset () const
  {
    return m_path.length () > 0;
  }

  void
  Path::addComponent (const QString& component)
  {
    Pool pool;

    if (Url::isValid (m_path))
    {
      const char * newPath =
          svn_path_url_add_component (m_path.TOUTF8(), component.TOUTF8(), pool);
      m_path = QString::FROMUTF8(newPath);
    }
    else
    {
      svn_stringbuf_t * pathStringbuf =
          svn_stringbuf_create (m_path.TOUTF8(), pool);

      svn_path_add_component (pathStringbuf,
                              component.TOUTF8());

      m_path = QString::FROMUTF8(pathStringbuf->data);
    }
  }

  void
  Path::addComponent (const char* component)
  {
    addComponent (QString::FROMUTF8(component));
  }

  void
  Path::split (QString & dirpath, QString & basename) const
  {
    Pool pool;

    const char * cdirpath;
    const char * cbasename;

    svn_path_split (m_path.TOUTF8(), &cdirpath, &cbasename, pool);
    dirpath = QString::FROMUTF8(cdirpath);
    basename = QString::FROMUTF8(cbasename);
  }

  void
  Path::split (QString & dir, QString & filename, QString & ext) const
  {
    QString basename;

    // first split path into dir and filename+ext
    split (dir, basename);

    // next search for last .
#if QT_VERSION < 0x040000
    int pos = basename.findRev(QChar('.'));
#else
    int pos = basename.lastIndexOf(QChar('.'));
#endif

    if (pos == -1)
    {
      filename = basename;
      ext = QString::fromLatin1("");
    }
    else
    {
      filename = basename.left(pos);
      ext = basename.mid(pos+1);
    }
  }

  Path
  Path::getTempDir ()
  {
    const char * tempdir = 0;
    Pool pool;

    if (apr_temp_dir_get (&tempdir, pool) != APR_SUCCESS)
    {
      tempdir = 0;
    }

    return tempdir;
  }

  unsigned int
  Path::length () const
  {
    return m_path.length ();
  }

  QString
  Path::native () const
  {
    Pool pool;

    return QString::FROMUTF8(svn_path_local_style (m_path.TOUTF8(), pool));
  }

}

/* -----------------------------------------------------------------
 * local variables:
 * eval: (load-file "../../rapidsvn-dev.el")
 * end:
 */
<commit_msg>fixed a problem with @ in path/file name (Bug #0000132 and another not reported bug)<commit_after>/*
 * ====================================================================
 * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library (in the file LGPL.txt); if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA  02110-1301  USA
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://rapidsvn.tigris.org/.
 * ====================================================================
 */

// subversion api
#include "svn_path.h"

// apr api
#include "apr_file_io.h"

// svncpp
#include "svnqt/path.hpp"
#include "svnqt/pool.hpp"
#include "svnqt/url.hpp"
#include "svnqt/svnqt_defines.hpp"

namespace svn
{
  Path::Path (const char * path)
  {
    init(QString::FROMUTF8(path));
  }

  Path::Path (const QString & path)
  {
    init (path);
  }

  Path::Path (const Path & path)
    : m_path(path.m_path)
  {
  }

  void
  Path::init (const QString& path)
  {
    Pool pool;

    if (path.isEmpty()) {
      m_path = "";
    } else {
      const char * int_path = svn_path_internal_style (path.TOUTF8(), pool.pool () );
      if (Url::isValid(path) ) {
        if (!svn_path_is_uri_safe(int_path)) {
            int_path = svn_path_uri_encode(int_path,pool);
        }
      }
      m_path = QString::FROMUTF8(int_path);
      if (Url::isValid(path) ) {
        /// @todo make sure that "@" is never used as revision paramter
        m_path.replace("@","%40");
      }
    }
  }

  const QString &
  Path::path () const
  {
    return m_path;
  }

  Path::operator const QString&()const
  {
    return m_path;
  }

  QString Path::prettyPath()const
  {
    if (!Url::isValid(m_path)) {
        return m_path;
    }
    Pool pool;
    const char * int_path = svn_path_uri_decode(m_path.TOUTF8(), pool.pool () );
    QString _p = QString::FROMUTF8(int_path);
    _p.replace("%40","@");
    return _p;
  }

  const QByteArray
  Path::cstr() const
  {
    return m_path.TOUTF8();
  }

  Path&
  Path::operator=(const Path & path)
  {
    if (this == &path)
      return *this;
    m_path = path.path();
    return *this;
  }

  bool
  Path::isset () const
  {
    return m_path.length () > 0;
  }

  void
  Path::addComponent (const QString& component)
  {
    Pool pool;

    if (Url::isValid (m_path))
    {
      const char * newPath =
          svn_path_url_add_component (m_path.TOUTF8(), component.TOUTF8(), pool);
      m_path = QString::FROMUTF8(newPath);
    }
    else
    {
      svn_stringbuf_t * pathStringbuf =
          svn_stringbuf_create (m_path.TOUTF8(), pool);

      svn_path_add_component (pathStringbuf,
                              component.TOUTF8());

      m_path = QString::FROMUTF8(pathStringbuf->data);
    }
  }

  void
  Path::addComponent (const char* component)
  {
    addComponent (QString::FROMUTF8(component));
  }

  void
  Path::split (QString & dirpath, QString & basename) const
  {
    Pool pool;

    const char * cdirpath;
    const char * cbasename;

    svn_path_split (m_path.TOUTF8(), &cdirpath, &cbasename, pool);
    dirpath = QString::FROMUTF8(cdirpath);
    basename = QString::FROMUTF8(cbasename);
  }

  void
  Path::split (QString & dir, QString & filename, QString & ext) const
  {
    QString basename;

    // first split path into dir and filename+ext
    split (dir, basename);

    // next search for last .
#if QT_VERSION < 0x040000
    int pos = basename.findRev(QChar('.'));
#else
    int pos = basename.lastIndexOf(QChar('.'));
#endif

    if (pos == -1)
    {
      filename = basename;
      ext = QString::fromLatin1("");
    }
    else
    {
      filename = basename.left(pos);
      ext = basename.mid(pos+1);
    }
  }

  Path
  Path::getTempDir ()
  {
    const char * tempdir = 0;
    Pool pool;

    if (apr_temp_dir_get (&tempdir, pool) != APR_SUCCESS)
    {
      tempdir = 0;
    }

    return tempdir;
  }

  unsigned int
  Path::length () const
  {
    return m_path.length ();
  }

  QString
  Path::native () const
  {
    Pool pool;

    return QString::FROMUTF8(svn_path_local_style (m_path.TOUTF8(), pool));
  }

}

/* -----------------------------------------------------------------
 * local variables:
 * eval: (load-file "../../rapidsvn-dev.el")
 * end:
 */
<|endoftext|>


<commit_before>#if ! defined (__CINT__) || defined (__MAKECINT__)
#include "AliLog.h"
#include "AliAnalysisManager.h"
#include "AliAnalysisDataContainer.h"
#include "PWG1/TRD/AliTRDinfoGen.h"
#include "PWG1/TRD/AliTRDpwg1Helper.h"
#include "PWG1/TRD/info/AliTRDeventInfo.h"
#endif

void AddTRDinfoGen(AliAnalysisManager *mgr, Int_t /*map*/, AliAnalysisDataContainer **/*ci*/, AliAnalysisDataContainer **co)
{
  Bool_t mc=mgr->GetMCtruthEventHandler();
  //AliLog::SetClassDebugLevel("AliTRDinfoGen", 2);
  AliTRDinfoGen *info(NULL);
  mgr->AddTask(info = new AliTRDinfoGen((char*)"TRDinfoGen"));
  info->SetDebugLevel(0);
  info->SetMCdata(mc);
  info->SetLocalTrkSelection();
  info->SetOCDB("alien://folder=/alice/data/2010/OCDB");
  // settings for collisions
  info->SetCollision(/*kFALSE*/);
  if(info->IsCollision()){
    if(!mc) info->SetTrigger(
      "CINT1B-ABCE-NOPF-ALL"
      " CINT1WU-B-NOPF-ALL"
      " CSCO1-ABCE-NOPF-CENT" // cosmic SPD trigger
    );
    info->SetLocalEvSelection();
  }

  // Connect IO slots
  mgr->ConnectInput (info, 0, mgr->GetCommonInputContainer());
  co[AliTRDpwg1Helper::kEventInfo] = mgr->CreateContainer("eventInfo", AliTRDeventInfo::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksBarrel] = mgr->CreateContainer("tracksBarrel", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksSA] = mgr->CreateContainer("tracksSA", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksKink] = mgr->CreateContainer("tracksKink", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kV0List] = mgr->CreateContainer("v0List", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  for(Int_t ios(1);ios<AliTRDpwg1Helper::kNOutSlots-1;ios++) mgr->ConnectOutput(info, ios, co[ios]);

  // add last monitor container
  AliAnalysisDataContainer *mon=mgr->CreateContainer(info->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("%s:TRD_Performance",mgr->GetCommonFileName()));
  mgr->ConnectOutput(info, AliTRDpwg1Helper::kNOutSlots-1, mon);
}

<commit_msg>trigger names changed (Markus)<commit_after>#if ! defined (__CINT__) || defined (__MAKECINT__)
#include "AliLog.h"
#include "AliAnalysisManager.h"
#include "AliAnalysisDataContainer.h"
#include "PWG1/TRD/AliTRDinfoGen.h"
#include "PWG1/TRD/AliTRDpwg1Helper.h"
#include "PWG1/TRD/info/AliTRDeventInfo.h"
#endif

void AddTRDinfoGen(AliAnalysisManager *mgr, Int_t /*map*/, AliAnalysisDataContainer **/*ci*/, AliAnalysisDataContainer **co)
{
  Bool_t mc=mgr->GetMCtruthEventHandler();
  //AliLog::SetClassDebugLevel("AliTRDinfoGen", 2);
  AliTRDinfoGen *info(NULL);
  mgr->AddTask(info = new AliTRDinfoGen((char*)"TRDinfoGen"));
  info->SetDebugLevel(0);
  info->SetMCdata(mc);
  info->SetLocalTrkSelection();
  info->SetOCDB("alien://folder=/alice/data/2010/OCDB");
  // settings for collisions
  info->SetCollision(/*kFALSE*/);
  if(info->IsCollision()){
    if(!mc) info->SetTrigger(
      "CINT1B-ABCE-NOPF-ALL"
      " CINT5-B-NOPF-ALL"
      " CINT1WU-B-NOPF-ALL"
      " CINT5WU-B-NOPF-ALL"
      " CSCO1-ABCE-NOPF-CENT" // cosmic SPD trigger
    );
    info->SetLocalEvSelection();
  }

  // Connect IO slots
  mgr->ConnectInput (info, 0, mgr->GetCommonInputContainer());
  co[AliTRDpwg1Helper::kEventInfo] = mgr->CreateContainer("eventInfo", AliTRDeventInfo::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksBarrel] = mgr->CreateContainer("tracksBarrel", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksSA] = mgr->CreateContainer("tracksSA", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kTracksKink] = mgr->CreateContainer("tracksKink", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  co[AliTRDpwg1Helper::kV0List] = mgr->CreateContainer("v0List", TObjArray::Class(), AliAnalysisManager::kExchangeContainer);
  for(Int_t ios(1);ios<AliTRDpwg1Helper::kNOutSlots-1;ios++) mgr->ConnectOutput(info, ios, co[ios]);

  // add last monitor container
  AliAnalysisDataContainer *mon=mgr->CreateContainer(info->GetName(), TObjArray::Class(), AliAnalysisManager::kOutputContainer, Form("%s:TRD_Performance",mgr->GetCommonFileName()));
  mgr->ConnectOutput(info, AliTRDpwg1Helper::kNOutSlots-1, mon);
}

<|endoftext|>