<commit_before>//   UString - UTF-8 C++ Library
//     Copyright (c) 2016, 2017 Jeremy Harmon <jeremy.harmon@zoho.com>
//     http://github.com/zordtk/ustring
//
// 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.

#include "UString.h"
#include "utf8/utf8.h"
#include <algorithm>
#include <iterator>

UString::UString(UChar ch) USTRING_NOEXCEPT
{
    append(ch);
}

UString::UString(const char *str) USTRING_NOEXCEPT
{
    if( str != nullptr )
        mData.assign(str);
}

UString::UString(const UString& str) USTRING_NOEXCEPT
{
    mData.assign(str.mData);
}

UString::UString(const std::string& str) USTRING_NOEXCEPT
{
    mData.assign(str);
}

UString& UString::insert(const UString& what, std::size_t where)
{
    if( where == 0 )
    {
        prepend(what);
        return *this;
    }
    else if( where > length()-1 )
    {
        append(what);
        return *this;
    }

    UString retStr;

    std::copy(begin(), std::next(begin(), where), std::back_inserter(retStr));
    retStr.append(what);
    std::copy(std::next(begin(), where), end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Assignment                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::assign(const UString& str)
{
    mData.assign(str.mData);
    return *this;
}

UString& UString::assign(const char* str)
{
    if( str != nullptr )
        mData.assign(str);
    return *this;
}

UString& UString::operator=(const UString& str)
{
    return assign(str);
}

UString& UString::operator=(const char* str)
{
    return assign(str);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Append/Prepend                                                                    ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::append(UChar ch)
{
    utf8::append(ch, std::back_inserter(mData));
    return *this;
}

UString& UString::append(const char* str)
{
    if( str != nullptr )
        mData.append(str);
    return *this;
}

UString& UString::append(const UString& str)
{
    mData.append(str.mData);
    return *this;
}

void UString::push_back(UChar ch)
{
    append(ch);
}

void UString::push_back(const UString& str)
{
    append(str);
}

UString& UString::prepend(UChar ch)
{
    mData = UString(ch).append(*this).mData;
    return *this;
}

UString& UString::prepend(const char *str)
{
    mData = UString(str).append(*this).mData;
    return *this;
}

UString& UString::prepend(const UString& str)
{
    mData = UString(str).append(*this).mData;
    return *this;
}

void UString::push_front(UChar ch)
{
    prepend(ch);
}

void UString::push_front(const UString& str)
{
    prepend(str);
}

UString& UString::operator+=(const UString& str)
{
    append(str);
    return *this;
}

UString& UString::operator+=(const char* str)
{
    append(str);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Comparison                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
bool UString::operator==(const UString& str) const
{
    return( mData == str.mData );
}

bool UString::operator==(const char* str) const
{
    return( str && mData == str );
}

bool UString::operator!=(const UString& str) const
{
    return( mData != str.mData );
}

bool UString::operator!=(const char* str) const
{
    return( str && mData != str );
}

int UString::compare(const UString& other) const
{
    return mData.compare(other.mData);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Case Conversion                                                                   ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::toLower()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toLower());

    assign(tmp);
    return *this;
}

UString& UString::toUpper()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toUpper());

    assign(tmp);
    return *this;
}

UString& UString::toTitleCase()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toTitleCase());

    assign(tmp);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Type-Casting                                                                      ///
/////////////////////////////////////////////////////////////////////////////////////////
const std::string& UString::toStdString() const
{
    return mData;
}

const std::u16string UString::toStdU16String() const
{
    std::u16string u16str;
    utf8::utf8to16(mData.begin(), mData.end(), std::back_inserter(u16str));
    return u16str;
}

const std::u32string UString::toStdU32String() const
{
    std::u32string u32str;
    utf8::utf8to32(mData.begin(), mData.end(), std::back_inserter(u32str));
    return u32str;
}

UString UString::fromStdU16String(const std::u16string& str)
{
    UString retStr;
    utf8::utf16to8(str.begin(), str.end(), std::back_inserter(retStr.mData));
    return retStr;
}

UString UString::fromStdU32String(const std::u32string& str)
{
    UString retStr;
    utf8::utf32to8(str.begin(), str.end(), std::back_inserter(retStr.mData));
    return retStr;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Size                                                                              ///
/////////////////////////////////////////////////////////////////////////////////////////
std::size_t UString::length() const
{
    return utf8::distance(mData.begin(), mData.end());
}

std::size_t UString::size() const
{
    return mData.size();
}

std::size_t UString::maxSize() const
{
    return mData.max_size();
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Character Indexing                                                                ///
/////////////////////////////////////////////////////////////////////////////////////////
const UChar UString::at(std::size_t i) const
{
    utf8::iterator<std::string::const_iterator> iter(mData.begin(), mData.begin(), mData.end());
    for(std::size_t j = 0; j < utf8::distance(mData.begin(), mData.end()); j++, ++iter)
    {
        if( j == i )
            return *iter;
    }

    return UCHAR_CODE_NULL;
}

const UChar UString::operator[](std::size_t i) const
{
    return at(i);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Sub-String                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
UString UString::subStr(std::size_t start, std::size_t len) const
{
    UString retStr;
    auto startIter = mData.begin();
    auto endIter   = mData.begin();

    utf8::advance(startIter, start, mData.end());
    if( len != npos )
    {
        endIter = startIter;
        utf8::advance(endIter, len, mData.end());
    }
    else
        endIter = mData.end();

    std::copy(startIter, endIter, std::back_inserter(retStr.mData));
    return retStr;
}

std::size_t UString::find(UChar ch, std::size_t pos) const
{
    auto startIter = begin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::find(startIter, end(), ch);
    if( iter != end() )
        return std::distance(begin(), iter);

    return npos;
}

std::size_t UString::find(const UString& find, std::size_t start) const
{
    auto startIter = begin();
    if( start != npos )
        std::advance(startIter, start);

    auto iter = std::search(startIter, end(), find.begin(), find.end());
    if( iter != end() )
        return std::distance(begin(), iter);

    return npos;
}

std::size_t UString::findLastOf(UChar ch, std::size_t pos) const
{
    auto startIter = rbegin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::find(startIter, rend(), ch);
    if( iter != rend() )
        return length() - std::distance(rbegin(), iter) - 1;

    return npos;
}

std::size_t UString::findLastOf(const UString& find, std::size_t pos) const
{
    auto startIter = rbegin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::search(startIter, rend(), find.rbegin(), find.rend());
    if( iter != rend() )
        return length() - std::distance(rbegin(), iter) - 1;

    return npos;
}

UString& UString::replace(std::size_t start, std::size_t len, const UString& with)
{
    UString retStr;

    auto firstHalfIter = begin();
    std::advance(firstHalfIter, start);
    std::copy(begin(), firstHalfIter, std::back_inserter(retStr));

    retStr.append(with);
    auto secondHalfIter = begin();
    std::advance(secondHalfIter, start+len);
    std::copy(secondHalfIter, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

UString& UString::replaceAll(const UString& what, const UString& with, std::size_t start)
{
    UString retStr = *this;

    std::size_t startPos = start;
    while( (startPos = retStr.find(what, startPos)) != npos )
    {
        retStr    = retStr.replace(startPos, what.length(), with);
        startPos += with.length();
    }

    assign(retStr);
    return *this;
}

UString& UString::replaceFirst(const UString& what, const UString& with, std::size_t start)
{
    UString retStr = *this;

    std::size_t pos = retStr.find(what, start);
    if( pos != npos )
        retStr = retStr.replace(pos, what.length(), with);

    assign(retStr);
    return *this;
}

UString& UString::replaceLast(const UString& what, const UString& with, std::size_t end)
{
    UString retStr = *this;
    if( end != npos )
        end = length() - end;

    std::size_t pos = retStr.findLastOf(what, end);

    if( pos != npos )
        retStr = retStr.replace(pos-what.length()+1, what.length(), with);

    assign(retStr);
    return *this;
}

UString& UString::clear()
{
    mData.clear();
    return *this;
}

UString& UString::erase(const UString::Iterator& start, const UString::Iterator& stop)
{
    UString retStr;

    std::copy(begin(), start, std::back_inserter(retStr));
    std::copy(stop, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

UString& UString::erase(std::size_t start, std::size_t num)
{
    if( start == 0 )
    {
        assign(subStr(num));
        return *this;
    }
    else if( start == length()-1 )
    {
        assign(subStr(0, length()-1));
        return *this;
    }

    UString retStr;
    auto firstHalfIter = begin();
    auto secondHalfIter = begin();

    std::advance(firstHalfIter, start);
    std::advance(secondHalfIter, start+num);

    std::copy(begin(), firstHalfIter, std::back_inserter(retStr));
    std::copy(secondHalfIter, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

std::ostream& operator<<(std::ostream& os, const UString& str)
{
    os << str.toStdString();
    return os;
}

bool operator<(const UString &str1, const UString &str2)
{
    return( str1.compare(str2) );
}<commit_msg>Changed the way operator< is compared<commit_after>//   UString - UTF-8 C++ Library
//     Copyright (c) 2016, 2017 Jeremy Harmon <jeremy.harmon@zoho.com>
//     http://github.com/zordtk/ustring
//
// 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.

#include "UString.h"
#include "utf8/utf8.h"
#include <algorithm>
#include <iterator>

UString::UString(UChar ch) USTRING_NOEXCEPT
{
    append(ch);
}

UString::UString(const char *str) USTRING_NOEXCEPT
{
    if( str != nullptr )
        mData.assign(str);
}

UString::UString(const UString& str) USTRING_NOEXCEPT
{
    mData.assign(str.mData);
}

UString::UString(const std::string& str) USTRING_NOEXCEPT
{
    mData.assign(str);
}

UString& UString::insert(const UString& what, std::size_t where)
{
    if( where == 0 )
    {
        prepend(what);
        return *this;
    }
    else if( where > length()-1 )
    {
        append(what);
        return *this;
    }

    UString retStr;

    std::copy(begin(), std::next(begin(), where), std::back_inserter(retStr));
    retStr.append(what);
    std::copy(std::next(begin(), where), end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Assignment                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::assign(const UString& str)
{
    mData.assign(str.mData);
    return *this;
}

UString& UString::assign(const char* str)
{
    if( str != nullptr )
        mData.assign(str);
    return *this;
}

UString& UString::operator=(const UString& str)
{
    return assign(str);
}

UString& UString::operator=(const char* str)
{
    return assign(str);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Append/Prepend                                                                    ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::append(UChar ch)
{
    utf8::append(ch, std::back_inserter(mData));
    return *this;
}

UString& UString::append(const char* str)
{
    if( str != nullptr )
        mData.append(str);
    return *this;
}

UString& UString::append(const UString& str)
{
    mData.append(str.mData);
    return *this;
}

void UString::push_back(UChar ch)
{
    append(ch);
}

void UString::push_back(const UString& str)
{
    append(str);
}

UString& UString::prepend(UChar ch)
{
    mData = UString(ch).append(*this).mData;
    return *this;
}

UString& UString::prepend(const char *str)
{
    mData = UString(str).append(*this).mData;
    return *this;
}

UString& UString::prepend(const UString& str)
{
    mData = UString(str).append(*this).mData;
    return *this;
}

void UString::push_front(UChar ch)
{
    prepend(ch);
}

void UString::push_front(const UString& str)
{
    prepend(str);
}

UString& UString::operator+=(const UString& str)
{
    append(str);
    return *this;
}

UString& UString::operator+=(const char* str)
{
    append(str);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Comparison                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
bool UString::operator==(const UString& str) const
{
    return( mData == str.mData );
}

bool UString::operator==(const char* str) const
{
    return( str && mData == str );
}

bool UString::operator!=(const UString& str) const
{
    return( mData != str.mData );
}

bool UString::operator!=(const char* str) const
{
    return( str && mData != str );
}

int UString::compare(const UString& other) const
{
    return mData.compare(other.mData);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Case Conversion                                                                   ///
/////////////////////////////////////////////////////////////////////////////////////////
UString& UString::toLower()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toLower());

    assign(tmp);
    return *this;
}

UString& UString::toUpper()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toUpper());

    assign(tmp);
    return *this;
}

UString& UString::toTitleCase()
{
    UString tmp;
    for( UChar ch : *this )
        tmp.append(ch.toTitleCase());

    assign(tmp);
    return *this;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Type-Casting                                                                      ///
/////////////////////////////////////////////////////////////////////////////////////////
const std::string& UString::toStdString() const
{
    return mData;
}

const std::u16string UString::toStdU16String() const
{
    std::u16string u16str;
    utf8::utf8to16(mData.begin(), mData.end(), std::back_inserter(u16str));
    return u16str;
}

const std::u32string UString::toStdU32String() const
{
    std::u32string u32str;
    utf8::utf8to32(mData.begin(), mData.end(), std::back_inserter(u32str));
    return u32str;
}

UString UString::fromStdU16String(const std::u16string& str)
{
    UString retStr;
    utf8::utf16to8(str.begin(), str.end(), std::back_inserter(retStr.mData));
    return retStr;
}

UString UString::fromStdU32String(const std::u32string& str)
{
    UString retStr;
    utf8::utf32to8(str.begin(), str.end(), std::back_inserter(retStr.mData));
    return retStr;
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Size                                                                              ///
/////////////////////////////////////////////////////////////////////////////////////////
std::size_t UString::length() const
{
    return utf8::distance(mData.begin(), mData.end());
}

std::size_t UString::size() const
{
    return mData.size();
}

std::size_t UString::maxSize() const
{
    return mData.max_size();
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Character Indexing                                                                ///
/////////////////////////////////////////////////////////////////////////////////////////
const UChar UString::at(std::size_t i) const
{
    utf8::iterator<std::string::const_iterator> iter(mData.begin(), mData.begin(), mData.end());
    for(std::size_t j = 0; j < utf8::distance(mData.begin(), mData.end()); j++, ++iter)
    {
        if( j == i )
            return *iter;
    }

    return UCHAR_CODE_NULL;
}

const UChar UString::operator[](std::size_t i) const
{
    return at(i);
}

/////////////////////////////////////////////////////////////////////////////////////////
/// Sub-String                                                                        ///
/////////////////////////////////////////////////////////////////////////////////////////
UString UString::subStr(std::size_t start, std::size_t len) const
{
    UString retStr;
    auto startIter = mData.begin();
    auto endIter   = mData.begin();

    utf8::advance(startIter, start, mData.end());
    if( len != npos )
    {
        endIter = startIter;
        utf8::advance(endIter, len, mData.end());
    }
    else
        endIter = mData.end();

    std::copy(startIter, endIter, std::back_inserter(retStr.mData));
    return retStr;
}

std::size_t UString::find(UChar ch, std::size_t pos) const
{
    auto startIter = begin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::find(startIter, end(), ch);
    if( iter != end() )
        return std::distance(begin(), iter);

    return npos;
}

std::size_t UString::find(const UString& find, std::size_t start) const
{
    auto startIter = begin();
    if( start != npos )
        std::advance(startIter, start);

    auto iter = std::search(startIter, end(), find.begin(), find.end());
    if( iter != end() )
        return std::distance(begin(), iter);

    return npos;
}

std::size_t UString::findLastOf(UChar ch, std::size_t pos) const
{
    auto startIter = rbegin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::find(startIter, rend(), ch);
    if( iter != rend() )
        return length() - std::distance(rbegin(), iter) - 1;

    return npos;
}

std::size_t UString::findLastOf(const UString& find, std::size_t pos) const
{
    auto startIter = rbegin();
    if( pos != npos )
        std::advance(startIter, pos);

    auto iter = std::search(startIter, rend(), find.rbegin(), find.rend());
    if( iter != rend() )
        return length() - std::distance(rbegin(), iter) - 1;

    return npos;
}

UString& UString::replace(std::size_t start, std::size_t len, const UString& with)
{
    UString retStr;

    auto firstHalfIter = begin();
    std::advance(firstHalfIter, start);
    std::copy(begin(), firstHalfIter, std::back_inserter(retStr));

    retStr.append(with);
    auto secondHalfIter = begin();
    std::advance(secondHalfIter, start+len);
    std::copy(secondHalfIter, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

UString& UString::replaceAll(const UString& what, const UString& with, std::size_t start)
{
    UString retStr = *this;

    std::size_t startPos = start;
    while( (startPos = retStr.find(what, startPos)) != npos )
    {
        retStr    = retStr.replace(startPos, what.length(), with);
        startPos += with.length();
    }

    assign(retStr);
    return *this;
}

UString& UString::replaceFirst(const UString& what, const UString& with, std::size_t start)
{
    UString retStr = *this;

    std::size_t pos = retStr.find(what, start);
    if( pos != npos )
        retStr = retStr.replace(pos, what.length(), with);

    assign(retStr);
    return *this;
}

UString& UString::replaceLast(const UString& what, const UString& with, std::size_t end)
{
    UString retStr = *this;
    if( end != npos )
        end = length() - end;

    std::size_t pos = retStr.findLastOf(what, end);

    if( pos != npos )
        retStr = retStr.replace(pos-what.length()+1, what.length(), with);

    assign(retStr);
    return *this;
}

UString& UString::clear()
{
    mData.clear();
    return *this;
}

UString& UString::erase(const UString::Iterator& start, const UString::Iterator& stop)
{
    UString retStr;

    std::copy(begin(), start, std::back_inserter(retStr));
    std::copy(stop, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

UString& UString::erase(std::size_t start, std::size_t num)
{
    if( start == 0 )
    {
        assign(subStr(num));
        return *this;
    }
    else if( start == length()-1 )
    {
        assign(subStr(0, length()-1));
        return *this;
    }

    UString retStr;
    auto firstHalfIter = begin();
    auto secondHalfIter = begin();

    std::advance(firstHalfIter, start);
    std::advance(secondHalfIter, start+num);

    std::copy(begin(), firstHalfIter, std::back_inserter(retStr));
    std::copy(secondHalfIter, end(), std::back_inserter(retStr));

    assign(retStr);
    return *this;
}

std::ostream& operator<<(std::ostream& os, const UString& str)
{
    os << str.toStdString();
    return os;
}

bool operator<(const UString &str1, const UString &str2)
{
    return( str1.toStdString() < str2.toStdString() );
}<|endoftext|>


<commit_before>#include "Gfx.h"
#include "DX11.h"
#include "Gui.h"
#include <dxgi1_2.h>
#include <imgui/imgui.h>
#include <utils_window.h>
#include <utils_dwm.h>
#include <bblib/logging.h>

namespace bb {

	Gfx::~Gfx () { }

	bool Gfx::Init ()
	{
		TRACE_MSG(LL_INFO, CTX_BB | CTX_INIT, "Initializing gfx");
		m_dx11 = new DX11;
		if (m_dx11->CreateDeviceD3D(nullptr) < 0)
		{
			TRACE_MSG(LL_ERROR, CTX_BB | CTX_GFX | CTX_INIT, "Cannot create DX11 device");
			m_dx11->CleanupDeviceD3D();
			return false;
		}
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX | CTX_INIT, "Created DX11 device");
		return true;
	}

	HWND Gfx::MkWindow (void * gui, int x, int y, int w, int h, int alpha, wchar_t const * clname, wchar_t const * wname)
	{
		WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, &Gui::GuiWndProcDispatch, 0L, 0L, ::GetModuleHandle(NULL), NULL, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL, clname, NULL };
		::RegisterClassEx(&wc);

		bool const dwm_on = isDwmEnabled();
		DWORD f = 0;
		if (dwm_on)
			f |= WS_EX_LAYERED;
		HWND hwnd = ::CreateWindowExW(
			  f
			, clname
			, wname
			//, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
			, 0
			, x, y, w, h
			, NULL
			, NULL
			, wc.hInstance
			, gui);

		if (dwm_on)
			SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), alpha, ULW_ALPHA);
		removeWindowBorder(hwnd); // @TODO: removeWindowBorder triggers WM_PAINT but it's too early (will be ignored)

		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Created window for gui (dwm=%u), hwnd=0x%08x", dwm_on, hwnd);
		return hwnd;
	}

	GfxWindow * Gfx::MkGfxWindow (HWND hwnd, Gui * gui, wchar_t const * clname, wchar_t const * wname)
	{
		GfxWindowPtr w(new GfxWindow);
		w->m_hwnd = hwnd;
		w->m_chain = m_dx11->CreateSwapChain(hwnd);
		w->m_view = nullptr; // created in WM_SIZE
		w->m_clName = std::move(bbstring(clname));
		w->m_wName = std::move(bbstring(wname));
		if (!w->m_gui)
		{
			w->m_gui = gui;
			w->m_gui->m_name = wname;
			w->m_gui->m_enabled = true;
			w->m_gui->m_gfxWindow = w.get();
			w->m_gui->m_dx11 = m_dx11;
			w->m_gui->Init(hwnd, m_dx11);
		}
		m_windows.push_back(std::move(w));
		return m_windows.back().get();
	}

	GfxWindow * Gfx::MkGuiWindow (int x, int y, int w, int h, int alpha, wchar_t const * clname, wchar_t const * wname, bool show)
	{
		TRACE_SCOPE(LL_INFO, CTX_BB | CTX_GFX);
		Gui * gui = new Gui;
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Created new gui @ 0x%x wname=%ws", gui, wname);
		HWND hwnd = MkWindow(static_cast<void *>(gui), x, y, w, h, alpha, clname, wname);
		GfxWindow * res = MkGfxWindow(hwnd, gui, clname, wname);

		::ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE);
		showInFromTaskBar(hwnd, false);
		return res;
	}

	bool Gfx::Done ()
	{
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Terminating gfx");
		m_dx11->CleanupDeviceD3D();
		delete m_dx11;
		m_dx11 = nullptr;
		return true;
	}

	void Gfx::NewFrame ()
	{
		for (GfxWindowPtr & w : m_windows)
		{
			w->NewFrame();
		}
	}

	void Gfx::Render ()
	{
		if (IsReady())
		{
			m_iconCache.Update();
			for (GfxWindowPtr & w : m_windows)
			{
				w->Render();
			}
		}
	}

#define USE_DYNAMIC_UPDATE 0

	ID3D11ShaderResourceView * Gfx::MkIconResourceView (uint32_t x, uint32_t y, uint32_t bits, uint8_t * bmpdata)
	{
		ID3D11ShaderResourceView * texview = nullptr;

		D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(
				DXGI_FORMAT_B8G8R8A8_UNORM
			,	x, y
			, 1, 1				// arraySize, mipLevels
			, D3D11_BIND_SHADER_RESOURCE		// bindFlags
#if USE_DYNAMIC_UPDATE
			, D3D11_USAGE_DYNAMIC						// dynamic usage. just for testing, default shoud be better (updates of icon textures should be rare)
			, D3D11_CPU_ACCESS_WRITE				// cpuaccessFlags
#else
			, D3D11_USAGE_DEFAULT						// default usage.
			, 0															// cpuaccessFlags
#endif
			, 1, 0, 0			// sampleCount, sampleQuality, miscFlags
			);

		D3D11_SUBRESOURCE_DATA data;
		memset(&data, 0, sizeof(D3D11_SUBRESOURCE_DATA));

		data.pSysMem = bmpdata;
		data.SysMemPitch = bits / 8 * x; // line size in byte
		data.SysMemSlicePitch = 0;
		ID3D11Texture2D * texture = nullptr;
		HRESULT hr = m_dx11->m_pd3dDevice->CreateTexture2D(&texdesc, &data, &texture);

		D3D11_SHADER_RESOURCE_VIEW_DESC viewdesc;
		memset(&viewdesc, 0, sizeof(viewdesc));
		viewdesc.Format = texdesc.Format;
		viewdesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		viewdesc.Texture2D.MipLevels = 0;
		viewdesc.Texture2D.MostDetailedMip = texdesc.MipLevels;

		HRESULT hr_view = m_dx11->m_pd3dDevice->CreateShaderResourceView(texture, nullptr, &texview);

		texture->Release();
		return texview;
	}

	bool Gfx::UpdateIconResourceView (uint32_t x, uint32_t y, uint32_t bits, uint8_t * bmpdata, ID3D11ShaderResourceView * view)
	{
#if USE_DYNAMIC_UPDATE
		D3D11_MAPPED_SUBRESOURCE mappedResource;
		memset(&mappedResource, 0, sizeof(D3D11_MAPPED_SUBRESOURCE));

		m_dx11->m_pd3dDeviceContext->Map(view->Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		memcpy(mappedResource.pData, bmpdata, x * y * bits / CHAR_BIT);
		m_dx11->m_pd3dDeviceContext->Unmap(vertexBuffer2.Get(), 0);
#else
		D3D11_SUBRESOURCE_DATA data;
		memset(&data, 0, sizeof(D3D11_SUBRESOURCE_DATA));
		data.pSysMem = bmpdata;
		data.SysMemPitch = bits / 8 * x; // line size in byte
		data.SysMemSlicePitch = 0;
		// @NOTE: UpdateSubresource can update only portion of texture.. make use of it @TODO
		//			ID3D11Texture2D * texture = nullptr;
		//			HRESULT hr = m_dx11->m_pd3dDevice->UpdateSubresource();
		//			HRESULT hr = m_dx11->m_pd3dDevice->CreateTexture2D(&texdesc, &data, &texture);
		return true;
#endif
	}

}
<commit_msg>* rounded win for widgets (including kosmological constant)<commit_after>#include "Gfx.h"
#include "DX11.h"
#include "Gui.h"
#include <dxgi1_2.h>
#include <imgui/imgui.h>
#include <utils_window.h>
#include <utils_dwm.h>
#include <bblib/logging.h>

namespace bb {

	Gfx::~Gfx () { }

	bool Gfx::Init ()
	{
		TRACE_MSG(LL_INFO, CTX_BB | CTX_INIT, "Initializing gfx");
		m_dx11 = new DX11;
		if (m_dx11->CreateDeviceD3D(nullptr) < 0)
		{
			TRACE_MSG(LL_ERROR, CTX_BB | CTX_GFX | CTX_INIT, "Cannot create DX11 device");
			m_dx11->CleanupDeviceD3D();
			return false;
		}
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX | CTX_INIT, "Created DX11 device");
		return true;
	}

	HWND Gfx::MkWindow (void * gui, int x, int y, int w, int h, int alpha, wchar_t const * clname, wchar_t const * wname)
	{
		WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, &Gui::GuiWndProcDispatch, 0L, 0L, ::GetModuleHandle(NULL), NULL, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL, clname, NULL };
		::RegisterClassEx(&wc);

		bool const dwm_on = isDwmEnabled();
		DWORD f = 0;
		if (dwm_on)
			f |= WS_EX_LAYERED;
		HWND hwnd = ::CreateWindowExW(
			  f
			, clname
			, wname
			//, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
			, 0
			, x, y, w, h
			, NULL
			, NULL
			, wc.hInstance
			, gui);

		if (dwm_on)
			SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), alpha, ULW_ALPHA);
		removeWindowBorder(hwnd); // @TODO: removeWindowBorder triggers WM_PAINT but it's too early (will be ignored)

		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Created window for gui (dwm=%u), hwnd=0x%08x", dwm_on, hwnd);
		return hwnd;
	}

	GfxWindow * Gfx::MkGfxWindow (HWND hwnd, Gui * gui, wchar_t const * clname, wchar_t const * wname)
	{
		GfxWindowPtr w(new GfxWindow);
		w->m_hwnd = hwnd;
		w->m_chain = m_dx11->CreateSwapChain(hwnd);
		w->m_view = nullptr; // created in WM_SIZE
		w->m_clName = std::move(bbstring(clname));
		w->m_wName = std::move(bbstring(wname));
		if (!w->m_gui)
		{
			w->m_gui = gui;
			w->m_gui->m_name = wname;
			w->m_gui->m_enabled = true;
			w->m_gui->m_gfxWindow = w.get();
			w->m_gui->m_dx11 = m_dx11;
			w->m_gui->Init(hwnd, m_dx11);
		}
		m_windows.push_back(std::move(w));
		return m_windows.back().get();
	}

	GfxWindow * Gfx::MkGuiWindow (int x, int y, int w, int h, int alpha, wchar_t const * clname, wchar_t const * wname, bool show)
	{
		TRACE_SCOPE(LL_INFO, CTX_BB | CTX_GFX);
		Gui * gui = new Gui;
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Created new gui @ 0x%x wname=%ws", gui, wname);
		HWND hwnd = MkWindow(static_cast<void *>(gui), x, y, w, h, alpha, clname, wname);
		GfxWindow * res = MkGfxWindow(hwnd, gui, clname, wname);

		// @TODO: find better place for this
		ImGuiStyle & style = ImGui::GetStyle();
		RECT rect;
		::GetClientRect(hwnd, &rect);
		int const cst = style.WindowRounding; // Cimrmanova opravna cst
		HRGN hrgn = ::CreateRoundRectRgn(0, 0, rect.right, rect.bottom, style.WindowRounding + cst, style.WindowRounding + cst);
		::SetWindowRgn(hwnd, hrgn, TRUE);
		::SetPropW(hwnd, L"region", hrgn);
		//@TODO on destroy
		//DeleteObject(GetProp(hWnd, "region"));
		//RemoveProp(hWnd, "region")

		::ShowWindow(hwnd, show ? SW_SHOW : SW_HIDE);
		showInFromTaskBar(hwnd, false);
		return res;
	}

	bool Gfx::Done ()
	{
		TRACE_MSG(LL_INFO, CTX_BB | CTX_GFX, "Terminating gfx");
		m_dx11->CleanupDeviceD3D();
		delete m_dx11;
		m_dx11 = nullptr;
		return true;
	}

	void Gfx::NewFrame ()
	{
		for (GfxWindowPtr & w : m_windows)
		{
			w->NewFrame();
		}
	}

	void Gfx::Render ()
	{
		if (IsReady())
		{
			m_iconCache.Update();
			for (GfxWindowPtr & w : m_windows)
			{
				w->Render();
			}
		}
	}

#define USE_DYNAMIC_UPDATE 0

	ID3D11ShaderResourceView * Gfx::MkIconResourceView (uint32_t x, uint32_t y, uint32_t bits, uint8_t * bmpdata)
	{
		ID3D11ShaderResourceView * texview = nullptr;

		D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(
				DXGI_FORMAT_B8G8R8A8_UNORM
			,	x, y
			, 1, 1				// arraySize, mipLevels
			, D3D11_BIND_SHADER_RESOURCE		// bindFlags
#if USE_DYNAMIC_UPDATE
			, D3D11_USAGE_DYNAMIC						// dynamic usage. just for testing, default shoud be better (updates of icon textures should be rare)
			, D3D11_CPU_ACCESS_WRITE				// cpuaccessFlags
#else
			, D3D11_USAGE_DEFAULT						// default usage.
			, 0															// cpuaccessFlags
#endif
			, 1, 0, 0			// sampleCount, sampleQuality, miscFlags
			);

		D3D11_SUBRESOURCE_DATA data;
		memset(&data, 0, sizeof(D3D11_SUBRESOURCE_DATA));

		data.pSysMem = bmpdata;
		data.SysMemPitch = bits / 8 * x; // line size in byte
		data.SysMemSlicePitch = 0;
		ID3D11Texture2D * texture = nullptr;
		HRESULT hr = m_dx11->m_pd3dDevice->CreateTexture2D(&texdesc, &data, &texture);

		D3D11_SHADER_RESOURCE_VIEW_DESC viewdesc;
		memset(&viewdesc, 0, sizeof(viewdesc));
		viewdesc.Format = texdesc.Format;
		viewdesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
		viewdesc.Texture2D.MipLevels = 0;
		viewdesc.Texture2D.MostDetailedMip = texdesc.MipLevels;

		HRESULT hr_view = m_dx11->m_pd3dDevice->CreateShaderResourceView(texture, nullptr, &texview);

		texture->Release();
		return texview;
	}

	bool Gfx::UpdateIconResourceView (uint32_t x, uint32_t y, uint32_t bits, uint8_t * bmpdata, ID3D11ShaderResourceView * view)
	{
#if USE_DYNAMIC_UPDATE
		D3D11_MAPPED_SUBRESOURCE mappedResource;
		memset(&mappedResource, 0, sizeof(D3D11_MAPPED_SUBRESOURCE));

		m_dx11->m_pd3dDeviceContext->Map(view->Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
		memcpy(mappedResource.pData, bmpdata, x * y * bits / CHAR_BIT);
		m_dx11->m_pd3dDeviceContext->Unmap(vertexBuffer2.Get(), 0);
#else
		D3D11_SUBRESOURCE_DATA data;
		memset(&data, 0, sizeof(D3D11_SUBRESOURCE_DATA));
		data.pSysMem = bmpdata;
		data.SysMemPitch = bits / 8 * x; // line size in byte
		data.SysMemSlicePitch = 0;
		// @NOTE: UpdateSubresource can update only portion of texture.. make use of it @TODO
		//			ID3D11Texture2D * texture = nullptr;
		//			HRESULT hr = m_dx11->m_pd3dDevice->UpdateSubresource();
		//			HRESULT hr = m_dx11->m_pd3dDevice->CreateTexture2D(&texdesc, &data, &texture);
		return true;
#endif
	}

}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: requesttypes.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: ihi $ $Date: 2007-11-23 14:23:05 $
 *
 *  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 CONFIGMGR_BACKEND_REQUESTTYPES_HXX_
#define CONFIGMGR_BACKEND_REQUESTTYPES_HXX_

#ifndef _CONFIGMGR_TREE_VALUENODE_HXX
#include "valuenode.hxx"
#endif
#ifndef CONFIGMGR_TREECHANGELIST_HXX
#include "treechangelist.hxx"
#endif
#ifndef CONFIGMGR_CONFIGPATH_HXX_
#include "configpath.hxx"
#endif

#ifndef _CONFIGMGR_UTILITY_HXX_
#include <utility.hxx>
#endif

#ifndef INCLUDED_MEMORY
#include <memory>
#define INCLUDED_MEMORY
#endif

namespace configmgr
{
// ---------------------------------------------------------------------------
    namespace backend
    {
// ---------------------------------------------------------------------------
        using configuration::AbsolutePath;
        using configuration::Name;
// ---------------------------------------------------------------------------
      //typedef std::pair<std::auto_ptr<ISubtree>, Name> ComponentData;
        struct ComponentDataStruct
        {
            const std::auto_ptr<ISubtree>& data;
            Name name;
            ComponentDataStruct (const std::auto_ptr<ISubtree>& _data, Name _name)
              : data(_data), name(_name) {}
        };
        typedef struct ComponentDataStruct ComponentData;

        class NodePath
        {
            AbsolutePath m_path;
        public:
            NodePath(AbsolutePath const & _path) : m_path(_path) {};

            AbsolutePath const & location() const { return m_path; }
            AbsolutePath context()          const { return m_path.getParentPath(); }

            bool isEmpty()              const { return m_path.isRoot(); }
            bool isModuleRoot()         const { return m_path.getDepth() == 1; }
            Name getModuleName()        const { return m_path.getModuleName(); }
            rtl::OUString toString()    const { return m_path.toString(); }
        };
// ---------------------------------------------------------------------------
        struct NodeInstance
        {
            typedef std::auto_ptr<ISubtree> Data;

            explicit
            NodeInstance(Data _node, AbsolutePath const & _rootpath)
            : m_node(_node)
            , m_root(_rootpath)
            {
            }

            Data        const & data() const { return m_node; }
            NodePath    const & root() const { return m_root; }

            Data &  mutableData() { return m_node; }
            Data extractData() { return m_node; }
        private:
            Data        m_node;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
        struct TemplateInstance
        {
            typedef std::auto_ptr<INode> Data;

            explicit
            TemplateInstance(Data _node, Name const & _name, Name const & _component)
            : m_node(_node)
            , m_name(_name)
            , m_component(_component)
            {
            }

            Data        const & data() const { return m_node; }
            Name        const & name() const { return m_name; }
            Name        const & component() const { return m_component; }

            Data extractData() { return m_node; }
    private:
            Data m_node;
            Name m_name; // if empty, this is a complete set of component templates
            Name m_component;
        };
// ---------------------------------------------------------------------------
        struct ComponentInstance
        {
            typedef std::auto_ptr<ISubtree> Data;

            explicit
            ComponentInstance(Data _node, Data _template, Name const & _component)
            : m_node(_node)
            , m_template(_template)
            , m_component(_component)
            {
            }

            Data        const & data() const { return m_node; }
            Data        const & templateData() const { return m_template; }
            Name        const & component() const { return m_component; }

            ComponentData  componentTemplateData () const { return ComponentData(m_template,m_component);}
            ComponentData  componentNodeData () const { return ComponentData(m_node,m_component);}
            Data &  mutableData() { return m_node; }
            Data extractData() { return m_node; }
            Data extractTemplateData() { return m_template; }
        private:
            Data        m_node;
            Data        m_template;
            Name        m_component;
        };
// ---------------------------------------------------------------------------
        struct UpdateInstance
        {
            typedef SubtreeChange *         Data;
            typedef SubtreeChange const *   ConstData;

            explicit
            UpdateInstance(Data _update, AbsolutePath const & _rootpath)
            : m_update(_update)
            , m_root(_rootpath)
            {
            }

            UpdateInstance(UpdateInstance & _aModifiableOther)
            : m_update(_aModifiableOther.m_update)
            , m_root(_aModifiableOther.m_root)
            {
            }

            Data                data()       { return m_update; }
            ConstData           data() const { return m_update; }
            NodePath    const & root() const { return m_root; }
        private:
            Data        m_update;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
        struct ConstUpdateInstance
        {
            typedef UpdateInstance::ConstData   Data, ConstData;

            explicit
            ConstUpdateInstance(Data _update, AbsolutePath const & _rootpath)
            : m_update(_update)
            , m_root(_rootpath)
            {
            }

            // conversion
            ConstUpdateInstance(UpdateInstance const & _aModifiable)
            : m_update(_aModifiable.data())
            , m_root(_aModifiable.root())
            {
            }

            Data                data() const { return m_update; }
            NodePath    const & root() const { return m_root; }
        private:
            Data        m_update;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Due to the use of auto_ptr, the XxxInstance classes cannot easily be used as return values
// To return them, they should be wrapped into a ResultHolder

        template <class Instance_>
        class ResultHolder
        {
            struct RCInstance : public configmgr::SimpleReferenceObject
            {
                RCInstance(Instance_ & _instance)
                    : instance(_instance) {}
                Instance_ instance;
            };
            typedef rtl::Reference< RCInstance > InstanceRef;

            InstanceRef m_xInstance;
        public:
            typedef Instance_ Instance;

            explicit
            ResultHolder(Instance & _rInstance)
            : m_xInstance( new RCInstance(_rInstance) )
            {}

            bool isEmpty() const { return !m_xInstance.is(); }

            bool is() const { return m_xInstance.is() && m_xInstance->instance.data().get(); }

            Instance const & instance() const { return  m_xInstance->instance; }

            Instance const & operator *() const { return  instance(); }
            Instance const * operator->() const { return &instance(); }
            Instance & mutableInstance() { return m_xInstance->instance; }

            typename Instance::Data extractDataAndClear()
            {
                typename Instance::Data aData = m_xInstance->instance.extractData();
                this->clear();
                return aData;
            }

            void releaseAndClear()
            {
                typename Instance::Data aData = this->extractDataAndClear();
                aData.release();
            }

            void clear() { m_xInstance.clear(); }
        };
// ---------------------------------------------------------------------------
        typedef ResultHolder< NodeInstance >        NodeResult;
        typedef ResultHolder< TemplateInstance >    TemplateResult;
        typedef ResultHolder< ComponentInstance >   ComponentResult;

// ---------------------------------------------------------------------------
    }
// ---------------------------------------------------------------------------
} // namespace

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.9.16); FILE MERGED 2008/04/01 12:27:25 thb 1.9.16.2: #i85898# Stripping all external header guards 2008/03/31 12:22:44 rt 1.9.16.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: requesttypes.hxx,v $
 * $Revision: 1.10 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef CONFIGMGR_BACKEND_REQUESTTYPES_HXX_
#define CONFIGMGR_BACKEND_REQUESTTYPES_HXX_

#include "valuenode.hxx"
#include "treechangelist.hxx"
#include "configpath.hxx"

#ifndef _CONFIGMGR_UTILITY_HXX_
#include <utility.hxx>
#endif

#ifndef INCLUDED_MEMORY
#include <memory>
#define INCLUDED_MEMORY
#endif

namespace configmgr
{
// ---------------------------------------------------------------------------
    namespace backend
    {
// ---------------------------------------------------------------------------
        using configuration::AbsolutePath;
        using configuration::Name;
// ---------------------------------------------------------------------------
      //typedef std::pair<std::auto_ptr<ISubtree>, Name> ComponentData;
        struct ComponentDataStruct
        {
            const std::auto_ptr<ISubtree>& data;
            Name name;
            ComponentDataStruct (const std::auto_ptr<ISubtree>& _data, Name _name)
              : data(_data), name(_name) {}
        };
        typedef struct ComponentDataStruct ComponentData;

        class NodePath
        {
            AbsolutePath m_path;
        public:
            NodePath(AbsolutePath const & _path) : m_path(_path) {};

            AbsolutePath const & location() const { return m_path; }
            AbsolutePath context()          const { return m_path.getParentPath(); }

            bool isEmpty()              const { return m_path.isRoot(); }
            bool isModuleRoot()         const { return m_path.getDepth() == 1; }
            Name getModuleName()        const { return m_path.getModuleName(); }
            rtl::OUString toString()    const { return m_path.toString(); }
        };
// ---------------------------------------------------------------------------
        struct NodeInstance
        {
            typedef std::auto_ptr<ISubtree> Data;

            explicit
            NodeInstance(Data _node, AbsolutePath const & _rootpath)
            : m_node(_node)
            , m_root(_rootpath)
            {
            }

            Data        const & data() const { return m_node; }
            NodePath    const & root() const { return m_root; }

            Data &  mutableData() { return m_node; }
            Data extractData() { return m_node; }
        private:
            Data        m_node;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
        struct TemplateInstance
        {
            typedef std::auto_ptr<INode> Data;

            explicit
            TemplateInstance(Data _node, Name const & _name, Name const & _component)
            : m_node(_node)
            , m_name(_name)
            , m_component(_component)
            {
            }

            Data        const & data() const { return m_node; }
            Name        const & name() const { return m_name; }
            Name        const & component() const { return m_component; }

            Data extractData() { return m_node; }
    private:
            Data m_node;
            Name m_name; // if empty, this is a complete set of component templates
            Name m_component;
        };
// ---------------------------------------------------------------------------
        struct ComponentInstance
        {
            typedef std::auto_ptr<ISubtree> Data;

            explicit
            ComponentInstance(Data _node, Data _template, Name const & _component)
            : m_node(_node)
            , m_template(_template)
            , m_component(_component)
            {
            }

            Data        const & data() const { return m_node; }
            Data        const & templateData() const { return m_template; }
            Name        const & component() const { return m_component; }

            ComponentData  componentTemplateData () const { return ComponentData(m_template,m_component);}
            ComponentData  componentNodeData () const { return ComponentData(m_node,m_component);}
            Data &  mutableData() { return m_node; }
            Data extractData() { return m_node; }
            Data extractTemplateData() { return m_template; }
        private:
            Data        m_node;
            Data        m_template;
            Name        m_component;
        };
// ---------------------------------------------------------------------------
        struct UpdateInstance
        {
            typedef SubtreeChange *         Data;
            typedef SubtreeChange const *   ConstData;

            explicit
            UpdateInstance(Data _update, AbsolutePath const & _rootpath)
            : m_update(_update)
            , m_root(_rootpath)
            {
            }

            UpdateInstance(UpdateInstance & _aModifiableOther)
            : m_update(_aModifiableOther.m_update)
            , m_root(_aModifiableOther.m_root)
            {
            }

            Data                data()       { return m_update; }
            ConstData           data() const { return m_update; }
            NodePath    const & root() const { return m_root; }
        private:
            Data        m_update;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
        struct ConstUpdateInstance
        {
            typedef UpdateInstance::ConstData   Data, ConstData;

            explicit
            ConstUpdateInstance(Data _update, AbsolutePath const & _rootpath)
            : m_update(_update)
            , m_root(_rootpath)
            {
            }

            // conversion
            ConstUpdateInstance(UpdateInstance const & _aModifiable)
            : m_update(_aModifiable.data())
            , m_root(_aModifiable.root())
            {
            }

            Data                data() const { return m_update; }
            NodePath    const & root() const { return m_root; }
        private:
            Data        m_update;
            NodePath    m_root;
        };
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Due to the use of auto_ptr, the XxxInstance classes cannot easily be used as return values
// To return them, they should be wrapped into a ResultHolder

        template <class Instance_>
        class ResultHolder
        {
            struct RCInstance : public configmgr::SimpleReferenceObject
            {
                RCInstance(Instance_ & _instance)
                    : instance(_instance) {}
                Instance_ instance;
            };
            typedef rtl::Reference< RCInstance > InstanceRef;

            InstanceRef m_xInstance;
        public:
            typedef Instance_ Instance;

            explicit
            ResultHolder(Instance & _rInstance)
            : m_xInstance( new RCInstance(_rInstance) )
            {}

            bool isEmpty() const { return !m_xInstance.is(); }

            bool is() const { return m_xInstance.is() && m_xInstance->instance.data().get(); }

            Instance const & instance() const { return  m_xInstance->instance; }

            Instance const & operator *() const { return  instance(); }
            Instance const * operator->() const { return &instance(); }
            Instance & mutableInstance() { return m_xInstance->instance; }

            typename Instance::Data extractDataAndClear()
            {
                typename Instance::Data aData = m_xInstance->instance.extractData();
                this->clear();
                return aData;
            }

            void releaseAndClear()
            {
                typename Instance::Data aData = this->extractDataAndClear();
                aData.release();
            }

            void clear() { m_xInstance.clear(); }
        };
// ---------------------------------------------------------------------------
        typedef ResultHolder< NodeInstance >        NodeResult;
        typedef ResultHolder< TemplateInstance >    TemplateResult;
        typedef ResultHolder< ComponentInstance >   ComponentResult;

// ---------------------------------------------------------------------------
    }
// ---------------------------------------------------------------------------
} // namespace

#endif
<|endoftext|>


<commit_before>#ifndef __CHIMERA_OPEN_GL_DEFS__HPP
#define __CHIMERA_OPEN_GL_DEFS__HPP

#include "GL/glew.h"

#include <GL/gl.h>

namespace Chimera {

enum StateMachine { TEXTURE_2D = GL_TEXTURE_2D, DEPTH_TEST = GL_DEPTH_TEST, BLEND = GL_BLEND };

enum FaceMaterial { FRONT = GL_FRONT, BACK = GL_BACK, FRONT_BACK = GL_FRONT_AND_BACK };

enum ModeMaterial {
    AMBIENT = GL_AMBIENT,
    DIFFUSE = GL_DIFFUSE,
    EMISSION = GL_EMISSION,
    SPECULAR = GL_SPECULAR,
    SHININESS = GL_SHININESS,
    AMBIENT_AND_DIFFUSE = GL_AMBIENT_AND_DIFFUSE
};

enum LightNum {
    LIGHT0 = GL_LIGHT0,
    LIGHT1 = GL_LIGHT1,
    LIGHT2 = GL_LIGHT2,
    LIGHT3 = GL_LIGHT3,
    LIGHT4 = GL_LIGHT4,
    LIGHT5 = GL_LIGHT5,
    LIGHT6 = GL_LIGHT6,
    LIGHT7 = GL_LIGHT7,
    LIGHTING = GL_LIGHTING
};

enum PolygonMode { FILL = GL_FILL, WIREFRAME = GL_LINE, POINTS = GL_POINT };

enum CullFace { CULL_FACE = GL_CULL_FACE };

enum ColorMaterial { COLOR_MATERIAL = GL_COLOR_MATERIAL };

enum ClientState {
    COLOR_ARRAY = GL_COLOR_ARRAY,
    EDGE_FLAG_ARRAY = GL_EDGE_FLAG_ARRAY,
    // FOG_COORD_ARRAY=GL_FOG_COORD_ARRAY,
    INDEX_ARRAY = GL_INDEX_ARRAY,
    NORMAL_ARRAY = GL_NORMAL_ARRAY,
    // SECONDARY_COLOR_ARRAY=GL_SECONDARY_COLOR_ARRAY,
    TEXTURE_COORD_ARRAY = GL_TEXTURE_COORD_ARRAY,
    VERTEX_ARRAY = GL_VERTEX_ARRAY
};
} // namespace Chimera
#endif
<commit_msg>limpeza<commit_after>#ifndef __CHIMERA_OPEN_GL_DEFS__HPP
#define __CHIMERA_OPEN_GL_DEFS__HPP

#include "GL/glew.h"
#include <GL/gl.h>

#endif
<|endoftext|>


<commit_before>// Copyright (c) 2010 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/browser/labs.h"

#include <algorithm>
#include <iterator>
#include <map>
#include <set>

#include "app/l10n_util.h"
#include "base/command_line.h"
#include "base/values.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"

namespace about_labs {

enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 };

unsigned kOsAll = kOsMac | kOsWin | kOsLinux;

struct Experiment {
  // The internal name of the experiment. This is never shown to the user.
  // It _is_ however stored in the prefs file, so you shouldn't change the
  // name of existing labs.
  const char* internal_name;

  // String id of the message containing the experiment's name.
  int visible_name_id;

  // String id of the message containing the experiment's description.
  int visible_description_id;

  // The platforms the experiment is available on
  // Needs to be more than a compile-time #ifdef because of profile sync.
  unsigned supported_platforms;  // bitmask

  // The commandline parameter that's added when this lab is active. This is
  // different from |internal_name| so that the commandline flag can be
  // renamed without breaking the prefs file.
  const char* command_line;
};

const Experiment kExperiments[] = {
  {
    "expose-for-tabs",  // Do not change; see above.
    IDS_LABS_TABPOSE_NAME,
    IDS_LABS_TABPOSE_DESCRIPTION,
    kOsMac,
#if defined(OS_MACOSX)
    // The switch exists only on OS X.
    switches::kEnableExposeForTabs
#else
    ""
#endif
  },
  {
    "vertical-tabs",  // Do not change; see above.
    IDS_LABS_SIDE_TABS_NAME,
    IDS_LABS_SIDE_TABS_DESCRIPTION,
    kOsWin,
    switches::kEnableVerticalTabs
  },
  {
    "tabbed-options",  // Do not change; see above.
    IDS_LABS_TABBED_OPTIONS_NAME,
    IDS_LABS_TABBED_OPTIONS_DESCRIPTION,
    kOsAll,
    switches::kEnableTabbedOptions
  },
  {
    "match-preview",  // Do not change; see above.
    IDS_LABS_INSTANT_NAME,
    IDS_LABS_INSTANT_DESCRIPTION,
    kOsWin,
    switches::kEnableMatchPreview
  },
  {
    "remoting",  // Do not change; see above.
    IDS_LABS_REMOTING_NAME,
#if defined(OS_WINDOWS)
    // Windows only supports host functionality at the moment.
    IDS_LABS_REMOTING_HOST_DESCRIPTION,
#elif defined(OS_LINUX)
    // Linux only supports client functionality at the moment.
    IDS_LABS_REMOTING_CLIENT_DESCRIPTION,
#else
    // On other platforms, this lab isn't available at all
    "",
#endif
    kOsWin | kOsLinux,
    switches::kEnableRemoting
  },
};

// Extracts the list of enabled lab experiments from a profile and stores them
// in a set.
void GetEnabledLabs(const PrefService* prefs, std::set<std::string>* result) {
  const ListValue* enabled_experiments = prefs->GetList(
      prefs::kEnabledLabsExperiments);
  if (!enabled_experiments)
    return;

  for (ListValue::const_iterator it = enabled_experiments->begin();
       it != enabled_experiments->end();
       ++it) {
    std::string experiment_name;
    if (!(*it)->GetAsString(&experiment_name)) {
      LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
      continue;
    }
    result->insert(experiment_name);
  }
}

// Takes a set of enabled lab experiments
void SetEnabledLabs(
    PrefService* prefs, const std::set<std::string>& enabled_experiments) {
  ListValue* experiments_list = prefs->GetMutableList(
      prefs::kEnabledLabsExperiments);
  if (!experiments_list)
    return;

  experiments_list->Clear();
  for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
       it != enabled_experiments.end();
       ++it) {
    experiments_list->Append(new StringValue(*it));
  }
}

// Removes all experiments from prefs::kEnabledLabsExperiments that are
// unknown, to prevent this list to become very long as experiments are added
// and removed.
void SanitizeList(PrefService* prefs) {
  std::set<std::string> known_experiments;
  for (size_t i = 0; i < arraysize(kExperiments); ++i)
    known_experiments.insert(kExperiments[i].internal_name);

  std::set<std::string> enabled_experiments;
  GetEnabledLabs(prefs, &enabled_experiments);

  std::set<std::string> new_enabled_experiments;
  std::set_intersection(
      known_experiments.begin(), known_experiments.end(),
      enabled_experiments.begin(), enabled_experiments.end(),
      std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));

  SetEnabledLabs(prefs, new_enabled_experiments);
}

void GetSanitizedEnabledLabs(
    PrefService* prefs, std::set<std::string>* result) {
  SanitizeList(prefs);
  GetEnabledLabs(prefs, result);
}

int GetCurrentPlatform() {
#if defined(OS_MACOSX)
  return kOsMac;
#elif defined(OS_WIN)
  return kOsWin;
#elif defined(OS_LINUX)
  return kOsLinux;
#else
#error Unknown platform
#endif
}

bool IsEnabled() {
#if defined(OS_CHROMEOS)
  // ChromeOS uses a different mechanism for about:labs; integrated with their
  // dom ui options.
  return false;
#elif defined(GOOGLE_CHROME_BUILD)
  // Don't enable this on the stable channel.
  return !platform_util::GetVersionStringModifier().empty();
#else
  return true;
#endif
}

void ConvertLabsToSwitches(Profile* profile, CommandLine* command_line) {
  // Do not activate labs features on the stable channel.
  if (!IsEnabled())
    return;

  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  std::map<std::string, const Experiment*> experiments;
  for (size_t i = 0; i < arraysize(kExperiments); ++i)
    experiments[kExperiments[i].internal_name] = &kExperiments[i];

  for (std::set<std::string>::iterator it = enabled_experiments.begin();
       it != enabled_experiments.end();
       ++it) {
    const std::string& experiment_name = *it;
    std::map<std::string, const Experiment*>::iterator experiment =
        experiments.find(experiment_name);
    DCHECK(experiment != experiments.end());
    if (experiment == experiments.end())
      continue;

    command_line->AppendSwitch(experiment->second->command_line);
  }
}

ListValue* GetLabsExperimentsData(Profile* profile) {
  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  int current_platform = GetCurrentPlatform();

  ListValue* experiments_data = new ListValue();
  for (size_t i = 0; i < arraysize(kExperiments); ++i) {
    const Experiment& experiment = kExperiments[i];
    if (!(experiment.supported_platforms & current_platform))
      continue;

    DictionaryValue* data = new DictionaryValue();
    data->SetString("internal_name", experiment.internal_name);
    data->SetString("name",
                    l10n_util::GetStringUTF16(experiment.visible_name_id));
    data->SetString("description",
                    l10n_util::GetStringUTF16(
                        experiment.visible_description_id));
    data->SetBoolean("enabled",
                      enabled_experiments.count(experiment.internal_name) > 0);

    experiments_data->Append(data);
  }
  return experiments_data;
}

static bool needs_restart_ = false;

bool IsRestartNeededToCommitChanges() {
  return needs_restart_;
}

void SetExperimentEnabled(
    Profile* profile, const std::string& internal_name, bool enable) {
  needs_restart_ = true;

  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  if (enable)
    enabled_experiments.insert(internal_name);
  else
    enabled_experiments.erase(internal_name);

  SetEnabledLabs(profile->GetPrefs(), enabled_experiments);
}

}  // namespace Labs
<commit_msg>Fix an empty string to fix r60578.<commit_after>// Copyright (c) 2010 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/browser/labs.h"

#include <algorithm>
#include <iterator>
#include <map>
#include <set>

#include "app/l10n_util.h"
#include "base/command_line.h"
#include "base/values.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "grit/generated_resources.h"

namespace about_labs {

enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 };

unsigned kOsAll = kOsMac | kOsWin | kOsLinux;

struct Experiment {
  // The internal name of the experiment. This is never shown to the user.
  // It _is_ however stored in the prefs file, so you shouldn't change the
  // name of existing labs.
  const char* internal_name;

  // String id of the message containing the experiment's name.
  int visible_name_id;

  // String id of the message containing the experiment's description.
  int visible_description_id;

  // The platforms the experiment is available on
  // Needs to be more than a compile-time #ifdef because of profile sync.
  unsigned supported_platforms;  // bitmask

  // The commandline parameter that's added when this lab is active. This is
  // different from |internal_name| so that the commandline flag can be
  // renamed without breaking the prefs file.
  const char* command_line;
};

const Experiment kExperiments[] = {
  {
    "expose-for-tabs",  // Do not change; see above.
    IDS_LABS_TABPOSE_NAME,
    IDS_LABS_TABPOSE_DESCRIPTION,
    kOsMac,
#if defined(OS_MACOSX)
    // The switch exists only on OS X.
    switches::kEnableExposeForTabs
#else
    ""
#endif
  },
  {
    "vertical-tabs",  // Do not change; see above.
    IDS_LABS_SIDE_TABS_NAME,
    IDS_LABS_SIDE_TABS_DESCRIPTION,
    kOsWin,
    switches::kEnableVerticalTabs
  },
  {
    "tabbed-options",  // Do not change; see above.
    IDS_LABS_TABBED_OPTIONS_NAME,
    IDS_LABS_TABBED_OPTIONS_DESCRIPTION,
    kOsAll,
    switches::kEnableTabbedOptions
  },
  {
    "match-preview",  // Do not change; see above.
    IDS_LABS_INSTANT_NAME,
    IDS_LABS_INSTANT_DESCRIPTION,
    kOsWin,
    switches::kEnableMatchPreview
  },
  {
    "remoting",  // Do not change; see above.
    IDS_LABS_REMOTING_NAME,
#if defined(OS_WINDOWS)
    // Windows only supports host functionality at the moment.
    IDS_LABS_REMOTING_HOST_DESCRIPTION,
#elif defined(OS_LINUX)
    // Linux only supports client functionality at the moment.
    IDS_LABS_REMOTING_CLIENT_DESCRIPTION,
#else
    // On other platforms, this lab isn't available at all.
    0,
#endif
    kOsWin | kOsLinux,
    switches::kEnableRemoting
  },
};

// Extracts the list of enabled lab experiments from a profile and stores them
// in a set.
void GetEnabledLabs(const PrefService* prefs, std::set<std::string>* result) {
  const ListValue* enabled_experiments = prefs->GetList(
      prefs::kEnabledLabsExperiments);
  if (!enabled_experiments)
    return;

  for (ListValue::const_iterator it = enabled_experiments->begin();
       it != enabled_experiments->end();
       ++it) {
    std::string experiment_name;
    if (!(*it)->GetAsString(&experiment_name)) {
      LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
      continue;
    }
    result->insert(experiment_name);
  }
}

// Takes a set of enabled lab experiments
void SetEnabledLabs(
    PrefService* prefs, const std::set<std::string>& enabled_experiments) {
  ListValue* experiments_list = prefs->GetMutableList(
      prefs::kEnabledLabsExperiments);
  if (!experiments_list)
    return;

  experiments_list->Clear();
  for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
       it != enabled_experiments.end();
       ++it) {
    experiments_list->Append(new StringValue(*it));
  }
}

// Removes all experiments from prefs::kEnabledLabsExperiments that are
// unknown, to prevent this list to become very long as experiments are added
// and removed.
void SanitizeList(PrefService* prefs) {
  std::set<std::string> known_experiments;
  for (size_t i = 0; i < arraysize(kExperiments); ++i)
    known_experiments.insert(kExperiments[i].internal_name);

  std::set<std::string> enabled_experiments;
  GetEnabledLabs(prefs, &enabled_experiments);

  std::set<std::string> new_enabled_experiments;
  std::set_intersection(
      known_experiments.begin(), known_experiments.end(),
      enabled_experiments.begin(), enabled_experiments.end(),
      std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));

  SetEnabledLabs(prefs, new_enabled_experiments);
}

void GetSanitizedEnabledLabs(
    PrefService* prefs, std::set<std::string>* result) {
  SanitizeList(prefs);
  GetEnabledLabs(prefs, result);
}

int GetCurrentPlatform() {
#if defined(OS_MACOSX)
  return kOsMac;
#elif defined(OS_WIN)
  return kOsWin;
#elif defined(OS_LINUX)
  return kOsLinux;
#else
#error Unknown platform
#endif
}

bool IsEnabled() {
#if defined(OS_CHROMEOS)
  // ChromeOS uses a different mechanism for about:labs; integrated with their
  // dom ui options.
  return false;
#elif defined(GOOGLE_CHROME_BUILD)
  // Don't enable this on the stable channel.
  return !platform_util::GetVersionStringModifier().empty();
#else
  return true;
#endif
}

void ConvertLabsToSwitches(Profile* profile, CommandLine* command_line) {
  // Do not activate labs features on the stable channel.
  if (!IsEnabled())
    return;

  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  std::map<std::string, const Experiment*> experiments;
  for (size_t i = 0; i < arraysize(kExperiments); ++i)
    experiments[kExperiments[i].internal_name] = &kExperiments[i];

  for (std::set<std::string>::iterator it = enabled_experiments.begin();
       it != enabled_experiments.end();
       ++it) {
    const std::string& experiment_name = *it;
    std::map<std::string, const Experiment*>::iterator experiment =
        experiments.find(experiment_name);
    DCHECK(experiment != experiments.end());
    if (experiment == experiments.end())
      continue;

    command_line->AppendSwitch(experiment->second->command_line);
  }
}

ListValue* GetLabsExperimentsData(Profile* profile) {
  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  int current_platform = GetCurrentPlatform();

  ListValue* experiments_data = new ListValue();
  for (size_t i = 0; i < arraysize(kExperiments); ++i) {
    const Experiment& experiment = kExperiments[i];
    if (!(experiment.supported_platforms & current_platform))
      continue;

    DictionaryValue* data = new DictionaryValue();
    data->SetString("internal_name", experiment.internal_name);
    data->SetString("name",
                    l10n_util::GetStringUTF16(experiment.visible_name_id));
    data->SetString("description",
                    l10n_util::GetStringUTF16(
                        experiment.visible_description_id));
    data->SetBoolean("enabled",
                      enabled_experiments.count(experiment.internal_name) > 0);

    experiments_data->Append(data);
  }
  return experiments_data;
}

static bool needs_restart_ = false;

bool IsRestartNeededToCommitChanges() {
  return needs_restart_;
}

void SetExperimentEnabled(
    Profile* profile, const std::string& internal_name, bool enable) {
  needs_restart_ = true;

  std::set<std::string> enabled_experiments;
  GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments);

  if (enable)
    enabled_experiments.insert(internal_name);
  else
    enabled_experiments.erase(internal_name);

  SetEnabledLabs(profile->GetPrefs(), enabled_experiments);
}

}  // namespace Labs
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unonrule.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 19:28:17 $
 *
 *  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_UNONRULE_HXX
#define _SVX_UNONRULE_HXX

#ifndef _COM_SUN_STAR_CONTAINER_XINDEXREPLACE_HPP_
#include <com/sun/star/container/XIndexReplace.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XANYCOMPARE_HPP_
#include <com/sun/star/ucb/XAnyCompare.hpp>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

class SdrModel;
class SvxNumRule;

SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule( const SvxNumRule* pRule ) throw();
SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule( SdrModel* pModel ) throw();
const SvxNumRule& SvxGetNumRule( ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > xRule ) throw( ::com::sun::star::lang::IllegalArgumentException );
bool SvxGetNumRule( ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > xRule, SvxNumRule& rNumRule );
SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XAnyCompare > SvxCreateNumRuleCompare() throw();

#endif

<commit_msg>INTEGRATION: CWS changefileheader (1.7.1256); FILE MERGED 2008/04/01 12:46:28 thb 1.7.1256.2: #i85898# Stripping all external header guards 2008/03/31 14:18:01 rt 1.7.1256.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: unonrule.hxx,v $
 * $Revision: 1.8 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SVX_UNONRULE_HXX
#define _SVX_UNONRULE_HXX

#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/ucb/XAnyCompare.hpp>
#include "svx/svxdllapi.h"

class SdrModel;
class SvxNumRule;

SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule( const SvxNumRule* pRule ) throw();
SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule( SdrModel* pModel ) throw();
const SvxNumRule& SvxGetNumRule( ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > xRule ) throw( ::com::sun::star::lang::IllegalArgumentException );
bool SvxGetNumRule( ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > xRule, SvxNumRule& rNumRule );
SVX_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XAnyCompare > SvxCreateNumRuleCompare() throw();

#endif

<|endoftext|>


<commit_before>#include "BigFix/Error.h"
#include <gtest/gtest.h>

using namespace BigFix;

TEST( ErrorTest, ErrorIsAStdException )
{
  try
  {
    throw Error( "Oh noes!" );
  }
  catch ( const std::exception& e )
  {
    EXPECT_EQ( std::string( "Oh noes!" ), e.what() );
  }
  catch ( ... )
  {
    FAIL();
  }
}
<commit_msg>gtest will catch the case where this isn't a std::exception<commit_after>#include "BigFix/Error.h"
#include <gtest/gtest.h>

using namespace BigFix;

TEST( ErrorTest, ErrorIsAStdException )
{
  try
  {
    throw Error( "Oh noes!" );
  }
  catch ( const std::exception& e )
  {
    EXPECT_EQ( std::string( "Oh noes!" ), e.what() );
  }
}
<|endoftext|>


<commit_before><commit_msg>Bugfix: check for zero before dividing by `(double) number_of_frames`.<commit_after><|endoftext|>


<commit_before>/*!
\file
	\brief
		Om source file.
	\version
		0.1.2
	\date
		2012-2013
	\copyright
		Copyright (c) Sparist.  All rights reserved.  This program and the accompanying materials are made available under the terms of the Eclipse Public License, Version 1.0, which accompanies this distribution.
	\authors
		Jason Erb - Initial API, implementation, and documentation.
*/

#include "om/code_point.hpp"

#if defined( Om_Macros_Test_ )

	#include "UnitTest++.h"

namespace Om {

	namespace Symbols {

		SUITE( CodePoint ) {}

	}

}

#endif
<commit_msg>Removed erroneous Symbols namespace from CodePoint.<commit_after>/*!
\file
	\brief
		Om source file.
	\version
		0.1.2
	\date
		2012-2013
	\copyright
		Copyright (c) Sparist.  All rights reserved.  This program and the accompanying materials are made available under the terms of the Eclipse Public License, Version 1.0, which accompanies this distribution.
	\authors
		Jason Erb - Initial API, implementation, and documentation.
*/

#include "om/code_point.hpp"

#if defined( Om_Macros_Test_ )

	#include "UnitTest++.h"

namespace Om {

	SUITE( CodePoint ) {}

}

#endif
<|endoftext|>