Files
Plugin/Source/SenseGloveCore/Private/SGCore/SGFingerCommand.cpp
T

274 lines
10 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 "SGCore/SGFingerCommand.h"
#include "Runtime/Launch/Resources/Version.h"
#include "SGCoreImpl/SGExportedFunctions.h"
#include "SGInterop/SGIC_FSGBuzzCommandImpl.h"
#include "SGInterop/SGIC_FSGFingerCommandImpl.h"
#include "SGInterop/SGIC_FSGForceFeedbackCommandImpl.h"
#include "SGInterop/SGIC_FSGTimedBuzzCommandImpl.h"
#include "SGInterop/SGIC_FString.h"
#include "SGInterop/SGIC_TArray_int32.h"
#include "SGInterop/SGIC_TSharedPtr_FSGBuzzCommandImpl.h"
#include "SGInterop/SGIC_TSharedPtr_FSGFingerCommandImpl.h"
#include "SGInterop/SGIC_TSharedPtr_FSGForceFeedbackCommandImpl.h"
#include "SGInterop/SGIC_TSharedPtr_FSGTimedBuzzCommandImpl.h"
struct USGFingerCommand::FImpl
{
/************************
* Member variables
************************/
TSharedPtr<FSGFingerCommandImpl> FingerCommandImpl;
/************************
* Owner object
************************/
USGFingerCommand* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(USGFingerCommand* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
USGFingerCommand::USGFingerCommand()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGFingerCommandImpl OutSharedPtrContainer;
SGCoreImpl_FSGFingerCommandImpl_ctor_MakeShared(&OutSharedPtrContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(const TArray<int32>& InLevels)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGFingerCommandImpl OutSharedPtrContainer;
FSGIC_TArray_int32 LevelsContainer{InLevels};
SGCoreImpl_FSGFingerCommandImpl_ctor_Levels_MakeShared(&OutSharedPtrContainer, &LevelsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(const FSGFingerCommandImpl& FingerCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGFingerCommandImpl OutSharedPtrContainer;
FSGIC_FSGFingerCommandImpl RhsContainer{FingerCommandImpl};
SGCoreImpl_FSGFingerCommandImpl_ctor_copy_MakeShared(
&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(const FSGBuzzCommandImpl& BuzzCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGBuzzCommandImpl OutSharedPtrContainer;
FSGIC_FSGBuzzCommandImpl RhsContainer{BuzzCommandImpl};
SGCoreImpl_FSGBuzzCommandImpl_ctor_copy_MakeShared(
&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(const FSGForceFeedbackCommandImpl& ForceFeedbackCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGForceFeedbackCommandImpl OutSharedPtrContainer;
FSGIC_FSGForceFeedbackCommandImpl RhsContainer{ForceFeedbackCommandImpl};
SGCoreImpl_FSGForceFeedbackCommandImpl_ctor_copy_MakeShared(
&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(const FSGTimedBuzzCommandImpl& TimedBuzzCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_TSharedPtr_FSGTimedBuzzCommandImpl OutSharedPtrContainer;
FSGIC_FSGTimedBuzzCommandImpl RhsContainer{TimedBuzzCommandImpl};
SGCoreImpl_FSGTimedBuzzCommandImpl_ctor_copy_MakeShared(
&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
USGFingerCommand::USGFingerCommand(TSharedRef<FSGFingerCommandImpl> FingerCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->FingerCommandImpl = MoveTemp(FingerCommandImpl);
}
USGFingerCommand::USGFingerCommand(TSharedRef<FSGBuzzCommandImpl> BuzzCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->FingerCommandImpl = MoveTemp(BuzzCommandImpl);
}
USGFingerCommand::USGFingerCommand(TSharedRef<FSGForceFeedbackCommandImpl> ForceFeedbackCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->FingerCommandImpl = MoveTemp(ForceFeedbackCommandImpl);
}
USGFingerCommand::USGFingerCommand(TSharedRef<FSGTimedBuzzCommandImpl> TimedBuzzCommandImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->FingerCommandImpl = MoveTemp(TimedBuzzCommandImpl);
}
USGFingerCommand::~USGFingerCommand() = default;
void USGFingerCommand::SetFingerCommandImpl(const FSGFingerCommandImpl& FingerCommandImpl)
{
FSGIC_TSharedPtr_FSGFingerCommandImpl OutSharedPtrContainer;
FSGIC_FSGFingerCommandImpl RhsContainer{FingerCommandImpl};
SGCoreImpl_FSGFingerCommandImpl_ctor_copy_MakeShared(&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
void USGFingerCommand::SetFingerCommandImpl(const FSGBuzzCommandImpl& BuzzCommandImpl)
{
FSGIC_TSharedPtr_FSGBuzzCommandImpl OutSharedPtrContainer;
FSGIC_FSGBuzzCommandImpl RhsContainer{BuzzCommandImpl};
SGCoreImpl_FSGBuzzCommandImpl_ctor_copy_MakeShared(&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
void USGFingerCommand::SetFingerCommandImpl(const FSGForceFeedbackCommandImpl& ForceFeedbackCommandImpl)
{
FSGIC_TSharedPtr_FSGForceFeedbackCommandImpl OutSharedPtrContainer;
FSGIC_FSGForceFeedbackCommandImpl RhsContainer{ForceFeedbackCommandImpl};
SGCoreImpl_FSGForceFeedbackCommandImpl_ctor_copy_MakeShared(&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
void USGFingerCommand::SetFingerCommandImpl(const FSGTimedBuzzCommandImpl& TimedBuzzCommandImpl)
{
FSGIC_TSharedPtr_FSGTimedBuzzCommandImpl OutSharedPtrContainer;
FSGIC_FSGTimedBuzzCommandImpl RhsContainer{TimedBuzzCommandImpl};
SGCoreImpl_FSGTimedBuzzCommandImpl_ctor_copy_MakeShared(&OutSharedPtrContainer, &RhsContainer);
Pimpl->FingerCommandImpl = MoveTemp(OutSharedPtrContainer.Ptr);
}
void USGFingerCommand::SetFingerCommandImpl(TSharedRef<FSGFingerCommandImpl> FingerCommandImpl)
{
Pimpl->FingerCommandImpl = MoveTemp(FingerCommandImpl);
}
void USGFingerCommand::SetFingerCommandImpl(TSharedRef<FSGBuzzCommandImpl> BuzzCommandImpl)
{
Pimpl->FingerCommandImpl = MoveTemp(BuzzCommandImpl);
}
void USGFingerCommand::SetFingerCommandImpl(TSharedRef<FSGForceFeedbackCommandImpl> ForceFeedbackCommandImpl)
{
Pimpl->FingerCommandImpl = MoveTemp(ForceFeedbackCommandImpl);
}
void USGFingerCommand::SetFingerCommandImpl(TSharedRef<FSGTimedBuzzCommandImpl> TimedBuzzCommandImpl)
{
Pimpl->FingerCommandImpl = MoveTemp(TimedBuzzCommandImpl);
}
TSharedRef<FSGFingerCommandImpl> USGFingerCommand::ToFingerCommandImpl() const
{
return Pimpl->FingerCommandImpl.ToSharedRef();
}
TArray<int32> USGFingerCommand::GetLevels() const
{
FSGIC_TSharedPtr_FSGFingerCommandImpl InstanceContainer{ToFingerCommandImpl()};
FSGIC_TArray_int32 OutLevelsContainer;
SGCoreImpl_FSGFingerCommandImpl_GetLevels(&InstanceContainer, &OutLevelsContainer);
return MoveTemp(OutLevelsContainer.Array);
}
int32 USGFingerCommand::GetLevel(const int32 Finger) const
{
FSGIC_TSharedPtr_FSGFingerCommandImpl InstanceContainer{ToFingerCommandImpl()};
const int32 Level = SGCoreImpl_FSGFingerCommandImpl_GetLevel(&InstanceContainer, Finger);
return Level;
}
void USGFingerCommand::SetLevel(const int32 Finger, const int32 Value)
{
FSGIC_TSharedPtr_FSGFingerCommandImpl InstanceContainer{ToFingerCommandImpl()};
SGCoreImpl_FSGFingerCommandImpl_SetLevel(&InstanceContainer, Finger, Value);
}
bool USGFingerCommand::Equals(const USGFingerCommand* FingerCommand) const
{
FSGIC_TSharedPtr_FSGFingerCommandImpl InstanceContainer{ToFingerCommandImpl()};
FSGIC_FSGFingerCommandImpl FingerCommandImplContainer{FingerCommand->ToFingerCommandImpl().Get()};
const bool bEquals = SGCoreImpl_FSGFingerCommandImpl_Equals(&InstanceContainer, &FingerCommandImplContainer);
return bEquals;
}
FString USGFingerCommand::ToString() const
{
FSGIC_TSharedPtr_FSGFingerCommandImpl InstanceContainer{ToFingerCommandImpl()};
FSGIC_FString OutStringContainer;
SGCoreImpl_FSGFingerCommandImpl_ToString(&InstanceContainer, &OutStringContainer);
return MoveTemp(OutStringContainer.String);
}
USGFingerCommand::FImpl::FImpl(USGFingerCommand* InOwner)
: Owner(InOwner)
{
}
USGFingerCommand::FImpl::~FImpl() = default;
void USGFingerCommand::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}