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

236 lines
8.8 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/SGHapticChannelInfo.h"
#include "SGCoreImpl/SGHapticChannelInfoImpl.h"
#include "SGCoreImpl/SGExportedFunctions.h"
#include "SGInterop/SGIC_ESGHapticChannelType.h"
#include "SGInterop/SGIC_ESGWaveformType.h"
#include "SGInterop/SGIC_FSGHapticChannelInfoImpl.h"
#include "SGInterop/SGIC_FString.h"
#include "SGInterop/SGIC_TArray_FString.h"
#include "SGInterop/SGIC_TArray_int32.h"
struct USGHapticChannelInfo::FImpl
{
/************************
* Member variables
************************/
FSGHapticChannelInfoImpl HapticChannelInfoImpl;
/************************
* Owner object
************************/
USGHapticChannelInfo* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(USGHapticChannelInfo* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
USGHapticChannelInfo* USGHapticChannelInfo::NewHapticChannelInfo(UObject* Outer,
const FSGHapticChannelInfoImpl& HapticChannelInfoImpl)
{
USGHapticChannelInfo* Instance = NewObject<USGHapticChannelInfo>(Outer);
Instance->SetHapticChannelInfoImpl(HapticChannelInfoImpl);
return Instance;
}
USGHapticChannelInfo* USGHapticChannelInfo::NewHapticChannelInfo(UObject* Outer)
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoImplContainer;
SGCoreImpl_FSGHapticChannelInfoImpl_ctor(&OutHapticChannelInfoImplContainer);
return NewHapticChannelInfo(Outer, MoveTemp(OutHapticChannelInfoImplContainer.HapticChannelInfoImpl));
}
USGHapticChannelInfo* USGHapticChannelInfo::NewHapticChannelInfo(
UObject* Outer,
const TArray<int32>& StreamIndex, const TArray<int32>& FireAndForgetIndex)
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoImplContainer;
FSGIC_TArray_int32 StreamIndexContainer{StreamIndex};
FSGIC_TArray_int32 FireAndForgetContainer{FireAndForgetIndex};
SGCoreImpl_FSGHapticChannelInfoImpl_ctor_StreamIndex_FireAndForgetIndex(
&OutHapticChannelInfoImplContainer, &StreamIndexContainer, &FireAndForgetContainer);
return NewHapticChannelInfo(Outer, MoveTemp(OutHapticChannelInfoImplContainer.HapticChannelInfoImpl));
}
FString USGHapticChannelInfo::GenerateAddress(const int32 DeviceIndex, const int32 ChannelIndex)
{
FSGIC_FString OutStringContainer;
SGCoreImpl_FSGHapticChannelInfoImpl_GenerateAddress(&OutStringContainer, DeviceIndex, ChannelIndex);
return OutStringContainer.String;
}
USGHapticChannelInfo* USGHapticChannelInfo::Parse(UObject* Outer, const FString& IpcString)
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoImplContainer;
FSGIC_FString IpcStringContainer{IpcString};
SGCoreImpl_FSGHapticChannelInfoImpl_Parse(&OutHapticChannelInfoImplContainer, &IpcStringContainer);
return NewHapticChannelInfo(Outer, MoveTemp(OutHapticChannelInfoImplContainer.HapticChannelInfoImpl));
}
int32 USGHapticChannelInfo::GetStreamingType()
{
return SGCoreImpl_FSGHapticChannelInfoImpl_GetStreamingType();
}
int32 USGHapticChannelInfo::GetFireAndForgetType()
{
return SGCoreImpl_FSGHapticChannelInfoImpl_GetFireAndForgetType();
}
USGHapticChannelInfo::USGHapticChannelInfo()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoImplContainer;
SGCoreImpl_FSGHapticChannelInfoImpl_ctor(&OutHapticChannelInfoImplContainer);
Pimpl->HapticChannelInfoImpl = MoveTemp(OutHapticChannelInfoImplContainer.HapticChannelInfoImpl);
}
USGHapticChannelInfo::USGHapticChannelInfo(const TArray<int32>& StreamIndex, const TArray<int32>& FireAndForgetIndex)
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoImplContainer;
FSGIC_TArray_int32 StreamIndexContainer{StreamIndex};
FSGIC_TArray_int32 FireAndForgetContainer{FireAndForgetIndex};
SGCoreImpl_FSGHapticChannelInfoImpl_ctor_StreamIndex_FireAndForgetIndex(
&OutHapticChannelInfoImplContainer, &StreamIndexContainer, &FireAndForgetContainer);
Pimpl->HapticChannelInfoImpl = MoveTemp(OutHapticChannelInfoImplContainer.HapticChannelInfoImpl);
}
USGHapticChannelInfo::USGHapticChannelInfo(const FSGHapticChannelInfoImpl& HapticChannelInfoImpl)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
SetHapticChannelInfoImpl(HapticChannelInfoImpl);
}
USGHapticChannelInfo::~USGHapticChannelInfo() = default;
void USGHapticChannelInfo::SetHapticChannelInfoImpl(const FSGHapticChannelInfoImpl& HapticChannelInfoImpl)
{
FSGIC_FSGHapticChannelInfoImpl OutHapticChannelInfoContainer;
FSGIC_FSGHapticChannelInfoImpl RhsContainer{HapticChannelInfoImpl};
SGCoreImpl_FSGHapticChannelInfoImpl_ctor_copy(&OutHapticChannelInfoContainer, &RhsContainer);
Pimpl->HapticChannelInfoImpl = MoveTemp(OutHapticChannelInfoContainer.HapticChannelInfoImpl);
}
const FSGHapticChannelInfoImpl& USGHapticChannelInfo::ToHapticChannelInfoImpl() const
{
return Pimpl->HapticChannelInfoImpl;
}
int32 USGHapticChannelInfo::GetStreamChannelCount() const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
return SGCoreImpl_FSGHapticChannelInfoImpl_GetStreamChannelCount(&InstanceContainer);
}
int32 USGHapticChannelInfo::GetFireAndForgetChannelCount() const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
return SGCoreImpl_FSGHapticChannelInfoImpl_GetFireAndForgetChannelCount(&InstanceContainer);
}
int32 USGHapticChannelInfo::GetTotalChannelCount() const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
return SGCoreImpl_FSGHapticChannelInfoImpl_GetTotalChannelCount(&InstanceContainer);
}
FString USGHapticChannelInfo::GetAddress_Unguarded(const ESGHapticChannelType Type, const int32 TypeIndex) const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
FSGIC_FString OutStringContainer;
FSGIC_ESGHapticChannelType TypeContainer{Type};
SGCoreImpl_FSGHapticChannelInfoImpl_GetAddress_Unguarded(
&InstanceContainer, &OutStringContainer, &TypeContainer, TypeIndex);
return OutStringContainer.String;
}
void USGHapticChannelInfo::GetIpcParams_Unguarded(
const ESGHapticChannelType Type, const int32 TypeIndex, int32& OutIndex, FString& OutAddressString) const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
FSGIC_ESGHapticChannelType TypeContainer{Type};
FSGIC_FString OutAddressStringContainer;
SGCoreImpl_FSGHapticChannelInfoImpl_GetIpcParams_Unguarded(
&InstanceContainer, &TypeContainer, TypeIndex, &OutIndex, &OutAddressString);
OutAddressString = MoveTemp(OutAddressStringContainer.String);
}
void USGHapticChannelInfo::RegenerateAddresses(const int32 ForDeviceIndex)
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
SGCoreImpl_FSGHapticChannelInfoImpl_RegenerateAddresses(&InstanceContainer, ForDeviceIndex);
}
TArray<FString> USGHapticChannelInfo::GetAllAddresses() const
{
FSGIC_FSGHapticChannelInfoImpl InstanceContainer{ToHapticChannelInfoImpl()};
FSGIC_TArray_FString* OutArrayContainer;
SGCoreImpl_FSGHapticChannelInfoImpl_GetAllAddresses(&InstanceContainer, &OutArrayContainer);
return OutArrayContainer->Array;
}
USGHapticChannelInfo::FImpl::FImpl(USGHapticChannelInfo* InOwner)
: Owner(InOwner)
{
}
USGHapticChannelInfo::FImpl::~FImpl() = default;
void USGHapticChannelInfo::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}