/** * @file * * @author Mamadou Babaei * * @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/SGBuzzCommandImpl.h" #include "SGCoreImpl/SGCoreEnumCast.h" #include "SGBuildHacks/SGInclude_Core_BuzzCommand.h" #include "SGUtils/SGArrayUtils.h" struct FSGBuzzCommandImpl::FImpl { /************************ * Member variables ************************/ /************************ * Owner object ************************/ FSGBuzzCommandImpl* Owner; /************************ * Constructor / Destructor ************************/ explicit FImpl(FSGBuzzCommandImpl* InOwner); ~FImpl(); /************************ * Default copy constructor & copy assignment operator ************************/ FImpl(const FImpl& Rhs) = default; FImpl& operator=(const FImpl& Rhs) = default; }; const FSGBuzzCommandImpl& FSGBuzzCommandImpl::Off() { static const FSGBuzzCommandImpl Command(FBuzzCommandType::Off()); return Command; } FSGBuzzCommandImpl::FSGBuzzCommandImpl() : FSGFingerCommandImpl(MakeShared()), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const TArray& BuzzLevels) : FSGFingerCommandImpl(MakeShared(FSGArrayUtils::ToStdVector(BuzzLevels))), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const int32 Thumb, const int32 Index, const int32 Middle, const int32 Ring, const int32 Pinky) : FSGFingerCommandImpl(MakeShared(Thumb, Index, Middle, Ring, Pinky)), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const ESGFinger Finger, const int32 BuzzLevel) : FSGFingerCommandImpl(MakeShared(FSGCoreEnumCast::ToEFinger(Finger), BuzzLevel)), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const FBuzzCommandType& BuzzCommand) : FSGFingerCommandImpl(MakeShared(BuzzCommand)), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const TSharedRef BuzzCommand) : FSGFingerCommandImpl(BuzzCommand), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{this}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{this})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { } FSGBuzzCommandImpl::FSGBuzzCommandImpl(const FSGBuzzCommandImpl& Rhs) : FSGFingerCommandImpl(Rhs), #if ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl}, PimplDeleter)) #else Pimpl(TUniquePtr(new FImpl{*Rhs.Pimpl})) #endif /* ENGINE_MAJOR_VERSION == 5 || ( ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION > 22 ) */ { Pimpl->Owner = this; } FSGBuzzCommandImpl::FSGBuzzCommandImpl(FSGBuzzCommandImpl&& Rhs) noexcept = default; FSGBuzzCommandImpl::~FSGBuzzCommandImpl() = default; FSGBuzzCommandImpl& FSGBuzzCommandImpl::operator=(const FSGBuzzCommandImpl& Rhs) { FSGFingerCommandImpl::operator=(Rhs); *Pimpl = *Rhs.Pimpl; Pimpl->Owner = this; return *this; } FSGBuzzCommandImpl& FSGBuzzCommandImpl::operator=(FSGBuzzCommandImpl&& Rhs) noexcept = default; const FSGBuzzCommandImpl::FBuzzCommandType& FSGBuzzCommandImpl::ToBuzzCommand() const { return *StaticCastSharedRef(ToFingerCommandRef()); } TSharedRef FSGBuzzCommandImpl::ToBuzzCommandRef() const { return StaticCastSharedRef(ToFingerCommandRef()); } FSGBuzzCommandImpl::FBuzzCommandType& FSGBuzzCommandImpl::ToBuzzCommand() { return *StaticCastSharedRef(ToFingerCommandRef()); } TSharedRef FSGBuzzCommandImpl::ToBuzzCommandRef() { return StaticCastSharedRef(ToFingerCommandRef()); } FSGBuzzCommandImpl FSGBuzzCommandImpl::Copy() const { return FSGBuzzCommandImpl(ToBuzzCommandRef()->Copy()); } FSGBuzzCommandImpl FSGBuzzCommandImpl::Merge(const FSGBuzzCommandImpl& Command) const { return FSGBuzzCommandImpl(ToBuzzCommandRef()->Merge(Command.ToBuzzCommand())); } FSGBuzzCommandImpl::FImpl::FImpl(FSGBuzzCommandImpl* InOwner) : Owner(InOwner) { } FSGBuzzCommandImpl::FImpl::~FImpl() = default; void FSGBuzzCommandImpl::FImplDeleter::operator()(const FSGBuzzCommandImpl::FImpl* P) const { delete P; }