<commit_before>/*
 * Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 */

#include "Creature.h"
#include "CreatureAI.h"
#include "Errors.h"
#include "MoveSpline.h"
#include "MoveSplineInit.h"
#include "Player.h"
#include "PointMovementGenerator.h"
#include "World.h"

//----- Point Movement Generator
template<class T>
void PointMovementGenerator<T>::DoInitialize(T* unit)
{
    if (!unit->IsStopped())
        unit->StopMoving();

    unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
    i_recalculateSpeed = false;
    Movement::MoveSplineInit init(unit);
    if (m_precomputedPath.size() > 2) // pussywizard: for charge
        init.MovebyPath(m_precomputedPath);
    else if (_generatePath)
    {
        PathGenerator path(unit);
        bool result = path.CalculatePath(i_x, i_y, i_z, _forceDestination);
        if (result && !(path.GetPathType() & PATHFIND_NOPATH) && path.GetPath().size() > 2)
        {
            m_precomputedPath = path.GetPath();
            init.MovebyPath(m_precomputedPath);
        }
        else
        {
            // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
            if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
            {
                i_x += 0.2f * cos(unit->GetOrientation());
                i_y += 0.2f * sin(unit->GetOrientation());
            }

            init.MoveTo(i_x, i_y, i_z, true);
        }
    }
    else
    {
        // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
        if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
        {
            i_x += 0.2f * cos(unit->GetOrientation());
            i_y += 0.2f * sin(unit->GetOrientation());
        }

        init.MoveTo(i_x, i_y, i_z, true);
    }
    if (speed > 0.0f)
        init.SetVelocity(speed);

    if (i_orientation > 0.0f)
    {
        init.SetFacing(i_orientation);
    }

    init.Launch();
}

template<class T>
bool PointMovementGenerator<T>::DoUpdate(T* unit, uint32 /*diff*/)
{
    if (!unit)
        return false;

    if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
    {
        unit->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
        return true;
    }

    unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);

    if (i_recalculateSpeed && !unit->movespline->Finalized())
    {
        i_recalculateSpeed = false;
        Movement::MoveSplineInit init(unit);

        // xinef: speed changed during path execution, calculate remaining path and launch it once more
        if (m_precomputedPath.size())
        {
            uint32 offset = std::min(uint32(unit->movespline->_currentSplineIdx()), uint32(m_precomputedPath.size()));
            Movement::PointsArray::iterator offsetItr = m_precomputedPath.begin();
            std::advance(offsetItr, offset);
            m_precomputedPath.erase(m_precomputedPath.begin(), offsetItr);

            // restore 0 element (current position)
            m_precomputedPath.insert(m_precomputedPath.begin(), G3D::Vector3(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()));

            if (m_precomputedPath.size() > 2)
                init.MovebyPath(m_precomputedPath);
            else if (m_precomputedPath.size() == 2)
                init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
        }
        else
            init.MoveTo(i_x, i_y, i_z, true);
        if (speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
            init.SetVelocity(speed);

        if (i_orientation > 0.0f)
        {
            init.SetFacing(i_orientation);
        }

        init.Launch();
    }

    return !unit->movespline->Finalized();
}

template<class T>
void PointMovementGenerator<T>::DoFinalize(T* unit)
{
    unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);

    if (unit->movespline->Finalized())
        MovementInform(unit);
}

template<class T>
void PointMovementGenerator<T>::DoReset(T* unit)
{
    if (!unit->IsStopped())
        unit->StopMoving();

    unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
}

template<class T>
void PointMovementGenerator<T>::MovementInform(T* /*unit*/)
{
}

template <> void PointMovementGenerator<Creature>::MovementInform(Creature* unit)
{
    if (unit->AI())
        unit->AI()->MovementInform(POINT_MOTION_TYPE, id);
}

template void PointMovementGenerator<Player>::DoInitialize(Player*);
template void PointMovementGenerator<Creature>::DoInitialize(Creature*);
template void PointMovementGenerator<Player>::DoFinalize(Player*);
template void PointMovementGenerator<Creature>::DoFinalize(Creature*);
template void PointMovementGenerator<Player>::DoReset(Player*);
template void PointMovementGenerator<Creature>::DoReset(Creature*);
template bool PointMovementGenerator<Player>::DoUpdate(Player*, uint32);
template bool PointMovementGenerator<Creature>::DoUpdate(Creature*, uint32);

void AssistanceMovementGenerator::Finalize(Unit* unit)
{
    unit->ToCreature()->SetNoCallAssistance(false);
    unit->ToCreature()->CallAssistance();
    if (unit->IsAlive())
        unit->GetMotionMaster()->MoveSeekAssistanceDistract(sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY));
}

bool EffectMovementGenerator::Update(Unit* unit, uint32)
{
    return !unit->movespline->Finalized();
}

void EffectMovementGenerator::Finalize(Unit* unit)
{
    if (unit->GetTypeId() != TYPEID_UNIT)
        return;

    if (unit->GetTypeId() == TYPEID_UNIT && unit->HasUnitMovementFlag(MOVEMENTFLAG_FALLING) && unit->movespline->isFalling()) // pussywizard
        unit->RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING);

    // Need restore previous movement since we have no proper states system
    //if (unit->IsAlive() && !unit->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_FLEEING))
    //{
    //    if (Unit* victim = unit->GetVictim())
    //        unit->GetMotionMaster()->MoveChase(victim);
    //    else
    //        unit->GetMotionMaster()->Initialize();
    //}

    if (unit->ToCreature()->AI())
        unit->ToCreature()->AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id);
}
<commit_msg>fix(Core/Movement): Fix strange teleport when rooting a fleeing NPC (#5555)<commit_after>/*
 * Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
 * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
 */

#include "Creature.h"
#include "CreatureAI.h"
#include "Errors.h"
#include "MoveSpline.h"
#include "MoveSplineInit.h"
#include "Player.h"
#include "PointMovementGenerator.h"
#include "World.h"

//----- Point Movement Generator
template<class T>
void PointMovementGenerator<T>::DoInitialize(T* unit)
{
    if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
    {
        // the next line is to ensure that a new spline is created in DoUpdate() once the unit is no longer rooted/stunned
        // todo: rename this flag to something more appropriate since it is set to true even without speed change now.
        i_recalculateSpeed = true;
        return;
    }

    if (!unit->IsStopped())
        unit->StopMoving();

    unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
    i_recalculateSpeed = false;
    Movement::MoveSplineInit init(unit);
    if (m_precomputedPath.size() > 2) // pussywizard: for charge
        init.MovebyPath(m_precomputedPath);
    else if (_generatePath)
    {
        PathGenerator path(unit);
        bool result = path.CalculatePath(i_x, i_y, i_z, _forceDestination);
        if (result && !(path.GetPathType() & PATHFIND_NOPATH) && path.GetPath().size() > 2)
        {
            m_precomputedPath = path.GetPath();
            init.MovebyPath(m_precomputedPath);
        }
        else
        {
            // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
            if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
            {
                i_x += 0.2f * cos(unit->GetOrientation());
                i_y += 0.2f * sin(unit->GetOrientation());
            }

            init.MoveTo(i_x, i_y, i_z, true);
        }
    }
    else
    {
        // Xinef: fix strange client visual bug, moving on z coordinate only switches orientation by 180 degrees (visual only)
        if (G3D::fuzzyEq(unit->GetPositionX(), i_x) && G3D::fuzzyEq(unit->GetPositionY(), i_y))
        {
            i_x += 0.2f * cos(unit->GetOrientation());
            i_y += 0.2f * sin(unit->GetOrientation());
        }

        init.MoveTo(i_x, i_y, i_z, true);
    }
    if (speed > 0.0f)
        init.SetVelocity(speed);

    if (i_orientation > 0.0f)
    {
        init.SetFacing(i_orientation);
    }

    init.Launch();
}

template<class T>
bool PointMovementGenerator<T>::DoUpdate(T* unit, uint32 /*diff*/)
{
    if (!unit)
        return false;

    if (unit->HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED))
    {
        unit->ClearUnitState(UNIT_STATE_ROAMING_MOVE);
        return true;
    }

    unit->AddUnitState(UNIT_STATE_ROAMING_MOVE);

    if (i_recalculateSpeed && !unit->movespline->Finalized())
    {
        i_recalculateSpeed = false;
        Movement::MoveSplineInit init(unit);

        // xinef: speed changed during path execution, calculate remaining path and launch it once more
        if (m_precomputedPath.size())
        {
            uint32 offset = std::min(uint32(unit->movespline->_currentSplineIdx()), uint32(m_precomputedPath.size()));
            Movement::PointsArray::iterator offsetItr = m_precomputedPath.begin();
            std::advance(offsetItr, offset);
            m_precomputedPath.erase(m_precomputedPath.begin(), offsetItr);

            // restore 0 element (current position)
            m_precomputedPath.insert(m_precomputedPath.begin(), G3D::Vector3(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()));

            if (m_precomputedPath.size() > 2)
                init.MovebyPath(m_precomputedPath);
            else if (m_precomputedPath.size() == 2)
                init.MoveTo(m_precomputedPath[1].x, m_precomputedPath[1].y, m_precomputedPath[1].z, true);
        }
        else
            init.MoveTo(i_x, i_y, i_z, true);
        if (speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
            init.SetVelocity(speed);

        if (i_orientation > 0.0f)
        {
            init.SetFacing(i_orientation);
        }

        init.Launch();
    }

    return !unit->movespline->Finalized();
}

template<class T>
void PointMovementGenerator<T>::DoFinalize(T* unit)
{
    unit->ClearUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);

    if (unit->movespline->Finalized())
        MovementInform(unit);
}

template<class T>
void PointMovementGenerator<T>::DoReset(T* unit)
{
    if (!unit->IsStopped())
        unit->StopMoving();

    unit->AddUnitState(UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE);
}

template<class T>
void PointMovementGenerator<T>::MovementInform(T* /*unit*/)
{
}

template <> void PointMovementGenerator<Creature>::MovementInform(Creature* unit)
{
    if (unit->AI())
        unit->AI()->MovementInform(POINT_MOTION_TYPE, id);
}

template void PointMovementGenerator<Player>::DoInitialize(Player*);
template void PointMovementGenerator<Creature>::DoInitialize(Creature*);
template void PointMovementGenerator<Player>::DoFinalize(Player*);
template void PointMovementGenerator<Creature>::DoFinalize(Creature*);
template void PointMovementGenerator<Player>::DoReset(Player*);
template void PointMovementGenerator<Creature>::DoReset(Creature*);
template bool PointMovementGenerator<Player>::DoUpdate(Player*, uint32);
template bool PointMovementGenerator<Creature>::DoUpdate(Creature*, uint32);

void AssistanceMovementGenerator::Finalize(Unit* unit)
{
    unit->ToCreature()->SetNoCallAssistance(false);
    unit->ToCreature()->CallAssistance();
    if (unit->IsAlive())
        unit->GetMotionMaster()->MoveSeekAssistanceDistract(sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY));
}

bool EffectMovementGenerator::Update(Unit* unit, uint32)
{
    return !unit->movespline->Finalized();
}

void EffectMovementGenerator::Finalize(Unit* unit)
{
    if (unit->GetTypeId() != TYPEID_UNIT)
        return;

    if (unit->GetTypeId() == TYPEID_UNIT && unit->HasUnitMovementFlag(MOVEMENTFLAG_FALLING) && unit->movespline->isFalling()) // pussywizard
        unit->RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING);

    // Need restore previous movement since we have no proper states system
    //if (unit->IsAlive() && !unit->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_FLEEING))
    //{
    //    if (Unit* victim = unit->GetVictim())
    //        unit->GetMotionMaster()->MoveChase(victim);
    //    else
    //        unit->GetMotionMaster()->Initialize();
    //}

    if (unit->ToCreature()->AI())
        unit->ToCreature()->AI()->MovementInform(EFFECT_MOTION_TYPE, m_Id);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: inidef.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 16:20:06 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _INTN_HXX //autogen
#include <tools/intn.hxx>
#endif
#include "inetdef.hxx"
#include "inidef.hxx"

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

class SfxStdIniDef_Impl: public SfxIniDefaulter
{
public:
                    SfxStdIniDef_Impl( SfxIniDefaultManager *pDefMgr )
                    :   SfxIniDefaulter( pDefMgr )
                    {}
    virtual BOOL    QueryDefault( String &rValue, const SfxIniEntry &rEntry );
};

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

BOOL SfxStdIniDef_Impl::QueryDefault( String &rValue, const SfxIniEntry &rEntry )
{
    switch ( rEntry.GetKey() )
    {
        case SFX_KEY_BROWSERRESTORE:
        {
            rValue = "1";
            return TRUE;
        }

        case SFX_KEY_INET_HOME:
        {
            if ( System::GetLanguage() == LANGUAGE_GERMAN )
                rValue = "http://www.stardivision.de";
            else
                rValue = "http://www.stardivision.com";
            return TRUE;
        }

        case SFX_KEY_INET_MEMCACHE:
            rValue = "4";
            return TRUE;

        case SFX_KEY_INET_DISKCACHE:
            rValue = "2048";
            return TRUE;

        case SFX_KEY_INET_CACHEEXPIRATION:
            rValue = "3";
            return TRUE;

        case SFX_KEY_INET_MAXHTTPCONS:
            rValue = "4";
            return TRUE;

        case SFX_KEY_INET_MAXFTPCONS:
            rValue = "2";
            return TRUE;

//          case SFX_KEY_INET_JAVAMINHEAP:
//              rValue = "256";
//              return TRUE;

//          case SFX_KEY_INET_JAVAMAXHEAP:
//              rValue = "";
//              return TRUE;

        case SFX_KEY_INET_USERAGENT:
            rValue = INET_DEF_CALLERNAME;
            return TRUE;

        case SFX_KEY_INET_EXE_JAVASCRIPT:
#ifdef SOLAR_JAVA
            rValue = "0"; // noch "0", solange es noch soviel Bugs gibt
#else
            rValue = "0"; // immer "0"
#endif
            return TRUE;

        case SFX_KEY_INET_EXE_PLUGIN:
            rValue = "1";
            return TRUE;

/*      case SFX_KEY_INET_JAVA_ENABLE:
#ifdef SOLAR_JAVA
            rValue = "1";
#else
            rValue = "0";
#endif
            return TRUE; */

//          case SFX_KEY_INET_NETACCESS:
//              rValue = "2";
//              return TRUE;

        case SFX_KEY_INET_CHANNELS:
            rValue = "1";
            return TRUE;

        case SFX_KEY_BASIC_ENABLE:
            rValue = "1";
            return TRUE;

        case SFX_KEY_INET_COOKIES:
            rValue = "1";
            return TRUE;

        case SFX_KEY_ICONGRID:
            rValue = "100;70;0";
            return TRUE;

        case SFX_KEY_METAFILEPRINT:
            rValue = "1";
            return TRUE;
    }

    return SfxIniDefaulter::QueryDefault( rValue, rEntry );
}

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

SfxIniDefaultManager::SfxIniDefaultManager()
:   _pList( new SfxIniDefaulterList )
{
    new SfxStdIniDef_Impl( this );
}

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

SfxIniDefaultManager::~SfxIniDefaultManager()
{
    if ( _pList )
    {
        for ( USHORT n = _pList->Count(); n--; )
            delete _pList->GetObject(n);
        delete _pList;
    }
}

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

BOOL SfxIniDefaultManager::QueryDefault
(
    String&             rValue,     /* out: Default-Wert f"ur 'rEntry'
                                       (Default ist Leerstring) */
    const SfxIniEntry&  rEntry      // in:  Beschreibung des Eintrags
)

/*  [Beschreibung]

    "Uber diese interne Methode besorgt sich der <SfxIniManager> den
    Default f"ur einen in 'rEntry' beschriebenen Eintrag.
*/

{
    for ( USHORT n = _pList->Count(); n--; )
        if ( _pList->GetObject(n)->QueryDefault( rValue, rEntry ) )
            return TRUE;
    return FALSE;
}

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

SfxIniDefaulter::SfxIniDefaulter( SfxIniDefaultManager *pManager )

/*  [Beschreibung]

    Der Ctor dieser Klasse meldet die neue Instanz automatisch am
    <SfxiniDefaultManager> 'pManager' an.
*/

:   _pManager( pManager )

{
    pManager->Insert( this );
}

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

SfxIniDefaulter::~SfxIniDefaulter()

/*  [Beschreibung]

    Der Dtor dieser Klasse meldet die neue Instanz automatisch am
    <SfxiniDefaultManager> ab, der im Ctor angegeben wurde.
*/

{
    _pManager->Remove( this );
}

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

BOOL SfxIniDefaulter::QueryDefault
(
    String&             rValue,     /* out: Default-Wert f"ur 'rEntry'
                                       (Default ist Leerstring) */
    const SfxIniEntry&  rEntry      // in:  Beschreibung des Eintrags
)

/*  [Beschreibung]

    Diese virtuelle Methode mu\s "uberladen werden. Sie soll dann in
    'rValue' einen Default-Wert f"ur den in 'rEntry' beschriebenen
    ini-Eintrag setzen, falls ihr dieser bekannt ist.

    [Returnwert]

    TRUE            In 'rValue' befindet sich der Default-Wert.

    FALSE           F"ur diesen Eintrag ist kein Default-Wert bekannt.

*/

{
    return FALSE;
};

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

SfxIniEntry::SfxIniEntry
(
    const String&   aGroup,
    const String&   aKey,
    SfxIniGroup     eGroup,
    SfxIniKey       eKey,
    USHORT          nIndex
)
:   _aGroup( aGroup ),
    _aKey( aKey ),
    _eGroup( eGroup ),
    _eKey( eKey ),
    _nIndex( nIndex )
{
}

<commit_msg>INTEGRATION: CWS internatiodel (1.2.562); FILE MERGED 2006/01/19 19:17:05 er 1.2.562.2: RESYNC: (1.2-1.3); FILE MERGED 2005/06/24 13:12:46 er 1.2.562.1: #i50205# get rid of class International<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: inidef.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: vg $ $Date: 2006-04-07 16:00:51 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#include "inetdef.hxx"
#include "inidef.hxx"

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

class SfxStdIniDef_Impl: public SfxIniDefaulter
{
public:
                    SfxStdIniDef_Impl( SfxIniDefaultManager *pDefMgr )
                    :   SfxIniDefaulter( pDefMgr )
                    {}
    virtual BOOL    QueryDefault( String &rValue, const SfxIniEntry &rEntry );
};

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

BOOL SfxStdIniDef_Impl::QueryDefault( String &rValue, const SfxIniEntry &rEntry )
{
    switch ( rEntry.GetKey() )
    {
        case SFX_KEY_BROWSERRESTORE:
        {
            rValue = "1";
            return TRUE;
        }

        case SFX_KEY_INET_HOME:
        {
            if ( System::GetLanguage() == LANGUAGE_GERMAN )
                rValue = "http://www.stardivision.de";
            else
                rValue = "http://www.stardivision.com";
            return TRUE;
        }

        case SFX_KEY_INET_MEMCACHE:
            rValue = "4";
            return TRUE;

        case SFX_KEY_INET_DISKCACHE:
            rValue = "2048";
            return TRUE;

        case SFX_KEY_INET_CACHEEXPIRATION:
            rValue = "3";
            return TRUE;

        case SFX_KEY_INET_MAXHTTPCONS:
            rValue = "4";
            return TRUE;

        case SFX_KEY_INET_MAXFTPCONS:
            rValue = "2";
            return TRUE;

//          case SFX_KEY_INET_JAVAMINHEAP:
//              rValue = "256";
//              return TRUE;

//          case SFX_KEY_INET_JAVAMAXHEAP:
//              rValue = "";
//              return TRUE;

        case SFX_KEY_INET_USERAGENT:
            rValue = INET_DEF_CALLERNAME;
            return TRUE;

        case SFX_KEY_INET_EXE_JAVASCRIPT:
#ifdef SOLAR_JAVA
            rValue = "0"; // noch "0", solange es noch soviel Bugs gibt
#else
            rValue = "0"; // immer "0"
#endif
            return TRUE;

        case SFX_KEY_INET_EXE_PLUGIN:
            rValue = "1";
            return TRUE;

/*      case SFX_KEY_INET_JAVA_ENABLE:
#ifdef SOLAR_JAVA
            rValue = "1";
#else
            rValue = "0";
#endif
            return TRUE; */

//          case SFX_KEY_INET_NETACCESS:
//              rValue = "2";
//              return TRUE;

        case SFX_KEY_INET_CHANNELS:
            rValue = "1";
            return TRUE;

        case SFX_KEY_BASIC_ENABLE:
            rValue = "1";
            return TRUE;

        case SFX_KEY_INET_COOKIES:
            rValue = "1";
            return TRUE;

        case SFX_KEY_ICONGRID:
            rValue = "100;70;0";
            return TRUE;

        case SFX_KEY_METAFILEPRINT:
            rValue = "1";
            return TRUE;
    }

    return SfxIniDefaulter::QueryDefault( rValue, rEntry );
}

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

SfxIniDefaultManager::SfxIniDefaultManager()
:   _pList( new SfxIniDefaulterList )
{
    new SfxStdIniDef_Impl( this );
}

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

SfxIniDefaultManager::~SfxIniDefaultManager()
{
    if ( _pList )
    {
        for ( USHORT n = _pList->Count(); n--; )
            delete _pList->GetObject(n);
        delete _pList;
    }
}

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

BOOL SfxIniDefaultManager::QueryDefault
(
    String&             rValue,     /* out: Default-Wert f"ur 'rEntry'
                                       (Default ist Leerstring) */
    const SfxIniEntry&  rEntry      // in:  Beschreibung des Eintrags
)

/*  [Beschreibung]

    "Uber diese interne Methode besorgt sich der <SfxIniManager> den
    Default f"ur einen in 'rEntry' beschriebenen Eintrag.
*/

{
    for ( USHORT n = _pList->Count(); n--; )
        if ( _pList->GetObject(n)->QueryDefault( rValue, rEntry ) )
            return TRUE;
    return FALSE;
}

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

SfxIniDefaulter::SfxIniDefaulter( SfxIniDefaultManager *pManager )

/*  [Beschreibung]

    Der Ctor dieser Klasse meldet die neue Instanz automatisch am
    <SfxiniDefaultManager> 'pManager' an.
*/

:   _pManager( pManager )

{
    pManager->Insert( this );
}

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

SfxIniDefaulter::~SfxIniDefaulter()

/*  [Beschreibung]

    Der Dtor dieser Klasse meldet die neue Instanz automatisch am
    <SfxiniDefaultManager> ab, der im Ctor angegeben wurde.
*/

{
    _pManager->Remove( this );
}

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

BOOL SfxIniDefaulter::QueryDefault
(
    String&             rValue,     /* out: Default-Wert f"ur 'rEntry'
                                       (Default ist Leerstring) */
    const SfxIniEntry&  rEntry      // in:  Beschreibung des Eintrags
)

/*  [Beschreibung]

    Diese virtuelle Methode mu\s "uberladen werden. Sie soll dann in
    'rValue' einen Default-Wert f"ur den in 'rEntry' beschriebenen
    ini-Eintrag setzen, falls ihr dieser bekannt ist.

    [Returnwert]

    TRUE            In 'rValue' befindet sich der Default-Wert.

    FALSE           F"ur diesen Eintrag ist kein Default-Wert bekannt.

*/

{
    return FALSE;
};

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

SfxIniEntry::SfxIniEntry
(
    const String&   aGroup,
    const String&   aKey,
    SfxIniGroup     eGroup,
    SfxIniKey       eKey,
    USHORT          nIndex
)
:   _aGroup( aGroup ),
    _aKey( aKey ),
    _eGroup( eGroup ),
    _eKey( eKey ),
    _nIndex( nIndex )
{
}

<|endoftext|>


<commit_before>/*
 * This file is part of ofono-qt
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <QtTest/QtTest>
#include <QtCore/QObject>

#include <ofonophonebook.h>

#include <QtDebug>

class TestOfonoPhonebook : public QObject
{
    Q_OBJECT

private slots:

    void initTestCase()
    {
	m = new OfonoPhonebook(OfonoModem::ManualSelect, "/phonesim", this);
	QCOMPARE(m->modem()->isValid(), true);

	if (!m->modem()->powered()) {
  	    m->modem()->setPowered(true);
            QTest::qWait(5000);
        }
        if (!m->modem()->online()) {
  	    m->modem()->setOnline(true);
            QTest::qWait(5000);
        }

    }

    void testOfonoPhonebook()
    {
        QSignalSpy import(m, SIGNAL(importComplete(bool, QString)));
	m->import();

        for (int i=0; i<30; i++) {
            if (import.count() > 0)
                break;
            QTest::qWait(1000);
        }
	QCOMPARE(import.count(), 1);
	QVariantList list = import.takeFirst();
        QCOMPARE(list.at(0).toBool(), true);
        QVERIFY(list.at(1).toStringList().length() > 0);
    }

    void cleanupTestCase()
    {

    }

private:
    OfonoPhonebook *m;
};

QTEST_MAIN(TestOfonoPhonebook)
#include "test_ofonophonebook.moc"
<commit_msg>Check interface validity before starting tests<commit_after>/*
 * This file is part of ofono-qt
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Alexander Kanavin <alexander.kanavin@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <QtTest/QtTest>
#include <QtCore/QObject>

#include <ofonophonebook.h>

#include <QtDebug>

class TestOfonoPhonebook : public QObject
{
    Q_OBJECT

private slots:

    void initTestCase()
    {
	m = new OfonoPhonebook(OfonoModem::ManualSelect, "/phonesim", this);
	QCOMPARE(m->modem()->isValid(), true);

	if (!m->modem()->powered()) {
  	    m->modem()->setPowered(true);
            QTest::qWait(5000);
        }
        if (!m->modem()->online()) {
  	    m->modem()->setOnline(true);
            QTest::qWait(5000);
        }
	QCOMPARE(m->isValid(), true);
    }

    void testOfonoPhonebook()
    {
        QSignalSpy import(m, SIGNAL(importComplete(bool, QString)));
	m->import();

        for (int i=0; i<30; i++) {
            if (import.count() > 0)
                break;
            QTest::qWait(1000);
        }
	QCOMPARE(import.count(), 1);
	QVariantList list = import.takeFirst();
        QCOMPARE(list.at(0).toBool(), true);
        QVERIFY(list.at(1).toStringList().length() > 0);
    }

    void cleanupTestCase()
    {

    }

private:
    OfonoPhonebook *m;
};

QTEST_MAIN(TestOfonoPhonebook)
#include "test_ofonophonebook.moc"
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: transfrm.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2006-04-19 13:47:32 $
 *
 *  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 _SVX_TRANSFRM_HXX
#define _SVX_TRANSFRM_HXX

// include ---------------------------------------------------------------

#include "dlgctrl.hxx"

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif
class SdrView;

/*************************************************************************
|*
|* Transform-Tab-Dialog
|*
\************************************************************************/

/** put this into the nAnchorTypes parameter of the SvxTransformTabDialog c'tor
    to disable the size controls */
const USHORT SVX_OBJ_NORESIZE = 0x0100;

/** put this into the nAnchorTypes parameter of the SvxTransformTabDialog c'tor
    to disable the protect controls */
const USHORT SVX_OBJ_NOPROTECT = 0x0200;

class SvxTransformTabDialog : public SfxTabDialog
{
private:
    const SdrView*      pView;

    USHORT              nAnchorCtrls;
    Link                aValidateLink;

    virtual void        PageCreated( USHORT nId, SfxTabPage &rPage );

public:

            SvxTransformTabDialog( Window* pParent, const SfxItemSet* pAttr,
                            const SdrView* pView,
                            USHORT nAnchorTypes = 0);
            ~SvxTransformTabDialog();

            //link for the Writer to validate positions
            void SetValidateFramePosLink( const Link& rLink );
};

/*************************************************************************
|*
|* position and size tab page
|*
\************************************************************************/

class SvxPositionSizeTabPage : public SvxTabPage
{
private:
    // position
    FixedLine           maFlPosition;
    FixedText           maFtPosX;
    MetricField         maMtrPosX;
    FixedText           maFtPosY;
    MetricField         maMtrPosY;
    FixedText           maFtPosReference;
    SvxRectCtl          maCtlPos;

    // size
    FixedLine           maFlSize;
    FixedText           maFtWidth;
    MetricField         maMtrWidth;
    FixedText           maFtHeight;
    MetricField         maMtrHeight;
    CheckBox            maCbxScale;
    FixedText           maFtSizeReference;
    SvxRectCtl          maCtlSize;

/*  // anchor
    FixedLine           maAnchorBox;
    FixedText           maFtAnchor;
    ListBox             maDdLbAnchor;
*/
    // protect
    FixedLine           maFlProtect;
    TriStateBox         maTsbPosProtect;
    TriStateBox         maTsbSizeProtect;

    // adjust
    FixedLine           maFlAdjust;
    TriStateBox         maTsbAutoGrowWidth;
    TriStateBox         maTsbAutoGrowHeight;

    // ???
//  FixedText           maFtOrient;
//  ListBox             maDdLbOrient;

    FixedLine           maFlDivider;

private:
    const SfxItemSet&   mrOutAttrs;

    const SdrView*      mpView;
    Rectangle           maRect;
    Rectangle           maWorkArea;

    Point               maAnchorPos;
    SfxMapUnit          mePoolUnit;
    FieldUnit           meDlgUnit;
    MapUnit             meMapUnit;
    TriState            mnProtectSizeState;
    bool                mbPageDisabled;
    bool                mbProtectDisabled;
    bool                mbSizeDisabled;

    // frome size
    UINT32              mlOldWidth;
    UINT32              mlOldHeight;
    RECT_POINT          meRP;

    //------------------------------------
#if _SOLAR__PRIVATE
    DECL_LINK( ChangePosProtectHdl, void * );
    DECL_LINK( ChangeSizeProtectHdl, void * );
    DECL_LINK( ChangePosXHdl, void * );
    DECL_LINK( ChangePosYHdl, void * );
//  DECL_LINK( SetAnchorHdl, ListBox * );
//  DECL_LINK( SetOrientHdl, ListBox * );

    void SetMinMaxPosition();
    void GetTopLeftPosition( long& rX, long& rY, const Rectangle& rRect );
#endif

#if _SOLAR__PRIVATE
    DECL_LINK( ChangeWidthHdl, void * );
    DECL_LINK( ChangeHeightHdl, void * );
    DECL_LINK( ClickSizeProtectHdl, void * );
    DECL_LINK( ClickAutoHdl, void * );

    void        DisableSizeControls();
    void        SetMaxSize( Rectangle aRect );
    Rectangle   GetRect();
#endif

public:
    SvxPositionSizeTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { mpView = pSdrView; }

//  void         ShowAnchorCtrls(USHORT nAnchorCtrls); // Writer-spezifische Controls anzeigen
    virtual void FillUserData();

    void        DisableResize();
    void        DisableProtect();
};

/*************************************************************************
|*
|* Drehwinkel-Tab-Page
|*
\************************************************************************/
class SvxAngleTabPage : public SvxTabPage
{
private:
    FixedLine           aFlPosition;
    FixedText           aFtPosX;
    MetricField         aMtrPosX;
    FixedText           aFtPosY;
    MetricField         aMtrPosY;
    FixedText           aFtPosPresets;
    SvxRectCtl          aCtlRect;

    FixedLine           aFlAngle;
    FixedText           aFtAngle;
    MetricField         aMtrAngle;
    FixedText           aFtAnglePresets;
    SvxRectCtl          aCtlAngle;

    const SfxItemSet&   rOutAttrs;

    const SdrView*      pView;
    Rectangle           aRect;

    Point               aAnchorPos;
    SfxMapUnit          ePoolUnit;
    FieldUnit           eDlgUnit;
    MapUnit             eMapUnit;
    //------------------------------------
#if _SOLAR__PRIVATE
    DECL_LINK( ModifiedHdl, void * );
#endif
public:
         SvxAngleTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { pView = pSdrView; }
};

/*************************************************************************
|*
|* Schraegstellen/Eckenradius-Tab-Page
|*
\************************************************************************/
class SvxSlantTabPage : public SvxTabPage
{
private:
    FixedLine           aFlRadius;
    FixedText           aFtRadius;
    MetricField         aMtrRadius;
    //TriStateBox           aTsbVertical;
    FixedLine           aFlAngle;
    FixedText           aFtAngle;
    MetricField         aMtrAngle;
    //SvxRectCtl            aCtlAngle;

    const SfxItemSet&   rOutAttrs;

    const SdrView*      pView;
    Rectangle           aRect;

    SfxMapUnit          ePoolUnit;
    FieldUnit           eDlgUnit;
    MapUnit             eMapUnit;
    //------------------------------------
#if _SOLAR__PRIVATE
    DECL_LINK( ModifiedHdl, void * );
#endif
public:
         SvxSlantTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { pView = pSdrView; }
};

#endif // _SVX_TRANSFRM_HXX

<commit_msg>INTEGRATION: CWS warnings01 (1.4.222); FILE MERGED 2006/05/23 18:28:41 sb 1.4.222.2: RESYNC: (1.4-1.5); FILE MERGED 2006/05/05 11:03:43 os 1.4.222.1: warnings removed<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: transfrm.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 15:36:19 $
 *
 *  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 _SVX_TRANSFRM_HXX
#define _SVX_TRANSFRM_HXX

// include ---------------------------------------------------------------

#include "dlgctrl.hxx"

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif
class SdrView;

/*************************************************************************
|*
|* Transform-Tab-Dialog
|*
\************************************************************************/

/** put this into the nAnchorTypes parameter of the SvxTransformTabDialog c'tor
    to disable the size controls */
const USHORT SVX_OBJ_NORESIZE = 0x0100;

/** put this into the nAnchorTypes parameter of the SvxTransformTabDialog c'tor
    to disable the protect controls */
const USHORT SVX_OBJ_NOPROTECT = 0x0200;

class SvxTransformTabDialog : public SfxTabDialog
{
private:
    const SdrView*      pView;

    USHORT              nAnchorCtrls;
    Link                aValidateLink;

    virtual void        PageCreated( USHORT nId, SfxTabPage &rPage );

public:

            SvxTransformTabDialog( Window* pParent, const SfxItemSet* pAttr,
                            const SdrView* pView,
                            USHORT nAnchorTypes = 0);
            ~SvxTransformTabDialog();

            //link for the Writer to validate positions
            void SetValidateFramePosLink( const Link& rLink );
};

/*************************************************************************
|*
|* position and size tab page
|*
\************************************************************************/

class SvxPositionSizeTabPage : public SvxTabPage
{
private:
    // position
    FixedLine           maFlPosition;
    FixedText           maFtPosX;
    MetricField         maMtrPosX;
    FixedText           maFtPosY;
    MetricField         maMtrPosY;
    FixedText           maFtPosReference;
    SvxRectCtl          maCtlPos;

    // size
    FixedLine           maFlSize;
    FixedText           maFtWidth;
    MetricField         maMtrWidth;
    FixedText           maFtHeight;
    MetricField         maMtrHeight;
    CheckBox            maCbxScale;
    FixedText           maFtSizeReference;
    SvxRectCtl          maCtlSize;

    // protect
    FixedLine           maFlProtect;
    TriStateBox         maTsbPosProtect;
    TriStateBox         maTsbSizeProtect;

    // adjust
    FixedLine           maFlAdjust;
    TriStateBox         maTsbAutoGrowWidth;
    TriStateBox         maTsbAutoGrowHeight;

    FixedLine           maFlDivider;

private:
    const SfxItemSet&   mrOutAttrs;

    const SdrView*      mpView;
    Rectangle           maRect;
    Rectangle           maWorkArea;

    Point               maAnchorPos;
    SfxMapUnit          mePoolUnit;
    FieldUnit           meDlgUnit;
    MapUnit             meMapUnit;
    TriState            mnProtectSizeState;
    bool                mbPageDisabled;
    bool                mbProtectDisabled;
    bool                mbSizeDisabled;

    // frome size
    UINT32              mlOldWidth;
    UINT32              mlOldHeight;
    RECT_POINT          meRP;

    //------------------------------------
#if _SOLAR__PRIVATE
    DECL_LINK( ChangePosProtectHdl, void * );
    DECL_LINK( ChangeSizeProtectHdl, void * );
    DECL_LINK( ChangePosXHdl, void * );
    DECL_LINK( ChangePosYHdl, void * );
//  DECL_LINK( SetAnchorHdl, ListBox * );
//  DECL_LINK( SetOrientHdl, ListBox * );

    void SetMinMaxPosition();
    void GetTopLeftPosition( long& rX, long& rY, const Rectangle& rRect );
#endif

#if _SOLAR__PRIVATE
    DECL_LINK( ChangeWidthHdl, void * );
    DECL_LINK( ChangeHeightHdl, void * );
    DECL_LINK( ClickSizeProtectHdl, void * );
    DECL_LINK( ClickAutoHdl, void * );

    void        DisableSizeControls();
    void        SetMaxSize( Rectangle aRect );
    Rectangle   GetRect();
#endif

public:
    SvxPositionSizeTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { mpView = pSdrView; }

//  void         ShowAnchorCtrls(USHORT nAnchorCtrls); // Writer-spezifische Controls anzeigen
    virtual void FillUserData();

    void        DisableResize();
    void        DisableProtect();
};

/*************************************************************************
|*
|* Drehwinkel-Tab-Page
|*
\************************************************************************/
class SvxAngleTabPage : public SvxTabPage
{
private:
    FixedLine           aFlPosition;
    FixedText           aFtPosX;
    MetricField         aMtrPosX;
    FixedText           aFtPosY;
    MetricField         aMtrPosY;
    FixedText           aFtPosPresets;
    SvxRectCtl          aCtlRect;

    FixedLine           aFlAngle;
    FixedText           aFtAngle;
    MetricField         aMtrAngle;
    FixedText           aFtAnglePresets;
    SvxRectCtl          aCtlAngle;

    const SfxItemSet&   rOutAttrs;

    const SdrView*      pView;
    Rectangle           aRect;

    Point               aAnchorPos;
    SfxMapUnit          ePoolUnit;
    FieldUnit           eDlgUnit;
    MapUnit             eMapUnit;
    //------------------------------------
#if _SOLAR__PRIVATE
    DECL_LINK( ModifiedHdl, void * );
#endif
public:
         SvxAngleTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { pView = pSdrView; }
};

/*************************************************************************
|*
|* Schraegstellen/Eckenradius-Tab-Page
|*
\************************************************************************/
class SvxSlantTabPage : public SvxTabPage
{
private:
    FixedLine           aFlRadius;
    FixedText           aFtRadius;
    MetricField         aMtrRadius;
    //TriStateBox           aTsbVertical;
    FixedLine           aFlAngle;
    FixedText           aFtAngle;
    MetricField         aMtrAngle;
    //SvxRectCtl            aCtlAngle;

    const SfxItemSet&   rOutAttrs;

    const SdrView*      pView;
    Rectangle           aRect;

    SfxMapUnit          ePoolUnit;
    FieldUnit           eDlgUnit;
    MapUnit             eMapUnit;
    //------------------------------------
public:
         SvxSlantTabPage( Window* pParent, const SfxItemSet& rInAttrs  );

    static SfxTabPage* Create( Window*, const SfxItemSet& );
    static USHORT*     GetRanges();

    virtual BOOL FillItemSet( SfxItemSet& );
    virtual void Reset( const SfxItemSet & );

    virtual void ActivatePage( const SfxItemSet& rSet );
    virtual int  DeactivatePage( SfxItemSet* pSet );

    virtual void PointChanged( Window* pWindow, RECT_POINT eRP );

    void         Construct();
    void         SetView( const SdrView* pSdrView ) { pView = pSdrView; }
};

#endif // _SVX_TRANSFRM_HXX

<|endoftext|>


<commit_before><commit_msg>translate comments<commit_after><|endoftext|>


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

#include "PreSieve.h"
#include "SieveOfEratosthenes.h"

#include <stdexcept>
#include <cstdlib>
#include <cstring>
#include <cassert>

const uint32_t PreSieve::smallPrimes_[9] = { 2, 3, 5, 7, 11, 13, 17, 19, 23 };

/**
 * Pre-sieve multiples of small primes <= limit to speed up the sieve
 * of Eratosthenes.
 * @pre limit >= 11 && limit <= 23
 * @see SieveOfEratosthenes::sieve(uint32_t)
 */
PreSieve::PreSieve(uint32_t limit) : wheelArray_(NULL), size_(0) {
  // limit <= 23 prevents 32 bit overflows
  if (limit < 11 || limit > 23)
    throw std::overflow_error("PreSieve: limit must be >= 11 && <= 23.");
  limit_ = limit;
  primeProduct_ = this->getPrimeProduct(limit_);
  size_ = primeProduct_ / SieveOfEratosthenes::NUMBERS_PER_BYTE;
  this->initWheelArray();
}

PreSieve::~PreSieve() {
  delete[] wheelArray_;
}

uint32_t PreSieve::getPrimeProduct(uint32_t limit) const {
  assert(limit <= 23);
  uint32_t pp = 1;
  for (int i = 0; i < 9 && smallPrimes_[i] <= limit; i++)
    pp *= smallPrimes_[i];
  return pp;
}

/**
 * Allocate the wheelArray_ and remove the multiples of small
 * primes <= limit_ from it.
 */
void PreSieve::initWheelArray() {
  assert(SieveOfEratosthenes::NUMBERS_PER_BYTE == 30);
  assert(size_ > 0);
  const unsigned int unsetBit[30] = {
      BIT0, 0xff, 0xff, 0xff, BIT1, 0xff,
      BIT2, 0xff, 0xff, 0xff, BIT3, 0xff,
      BIT4, 0xff, 0xff, 0xff, BIT5, 0xff,
      0xff, 0xff, 0xff, 0xff, BIT6, 0xff,
      BIT7, 0xff, 0xff, 0xff, 0xff, 0xff };

  wheelArray_ = new uint8_t[size_];
  // initialization, set bits of the first byte to 1
  wheelArray_[0] = 0xff;
  uint32_t primeProduct = 2 * 3 * 5;

  for (int i = 3; i < 9 && smallPrimes_[i] <= limit_; i++) {
    // cross off the multiples of primes < smallPrimes_[i]
    // up to the current prime product
    uint32_t pp30 = primeProduct / SieveOfEratosthenes::NUMBERS_PER_BYTE;
    for (uint32_t j = 1; j < smallPrimes_[i]; j++) {
      assert((j + 1) * pp30 <= size_);
      std::memcpy(&wheelArray_[j * pp30], wheelArray_, pp30);
    }
    primeProduct *= smallPrimes_[i];
    // '- 7' is a correction for primes of type i*30 + 31
    uint32_t multiple = smallPrimes_[i] - 7;
    // cross off the multiples of smallPrimes_[i] up to the current
    // prime product
    while (multiple < primeProduct) {
      uint32_t multipleIndex = multiple / SieveOfEratosthenes::NUMBERS_PER_BYTE;
      uint32_t bitPosition = multiple % SieveOfEratosthenes::NUMBERS_PER_BYTE;
      assert(multipleIndex < size_);
      wheelArray_[multipleIndex] &= unsetBit[bitPosition];
      multiple += smallPrimes_[i] * 2;
    }
  }
}

/**
 * Pre-sieve multiples of small primes <= limit_ (e.g. 19).
 * Resets the sieve array (resets bits to 1) of SieveOfEratosthenes
 * objects after each sieved segment and removes the multiples of
 * small primes without sieving.
 * @see SieveOfEratosthenes::sieve(uint32_t)
 */
void PreSieve::doIt(uint8_t* sieve,
                    uint32_t sieveSize,
                    uint64_t segmentLow) const
{
  // calculate the position of segmentLow within the wheelArray_
  uint32_t sieveOffset = static_cast<uint32_t> (
      segmentLow % primeProduct_) / SieveOfEratosthenes::NUMBERS_PER_BYTE;
  uint32_t sizeLeft = size_ - sieveOffset;

  if (sizeLeft > sieveSize) {
    // copy a chunk of sieveSize bytes to the sieve array
    std::memcpy(sieve, &wheelArray_[sieveOffset], sieveSize);
  } else {
    // copy the last remaining bytes at the end of wheelArray_ to the
    // beginning of the sieve array
    std::memcpy(sieve, &wheelArray_[sieveOffset], sizeLeft);
    // restart copying at the beginning of wheelArray_
    sieveOffset = sizeLeft;
    while (sieveOffset + size_ < sieveSize) {
      std::memcpy(&sieve[sieveOffset], wheelArray_, size_);
      sieveOffset += size_;
    }
    std::memcpy(&sieve[sieveOffset], wheelArray_, sieveSize - sieveOffset);
  }
}
<commit_msg>minor changes<commit_after>//
// Copyright (c) 2011 Kim Walisch, <kim.walisch@gmail.com>.
// All rights reserved.
//
// This file is part of primesieve.
// Visit: http://primesieve.googlecode.com
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//   * Redistributions of source code must retain the above copyright
//     notice, this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above
//     copyright notice, this list of conditions and the following
//     disclaimer in the documentation and/or other materials provided
//     with the distribution.
//   * Neither the name of the author nor the names of its
//     contributors may be used to endorse or promote products derived
//     from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.

#include "PreSieve.h"
#include "SieveOfEratosthenes.h"

#include <stdexcept>
#include <cstdlib>
#include <cstring>
#include <cassert>

const uint32_t PreSieve::smallPrimes_[9] = { 2, 3, 5, 7, 11, 13, 17, 19, 23 };

/**
 * Pre-sieve multiples of small primes <= limit to speed up the sieve
 * of Eratosthenes.
 * @pre limit >= 11 && limit <= 23
 * @see SieveOfEratosthenes::sieve(uint32_t)
 */
PreSieve::PreSieve(uint32_t limit) : wheelArray_(NULL), size_(0) {
  // limit <= 23 prevents 32 bit overflows
  if (limit < 11 || limit > 23)
    throw std::overflow_error("PreSieve: limit must be >= 11 && <= 23.");
  limit_ = limit;
  primeProduct_ = this->getPrimeProduct(limit_);
  size_ = primeProduct_ / SieveOfEratosthenes::NUMBERS_PER_BYTE;
  this->initWheelArray();
}

PreSieve::~PreSieve() {
  delete[] wheelArray_;
}

uint32_t PreSieve::getPrimeProduct(uint32_t limit) const {
  assert(limit <= 23);
  uint32_t pp = 1;
  for (int i = 0; i < 9 && smallPrimes_[i] <= limit; i++)
    pp *= smallPrimes_[i];
  return pp;
}

/**
 * Allocate the wheelArray_ and remove the multiples of small
 * primes <= limit_ from it.
 */
void PreSieve::initWheelArray() {
  assert(SieveOfEratosthenes::NUMBERS_PER_BYTE == 30);
  assert(size_ > 0);
  const uint32_t unsetBit[30] = {
      BIT0, 0xff, 0xff, 0xff, BIT1, 0xff,
      BIT2, 0xff, 0xff, 0xff, BIT3, 0xff,
      BIT4, 0xff, 0xff, 0xff, BIT5, 0xff,
      0xff, 0xff, 0xff, 0xff, BIT6, 0xff,
      BIT7, 0xff, 0xff, 0xff, 0xff, 0xff };

  wheelArray_ = new uint8_t[size_];
  // initialization, set bits of the first byte to 1
  wheelArray_[0] = 0xff;
  uint32_t primeProduct = 2 * 3 * 5;

  for (int i = 3; i < 9 && smallPrimes_[i] <= limit_; i++) {
    // cross off the multiples of primes < smallPrimes_[i]
    // up to the current prime product
    uint32_t pp30 = primeProduct / SieveOfEratosthenes::NUMBERS_PER_BYTE;
    for (uint32_t j = 1; j < smallPrimes_[i]; j++) {
      assert((j + 1) * pp30 <= size_);
      std::memcpy(&wheelArray_[j * pp30], wheelArray_, pp30);
    }
    primeProduct *= smallPrimes_[i];
    // '- 7' is a correction for primes of type i*30 + 31
    uint32_t multiple = smallPrimes_[i] - 7;
    // cross off the multiples of smallPrimes_[i] up to the current
    // prime product
    while (multiple < primeProduct) {
      uint32_t multipleIndex = multiple / SieveOfEratosthenes::NUMBERS_PER_BYTE;
      uint32_t bitPosition = multiple % SieveOfEratosthenes::NUMBERS_PER_BYTE;
      assert(multipleIndex < size_);
      wheelArray_[multipleIndex] &= unsetBit[bitPosition];
      multiple += smallPrimes_[i] * 2;
    }
  }
}

/**
 * Pre-sieve multiples of small primes <= limit_ (e.g. 19).
 * Resets the sieve array (resets bits to 1) of SieveOfEratosthenes
 * objects after each sieved segment and removes the multiples of
 * small primes without sieving.
 * @see SieveOfEratosthenes::sieve(uint32_t)
 */
void PreSieve::doIt(uint8_t* sieve,
                    uint32_t sieveSize,
                    uint64_t segmentLow) const
{
  // calculate the position of segmentLow within the wheelArray_
  uint32_t sieveOffset = static_cast<uint32_t> (
      segmentLow % primeProduct_) / SieveOfEratosthenes::NUMBERS_PER_BYTE;
  uint32_t sizeLeft = size_ - sieveOffset;

  if (sizeLeft > sieveSize) {
    // copy a chunk of sieveSize bytes to the sieve array
    std::memcpy(sieve, &wheelArray_[sieveOffset], sieveSize);
  } else {
    // copy the last remaining bytes at the end of wheelArray_ to the
    // beginning of the sieve array
    std::memcpy(sieve, &wheelArray_[sieveOffset], sizeLeft);
    // restart copying at the beginning of wheelArray_
    sieveOffset = sizeLeft;
    while (sieveOffset + size_ < sieveSize) {
      std::memcpy(&sieve[sieveOffset], wheelArray_, size_);
      sieveOffset += size_;
    }
    std::memcpy(&sieve[sieveOffset], wheelArray_, sieveSize - sieveOffset);
  }
}
<|endoftext|>


<commit_before>// Copyright (c) 2016 Kasper Kronborg Isager and Radosław Niemczyk.
#include <vector>
#include <iostream>
#include <fstream>
#include <hayai/hayai.hpp>
#include <hayai/hayai_posix_main.cpp>
#include <hemingway/vector.hpp>
#include <hemingway/table.hpp>

using namespace lsh;

std::vector<vector> parse(std::string path) {
  std::ifstream stream(path, std::ios::binary);
  std::vector<vector> vectors;

  std::vector<char> buffer(1 << 20);

  while (!stream.eof()) {
    stream.read(&buffer[0], 1 << 20);

    int read = stream.gcount();

    for (int i = 0; i < read; i += 8) {
      unsigned long n;

      for (int j = 0; j < 8; j++) {
        ((char*) &n)[j] = buffer[i + j];
      }

      std::vector<bool> c(64);

      for (int j = 0; j < 64; j++) {
          c[j] = (n >> (63 - j)) & 1;
      }

      vectors.push_back(vector(c));
    }
  }

  return vectors;
}

std::vector<vector> vs = parse("bench/data/vectors.bin");
std::vector<vector> qs = parse("bench/data/queries.bin");
std::vector<vector> gt;

double delta = 0.01;

unsigned short r = 4;
unsigned short l = (1 << (r + 1)) - 1;
unsigned short k = ceil(log2(1 - pow(delta, 1.0 / l)) / log2(1 - r / 64.0));

table t_lin(table::brute({.dimensions = 64}));

table t_cla({.dimensions = 64, .samples = k, .partitions = l});
table t_cov({.dimensions = 64, .radius = r});

unsigned int vn = vs.size();
unsigned int qn = qs.size();

unsigned int vi;
unsigned int qi;

unsigned int runs = 50;

void print_stats(const table& t) {
  table::statistics s = t.stats();

  std::cout << "               ";
  std::cout << "Number of buckets: ";
  std::cout << s.buckets / (1.0 * s.partitions);
  std::cout << " /partition" << std::endl;

  std::cout << "               ";
  std::cout << "Number of vectors: ";
  std::cout << s.vectors / (1.0 * s.buckets);
  std::cout << " /bucket" << std::endl;
}

void print_results(const std::vector<vector>& fs) {
  unsigned int fn = 0;

  for (unsigned int i = 0; i < qn; i++) {
    vector q = qs[i];
    vector t = gt[i];

    if (vector::distance(q, t) <= r) {
      vector f =  fs[i];

      if (f.size() == 0 || vector::distance(q, f) > r) {
        fn++;
      }
    }
  }

  std::cout << "                 ";
  std::cout << "False negatives: ";
  std::cout << fn / (1.0 * qn);
  std::cout << " /query" << std::endl;
}

BENCHMARK(table, insert_linear, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_lin.insert(vs[i]);
}

BENCHMARK(table, insert_classic, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_cla.insert(vs[i]);

  if (i == vn - 1) {
    print_stats(t_cla);
  }
}

BENCHMARK(table, insert_covering, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_cov.insert(vs[i]);

  if (i == vn - 1) {
    print_stats(t_cov);
  }
}

BENCHMARK(table, query_linear, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector r = t_lin.query(q);

  gt.push_back(r);
}

std::vector<vector> vf_cla;

BENCHMARK(table, query_classic, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector t = gt[i];

  vf_cla.push_back(t_cla.query(q));

  if (i == qn - 1) {
    print_results(vf_cla);
  }
}

std::vector<vector> vf_cov;

BENCHMARK(table, query_covering, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector t = gt[i];

  vf_cov.push_back(t_cov.query(q));

  if (i == qn - 1) {
    print_results(vf_cov);
  }
}
<commit_msg>That whitespace...<commit_after>// Copyright (c) 2016 Kasper Kronborg Isager and Radosław Niemczyk.
#include <vector>
#include <iostream>
#include <fstream>
#include <hayai/hayai.hpp>
#include <hayai/hayai_posix_main.cpp>
#include <hemingway/vector.hpp>
#include <hemingway/table.hpp>

using namespace lsh;

std::vector<vector> parse(std::string path) {
  std::ifstream stream(path, std::ios::binary);
  std::vector<vector> vectors;

  std::vector<char> buffer(1 << 20);

  while (!stream.eof()) {
    stream.read(&buffer[0], 1 << 20);

    int read = stream.gcount();

    for (int i = 0; i < read; i += 8) {
      unsigned long n;

      for (int j = 0; j < 8; j++) {
        ((char*) &n)[j] = buffer[i + j];
      }

      std::vector<bool> c(64);

      for (int j = 0; j < 64; j++) {
          c[j] = (n >> (63 - j)) & 1;
      }

      vectors.push_back(vector(c));
    }
  }

  return vectors;
}

std::vector<vector> vs = parse("bench/data/vectors.bin");
std::vector<vector> qs = parse("bench/data/queries.bin");
std::vector<vector> gt;

double delta = 0.01;

unsigned short r = 4;
unsigned short l = (1 << (r + 1)) - 1;
unsigned short k = ceil(log2(1 - pow(delta, 1.0 / l)) / log2(1 - r / 64.0));

table t_lin(table::brute({.dimensions = 64}));

table t_cla({.dimensions = 64, .samples = k, .partitions = l});
table t_cov({.dimensions = 64, .radius = r});

unsigned int vn = vs.size();
unsigned int qn = qs.size();

unsigned int vi;
unsigned int qi;

unsigned int runs = 50;

void print_stats(const table& t) {
  table::statistics s = t.stats();

  std::cout << "               ";
  std::cout << "Number of buckets: ";
  std::cout << s.buckets / (1.0 * s.partitions);
  std::cout << " /partition" << std::endl;

  std::cout << "               ";
  std::cout << "Number of vectors: ";
  std::cout << s.vectors / (1.0 * s.buckets);
  std::cout << " /bucket" << std::endl;
}

void print_results(const std::vector<vector>& fs) {
  unsigned int fn = 0;

  for (unsigned int i = 0; i < qn; i++) {
    vector q = qs[i];
    vector t = gt[i];

    if (vector::distance(q, t) <= r) {
      vector f = fs[i];

      if (f.size() == 0 || vector::distance(q, f) > r) {
        fn++;
      }
    }
  }

  std::cout << "                 ";
  std::cout << "False negatives: ";
  std::cout << fn / (1.0 * qn);
  std::cout << " /query" << std::endl;
}

BENCHMARK(table, insert_linear, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_lin.insert(vs[i]);
}

BENCHMARK(table, insert_classic, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_cla.insert(vs[i]);

  if (i == vn - 1) {
    print_stats(t_cla);
  }
}

BENCHMARK(table, insert_covering, runs, vn / runs) {
  unsigned int i = vi++ % vn;

  t_cov.insert(vs[i]);

  if (i == vn - 1) {
    print_stats(t_cov);
  }
}

BENCHMARK(table, query_linear, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector r = t_lin.query(q);

  gt.push_back(r);
}

std::vector<vector> vf_cla;

BENCHMARK(table, query_classic, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector t = gt[i];

  vf_cla.push_back(t_cla.query(q));

  if (i == qn - 1) {
    print_results(vf_cla);
  }
}

std::vector<vector> vf_cov;

BENCHMARK(table, query_covering, runs, qn / runs) {
  unsigned int i = qi++ % qn;

  vector q = qs[i];
  vector t = gt[i];

  vf_cov.push_back(t_cov.query(q));

  if (i == qn - 1) {
    print_results(vf_cov);
  }
}
<|endoftext|>


<commit_before><commit_msg>CID#736510 mem leaks in early error return cases<commit_after><|endoftext|>


<commit_before>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 *
 */

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <vector>
#include <trng/lcg64_shift.hpp>

/**
 * @author Franz Wilhelmstötter
 * @version $Date: 2012-12-19 $
 */
template<class Random>
class TRNGRandomOutput {
public:

	TRNGRandomOutput(
		unsigned long long seed,
		unsigned int splitp,
		unsigned int splits,
		unsigned long long jump,
		unsigned int jump2
	) {
		_random.seed(seed);
		_random.split(splitp, splits);
		_random.jump(jump);
		_random.jump2(jump2);

		std::stringstream name;
		name << seed << "-";
		name << splitp << "-" << splits << "-";
		name << jump << "-";
		name << jump2;
		_fileName = name.str();
	}

	~TRNGRandomOutput() {
	}

	std::string next() {
		std::stringstream out;
		out << static_cast<long long>(_random());
		return out.str();
	}

	std::string fileName() {
		return _fileName;
	}

private:
	Random _random;
	std::string _fileName;
};

template<class Random>
void write(const std::string& dir, TRNGRandomOutput<Random>& random, std::size_t numbers) {
	std::string file = dir + "/" + random.fileName();
	std::fstream out(file.c_str(), std::fstream::out);

	for (std::size_t i = 0; i < numbers; ++i) {
		out << random.next() << std::endl;
	}

	out.close();
}

int main(void) {

	int count = 0;

	for (unsigned long long seed = 0; seed < 2; ++seed) {
		for (unsigned int splitp = 5; splitp < 10; splitp += 3) {
			for (unsigned int splits = 0; splits < splitp; splits += 2) {
				for (unsigned long long jump = 0; jump < 2; ++jump) {
					for (unsigned int jump2 = 0; jump2 < 64; jump2 += 23) {

						std::cout <<
							"{new Long(" << static_cast<long long>(seed*74236788222246L) << "L), " <<
							"new Integer(" << static_cast<long long>(splitp) << "), " <<
							"new Integer(" << static_cast<long long>(splits) << "), " <<
							"new Long(" << static_cast<long long>(jump*948392782247324L) << "L), " <<
							"new Integer(" << static_cast<long long>(jump2) << ")}," << std::endl;

						TRNGRandomOutput<trng::lcg64_shift> random(
							seed*74236788222246L,
							splitp, splits,
							jump*948392782247324L, jump2
						);
						write<trng::lcg64_shift>("output", random, 150);
					}
				}
			}
		}
	}

	return 0;
}
<commit_msg>Some code cleanup.<commit_after>/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 *
 */

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <vector>
#include <trng/lcg64_shift.hpp>

/**
 * @author Franz Wilhelmstötter
 * @version $Date: 2013-12-08 $
 */
template<class Random>
class TRNGRandomOutput {
public:

	TRNGRandomOutput(
		unsigned long long seed,
		unsigned int splitp,
		unsigned int splits,
		unsigned long long jump,
		unsigned int jump2
	) {
		_random.seed(seed);
		_random.split(splitp, splits);
		_random.jump(jump);
		_random.jump2(jump2);

		std::stringstream name;
		name << seed << "-";
		name << splitp << "-" << splits << "-";
		name << jump << "-";
		name << jump2;
		_fileName = name.str();
	}

	~TRNGRandomOutput() {
	}

	std::string next() {
		std::stringstream out;
		out << static_cast<long long>(_random());
		return out.str();
	}

	std::string fileName() {
		return _fileName;
	}

private:
	Random _random;
	std::string _fileName;
};

template<class Random>
void write(const std::string& dir, TRNGRandomOutput<Random>& random, std::size_t numbers) {
	std::string file = dir + "/" + random.fileName();
	std::fstream out(file.c_str(), std::fstream::out);

	for (std::size_t i = 0; i < numbers; ++i) {
		out << random.next() << std::endl;
	}

	out.close();
}

int main(void) {

	int count = 0;

	for (unsigned long long seed = 0; seed < 2; ++seed) {
		for (unsigned int splitp = 5; splitp < 10; splitp += 3) {
			for (unsigned int splits = 0; splits < splitp; splits += 2) {
				for (unsigned long long jump = 0; jump < 2; ++jump) {
					for (unsigned int jump2 = 0; jump2 < 64; jump2 += 23) {

						std::cout <<
							"{new Long(" << static_cast<long long>(seed*74236788222246L) << "L), " <<
							"new Integer(" << static_cast<long long>(splitp) << "), " <<
							"new Integer(" << static_cast<long long>(splits) << "), " <<
							"new Long(" << static_cast<long long>(jump*948392782247324L) << "L), " <<
							"new Integer(" << static_cast<long long>(jump2) << ")}," << std::endl;

						TRNGRandomOutput<trng::lcg64_shift> random(
							seed*74236788222246L,
							splitp, splits,
							jump*948392782247324L, jump2
						);
						write<trng::lcg64_shift>("output", random, 150);
					}
				}
			}
		}
	}

	return 0;
}
<|endoftext|>


<commit_before>MATFile *pmat;
	int i;
	int	  ndir;
	const char **dir;
	const char *file = "pqfile.mat";
	mxArray *pa;
	const char *name;
	double *in1pr;
	cout << "Hello World!" << endl;
	pmat = matOpen("test.mat", "r");
	if (pmat == NULL) {
		printf("Error opening file\n");

	}
	dir = (const char **)matGetDir(pmat, &ndir);
	if (dir == NULL) {
		printf("Error reading directory of file %s\n", file);
		return(1);
	}
	else {
		printf("Directory of %s:\n", file);
		for (i = 0; i < ndir; i++)
			printf("%s\n", dir[i]);
	}

	mxFree(dir);
	if (matClose(pmat) != 0) {
		printf("Error closing file %s\n", file);
		return(1);
	}
	pmat = matOpen(file, "r");
	if (pmat == NULL) {
		printf("Error reopening file %s\n", file);
		return(1);
	}
	printf("\nExamining the header for each variable:\n");
	for (i = 0; i < ndir; i++) {
		pa = matGetNextVariableInfo(pmat, &name);
		if (pa == NULL) {
			printf("Error reading in file %s\n", file);
			return(1);
		}
		/* Diagnose header pa */
		printf("According to its header, array %s has %d dimensions\n",
			name, mxGetNumberOfDimensions(pa));
		cout << "Value of the dimensions are: ";
		cout << *(mxGetDimensions(pa)+3) << endl;
		if (mxIsFromGlobalWS(pa))
			printf("  and was a global variable when saved\n");
		else
			printf("  and was a local variable when saved\n");
		mxDestroyArray(pa);
	}
	if (matClose(pmat) != 0) {
		printf("Error closing file %s\n", file);
		return(1);
	}
	pmat = matOpen(file, "r");
	if (pmat == NULL) {
		printf("Error reopening file %s\n", file);
		return(1);
	}

	printf("\nReading in the actual array contents:\n");
	for (i = 0; i<ndir; i++) {
		pa = matGetNextVariable(pmat, &name);
		in1pr = mxGetPr(pa);
		cout << "Value of end variable: ";
		cout << *(in1pr+2) << endl;
		if (pa == NULL) {
			printf("Error reading in file %s\n", file);
			return(1);
		}
		/*
		* Diagnose array pa
		*/
		printf("According to its contents, array %s has %d dimensions\n",
			name, mxGetNumberOfDimensions(pa));
		if (mxIsFromGlobalWS(pa))
			printf("  and was a global variable when saved\n");
		else
			printf("  and was a local variable when saved\n");
		//mxDestroyArray(pa);
	}

	if (matClose(pmat) != 0) {
		printf("Error closing file %s\n", file);
		return(1);
	}
	cout << "Value of var variable: ";
	cout << &pa << endl;
	//mexPrintf("in1=%f\n", *in1pr);
	cin >> i;
	return 0;<commit_msg>backup deleted<commit_after><|endoftext|>