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

188 lines
5.7 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2025 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/SGThresholdCommandImpl.h"
#include <vector>
#include "SGBuildHacks/SGInclude_Core_ThresholdCommand.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGThresholdCommandImpl::FImpl
{
/************************
* Member variables
************************/
FThresholdCommandType ThresholdCommand;
/************************
* Owner object
************************/
FSGThresholdCommandImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGThresholdCommandImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGThresholdCommandImpl::FSGThresholdCommandImpl()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGThresholdCommandImpl::FSGThresholdCommandImpl(
const TArray<bool>& AffectedFingers, const TArray<float>& ThresholdValues)
{
std::vector<bool> AffectedFingersVector{FSGArrayUtils::ToStdVector(AffectedFingers)};
std::vector<float> ThresholdValuesVector{FSGArrayUtils::ToStdVector(ThresholdValues)};
Pimpl->ThresholdCommand = FThresholdCommandType{MoveTemp(AffectedFingersVector), MoveTemp(ThresholdValuesVector)};
}
FSGThresholdCommandImpl::FSGThresholdCommandImpl(
const FThresholdCommandType& ThresholdCommand)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->ThresholdCommand = ThresholdCommand;
}
FSGThresholdCommandImpl::FSGThresholdCommandImpl(const FSGThresholdCommandImpl& Rhs)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
{
Pimpl->Owner = this;
}
FSGThresholdCommandImpl::FSGThresholdCommandImpl(FSGThresholdCommandImpl&& Rhs) SG_NOEXCEPT = default;
FSGThresholdCommandImpl::~FSGThresholdCommandImpl() = default;
FSGThresholdCommandImpl& FSGThresholdCommandImpl::operator=(const FSGThresholdCommandImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGThresholdCommandImpl& FSGThresholdCommandImpl::operator=(FSGThresholdCommandImpl&& Rhs) SG_NOEXCEPT = default;
const FSGThresholdCommandImpl::FThresholdCommandType& FSGThresholdCommandImpl::ToThresholdCommand() const
{
return Pimpl->ThresholdCommand;
}
FSGThresholdCommandImpl::FThresholdCommandType& FSGThresholdCommandImpl::ToThresholdCommand()
{
return Pimpl->ThresholdCommand;
}
float FSGThresholdCommandImpl::GetThreshold(int32 Finger) const
{
return Pimpl->ThresholdCommand.GetThreshold(Finger);
}
void FSGThresholdCommandImpl::SetThreshold(const int32 Finger, const float ThresholdValue)
{
Pimpl->ThresholdCommand.SetThreshold(Finger, ThresholdValue);
}
TArray<float> FSGThresholdCommandImpl::GetThresholds() const
{
const TArray<float> Thresholds{FSGArrayUtils::FromStdVector(Pimpl->ThresholdCommand.GetThresholds())};
return Thresholds;
}
void FSGThresholdCommandImpl::SetThresholds(const TArray<bool>& AffectedFingers, const TArray<float>& ThresholdValues)
{
std::vector<bool> AffectedFingersVector{FSGArrayUtils::ToStdVector(AffectedFingers)};
std::vector<float> ThresholdValuesVector{FSGArrayUtils::ToStdVector(ThresholdValues)};
Pimpl->ThresholdCommand.SetThresholds(MoveTemp(AffectedFingersVector), MoveTemp(ThresholdValuesVector));
}
bool FSGThresholdCommandImpl::GetFingerActive(const int32 Finger) const
{
return Pimpl->ThresholdCommand.GetFingerActive(Finger);
}
TArray<bool> FSGThresholdCommandImpl::GetActiveFingers() const
{
const TArray<bool> ActiveFingers{FSGArrayUtils::FromStdVector(Pimpl->ThresholdCommand.GetActiveFingers())};
return ActiveFingers;
}
void FSGThresholdCommandImpl::ClearThreshold(const int32 Finger)
{
Pimpl->ThresholdCommand.ClearThreshold(Finger);
}
void FSGThresholdCommandImpl::ClearThresholds()
{
Pimpl->ThresholdCommand.ClearThresholds();
}
bool FSGThresholdCommandImpl::Equals(const FSGThresholdCommandImpl& ThresholdCommand) const
{
return Pimpl->ThresholdCommand.Equals(ThresholdCommand.ToThresholdCommand());
}
FString FSGThresholdCommandImpl::ToString() const
{
const FString String{UTF8_TO_TCHAR(Pimpl->ThresholdCommand.ToString().c_str())};
return String;
}
FSGThresholdCommandImpl::FImpl::FImpl(FSGThresholdCommandImpl* InOwner)
: Owner(InOwner)
{
}
FSGThresholdCommandImpl::FImpl::~FImpl() = default;
void FSGThresholdCommandImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}