/* * This source file is part of RmlUi, the HTML/CSS Interface Middleware * * For the latest information, see http://github.com/mikke89/RmlUi * * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd * Copyright (c) 2019-2023 The RmlUi Team, and contributors * * 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. * */ namespace Rml { inline Variant::Type Variant::GetType() const { return type; } template Variant::Variant(T&& t) { Set(std::forward(t)); } template Variant& Variant::operator=(T&& t) { Clear(); Set(std::forward(t)); return *this; } template ::value, int>> bool Variant::GetInto(T& value) const { switch (type) { case BOOL: return TypeConverter::Convert(*reinterpret_cast(data), value); case BYTE: return TypeConverter::Convert(*reinterpret_cast(data), value); case CHAR: return TypeConverter::Convert(*reinterpret_cast(data), value); case FLOAT: return TypeConverter::Convert(*reinterpret_cast(data), value); case DOUBLE: return TypeConverter::Convert(*reinterpret_cast(data), value); case INT: return TypeConverter::Convert(*reinterpret_cast(data), value); case INT64: return TypeConverter::Convert(*reinterpret_cast(data), value); case UINT: return TypeConverter::Convert(*reinterpret_cast(data), value); case UINT64: return TypeConverter::Convert(*reinterpret_cast(data), value); case STRING: return TypeConverter::Convert(*reinterpret_cast(data), value); case VECTOR2: return TypeConverter::Convert(*reinterpret_cast(data), value); case VECTOR3: return TypeConverter::Convert(*reinterpret_cast(data), value); case VECTOR4: return TypeConverter::Convert(*reinterpret_cast(data), value); case COLOURF: return TypeConverter::Convert(*reinterpret_cast(data), value); case COLOURB: return TypeConverter::Convert(*reinterpret_cast(data), value); case SCRIPTINTERFACE: return TypeConverter::Convert(*reinterpret_cast(data), value); case VOIDPTR: return TypeConverter::Convert(*reinterpret_cast(data), value); case TRANSFORMPTR: return TypeConverter::Convert(*reinterpret_cast(data), value); case TRANSITIONLIST: return TypeConverter::Convert(*reinterpret_cast(data), value); case ANIMATIONLIST: return TypeConverter::Convert(*reinterpret_cast(data), value); case DECORATORSPTR: return TypeConverter::Convert(*reinterpret_cast(data), value); case FILTERSPTR: return TypeConverter::Convert(*reinterpret_cast(data), value); case FONTEFFECTSPTR: return TypeConverter::Convert(*reinterpret_cast(data), value); case COLORSTOPLIST: return TypeConverter::Convert(*(ColorStopList*)data, value); break; case BOXSHADOWLIST: return TypeConverter::Convert(*reinterpret_cast(data), value); case NONE: break; } return false; } template ::value, int>> bool Variant::GetInto(T& value) const { static_assert(sizeof(T) <= sizeof(int64_t), "Enum underlying type exceeds maximum supported integer type size"); int64_t stored_value = 0; if (GetInto(stored_value)) { value = static_cast(stored_value); return true; } return false; } template T Variant::Get(T default_value) const { GetInto(default_value); return default_value; } template const T& Variant::GetReference() const { return *reinterpret_cast(&data); } template void Variant::Set(const T value) { static_assert(sizeof(T) <= sizeof(int64_t), "Enum underlying type exceeds maximum supported integer type size"); type = INT64; *(reinterpret_cast(data)) = static_cast(value); } } // namespace Rml