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

199 lines
7.0 KiB
C++
Raw Normal View History

2022-11-02 22:43:14 +01:00
/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 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/SGCalibrationDataPointImpl.h"
#include <string>
#include <vector>
#include "Containers/StringConv.h"
#include "Runtime/Launch/Resources/Version.h"
#include "SGBuildHacks/SGInclude_Core_CalibrationDataPoint.h"
#include "SGBuildHacks/SGInclude_Core_Vect3D.h"
#include "SGCoreImpl/SGVect3DImpl.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGCalibrationDataPointImpl::FImpl
{
/************************
* Member variables
************************/
FCalibrationDataPointType CalibrationDataPoint;
/************************
* Owner object
************************/
FSGCalibrationDataPointImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGCalibrationDataPointImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGCalibrationDataPointImpl::FSGCalibrationDataPointImpl()
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
2022-11-02 22:43:14 +01:00
{
}
FSGCalibrationDataPointImpl::FSGCalibrationDataPointImpl(const int32 CurrentStage,
const TArray<FVector>& CalibrationValues)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
2022-11-02 22:43:14 +01:00
{
std::vector<FSGVect3DImpl::FVect3DType> Values(
FSGArrayUtils::ToStdVector<FVector, FSGVect3DImpl::FVect3DType, FSGVect3DImpl, &FSGVect3DImpl::ToVect3D>(
CalibrationValues));
Pimpl->CalibrationDataPoint = FCalibrationDataPointType(CurrentStage, MoveTemp(Values));
}
FSGCalibrationDataPointImpl::FSGCalibrationDataPointImpl(const FCalibrationDataPointType& CalibrationDataPoint)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
2022-11-02 22:43:14 +01:00
{
Pimpl->CalibrationDataPoint = CalibrationDataPoint;
}
FSGCalibrationDataPointImpl::FSGCalibrationDataPointImpl(const FSGCalibrationDataPointImpl& Rhs)
:
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
2022-11-02 22:43:14 +01:00
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
#else
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}))
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
2022-11-02 22:43:14 +01:00
{
Pimpl->Owner = this;
}
FSGCalibrationDataPointImpl::FSGCalibrationDataPointImpl(FSGCalibrationDataPointImpl&& Rhs)
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
noexcept
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
= default;
2022-11-02 22:43:14 +01:00
FSGCalibrationDataPointImpl::~FSGCalibrationDataPointImpl() = default;
FSGCalibrationDataPointImpl& FSGCalibrationDataPointImpl::operator=(const FSGCalibrationDataPointImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGCalibrationDataPointImpl& FSGCalibrationDataPointImpl::operator=(FSGCalibrationDataPointImpl&& Rhs)
#if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 )
noexcept
#endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 24 ) */
2022-11-02 22:43:14 +01:00
= default;
const FSGCalibrationDataPointImpl::FCalibrationDataPointType&
FSGCalibrationDataPointImpl::ToCalibrationDataPoint() const
{
return Pimpl->CalibrationDataPoint;
}
TArray<FVector> FSGCalibrationDataPointImpl::GetCalibrationValues() const
{
std::vector<FSGVect3DImpl::FVect3DType> Values(Pimpl->CalibrationDataPoint.GetCalibrationValues());
TArray<FVector> CalibrationValues{
FSGArrayUtils::FromStdVector<FSGVect3DImpl::FVect3DType, FVector, FSGVect3DImpl, &FSGVect3DImpl::ToFVector>(
MoveTemp(Values))
};
return CalibrationValues;
}
void FSGCalibrationDataPointImpl::SetCalibrationValues(const TArray<FVector>& CalibrationValues)
{
std::vector<FSGVect3DImpl::FVect3DType> CalibrationValuesVector{
FSGArrayUtils::ToStdVector<FVector, FSGVect3DImpl::FVect3DType, FSGVect3DImpl, &FSGVect3DImpl::ToVect3D>(
CalibrationValues)
};
Pimpl->CalibrationDataPoint.SetCalibrationValues(MoveTemp(CalibrationValuesVector));
}
int32 FSGCalibrationDataPointImpl::GetStage() const
{
return Pimpl->CalibrationDataPoint.GetStage();
}
void FSGCalibrationDataPointImpl::SetStage(const int32 Stage)
{
Pimpl->CalibrationDataPoint.SetStage(Stage);
}
FString FSGCalibrationDataPointImpl::ToLogData(const FString& Delimiter) const
{
std::string DelimiterString(TCHAR_TO_UTF8(*Delimiter));
FString LogData(UTF8_TO_TCHAR(Pimpl->CalibrationDataPoint.ToLogData(MoveTemp(DelimiterString)).c_str()));
return LogData;
}
FSGCalibrationDataPointImpl::FImpl::FImpl(FSGCalibrationDataPointImpl* InOwner)
: Owner(InOwner)
{
}
FSGCalibrationDataPointImpl::FImpl::~FImpl() = default;
void FSGCalibrationDataPointImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}