revamp sglog to use unreal's tuniqueptr instead of std::unique_ptr

This commit is contained in:
Mamadou Babaei
2025-06-04 02:23:58 +02:00
parent 73957cfe66
commit 9682585c00
3 changed files with 113 additions and 75 deletions
+108 -70
View File
@@ -42,7 +42,10 @@ DEFINE_LOG_CATEGORY(LogGeneric)
struct FSGLogCore::FStaticImpl
{
public:
/************************
* Type definitions
************************/
struct VerbosityMapper
{
FString Tag;
@@ -51,33 +54,56 @@ public:
VerbosityMapper(const FString& InTag, const FColor& InColor);
};
public:
/************************
* Member variables
************************/
TMap<FSGLogCore::EVerbosity, VerbosityMapper> VerbosityMap;
bool bInitialized;
public:
/************************
* Constructor / Destructor
************************/
FStaticImpl();
~FStaticImpl();
};
struct FSGLogCore::FImpl
{
public:
/************************
* Member variables
************************/
FSGLogCore::EVerbosity Verbosity;
FSGLogCore::ECategory Category;
FString File;
FString Function;
FString Line;
/************************
* Constructor / Destructor
************************/
FImpl();
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGLogCore::FStaticImplDeleter FSGLogCore::SPimplDeleter;
std::unique_ptr<FSGLogCore::FStaticImpl, FSGLogCore::FStaticImplDeleter> FSGLogCore::SPimpl =
std::unique_ptr<FSGLogCore::FStaticImpl, FSGLogCore::FStaticImplDeleter>(
new FSGLogCore::FStaticImpl{}, FSGLogCore::SPimplDeleter);
TUniquePtr<FSGLogCore::FStaticImpl, FSGLogCore::FStaticImplDeleter> FSGLogCore::SPimpl{
new FStaticImpl{}, FStaticImplDeleter()
};
FSGLogCore::FSGLogCore(const EVerbosity& Verbosity, const ECategory& Category, const std::string& File,
const std::string& Function, const int32 Line)
: Pimpl(std::unique_ptr<FImpl, FImplDeleter>(new FImpl{}, PimplDeleter)),
const std::string& Function, const int32 Line)
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{}, PimplDeleter)),
bAnyEntries(false)
{
#if defined ( SENSEGLOVE_LOGGING )
@@ -85,12 +111,14 @@ FSGLogCore::FSGLogCore(const EVerbosity& Verbosity, const ECategory& Category, c
{
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Fatal,
FStaticImpl::VerbosityMapper(TEXT("FATAL"), FColor::White));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Error, FStaticImpl::VerbosityMapper(TEXT("ERROR"), FColor::Red));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Error,
FStaticImpl::VerbosityMapper(TEXT("ERROR"), FColor::Red));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Warning,
FStaticImpl::VerbosityMapper(TEXT("WARNING"), FColor::Yellow));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Display,
FStaticImpl::VerbosityMapper(TEXT("DISPLAY"), FColor::Green));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Log, FStaticImpl::VerbosityMapper(TEXT("LOG"), FColor::Silver));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Log,
FStaticImpl::VerbosityMapper(TEXT("LOG"), FColor::Silver));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::Verbose,
FStaticImpl::VerbosityMapper(TEXT("VERBOSE"), FColor::Purple));
SPimpl->VerbosityMap.Add(FSGLogCore::EVerbosity::VeryVerbose,
@@ -127,46 +155,46 @@ FSGLogCore::~FSGLogCore()
switch (Verbosity)
{
case EVerbosity::Display:
{
UE_LOG(LogGeneric, Display, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Display, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Error:
{
UE_LOG(LogGeneric, Error, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Error, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Fatal:
{
UE_LOG(LogGeneric, Fatal, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Fatal, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Log:
{
UE_LOG(LogGeneric, Log, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Log, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Verbose:
{
UE_LOG(LogGeneric, Verbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Verbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::VeryVerbose:
{
UE_LOG(LogGeneric, VeryVerbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, VeryVerbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Warning:
{
UE_LOG(LogGeneric, Warning, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogGeneric, Warning, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
}
}
@@ -176,46 +204,46 @@ FSGLogCore::~FSGLogCore()
switch (Verbosity)
{
case EVerbosity::Display:
{
UE_LOG(LogEditor, Display, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Display, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Error:
{
UE_LOG(LogEditor, Error, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Error, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Fatal:
{
UE_LOG(LogEditor, Fatal, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Fatal, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Log:
{
UE_LOG(LogEditor, Log, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Log, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Verbose:
{
UE_LOG(LogEditor, Verbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Verbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::VeryVerbose:
{
UE_LOG(LogEditor, VeryVerbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, VeryVerbose, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
case EVerbosity::Warning:
{
UE_LOG(LogEditor, Warning, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
{
UE_LOG(LogEditor, Warning, TEXT("%s"), Message.GetCharArray().GetData());
}
break;
}
}
#endif /* defined ( SENSEGLOVE_LOGGING ) */
@@ -226,8 +254,10 @@ FSGLogCore::FStaticImpl::FStaticImpl()
{
}
FSGLogCore::FStaticImpl::~FStaticImpl() = default;
FSGLogCore::FStaticImpl::VerbosityMapper::VerbosityMapper(const FString& InTag,
const FColor& InColor)
const FColor& InColor)
: Tag(InTag),
Color(InColor)
{
@@ -238,7 +268,15 @@ void FSGLogCore::FStaticImplDeleter::operator()(const FSGLogCore::FStaticImpl* P
delete Pointer;
}
FSGLogCore::FImpl::FImpl()
: Verbosity(EVerbosity::Verbose),
Category(ECategory::Generic)
{
}
FSGLogCore::FImpl::~FImpl() = default;
void FSGLogCore::FImplDeleter::operator()(const FSGLogCore::FImpl* Pointer) const
{
delete Pointer;
}
}
+4 -5
View File
@@ -35,10 +35,9 @@
#pragma once
#include <memory>
#include <string>
#include <cstddef>
#include <cstdio>
#include <string>
#include "Containers/StringConv.h"
#include "Containers/UnrealString.h"
@@ -47,6 +46,7 @@
#include "Math/Rotator.h"
#include "Math/Transform.h"
#include "Math/Vector.h"
#include "Templates/SharedPointer.h"
#include "Templates/UnrealTemplate.h"
DECLARE_LOG_CATEGORY_EXTERN(LogEditor, All, All);
@@ -646,8 +646,7 @@ private:
void operator()(const FStaticImpl* Pointer) const;
};
static std::unique_ptr<FStaticImpl, FStaticImplDeleter> SPimpl;
static FStaticImplDeleter SPimplDeleter;
static TUniquePtr<FStaticImpl, FStaticImplDeleter> SPimpl;
struct FImpl;
@@ -656,7 +655,7 @@ private:
void operator()(const FImpl* Pointer) const;
};
std::unique_ptr<FImpl, FImplDeleter> Pimpl;
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
private: