<commit_before>/*************************************************************************
 *
 *  $RCSfile: saldata.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-01 14:07:44 $
 *
 *  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 _SVWIN_H
#include <tools/svwin.h>
#endif
#include "rtl/tencinfo.h"

#define _SV_SALDATA_CXX

#ifndef _SV_SALDATA_HXX
#include <saldata.hxx>
#endif
#include <svapp.hxx>

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

rtl_TextEncoding ImplSalGetSystemEncoding()
{
    static UINT nOldAnsiCodePage = 0;
    static rtl_TextEncoding eEncoding = RTL_TEXTENCODING_MS_1252;

    UINT nAnsiCodePage = GetACP();
    if ( nAnsiCodePage != nOldAnsiCodePage )
    {
        rtl_TextEncoding nEnc
            = rtl_getTextEncodingFromWindowsCodePage(nAnsiCodePage);
        if (nEnc != RTL_TEXTENCODING_DONTKNOW)
            eEncoding = nEnc;
    }

    return eEncoding;
}

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

ByteString ImplSalGetWinAnsiString( const UniString& rStr, BOOL bFileName )
{
    rtl_TextEncoding eEncoding = ImplSalGetSystemEncoding();
    if ( bFileName )
    {
        return ByteString( rStr, eEncoding,
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE |
                           RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR |
                           RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 );
    }
    else
    {
        return ByteString( rStr, eEncoding,
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |
                           RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR |
                           RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 );
    }
}

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

UniString ImplSalGetUniString( const sal_Char* pStr, xub_StrLen nLen )
{
    return UniString( pStr, nLen, ImplSalGetSystemEncoding(),
                      RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT |
                      RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
                      RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT );
}

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

int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 )
{
    int         nRet;
    wchar_t     c1;
    char       c2;
    do
    {
        // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
        c1 = *pStr1;
        c2 = *pStr2;
        if ( (c1 >= 65) && (c1 <= 90) )
            c1 += 32;
        if ( (c2 >= 65) && (c2 <= 90) )
            c2 += 32;
        nRet = ((sal_Int32)c1)-((sal_Int32)((unsigned char)c2));
        if ( nRet != 0 )
            break;

        pStr1++;
        pStr2++;
    }
    while ( c2 );

    return nRet;
}

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

LONG ImplSetWindowLong( HWND hWnd, int nIndex, DWORD dwNewLong )
{
    if ( aSalShlData.mbWNT )
        return SetWindowLongW( hWnd, nIndex, dwNewLong );
    else
        return SetWindowLongA( hWnd, nIndex, dwNewLong );
}

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

LONG ImplGetWindowLong( HWND hWnd, int nIndex )
{
    if ( aSalShlData.mbWNT )
        return GetWindowLongW( hWnd, nIndex );
    else
        return GetWindowLongA( hWnd, nIndex );
}

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

WIN_BOOL ImplPostMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
    if ( aSalShlData.mbWNT )
        return PostMessageW( hWnd, nMsg, wParam, lParam );
    else
        return PostMessageA( hWnd, nMsg, wParam, lParam );
}

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

WIN_BOOL ImplSendMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
    WIN_BOOL bRet;
    if ( aSalShlData.mbWNT )
        bRet = SendMessageW( hWnd, nMsg, wParam, lParam );
    else
        bRet = SendMessageA( hWnd, nMsg, wParam, lParam );

    return bRet;
}

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

WIN_BOOL ImplGetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax )
{
    if ( aSalShlData.mbWNT )
        return GetMessageW( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax );
    else
        return GetMessageA( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax );
}

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

WIN_BOOL ImplPeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg )
{
    if ( aSalShlData.mbWNT )
        return PeekMessageW( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg );
    else
        return PeekMessageA( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg );
}

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

LONG ImplDispatchMessage( CONST MSG *lpMsg )
{
    if ( aSalShlData.mbWNT )
        return DispatchMessageW( lpMsg );
    else
        return DispatchMessageA( lpMsg );
}

<commit_msg>INTEGRATION: CWS vclcleanup02 (1.4.228); FILE MERGED 2003/12/18 09:45:41 mt 1.4.228.1: #i23061# header cleanup, remove #ifdef ???_CXX and #define ???_CXX, also removed .impl files and fixed some windows compiler warnings<commit_after>/*************************************************************************
 *
 *  $RCSfile: saldata.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: vg $ $Date: 2004-01-06 14:51:01 $
 *
 *  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 _SVWIN_H
#include <tools/svwin.h>
#endif
#include "rtl/tencinfo.h"

#ifndef _SV_SALDATA_HXX
#include <saldata.hxx>
#endif
#include <svapp.hxx>

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

rtl_TextEncoding ImplSalGetSystemEncoding()
{
    static UINT nOldAnsiCodePage = 0;
    static rtl_TextEncoding eEncoding = RTL_TEXTENCODING_MS_1252;

    UINT nAnsiCodePage = GetACP();
    if ( nAnsiCodePage != nOldAnsiCodePage )
    {
        rtl_TextEncoding nEnc
            = rtl_getTextEncodingFromWindowsCodePage(nAnsiCodePage);
        if (nEnc != RTL_TEXTENCODING_DONTKNOW)
            eEncoding = nEnc;
    }

    return eEncoding;
}

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

ByteString ImplSalGetWinAnsiString( const UniString& rStr, BOOL bFileName )
{
    rtl_TextEncoding eEncoding = ImplSalGetSystemEncoding();
    if ( bFileName )
    {
        return ByteString( rStr, eEncoding,
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE |
                           RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR |
                           RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 );
    }
    else
    {
        return ByteString( rStr, eEncoding,
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT |
                           RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |
                           RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR |
                           RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 );
    }
}

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

UniString ImplSalGetUniString( const sal_Char* pStr, xub_StrLen nLen )
{
    return UniString( pStr, nLen, ImplSalGetSystemEncoding(),
                      RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT |
                      RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
                      RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT );
}

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

int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 )
{
    int         nRet;
    wchar_t     c1;
    char       c2;
    do
    {
        // Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
        c1 = *pStr1;
        c2 = *pStr2;
        if ( (c1 >= 65) && (c1 <= 90) )
            c1 += 32;
        if ( (c2 >= 65) && (c2 <= 90) )
            c2 += 32;
        nRet = ((sal_Int32)c1)-((sal_Int32)((unsigned char)c2));
        if ( nRet != 0 )
            break;

        pStr1++;
        pStr2++;
    }
    while ( c2 );

    return nRet;
}

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

LONG ImplSetWindowLong( HWND hWnd, int nIndex, DWORD dwNewLong )
{
    if ( aSalShlData.mbWNT )
        return SetWindowLongW( hWnd, nIndex, dwNewLong );
    else
        return SetWindowLongA( hWnd, nIndex, dwNewLong );
}

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

LONG ImplGetWindowLong( HWND hWnd, int nIndex )
{
    if ( aSalShlData.mbWNT )
        return GetWindowLongW( hWnd, nIndex );
    else
        return GetWindowLongA( hWnd, nIndex );
}

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

WIN_BOOL ImplPostMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
    if ( aSalShlData.mbWNT )
        return PostMessageW( hWnd, nMsg, wParam, lParam );
    else
        return PostMessageA( hWnd, nMsg, wParam, lParam );
}

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

WIN_BOOL ImplSendMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
{
    WIN_BOOL bRet;
    if ( aSalShlData.mbWNT )
        bRet = SendMessageW( hWnd, nMsg, wParam, lParam );
    else
        bRet = SendMessageA( hWnd, nMsg, wParam, lParam );

    return bRet;
}

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

WIN_BOOL ImplGetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax )
{
    if ( aSalShlData.mbWNT )
        return GetMessageW( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax );
    else
        return GetMessageA( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax );
}

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

WIN_BOOL ImplPeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg )
{
    if ( aSalShlData.mbWNT )
        return PeekMessageW( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg );
    else
        return PeekMessageA( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg );
}

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

LONG ImplDispatchMessage( CONST MSG *lpMsg )
{
    if ( aSalShlData.mbWNT )
        return DispatchMessageW( lpMsg );
    else
        return DispatchMessageA( lpMsg );
}

<|endoftext|>


<commit_before><commit_msg>Guard against wrap-around in SvxFontHeightItem<commit_after><|endoftext|>


<commit_before>#include "audio_facade.h"
#include "audio_engine.h"
#include "audio_handle_impl.h"
#include "audio_source_behaviour.h"

using namespace Halley;

constexpr bool ownAudioThread = false;

AudioFacade::AudioFacade(AudioOutputAPI& output)
	: output(output)
	, running(false)
{
}

AudioFacade::~AudioFacade()
{
	AudioFacade::stopPlayback();
}

void AudioFacade::init()
{
}

void AudioFacade::deInit()
{
	stopPlayback();
}

Vector<std::unique_ptr<const AudioDevice>> AudioFacade::getAudioDevices()
{
	return output.getAudioDevices();
}

void AudioFacade::startPlayback(int deviceNumber)
{
	if (running) {
		stopPlayback();
	}

	auto devices = getAudioDevices();
	if (int(devices.size()) > deviceNumber) {
		engine = std::make_unique<AudioEngine>();

		AudioSpec format;
		format.bufferSize = 2048;
		format.format = AudioSampleFormat::Int16;
		format.numChannels = 2;
		format.sampleRate = 48000;

		AudioSpec obtained = output.openAudioDevice(format, devices.at(deviceNumber).get(), [this]() { onNeedBuffer(); });

		engine->start(obtained, output);
		running = true;

		if (ownAudioThread) {
			audioThread = std::thread([this]() { run(); });
		}

		output.startPlayback();
	}
}

void AudioFacade::stopPlayback()
{
	if (running) {
		{
			std::unique_lock<std::mutex> lock(audioMutex);
			musicTracks.clear();
			running = false;
			engine->stop();
		}
		if (ownAudioThread) {
			audioThread.join();
		}
		output.stopPlayback();
		engine.reset();
	}
}

AudioHandle AudioFacade::playUI(std::shared_ptr<const AudioClip> clip, float volume, float pan, bool loop)
{
	return play(clip, AudioSourcePosition::makeUI(pan), volume, loop);
}

AudioHandle AudioFacade::playMusic(std::shared_ptr<const AudioClip> clip, int track, float fadeInTime, bool loop)
{
	bool hasFade = fadeInTime > 0.0001f;

	stopMusic(track, fadeInTime);
	auto handle = play(clip, AudioSourcePosition::makeFixed(), hasFade ? 0.0f : 1.0f, true);
	musicTracks[track] = handle;

	if (hasFade) {
		handle->setBehaviour(std::make_unique<AudioSourceFadeBehaviour>(fadeInTime, 1.0f, false));
	}

	return handle;
}

AudioHandle AudioFacade::play(std::shared_ptr<const AudioClip> clip, AudioSourcePosition position, float volume, bool loop)
{
	size_t id = uniqueId++;
	enqueue([=] () {
		engine->play(id, clip, position, volume, loop);
	});
	return std::make_shared<AudioHandleImpl>(*this, id);
}

AudioHandle AudioFacade::getMusic(int track)
{
	auto iter = musicTracks.find(track);
	if (iter != musicTracks.end()) {
		return iter->second;
	} else {
		return AudioHandle();
	}
}

void AudioFacade::stopMusic(int track, float fadeOutTime)
{
	auto iter = musicTracks.find(track);
	if (iter != musicTracks.end()) {
		stopMusic(iter->second, fadeOutTime);
		musicTracks.erase(iter);
	}
}

void AudioFacade::stopAllMusic(float fadeOutTime)
{
	for (auto& m: musicTracks) {
		stopMusic(m.second, fadeOutTime);
	}
	musicTracks.clear();
}

void AudioFacade::stopMusic(AudioHandle& handle, float fadeOutTime)
{
	if (fadeOutTime > 0.001f) {
		handle->setBehaviour(std::make_unique<AudioSourceFadeBehaviour>(fadeOutTime, 0.0f, true));
	} else {
		handle->stop();
	}
}

void AudioFacade::onNeedBuffer()
{
	if (!ownAudioThread) {
		stepAudio();
	}
}

void AudioFacade::setGroupVolume(String groupName, float gain)
{
	// TODO
}

void AudioFacade::setListener(AudioListenerData listener)
{
	enqueue([=] () {
		engine->setListener(listener);
	});
}

void AudioFacade::run()
{
	while (running) {
		stepAudio();
	}
}

void AudioFacade::stepAudio()
{
	std::vector<std::function<void()>> toDo;
	{
		std::unique_lock<std::mutex> lock(audioMutex);
		if (!running) {
			return;
		}
		toDo = std::move(inbox);
		inbox.clear();
		playingSoundsNext = engine->getPlayingSounds();
	}

	for (auto& action : toDo) {
		action();
	}

	if (ownAudioThread) {
		engine->run();
	} else {
		engine->generateBuffer();
	}
}

void AudioFacade::enqueue(std::function<void()> action)
{
	if (running) {
		outbox.push_back(action);
	}
}

void AudioFacade::pump()
{
	if (running) {
		std::unique_lock<std::mutex> lock(audioMutex);

		if (!outbox.empty()) {
			size_t i = inbox.size();
			inbox.resize(i + outbox.size());
			for (auto& o: outbox) {
				inbox[i++] = std::move(o);
			}
			outbox.clear();
		}

		playingSounds = playingSoundsNext;
	} else {
		inbox.clear();
		outbox.clear();
	}
}
<commit_msg>Print available audio devices.<commit_after>#include "audio_facade.h"
#include "audio_engine.h"
#include "audio_handle_impl.h"
#include "audio_source_behaviour.h"
#include "halley/support/console.h"

using namespace Halley;

constexpr bool ownAudioThread = false;

AudioFacade::AudioFacade(AudioOutputAPI& output)
	: output(output)
	, running(false)
{
}

AudioFacade::~AudioFacade()
{
	AudioFacade::stopPlayback();
}

void AudioFacade::init()
{
	std::cout << ConsoleColour(Console::GREEN) << "\nInitializing audio...\n" << ConsoleColour();
	std::cout << "Audio devices available:" << std::endl;
	int i = 0;
	for (auto& device: getAudioDevices()) {
		std::cout << "\t" << i++ << ": " << device->getName() << std::endl;
	}
}

void AudioFacade::deInit()
{
	stopPlayback();
}

Vector<std::unique_ptr<const AudioDevice>> AudioFacade::getAudioDevices()
{
	return output.getAudioDevices();
}

void AudioFacade::startPlayback(int deviceNumber)
{
	std::cout << "Using audio device: " << deviceNumber << std::endl;

	if (running) {
		stopPlayback();
	}

	auto devices = getAudioDevices();
	if (int(devices.size()) > deviceNumber) {
		engine = std::make_unique<AudioEngine>();

		AudioSpec format;
		format.bufferSize = 2048;
		format.format = AudioSampleFormat::Int16;
		format.numChannels = 2;
		format.sampleRate = 48000;

		AudioSpec obtained = output.openAudioDevice(format, devices.at(deviceNumber).get(), [this]() { onNeedBuffer(); });

		engine->start(obtained, output);
		running = true;

		if (ownAudioThread) {
			audioThread = std::thread([this]() { run(); });
		}

		output.startPlayback();
	}
}

void AudioFacade::stopPlayback()
{
	if (running) {
		{
			std::unique_lock<std::mutex> lock(audioMutex);
			musicTracks.clear();
			running = false;
			engine->stop();
		}
		if (ownAudioThread) {
			audioThread.join();
		}
		output.stopPlayback();
		engine.reset();
	}
}

AudioHandle AudioFacade::playUI(std::shared_ptr<const AudioClip> clip, float volume, float pan, bool loop)
{
	return play(clip, AudioSourcePosition::makeUI(pan), volume, loop);
}

AudioHandle AudioFacade::playMusic(std::shared_ptr<const AudioClip> clip, int track, float fadeInTime, bool loop)
{
	bool hasFade = fadeInTime > 0.0001f;

	stopMusic(track, fadeInTime);
	auto handle = play(clip, AudioSourcePosition::makeFixed(), hasFade ? 0.0f : 1.0f, true);
	musicTracks[track] = handle;

	if (hasFade) {
		handle->setBehaviour(std::make_unique<AudioSourceFadeBehaviour>(fadeInTime, 1.0f, false));
	}

	return handle;
}

AudioHandle AudioFacade::play(std::shared_ptr<const AudioClip> clip, AudioSourcePosition position, float volume, bool loop)
{
	size_t id = uniqueId++;
	enqueue([=] () {
		engine->play(id, clip, position, volume, loop);
	});
	return std::make_shared<AudioHandleImpl>(*this, id);
}

AudioHandle AudioFacade::getMusic(int track)
{
	auto iter = musicTracks.find(track);
	if (iter != musicTracks.end()) {
		return iter->second;
	} else {
		return AudioHandle();
	}
}

void AudioFacade::stopMusic(int track, float fadeOutTime)
{
	auto iter = musicTracks.find(track);
	if (iter != musicTracks.end()) {
		stopMusic(iter->second, fadeOutTime);
		musicTracks.erase(iter);
	}
}

void AudioFacade::stopAllMusic(float fadeOutTime)
{
	for (auto& m: musicTracks) {
		stopMusic(m.second, fadeOutTime);
	}
	musicTracks.clear();
}

void AudioFacade::stopMusic(AudioHandle& handle, float fadeOutTime)
{
	if (fadeOutTime > 0.001f) {
		handle->setBehaviour(std::make_unique<AudioSourceFadeBehaviour>(fadeOutTime, 0.0f, true));
	} else {
		handle->stop();
	}
}

void AudioFacade::onNeedBuffer()
{
	if (!ownAudioThread) {
		stepAudio();
	}
}

void AudioFacade::setGroupVolume(String groupName, float gain)
{
	// TODO
}

void AudioFacade::setListener(AudioListenerData listener)
{
	enqueue([=] () {
		engine->setListener(listener);
	});
}

void AudioFacade::run()
{
	while (running) {
		stepAudio();
	}
}

void AudioFacade::stepAudio()
{
	std::vector<std::function<void()>> toDo;
	{
		std::unique_lock<std::mutex> lock(audioMutex);
		if (!running) {
			return;
		}
		toDo = std::move(inbox);
		inbox.clear();
		playingSoundsNext = engine->getPlayingSounds();
	}

	for (auto& action : toDo) {
		action();
	}

	if (ownAudioThread) {
		engine->run();
	} else {
		engine->generateBuffer();
	}
}

void AudioFacade::enqueue(std::function<void()> action)
{
	if (running) {
		outbox.push_back(action);
	}
}

void AudioFacade::pump()
{
	if (running) {
		std::unique_lock<std::mutex> lock(audioMutex);

		if (!outbox.empty()) {
			size_t i = inbox.size();
			inbox.resize(i + outbox.size());
			for (auto& o: outbox) {
				inbox[i++] = std::move(o);
			}
			outbox.clear();
		}

		playingSounds = playingSoundsNext;
	} else {
		inbox.clear();
		outbox.clear();
	}
}
<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * @author David N. Bertoni
 */
#include "XSLTProcessorEnvSupportDefault.hpp"

#include <algorithm>

#include <util/XMLURL.hpp>

#include <PlatformSupport/DOMStringHelper.hpp>
#include <PlatformSupport/STLHelper.hpp>

#include <XPath/ElementPrefixResolverProxy.hpp>
#include <XPath/XPathExecutionContext.hpp>

#include <XMLSupport/XMLParserLiaison.hpp>

#include "KeyTable.hpp"
#include "StylesheetRoot.hpp"
#include "XSLTProcessor.hpp"
#include "XSLTInputSource.hpp"

XSLTProcessorEnvSupportDefault::XSLTProcessorEnvSupportDefault(XSLTProcessor*	theProcessor) :
	XSLTProcessorEnvSupport(),
	m_defaultSupport(),
	m_processor(theProcessor),
	m_keyTables(),
	m_xlocatorTable()
{
}

XSLTProcessorEnvSupportDefault::~XSLTProcessorEnvSupportDefault()
{
	reset();
}

void
XSLTProcessorEnvSupportDefault::installExternalFunctionGlobal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName,
			const Function&			function)
{
	XPathEnvSupportDefault::installExternalFunctionGlobal(theNamespace, extensionName, function);
}

void
XSLTProcessorEnvSupportDefault::uninstallExternalFunctionGlobal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName)
{
	XPathEnvSupportDefault::uninstallExternalFunctionGlobal(theNamespace, extensionName);
}

void
XSLTProcessorEnvSupportDefault::installExternalFunctionLocal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName,
			const Function&			function)
{
	m_defaultSupport.installExternalFunctionLocal(theNamespace, extensionName, function);
}

void
XSLTProcessorEnvSupportDefault::uninstallExternalFunctionLocal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName)
{
	m_defaultSupport.uninstallExternalFunctionLocal(theNamespace, extensionName);
}

void
XSLTProcessorEnvSupportDefault::reset()
{
#if !defined(XALAN_NO_NAMESPACES)
	using std::for_each;
#endif

	// Clean up the key table vector
	for_each(m_keyTables.begin(),
			 m_keyTables.end(),
			 makeMapValueDeleteFunctor(m_keyTables));

	m_keyTables.clear();

	m_xlocatorTable.clear();
}

KeyTable*
XSLTProcessorEnvSupportDefault::getKeyTable(const XalanNode*	doc) const
{
	const KeyTablesTableType::const_iterator		i =
					m_keyTables.find(doc);

	if (i == m_keyTables.end())
	{
		return 0;
	}
	else
	{
		return i->second;
	}
}

void
XSLTProcessorEnvSupportDefault::setKeyTable(
			KeyTable*			keytable,
			const XalanNode*	doc)
{
	// Get rid of any existing keytable
	delete m_keyTables[doc];

	m_keyTables[doc] = keytable;
}

const NodeRefListBase*
XSLTProcessorEnvSupportDefault::getNodeSetByKey(
			const XalanNode&		doc,
			const XalanDOMString&	name,
			const XalanDOMString&	ref,
			const PrefixResolver&	resolver,
			XPathExecutionContext&	executionContext) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getNodeSetByKey(doc,
											    name,
												ref,
												resolver,
												executionContext);
	}
	else
	{
		const NodeRefListBase*	nl = 0;

		const Stylesheet* const		theStylesheet =
			m_processor->getStylesheetRoot();

		if (theStylesheet != 0)
		{
			// $$$ ToDo: Figure out this const stuff!!!
			nl = theStylesheet->getNodeSetByKey(&const_cast<XalanNode&>(doc),
												name,
												ref,
												resolver,
												executionContext,
#if defined(XALAN_NO_MUTABLE)
												(KeysTableType&)m_keyTables);
#else
												m_keyTables);
#endif
		}

		if(0 == nl)
		{
			m_processor->error(XalanDOMString("There is no xsl:key declaration for '") + name + XalanDOMString("'!"));
		}

		return nl;
	}
}

XObject*
XSLTProcessorEnvSupportDefault::getVariable(
			XObjectFactory&		factory,
			const QName&		name) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getVariable(factory,
											name);
	}
	else
	{
		return m_processor->getVariable(name);
	}
}

XalanDocument*
XSLTProcessorEnvSupportDefault::parseXML(
		const XalanDOMString&	urlString,
		const XalanDOMString&	base)
{
	if (m_processor == 0)
	{
		return m_defaultSupport.parseXML(urlString, base);
	}
	else
	{
		XMLParserLiaison& parserLiaison = m_processor->getXMLParserLiaison();

		const XMLURL		xslURL(c_wstr(base), c_wstr(urlString));

		const XMLCh* const	urlText = xslURL.getURLText();

		XSLTInputSource		inputSource(urlText);

		XalanDocument*		theDocument =
			parserLiaison.parseXMLStream(inputSource);

		setSourceDocument(urlText, theDocument);

		return theDocument;
	}
}

XalanDocument*
XSLTProcessorEnvSupportDefault::getSourceDocument(const XalanDOMString&		theURI) const
{
	return m_defaultSupport.getSourceDocument(theURI);
}

void
XSLTProcessorEnvSupportDefault::setSourceDocument(
			const XalanDOMString&	theURI,
			XalanDocument*			theDocument)
{
	m_defaultSupport.setSourceDocument(theURI, theDocument);
}

XalanDOMString
XSLTProcessorEnvSupportDefault::findURIFromDoc(const XalanDocument*		owner) const
{
	return m_defaultSupport.findURIFromDoc(owner);
}

XalanDocument*
XSLTProcessorEnvSupportDefault::getDOMFactory() const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getDOMFactory();
	}
	else
	{
		return m_processor->getDOMFactory();
	}
}

bool
XSLTProcessorEnvSupportDefault::elementAvailable(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName) const
{
	return m_defaultSupport.elementAvailable(theNamespace,
											 extensionName);
}

bool
XSLTProcessorEnvSupportDefault::functionAvailable(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName) const
{
	return m_defaultSupport.functionAvailable(theNamespace,
											  extensionName);
}

XObject*
XSLTProcessorEnvSupportDefault::extFunction(
			XPathExecutionContext&			executionContext,
			const XalanDOMString&			theNamespace,
			const XalanDOMString&			extensionName,
			XalanNode*						context,
			const XObjectArgVectorType&		argVec) const
{
	return m_defaultSupport.extFunction(executionContext,
										theNamespace,
										extensionName,
										context,
										argVec);
}

XLocator*
XSLTProcessorEnvSupportDefault::getXLocatorFromNode(const XalanNode*	node) const
{
	const XLocatorTableType::const_iterator		i =
					m_xlocatorTable.find(node);

	if (i == m_xlocatorTable.end())
	{
		return 0;
	}
	else
	{
		return i->second;
	}
}

void
XSLTProcessorEnvSupportDefault::associateXLocatorToNode(
			const XalanNode*	node,
			XLocator*			xlocator)
{
	m_xlocatorTable[node] = xlocator;
}

bool
XSLTProcessorEnvSupportDefault::shouldStripSourceNode(const XalanNode&	node) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.shouldStripSourceNode(node);
	}
	else
	{
		return m_processor->shouldStripSourceNode(node);
	}
}

bool
XSLTProcessorEnvSupportDefault::problem(
			eSource					where,
			eClassification			classification,
			const XalanNode*		styleNode,
			const XalanNode*		sourceNode,
			const XalanDOMString&	msg,
			int						lineNo,
			int						charOffset) const
{
	return m_defaultSupport.problem(where,
									classification,
									styleNode,
									sourceNode,
									msg,
									lineNo,
									charOffset);
}

bool
XSLTProcessorEnvSupportDefault::problem(
			eSource					where,
			eClassification			classification,
			const PrefixResolver*	resolver,
			const XalanNode*		sourceNode,
			const XalanDOMString&	msg,
			int						lineNo,
			int						charOffset) const
{
	return m_defaultSupport.problem(where,
									classification,
									resolver,
									sourceNode,
									msg,
									lineNo,
									charOffset);
}
<commit_msg>Added some special-case code for URL handling.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 1999 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 * @author David N. Bertoni
 */
#include "XSLTProcessorEnvSupportDefault.hpp"

#include <algorithm>

#include <util/XMLURL.hpp>

#include <PlatformSupport/DOMStringHelper.hpp>
#include <PlatformSupport/STLHelper.hpp>

#include <XPath/ElementPrefixResolverProxy.hpp>
#include <XPath/XPathExecutionContext.hpp>

#include <XMLSupport/XMLParserLiaison.hpp>

#include "KeyTable.hpp"
#include "StylesheetRoot.hpp"
#include "XSLTProcessor.hpp"
#include "XSLTInputSource.hpp"

XSLTProcessorEnvSupportDefault::XSLTProcessorEnvSupportDefault(XSLTProcessor*	theProcessor) :
	XSLTProcessorEnvSupport(),
	m_defaultSupport(),
	m_processor(theProcessor),
	m_keyTables(),
	m_xlocatorTable()
{
}

XSLTProcessorEnvSupportDefault::~XSLTProcessorEnvSupportDefault()
{
	reset();
}

void
XSLTProcessorEnvSupportDefault::installExternalFunctionGlobal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName,
			const Function&			function)
{
	XPathEnvSupportDefault::installExternalFunctionGlobal(theNamespace, extensionName, function);
}

void
XSLTProcessorEnvSupportDefault::uninstallExternalFunctionGlobal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName)
{
	XPathEnvSupportDefault::uninstallExternalFunctionGlobal(theNamespace, extensionName);
}

void
XSLTProcessorEnvSupportDefault::installExternalFunctionLocal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName,
			const Function&			function)
{
	m_defaultSupport.installExternalFunctionLocal(theNamespace, extensionName, function);
}

void
XSLTProcessorEnvSupportDefault::uninstallExternalFunctionLocal(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName)
{
	m_defaultSupport.uninstallExternalFunctionLocal(theNamespace, extensionName);
}

void
XSLTProcessorEnvSupportDefault::reset()
{
#if !defined(XALAN_NO_NAMESPACES)
	using std::for_each;
#endif

	// Clean up the key table vector
	for_each(m_keyTables.begin(),
			 m_keyTables.end(),
			 makeMapValueDeleteFunctor(m_keyTables));

	m_keyTables.clear();

	m_xlocatorTable.clear();
}

KeyTable*
XSLTProcessorEnvSupportDefault::getKeyTable(const XalanNode*	doc) const
{
	const KeyTablesTableType::const_iterator		i =
					m_keyTables.find(doc);

	if (i == m_keyTables.end())
	{
		return 0;
	}
	else
	{
		return i->second;
	}
}

void
XSLTProcessorEnvSupportDefault::setKeyTable(
			KeyTable*			keytable,
			const XalanNode*	doc)
{
	// Get rid of any existing keytable
	delete m_keyTables[doc];

	m_keyTables[doc] = keytable;
}

const NodeRefListBase*
XSLTProcessorEnvSupportDefault::getNodeSetByKey(
			const XalanNode&		doc,
			const XalanDOMString&	name,
			const XalanDOMString&	ref,
			const PrefixResolver&	resolver,
			XPathExecutionContext&	executionContext) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getNodeSetByKey(doc,
											    name,
												ref,
												resolver,
												executionContext);
	}
	else
	{
		const NodeRefListBase*	nl = 0;

		const Stylesheet* const		theStylesheet =
			m_processor->getStylesheetRoot();

		if (theStylesheet != 0)
		{
			// $$$ ToDo: Figure out this const stuff!!!
			nl = theStylesheet->getNodeSetByKey(&const_cast<XalanNode&>(doc),
												name,
												ref,
												resolver,
												executionContext,
#if defined(XALAN_NO_MUTABLE)
												(KeysTableType&)m_keyTables);
#else
												m_keyTables);
#endif
		}

		if(0 == nl)
		{
			m_processor->error(XalanDOMString("There is no xsl:key declaration for '") + name + XalanDOMString("'!"));
		}

		return nl;
	}
}

XObject*
XSLTProcessorEnvSupportDefault::getVariable(
			XObjectFactory&		factory,
			const QName&		name) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getVariable(factory,
											name);
	}
	else
	{
		return m_processor->getVariable(name);
	}
}

XalanDocument*
XSLTProcessorEnvSupportDefault::parseXML(
		const XalanDOMString&	urlString,
		const XalanDOMString&	base)
{
	if (m_processor == 0)
	{
		return m_defaultSupport.parseXML(urlString, base);
	}
	else
	{
		XMLParserLiaison&	parserLiaison =
			m_processor->getXMLParserLiaison();

		// $$$ ToDo: we should re-work this code to only use
		// XMLRUL when necessary.
		XMLURL	xslURL;

		// This is a work-around for what I believe is a bug in the
		// Xerces URL code.  If a base identifier ends in a slash,
		// they chop of characters back to the _previous_ slash.
		// So, for instance, a base of "/foo/foo/foo/" and a
		// urlString of file.xml would become /foo/foo/file.xml,
		// instead of /foo/foo/foo/file.xml.
		const unsigned int	indexOfSlash = lastIndexOf(base, '/');

		if (indexOfSlash == length(base) - 1)
		{
			xslURL.setURL(c_wstr(base + urlString));
		}
		else
		{
			xslURL.setURL(c_wstr(base), c_wstr(urlString));
		}

		const XMLCh* const	urlText = xslURL.getURLText();

		XSLTInputSource		inputSource(urlText);

		XalanDocument*		theDocument =
			parserLiaison.parseXMLStream(inputSource);

		setSourceDocument(urlText, theDocument);

		return theDocument;
	}
}

XalanDocument*
XSLTProcessorEnvSupportDefault::getSourceDocument(const XalanDOMString&		theURI) const
{
	return m_defaultSupport.getSourceDocument(theURI);
}

void
XSLTProcessorEnvSupportDefault::setSourceDocument(
			const XalanDOMString&	theURI,
			XalanDocument*			theDocument)
{
	m_defaultSupport.setSourceDocument(theURI, theDocument);
}

XalanDOMString
XSLTProcessorEnvSupportDefault::findURIFromDoc(const XalanDocument*		owner) const
{
	return m_defaultSupport.findURIFromDoc(owner);
}

XalanDocument*
XSLTProcessorEnvSupportDefault::getDOMFactory() const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.getDOMFactory();
	}
	else
	{
		return m_processor->getDOMFactory();
	}
}

bool
XSLTProcessorEnvSupportDefault::elementAvailable(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName) const
{
	return m_defaultSupport.elementAvailable(theNamespace,
											 extensionName);
}

bool
XSLTProcessorEnvSupportDefault::functionAvailable(
			const XalanDOMString&	theNamespace,
			const XalanDOMString&	extensionName) const
{
	return m_defaultSupport.functionAvailable(theNamespace,
											  extensionName);
}

XObject*
XSLTProcessorEnvSupportDefault::extFunction(
			XPathExecutionContext&			executionContext,
			const XalanDOMString&			theNamespace,
			const XalanDOMString&			extensionName,
			XalanNode*						context,
			const XObjectArgVectorType&		argVec) const
{
	return m_defaultSupport.extFunction(executionContext,
										theNamespace,
										extensionName,
										context,
										argVec);
}

XLocator*
XSLTProcessorEnvSupportDefault::getXLocatorFromNode(const XalanNode*	node) const
{
	const XLocatorTableType::const_iterator		i =
					m_xlocatorTable.find(node);

	if (i == m_xlocatorTable.end())
	{
		return 0;
	}
	else
	{
		return i->second;
	}
}

void
XSLTProcessorEnvSupportDefault::associateXLocatorToNode(
			const XalanNode*	node,
			XLocator*			xlocator)
{
	m_xlocatorTable[node] = xlocator;
}

bool
XSLTProcessorEnvSupportDefault::shouldStripSourceNode(const XalanNode&	node) const
{
	if (m_processor == 0)
	{
		return m_defaultSupport.shouldStripSourceNode(node);
	}
	else
	{
		return m_processor->shouldStripSourceNode(node);
	}
}

bool
XSLTProcessorEnvSupportDefault::problem(
			eSource					where,
			eClassification			classification,
			const XalanNode*		styleNode,
			const XalanNode*		sourceNode,
			const XalanDOMString&	msg,
			int						lineNo,
			int						charOffset) const
{
	return m_defaultSupport.problem(where,
									classification,
									styleNode,
									sourceNode,
									msg,
									lineNo,
									charOffset);
}

bool
XSLTProcessorEnvSupportDefault::problem(
			eSource					where,
			eClassification			classification,
			const PrefixResolver*	resolver,
			const XalanNode*		sourceNode,
			const XalanDOMString&	msg,
			int						lineNo,
			int						charOffset) const
{
	return m_defaultSupport.problem(where,
									classification,
									resolver,
									sourceNode,
									msg,
									lineNo,
									charOffset);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ChartTypeHelper.hxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: ihi $ $Date: 2007-11-23 11:55:59 $
 *
 *  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 _CHART2_CHARTTYPEHELPER_HXX
#define _CHART2_CHARTTYPEHELPER_HXX

#ifndef _COM_SUN_STAR_CHART2_XCHARTTYPE_HPP_
#include <com/sun/star/chart2/XChartType.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_AXISTYPE_HPP_
#include <com/sun/star/chart2/AxisType.hpp>
#endif
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/chart2/XDiagram.hpp>

#ifndef _COM_SUN_STAR_DRAWING_DIRECTION3D_HPP_
#include <com/sun/star/drawing/Direction3D.hpp>
#endif

//.............................................................................
namespace chart
{
//.............................................................................

//-----------------------------------------------------------------------------
/**
*/

class ChartTypeHelper
{
public:
    static sal_Bool isSupportingGeometryProperties(  const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingStatisticProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingRegressionProperties(const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingMainAxis(            const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex );
    static sal_Bool isSupportingSecondaryAxis(       const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex );
    static sal_Bool isSupportingAreaProperties(      const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingSymbolProperties(    const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingOverlapAndGapWidthProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingBarConnectors(       const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingRightAngledAxes(     const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static bool     isSupportingAxisSideBySide(      const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );

    //returns sequence of ::com::sun::star::chart::DataLabelPlacement
    static ::com::sun::star::uno::Sequence < sal_Int32 > getSupportedLabelPlacements(
        const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Bool bSwapXAndY
        , const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries );

    static ::com::sun::star::drawing::Direction3D getDefaultSimpleLightDirection( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static ::com::sun::star::drawing::Direction3D getDefaultRealisticLightDirection( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getDefaultDirectLightColor( bool bSimple, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getDefaultAmbientLightColor( bool bSimple, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getNumberOfDisplayedSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nNumberOfSeries );
    static bool noBordersForSimpleScheme( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );

    static sal_Int32 //one of ::com::sun::star::chart2::AxisType
                    getAxisType( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType
                                , sal_Int32 nDimensionIndex );

    /** Determines if all data series of a chart type are attached to the same
        axis.

        @param rOutAxisIndex If, and only if, </TRUE> is returned this
               out-parameter is filled with the index (0 or 1) of the axis to
               which all series are attached.
     */
    static bool allSeriesAttachedToSameAxis(
        const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType,
        sal_Int32 & rOutAxisIndex );
};

//.............................................................................
} //namespace chart
//.............................................................................
#endif
<commit_msg>INTEGRATION: CWS chart19 (1.11.12); FILE MERGED 2007/12/18 13:46:19 bm 1.11.12.2: RESYNC: (1.11-1.12); FILE MERGED 2007/12/15 13:05:10 iha 1.11.12.1: #i16776# starting angle for pie charts<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ChartTypeHelper.hxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: rt $ $Date: 2008-02-18 15:59:02 $
 *
 *  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 _CHART2_CHARTTYPEHELPER_HXX
#define _CHART2_CHARTTYPEHELPER_HXX

#ifndef _COM_SUN_STAR_CHART2_XCHARTTYPE_HPP_
#include <com/sun/star/chart2/XChartType.hpp>
#endif
#ifndef _COM_SUN_STAR_CHART2_AXISTYPE_HPP_
#include <com/sun/star/chart2/AxisType.hpp>
#endif
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/chart2/XDiagram.hpp>

#ifndef _COM_SUN_STAR_DRAWING_DIRECTION3D_HPP_
#include <com/sun/star/drawing/Direction3D.hpp>
#endif

//.............................................................................
namespace chart
{
//.............................................................................

//-----------------------------------------------------------------------------
/**
*/

class ChartTypeHelper
{
public:
    static sal_Bool isSupportingGeometryProperties(  const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingStatisticProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingRegressionProperties(const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingMainAxis(            const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex );
    static sal_Bool isSupportingSecondaryAxis(       const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Int32 nDimensionIndex );
    static sal_Bool isSupportingAreaProperties(      const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingSymbolProperties(    const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingOverlapAndGapWidthProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingBarConnectors(       const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static sal_Bool isSupportingRightAngledAxes(     const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static bool     isSupportingAxisSideBySide(      const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount );
    static bool     isSupportingStartingAngle(       const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );

    //returns sequence of ::com::sun::star::chart::DataLabelPlacement
    static ::com::sun::star::uno::Sequence < sal_Int32 > getSupportedLabelPlacements(
        const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nDimensionCount, sal_Bool bSwapXAndY
        , const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries );

    static ::com::sun::star::drawing::Direction3D getDefaultSimpleLightDirection( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static ::com::sun::star::drawing::Direction3D getDefaultRealisticLightDirection( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getDefaultDirectLightColor( bool bSimple, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getDefaultAmbientLightColor( bool bSimple, const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );
    static sal_Int32 getNumberOfDisplayedSeries( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType, sal_Int32 nNumberOfSeries );
    static bool noBordersForSimpleScheme( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType );

    static sal_Int32 //one of ::com::sun::star::chart2::AxisType
                    getAxisType( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType
                                , sal_Int32 nDimensionIndex );

    /** Determines if all data series of a chart type are attached to the same
        axis.

        @param rOutAxisIndex If, and only if, </TRUE> is returned this
               out-parameter is filled with the index (0 or 1) of the axis to
               which all series are attached.
     */
    static bool allSeriesAttachedToSameAxis(
        const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType,
        sal_Int32 & rOutAxisIndex );
};

//.............................................................................
} //namespace chart
//.............................................................................
#endif
<|endoftext|>


<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_path.h"
#include "chrome/test/ui/ui_layout_test.h"

namespace {
  const char* kResources[] = {
    "content",
    "media-file.js",
    "video-test.js",
  };
}  // anonymous namespace

class AudioUILayoutTest : public UILayoutTest {
  protected:
    virtual ~AudioUILayoutTest() { }

    void RunMediaLayoutTest(const std::string& test_case_file_name) {
      FilePath test_dir;
      FilePath media_test_dir;
      media_test_dir = media_test_dir.AppendASCII("media");
      InitializeForLayoutTest(test_dir, media_test_dir, kNoHttpPort);

      // Copy resources first.
      for (size_t i = 0; i < arraysize(kResources); ++i) {
        AddResourceForLayoutTest(
            test_dir, media_test_dir.AppendASCII(kResources[i]));
      }

      printf("Test: %s\n", test_case_file_name.c_str());
      RunLayoutTest(test_case_file_name, kNoHttpPort);
    }
};

TEST_F(AudioUILayoutTest, AudioConstructorPreload) {
  RunMediaLayoutTest("audio-constructor-preload.html");
}

TEST_F(AudioUILayoutTest, AudioConstructor) {
  RunMediaLayoutTest("audio-constructor.html");
}

TEST_F(AudioUILayoutTest, AudioConstructorSrc) {
  RunMediaLayoutTest("audio-constructor-src.html");
}

TEST_F(AudioUILayoutTest, AudioDataUrl) {
  RunMediaLayoutTest("audio-data-url.html");
}

// The test fails since there is no real audio device on the build bots to get
// the ended event fired. Should pass once we run it on bots with audio devices.
TEST_F(AudioUILayoutTest, DISABLED_AudioGarbageCollect) {
  RunMediaLayoutTest("audio-garbage-collect.html");
}

TEST_F(AudioUILayoutTest, AudioNoInstalledEngines) {
  RunMediaLayoutTest("audio-no-installed-engines.html");
}

#if defined(OS_CHROMEOS) && defined(USE_AURA)
// http://crbug.com/115530
#define MAYBE_AudioOnlyVideoIntrinsicSize FLAKY_AudioOnlyVideoIntrinsicSize
#else
#define MAYBE_AudioOnlyVideoIntrinsicSize AudioOnlyVideoIntrinsicSize
#endif

TEST_F(AudioUILayoutTest, MAYBE_AudioOnlyVideoIntrinsicSize) {
  RunMediaLayoutTest("audio-only-video-intrinsic-size.html");
}

TEST_F(AudioUILayoutTest, AudioPlayEvent) {
  RunMediaLayoutTest("audio-play-event.html");
}

TEST_F(AudioUILayoutTest, MediaCanPlayWavAudio) {
  RunMediaLayoutTest("media-can-play-wav-audio.html");
}

TEST_F(AudioUILayoutTest, MediaDocumentAudioSize) {
  RunMediaLayoutTest("media-document-audio-size.html");
}

<commit_msg>Disable AudioUILayoutTest.AudioOnlyVideoIntrinsicSize on Aura ChromeOS.<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_path.h"
#include "chrome/test/ui/ui_layout_test.h"

namespace {
  const char* kResources[] = {
    "content",
    "media-file.js",
    "video-test.js",
  };
}  // anonymous namespace

class AudioUILayoutTest : public UILayoutTest {
  protected:
    virtual ~AudioUILayoutTest() { }

    void RunMediaLayoutTest(const std::string& test_case_file_name) {
      FilePath test_dir;
      FilePath media_test_dir;
      media_test_dir = media_test_dir.AppendASCII("media");
      InitializeForLayoutTest(test_dir, media_test_dir, kNoHttpPort);

      // Copy resources first.
      for (size_t i = 0; i < arraysize(kResources); ++i) {
        AddResourceForLayoutTest(
            test_dir, media_test_dir.AppendASCII(kResources[i]));
      }

      printf("Test: %s\n", test_case_file_name.c_str());
      RunLayoutTest(test_case_file_name, kNoHttpPort);
    }
};

TEST_F(AudioUILayoutTest, AudioConstructorPreload) {
  RunMediaLayoutTest("audio-constructor-preload.html");
}

TEST_F(AudioUILayoutTest, AudioConstructor) {
  RunMediaLayoutTest("audio-constructor.html");
}

TEST_F(AudioUILayoutTest, AudioConstructorSrc) {
  RunMediaLayoutTest("audio-constructor-src.html");
}

TEST_F(AudioUILayoutTest, AudioDataUrl) {
  RunMediaLayoutTest("audio-data-url.html");
}

// The test fails since there is no real audio device on the build bots to get
// the ended event fired. Should pass once we run it on bots with audio devices.
TEST_F(AudioUILayoutTest, DISABLED_AudioGarbageCollect) {
  RunMediaLayoutTest("audio-garbage-collect.html");
}

TEST_F(AudioUILayoutTest, AudioNoInstalledEngines) {
  RunMediaLayoutTest("audio-no-installed-engines.html");
}

#if defined(OS_CHROMEOS) && defined(USE_AURA)
// http://crbug.com/115530
#define MAYBE_AudioOnlyVideoIntrinsicSize DISABLED_AudioOnlyVideoIntrinsicSize
#else
#define MAYBE_AudioOnlyVideoIntrinsicSize AudioOnlyVideoIntrinsicSize
#endif

TEST_F(AudioUILayoutTest, MAYBE_AudioOnlyVideoIntrinsicSize) {
  RunMediaLayoutTest("audio-only-video-intrinsic-size.html");
}

TEST_F(AudioUILayoutTest, AudioPlayEvent) {
  RunMediaLayoutTest("audio-play-event.html");
}

TEST_F(AudioUILayoutTest, MediaCanPlayWavAudio) {
  RunMediaLayoutTest("media-can-play-wav-audio.html");
}

TEST_F(AudioUILayoutTest, MediaDocumentAudioSize) {
  RunMediaLayoutTest("media-document-audio-size.html");
}

<|endoftext|>


<commit_before>
//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2010 Francois Beaune
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Interface header.
#include "appleseed.h"

namespace foundation
{

//
// Library information.
//

// Return the name of the library.
const char* Appleseed::get_lib_name()
{
// Windows.
#if defined _WIN32

    return "appleseed.dll";

// Mac OS X.
#elif defined __APPLE__

    return "appleseed.dylib";

// Other operating system.
#else

    return "appleseed.so";

#endif
}

// Return the version string of the library.
const char* Appleseed::get_lib_version()
{
    return "1.1.0-UNOFFICIAL";
}

// Return the maturity level of the library.
const char* Appleseed::get_lib_maturity_level()
{
    return "pre-alpha";
}

// Return the build number of the library.
size_t Appleseed::get_lib_build_number()
{
    // This works as follow: the build number is stored in a static variable
    // whose name is unique (the text after build_number_ is a GUID).
    // Before compilation begins, a tool searches for this variable declaration
    // (in this file) and increases the build number by 1.
    static const size_t build_number_335A07D9_68C1_4E21_86FA_60C64BD6FE6C = 7599;
    return build_number_335A07D9_68C1_4E21_86FA_60C64BD6FE6C;
}

// Return the configuration of the library.
const char* Appleseed::get_lib_configuration()
{
#ifdef DEBUG
    return "Debug";
#else
    return "Release";
#endif
}

// Return the compilation date of the library.
const char* Appleseed::get_lib_compilation_date()
{
    return __DATE__;
}

// Return the compilation time of the library.
const char* Appleseed::get_lib_compilation_time()
{
    return __TIME__;
}

}   // namespace foundation
<commit_msg>changed library maturity level from "pre-alpha" to "alpha".<commit_after>
//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2010 Francois Beaune
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

// Interface header.
#include "appleseed.h"

namespace foundation
{

//
// Library information.
//

// Return the name of the library.
const char* Appleseed::get_lib_name()
{
// Windows.
#if defined _WIN32

    return "appleseed.dll";

// Mac OS X.
#elif defined __APPLE__

    return "appleseed.dylib";

// Other operating system.
#else

    return "appleseed.so";

#endif
}

// Return the version string of the library.
const char* Appleseed::get_lib_version()
{
    return "1.1.0-UNOFFICIAL";
}

// Return the maturity level of the library.
const char* Appleseed::get_lib_maturity_level()
{
    return "alpha";
}

// Return the build number of the library.
size_t Appleseed::get_lib_build_number()
{
    // This works as follow: the build number is stored in a static variable
    // whose name is unique (the text after build_number_ is a GUID).
    // Before compilation begins, a tool searches for this variable declaration
    // (in this file) and increases the build number by 1.
    static const size_t build_number_335A07D9_68C1_4E21_86FA_60C64BD6FE6C = 7605;
    return build_number_335A07D9_68C1_4E21_86FA_60C64BD6FE6C;
}

// Return the configuration of the library.
const char* Appleseed::get_lib_configuration()
{
#ifdef DEBUG
    return "Debug";
#else
    return "Release";
#endif
}

// Return the compilation date of the library.
const char* Appleseed::get_lib_compilation_date()
{
    return __DATE__;
}

// Return the compilation time of the library.
const char* Appleseed::get_lib_compilation_time()
{
    return __TIME__;
}

}   // namespace foundation
<|endoftext|>


<commit_before>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/notification_service.h"

#include "base/lazy_instance.h"
#include "base/thread_local.h"

static base::LazyInstance<base::ThreadLocalPointer<NotificationService> >
    lazy_tls_ptr(base::LINKER_INITIALIZED);

// static
NotificationService* NotificationService::current() {
  return lazy_tls_ptr.Pointer()->Get();
}

// static
bool NotificationService::HasKey(const NotificationSourceMap& map,
                                 const NotificationSource& source) {
  return map.find(source.map_key()) != map.end();
}

NotificationService::NotificationService() {
  DCHECK(current() == NULL);
#ifndef NDEBUG
  memset(observer_counts_, 0, sizeof(observer_counts_));
#endif

  lazy_tls_ptr.Pointer()->Set(this);
}

void NotificationService::AddObserver(NotificationObserver* observer,
                                      NotificationType type,
                                      const NotificationSource& source) {
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);

  // We have gotten some crashes where the observer pointer is NULL. The problem
  // is that this happens when we actually execute a notification, so have no
  // way of knowing who the bad observer was. We want to know when this happens
  // in release mode so we know what code to blame the crash on (since this is
  // guaranteed to crash later).
  CHECK(observer);

  NotificationObserverList* observer_list;
  if (HasKey(observers_[type.value], source)) {
    observer_list = observers_[type.value][source.map_key()];
  } else {
    observer_list = new NotificationObserverList;
    observers_[type.value][source.map_key()] = observer_list;
  }

  observer_list->AddObserver(observer);
#ifndef NDEBUG
  ++observer_counts_[type.value];
#endif
}

void NotificationService::RemoveObserver(NotificationObserver* observer,
                                         NotificationType type,
                                         const NotificationSource& source) {
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);
  DCHECK(HasKey(observers_[type.value], source));

  NotificationObserverList* observer_list =
      observers_[type.value][source.map_key()];
  if (observer_list) {
    observer_list->RemoveObserver(observer);
#ifndef NDEBUG
    --observer_counts_[type.value];
#endif
  }

  // TODO(jhughes): Remove observer list from map if empty?
}

void NotificationService::Notify(NotificationType type,
                                 const NotificationSource& source,
                                 const NotificationDetails& details) {
  DCHECK(type.value > NotificationType::ALL) <<
      "Allowed for observing, but not posting.";
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);

  // There's no particular reason for the order in which the different
  // classes of observers get notified here.

  // Notify observers of all types and all sources
  if (HasKey(observers_[NotificationType::ALL], AllSources()) &&
      source != AllSources()) {
    FOR_EACH_OBSERVER(NotificationObserver,
       *observers_[NotificationType::ALL][AllSources().map_key()],
       Observe(type, source, details));
  }

  // Notify observers of all types and the given source
  if (HasKey(observers_[NotificationType::ALL], source)) {
    FOR_EACH_OBSERVER(NotificationObserver,
        *observers_[NotificationType::ALL][source.map_key()],
        Observe(type, source, details));
  }

  // Notify observers of the given type and all sources
  if (HasKey(observers_[type.value], AllSources()) &&
      source != AllSources()) {
    FOR_EACH_OBSERVER(NotificationObserver,
                      *observers_[type.value][AllSources().map_key()],
                      Observe(type, source, details));
  }

  // Notify observers of the given type and the given source
  if (HasKey(observers_[type.value], source)) {
    FOR_EACH_OBSERVER(NotificationObserver,
                      *observers_[type.value][source.map_key()],
                      Observe(type, source, details));
  }
}

NotificationService::~NotificationService() {
  lazy_tls_ptr.Pointer()->Set(NULL);

#ifndef NDEBUG
  for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) {
    if (observer_counts_[i] > 0) {
      LOG(WARNING) << observer_counts_[i] << " notification observer(s) leaked"
          << " of notification type " << i;
    }
  }
#endif

  for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) {
    NotificationSourceMap omap = observers_[i];
    for (NotificationSourceMap::iterator it = omap.begin();
         it != omap.end(); ++it) {
      delete it->second;
    }
  }
}

NotificationObserver::~NotificationObserver() {}
<commit_msg>Add a note pointing at a bug so others don't waste time.<commit_after>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/notification_service.h"

#include "base/lazy_instance.h"
#include "base/thread_local.h"

static base::LazyInstance<base::ThreadLocalPointer<NotificationService> >
    lazy_tls_ptr(base::LINKER_INITIALIZED);

// static
NotificationService* NotificationService::current() {
  return lazy_tls_ptr.Pointer()->Get();
}

// static
bool NotificationService::HasKey(const NotificationSourceMap& map,
                                 const NotificationSource& source) {
  return map.find(source.map_key()) != map.end();
}

NotificationService::NotificationService() {
  DCHECK(current() == NULL);
#ifndef NDEBUG
  memset(observer_counts_, 0, sizeof(observer_counts_));
#endif

  lazy_tls_ptr.Pointer()->Set(this);
}

void NotificationService::AddObserver(NotificationObserver* observer,
                                      NotificationType type,
                                      const NotificationSource& source) {
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);

  // We have gotten some crashes where the observer pointer is NULL. The problem
  // is that this happens when we actually execute a notification, so have no
  // way of knowing who the bad observer was. We want to know when this happens
  // in release mode so we know what code to blame the crash on (since this is
  // guaranteed to crash later).
  CHECK(observer);

  NotificationObserverList* observer_list;
  if (HasKey(observers_[type.value], source)) {
    observer_list = observers_[type.value][source.map_key()];
  } else {
    observer_list = new NotificationObserverList;
    observers_[type.value][source.map_key()] = observer_list;
  }

  observer_list->AddObserver(observer);
#ifndef NDEBUG
  ++observer_counts_[type.value];
#endif
}

void NotificationService::RemoveObserver(NotificationObserver* observer,
                                         NotificationType type,
                                         const NotificationSource& source) {
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);
  DCHECK(HasKey(observers_[type.value], source));

  NotificationObserverList* observer_list =
      observers_[type.value][source.map_key()];
  if (observer_list) {
    observer_list->RemoveObserver(observer);
#ifndef NDEBUG
    --observer_counts_[type.value];
#endif
  }

  // TODO(jhughes): Remove observer list from map if empty?
}

void NotificationService::Notify(NotificationType type,
                                 const NotificationSource& source,
                                 const NotificationDetails& details) {
  DCHECK(type.value > NotificationType::ALL) <<
      "Allowed for observing, but not posting.";
  DCHECK(type.value < NotificationType::NOTIFICATION_TYPE_COUNT);

  // There's no particular reason for the order in which the different
  // classes of observers get notified here.

  // Notify observers of all types and all sources
  if (HasKey(observers_[NotificationType::ALL], AllSources()) &&
      source != AllSources()) {
    FOR_EACH_OBSERVER(NotificationObserver,
       *observers_[NotificationType::ALL][AllSources().map_key()],
       Observe(type, source, details));
  }

  // Notify observers of all types and the given source
  if (HasKey(observers_[NotificationType::ALL], source)) {
    FOR_EACH_OBSERVER(NotificationObserver,
        *observers_[NotificationType::ALL][source.map_key()],
        Observe(type, source, details));
  }

  // Notify observers of the given type and all sources
  if (HasKey(observers_[type.value], AllSources()) &&
      source != AllSources()) {
    FOR_EACH_OBSERVER(NotificationObserver,
                      *observers_[type.value][AllSources().map_key()],
                      Observe(type, source, details));
  }

  // Notify observers of the given type and the given source
  if (HasKey(observers_[type.value], source)) {
    FOR_EACH_OBSERVER(NotificationObserver,
                      *observers_[type.value][source.map_key()],
                      Observe(type, source, details));
  }
}

NotificationService::~NotificationService() {
  lazy_tls_ptr.Pointer()->Set(NULL);

#ifndef NDEBUG
  for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) {
    if (observer_counts_[i] > 0) {
      // This may not be completely fixable -- see
      // http://code.google.com/p/chromium/issues/detail?id=11010 .
      // But any new leaks should be fixed.
      LOG(WARNING) << observer_counts_[i] << " notification observer(s) leaked"
          << " of notification type " << i;
    }
  }
#endif

  for (int i = 0; i < NotificationType::NOTIFICATION_TYPE_COUNT; i++) {
    NotificationSourceMap omap = observers_[i];
    for (NotificationSourceMap::iterator it = omap.begin();
         it != omap.end(); ++it) {
      delete it->second;
    }
  }
}

NotificationObserver::~NotificationObserver() {}
<|endoftext|>


<commit_before>// Copyright (c) 2016, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-pinocchio.
// hpp-pinocchio 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
// 3 of the License, or (at your option) any later version.
//
// hpp-pinocchio 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
// General Lesser Public License for more details.  You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.

#include "pinocchio/multibody/visitor.hpp"
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/algorithm/jacobian.hpp"

namespace se3
{

  // Compute the vector of joint index of the subtree.
  // inline void
  // subtreeIndexes(const Model & model, SubtreeModel & stModel)
  // {
  //   JointIndex root = stModel.root;
  //   const size_t shift = root;
  //   std::vector<bool> shouldInclude (model.nbody-shift, true);
  //   for( Model::JointIndex i= (Model::JointIndex) (model.nbody-1);i>root;--i )
  //   {
  //     if (!shouldInclude[i - shift]) continue;
  //     Model::JointIndex j = i;
  //     while (j > root) j = model.parents[j];
  //     if (j == root) continue;
  //     j = i;
  //     while (j > root) {
  //       shouldInclude[j - shift] = false;
  //       j = model.parents[j];
  //     }
  //   }
  //   stModel.joints.clear();
  //   for(int i=(int)shouldInclude.size()-1; i>=0;--i)
  //     if (shouldInclude[i]) stModel.joints.push_back(i+shift);
  // }

  // struct SubtreeJacobianCenterOfMassBackwardStep
  // : public fusion::JointVisitor<SubtreeJacobianCenterOfMassBackwardStep>
  // {
  //   typedef boost::fusion::vector<const se3::Model &,
  //                                 se3::Data &,
  //                                 JointIndex
  //                                 > ArgsType;

  //   JOINT_VISITOR_INIT(SubtreeJacobianCenterOfMassBackwardStep);

  //   template<typename JointModel>
  //   static void algo(const se3::JointModelBase<JointModel> & jmodel,
  //                    se3::JointDataBase<typename JointModel::JointDataDerived> & jdata,
  //                    const se3::Model& model,
  //                    se3::Data& data,
  //                    const JointIndex& r )
  //   {
  //     const Model::JointIndex & i      = (Model::JointIndex) jmodel.id();
  //     const Model::JointIndex & parent = model.parents[i];

  //     if (i != r) {
  //       data.com[parent]  += data.com[i];
  //       data.mass[parent] += data.mass[i];
  //     }

  //     typedef Data::Matrix6x Matrix6x;
  //     typedef typename SizeDepType<JointModel::NV>::template ColsReturn<Matrix6x>::Type ColBlock;

  //     ColBlock Jcols = jmodel.jointCols(data.J);
  //     Jcols = data.oMi[i].act(jdata.S());

  //     if( JointModel::NV==1 )
  //       data.Jcom.col(jmodel.idx_v())
  //       = data.mass[i] * Jcols.template topLeftCorner<3,1>()
  //       - data.com[i].cross(Jcols.template bottomLeftCorner<3,1>());
  //     else
  //       jmodel.jointCols(data.Jcom)
  //       = data.mass[i] * Jcols.template topRows<3>()
  //       - skew(data.com[i]) * Jcols.template bottomRows<3>();

  //     data.com[i] /= data.mass[i];
  //   }

  // }    ;

  inline void
  subtreeCenterOfMass(const Model & model, Data & data,
                              const std::vector <JointIndex>& roots)
  {
    data.com[0].setZero ();
    data.mass[0] = 0;

    for(Model::JointIndex i=1;i<(Model::JointIndex)(model.nbody);++i)
    {
      const double mass = model.inertias[i].mass();
      const SE3::Vector3 & lever = model.inertias[i].lever();

      data.mass[i] = mass;
      data.com[i] = mass*data.oMi[i].act(lever);
    }

    // Assume root is sorted from largest id.
    // Nasty cast below, from (u-long) size_t to int.
    for( int root=int(roots.size()-1); root>=0; --root )
      {
        se3::JointIndex rootId = roots[root];

        // Backward loop on descendents
        for( se3::JointIndex jid = data.lastChild[rootId];jid>=rootId;--jid )
          {
            const Model::JointIndex & parent = model.parents[jid];
            data.com [parent] += data.com [jid];
            data.mass[parent] += data.mass[jid];
          } // end for jid

        // Backward loop on ancestors
        se3::JointIndex jid = model.parents[rootId];
        rootId = (root>0) ? roots[root-1] : 0;
        while (jid>rootId) // stopping when meeting the next subtree
          {
            const Model::JointIndex & parent = model.parents[jid];
            data.com [parent] += data.com [jid];
            data.mass[parent] += data.mass[jid];
            jid = parent;
          } // end while
      } // end for i

    data.com[0]  /= data.mass[0];
    data.Jcom    /= data.mass[0];
  }

  inline void
  subtreeJacobianCenterOfMass(const Model & model, Data & data,
                              const std::vector <JointIndex>& roots)
  {
    data.com[0].setZero ();
    data.mass[0] = 0;

    for(Model::JointIndex i=1;i<(Model::JointIndex)(model.nbody);++i)
    {
      const double mass = model.inertias[i].mass();
      const SE3::Vector3 & lever = model.inertias[i].lever();

      data.mass[i] = mass;
      data.com[i] = mass*data.oMi[i].act(lever);
    }

    // Assume root is sorted from largest id.
    // Nasty cast below, from (u-long) size_t to int.
    for( int root=int(roots.size()-1); root>=0; --root )
      {
        se3::JointIndex rootId = roots[root];

        // Backward loop on descendents
        for( se3::JointIndex jid = data.lastChild[rootId];jid>=rootId;--jid )
          {
            std::cout << "Bwd1 " << jid << std::endl;
            se3::JacobianCenterOfMassBackwardStep
              ::run(model.joints[jid],data.joints[jid],
                    JacobianCenterOfMassBackwardStep::ArgsType(model,data,false));
            std::cout << data.oMi [jid] << std::endl;
            std::cout << data.mass[jid] << std::endl;
            std::cout << data.com [jid].transpose() << std::endl;
          } // end for jid

        // Backward loop on ancestors
        se3::JointIndex jid = model.parents[rootId];
        rootId = (root>0) ? roots[root-1] : 0;
        while (jid>rootId) // stopping when meeting the next subtree
          {
            std::cout << "Bwd2 " << jid << std::endl;
            se3::JacobianCenterOfMassBackwardStep
              ::run(model.joints[jid],data.joints[jid],
                    JacobianCenterOfMassBackwardStep::ArgsType(model,data,false));

            jid = model.parents[jid];
          } // end while
      } // end for i

    data.com[0]  /= data.mass[0];
    data.Jcom    /= data.mass[0];
  }

} // namespace se3
<commit_msg>Clean code.<commit_after>// Copyright (c) 2016, Joseph Mirabel
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-pinocchio.
// hpp-pinocchio 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
// 3 of the License, or (at your option) any later version.
//
// hpp-pinocchio 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
// General Lesser Public License for more details.  You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-pinocchio. If not, see <http://www.gnu.org/licenses/>.

#include "pinocchio/multibody/visitor.hpp"
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/algorithm/jacobian.hpp"

namespace se3
{

  inline void
  subtreeCenterOfMass(const Model & model, Data & data,
                              const std::vector <JointIndex>& roots)
  {
    data.com[0].setZero ();
    data.mass[0] = 0;

    for(Model::JointIndex i=1;i<(Model::JointIndex)(model.nbody);++i)
    {
      const double mass = model.inertias[i].mass();
      const SE3::Vector3 & lever = model.inertias[i].lever();

      data.mass[i] = mass;
      data.com[i] = mass*data.oMi[i].act(lever);
    }

    // Assume root is sorted from largest id.
    // Nasty cast below, from (u-long) size_t to int.
    for( int root=int(roots.size()-1); root>=0; --root )
      {
        se3::JointIndex rootId = roots[root];

        // Backward loop on descendents
        for( se3::JointIndex jid = data.lastChild[rootId];jid>=rootId;--jid )
          {
            const Model::JointIndex & parent = model.parents[jid];
            data.com [parent] += data.com [jid];
            data.mass[parent] += data.mass[jid];
          } // end for jid

        // Backward loop on ancestors
        se3::JointIndex jid = model.parents[rootId];
        rootId = (root>0) ? roots[root-1] : 0;
        while (jid>rootId) // stopping when meeting the next subtree
          {
            const Model::JointIndex & parent = model.parents[jid];
            data.com [parent] += data.com [jid];
            data.mass[parent] += data.mass[jid];
            jid = parent;
          } // end while
      } // end for i

    data.com[0]  /= data.mass[0];
    data.Jcom    /= data.mass[0];
  }

  inline void
  subtreeJacobianCenterOfMass(const Model & model, Data & data,
                              const std::vector <JointIndex>& roots)
  {
    data.com[0].setZero ();
    data.mass[0] = 0;

    for(Model::JointIndex i=1;i<(Model::JointIndex)(model.nbody);++i)
    {
      const double mass = model.inertias[i].mass();
      const SE3::Vector3 & lever = model.inertias[i].lever();

      data.mass[i] = mass;
      data.com[i] = mass*data.oMi[i].act(lever);
    }

    // Assume root is sorted from largest id.
    // Nasty cast below, from (u-long) size_t to int.
    for( int root=int(roots.size()-1); root>=0; --root )
      {
        se3::JointIndex rootId = roots[root];

        // Backward loop on descendents
        for( se3::JointIndex jid = data.lastChild[rootId];jid>=rootId;--jid )
          {
            std::cout << "Bwd1 " << jid << std::endl;
            se3::JacobianCenterOfMassBackwardStep
              ::run(model.joints[jid],data.joints[jid],
                    JacobianCenterOfMassBackwardStep::ArgsType(model,data,false));
            std::cout << data.oMi [jid] << std::endl;
            std::cout << data.mass[jid] << std::endl;
            std::cout << data.com [jid].transpose() << std::endl;
          } // end for jid

        // Backward loop on ancestors
        se3::JointIndex jid = model.parents[rootId];
        rootId = (root>0) ? roots[root-1] : 0;
        while (jid>rootId) // stopping when meeting the next subtree
          {
            std::cout << "Bwd2 " << jid << std::endl;
            se3::JacobianCenterOfMassBackwardStep
              ::run(model.joints[jid],data.joints[jid],
                    JacobianCenterOfMassBackwardStep::ArgsType(model,data,false));

            jid = model.parents[jid];
          } // end while
      } // end for i

    data.com[0]  /= data.mass[0];
    data.Jcom    /= data.mass[0];
  }

} // namespace se3
<|endoftext|>