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

206 lines
6.3 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2025 SenseChannelInfo
*
* 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/SGHapticChannelInfoImpl.h"
#include "Containers/StringConv.h"
#include "SGBuildHacks/SGInclude_Core_HapticChannelInfo.h"
#include "SGCoreImpl/SGCoreEnumCast.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGHapticChannelInfoImpl::FImpl
{
/************************
* Member variables
************************/
FHapticChannelInfoType HapticChannelInfo;
/************************
* Owner object
************************/
FSGHapticChannelInfoImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGHapticChannelInfoImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FString FSGHapticChannelInfoImpl::GenerateAddress(const int32 DeviceIndex, const int32 ChannelIndex)
{
const FString Address{UTF8_TO_TCHAR(FHapticChannelInfoType::GenerateAddress(DeviceIndex, ChannelIndex).c_str())};
return Address;
}
FSGHapticChannelInfoImpl FSGHapticChannelInfoImpl::Parse(const FString& IpcString)
{
std::string IpcStdString{TCHAR_TO_UTF8(*IpcString)};
FHapticChannelInfoType HapticChannelInfo{FHapticChannelInfoType::Parse(MoveTemp(IpcStdString))};
const FSGHapticChannelInfoImpl HapticChannelInfoImpl{MoveTemp(HapticChannelInfo)};
return HapticChannelInfoImpl;
}
int32 FSGHapticChannelInfoImpl::GetStreamingType()
{
return FHapticChannelInfoType::GetStreamingType();
}
int32 FSGHapticChannelInfoImpl::GetFireAndForgetType()
{
return FHapticChannelInfoType::GetFireAndForgetType();
}
FSGHapticChannelInfoImpl::FSGHapticChannelInfoImpl()
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGHapticChannelInfoImpl::FSGHapticChannelInfoImpl(
const TArray<int32>& StreamIndex, const TArray<int32>& FireAndForgetIndex)
{
std::vector<int32> StreamIndexVector{
FSGArrayUtils::ToStdVector(StreamIndex)
};
std::vector<int32> FireAndForgetIndexVector{
FSGArrayUtils::ToStdVector<int32>(FireAndForgetIndex)
};
Pimpl->HapticChannelInfo = FHapticChannelInfoType{
MoveTemp(StreamIndexVector),
MoveTemp(FireAndForgetIndexVector)
};
}
FSGHapticChannelInfoImpl::FSGHapticChannelInfoImpl(const FHapticChannelInfoType& HapticChannelInfo)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
Pimpl->HapticChannelInfo = HapticChannelInfo;
}
FSGHapticChannelInfoImpl::FSGHapticChannelInfoImpl(const FSGHapticChannelInfoImpl& Rhs)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
{
Pimpl->Owner = this;
}
FSGHapticChannelInfoImpl::FSGHapticChannelInfoImpl(FSGHapticChannelInfoImpl&& Rhs) SG_NOEXCEPT = default;
FSGHapticChannelInfoImpl::~FSGHapticChannelInfoImpl() = default;
FSGHapticChannelInfoImpl& FSGHapticChannelInfoImpl::operator=(const FSGHapticChannelInfoImpl& Rhs)
{
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGHapticChannelInfoImpl& FSGHapticChannelInfoImpl::operator=(FSGHapticChannelInfoImpl&& Rhs) SG_NOEXCEPT = default;
const FSGHapticChannelInfoImpl::FHapticChannelInfoType& FSGHapticChannelInfoImpl::ToHapticChannelInfo() const
{
return Pimpl->HapticChannelInfo;
}
int32 FSGHapticChannelInfoImpl::GetStreamChannelCount() const
{
return Pimpl->HapticChannelInfo.GetStreamChannelCount();
}
int32 FSGHapticChannelInfoImpl::GetFireAndForgetChannelCount() const
{
return Pimpl->HapticChannelInfo.GetFireAndForgetChannelCount();
}
int32 FSGHapticChannelInfoImpl::GetTotalChannelCount() const
{
return Pimpl->HapticChannelInfo.GetTotalChannelCount();
}
FString FSGHapticChannelInfoImpl::GetAddress_Unguarded(const ESGHapticChannelType Type, const int32 TypeIndex) const
{
const FString Address{
UTF8_TO_TCHAR(
Pimpl->HapticChannelInfo.GetAddress_Unguarded(
FSGCoreEnumCast::ToEHapticChannelType(Type), TypeIndex).c_str(
))
};
return Address;
}
void FSGHapticChannelInfoImpl::GetIpcParams_Unguarded(
const ESGHapticChannelType Type, const int32 TypeIndex, int32& OutIndex, FString& OutAddressString) const
{
std::string OutAddressStdString;
Pimpl->HapticChannelInfo.GetIpcParams_Unguarded(
FSGCoreEnumCast::ToEHapticChannelType(Type), TypeIndex, OutIndex, OutAddressStdString);
OutAddressString = FString{UTF8_TO_TCHAR(OutAddressStdString.c_str())};
}
void FSGHapticChannelInfoImpl::RegenerateAddresses(const int32 ForDeviceIndex)
{
Pimpl->HapticChannelInfo.RegenerateAddresses(ForDeviceIndex);
}
TArray<FString> FSGHapticChannelInfoImpl::GetAllAddresses() const
{
const TArray<FString> AddressesArray{
FSGArrayUtils::FromStdVector(Pimpl->HapticChannelInfo.GetAllAddresses())
};
return AddressesArray;
}
FSGHapticChannelInfoImpl::FImpl::FImpl(FSGHapticChannelInfoImpl* InOwner)
: Owner(InOwner)
{
}
FSGHapticChannelInfoImpl::FImpl::~FImpl() = default;
void FSGHapticChannelInfoImpl::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}