Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGInterpolationSetImpl.cpp
T

228 lines
6.4 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2024 SenseGlove
*
* 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.
*
* @section DESCRIPTION
*
*
*/
#include "SGCoreImpl/SGInterpolationSetImpl.h"
#include <string>
#include "Containers/StringConv.h"
#include "SGBuildHacks/SGInclude_Core_Quat.h"
#include "SGBuildHacks/SGInclude_Core_InterpolationSet.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGInterpolationSetImpl::FImpl
{
/************************
* Member variables
************************/
FInterpolationSetType InterpolationSet;
/************************
* Owner object
************************/
FSGInterpolationSetImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGInterpolationSetImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGInterpolationSetImpl FSGInterpolationSetImpl::Deserialize(const FString& SerializedString)
{
std::string Serialized(TCHAR_TO_UTF8(*SerializedString));
const FSGInterpolationSetImpl InterpolationSet(FInterpolationSetType::Deserialize(MoveTemp(Serialized)));
return InterpolationSet;
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl(const float From1, const float From2, const float To1, const float To2)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->InterpolationSet = FInterpolationSetType(From1, From2, To1, To2);
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl(const float From1, const float From2, const float To1, const float To2,
const float Min, const float Max)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->InterpolationSet = FInterpolationSetType(From1, From2, To1, To2, Min, Max);
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl(const FInterpolationSetType& InterpolationSet)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->InterpolationSet = InterpolationSet;
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl(const FSGInterpolationSetImpl& Rhs)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
{
Pimpl->Owner = this;
}
FSGInterpolationSetImpl::FSGInterpolationSetImpl(FSGInterpolationSetImpl&& Rhs) SG_NOEXCEPT = default;
FSGInterpolationSetImpl::~FSGInterpolationSetImpl() = default;
FSGInterpolationSetImpl& FSGInterpolationSetImpl::operator=(const FSGInterpolationSetImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGInterpolationSetImpl& FSGInterpolationSetImpl::operator=(FSGInterpolationSetImpl&& Rhs) SG_NOEXCEPT = default;
const FSGInterpolationSetImpl::FInterpolationSetType& FSGInterpolationSetImpl::ToInterpolationSet() const
{
return Pimpl->InterpolationSet;
}
float FSGInterpolationSetImpl::GetX0() const
{
return Pimpl->InterpolationSet.GetX0();
}
void FSGInterpolationSetImpl::SetX0(const float X0)
{
Pimpl->InterpolationSet.SetX0(X0);
}
float FSGInterpolationSetImpl::GetX1() const
{
return Pimpl->InterpolationSet.GetX1();
}
void FSGInterpolationSetImpl::SetX1(const float X1)
{
Pimpl->InterpolationSet.SetX1(X1);
}
float FSGInterpolationSetImpl::GetY0() const
{
return Pimpl->InterpolationSet.GetY0();
}
void FSGInterpolationSetImpl::SetY0(const float Y0)
{
Pimpl->InterpolationSet.SetY0(Y0);
}
float FSGInterpolationSetImpl::GetY1() const
{
return Pimpl->InterpolationSet.GetY1();
}
void FSGInterpolationSetImpl::SetY1(const float Y1)
{
Pimpl->InterpolationSet.SetY1(Y1);
}
float FSGInterpolationSetImpl::GetMin() const
{
return Pimpl->InterpolationSet.GetMin();
}
void FSGInterpolationSetImpl::SetMin(const float Min)
{
Pimpl->InterpolationSet.SetMin(Min);
}
float FSGInterpolationSetImpl::GetMax() const
{
return Pimpl->InterpolationSet.GetMax();
}
void FSGInterpolationSetImpl::SetMax(const float Max)
{
Pimpl->InterpolationSet.SetMax(Max);
}
float FSGInterpolationSetImpl::Get(const float Value, const bool bLimit, const bool bNormalizeAngle) const
{
return Pimpl->InterpolationSet.Get(Value, bLimit, bNormalizeAngle);
}
bool FSGInterpolationSetImpl::Equals(const FSGInterpolationSetImpl& InterpolationSetImpl) const
{
return Pimpl->InterpolationSet.Equals(InterpolationSetImpl.ToInterpolationSet());
}
FString FSGInterpolationSetImpl::ToString() const
{
const FString String(UTF8_TO_TCHAR(Pimpl->InterpolationSet.ToString().c_str()));
return String;
}
FString FSGInterpolationSetImpl::ToString(const bool bLimits) const
{
const FString String(UTF8_TO_TCHAR(Pimpl->InterpolationSet.ToString(bLimits).c_str()));
return String;
}
FString FSGInterpolationSetImpl::Serialize() const
{
const FString Serialized(UTF8_TO_TCHAR(Pimpl->InterpolationSet.Serialize().c_str()));
return Serialized;
}
FSGInterpolationSetImpl::FImpl::FImpl(FSGInterpolationSetImpl* InOwner)
: Owner(InOwner)
{
}
FSGInterpolationSetImpl::FImpl::~FImpl() = default;
void FSGInterpolationSetImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}