From c64d2a94bfeb75d3b8b24d4a97b721de8c360c4a Mon Sep 17 00:00:00 2001 From: apistol78 Date: Thu, 2 May 2024 13:49:53 +0200 Subject: [PATCH] Traktor: Some cleanup in Core classes. --- code/Core/Misc/AvlTree.h | 6 +++--- code/Core/Misc/ImmutableCheck.h | 13 ++++++++----- code/Core/Misc/InvokeOnce.h | 29 ++++------------------------- code/Core/Object.h | 4 ++-- code/Core/Rtti/TypeInfo.cpp | 2 +- 5 files changed, 18 insertions(+), 36 deletions(-) diff --git a/code/Core/Misc/AvlTree.h b/code/Core/Misc/AvlTree.h index b7a44b71ea..78e0b1c72d 100644 --- a/code/Core/Misc/AvlTree.h +++ b/code/Core/Misc/AvlTree.h @@ -1,6 +1,6 @@ /* * TRAKTOR - * Copyright (c) 2022 Anders Pistol. + * Copyright (c) 2022-2024 Anders Pistol. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -39,7 +39,7 @@ class AvlTree KeyType key; ItemType item; - Node(const KeyType& key, const ItemType& item) + explicit Node(const KeyType& key, const ItemType& item) : left(nullptr) , right(nullptr) , key(key) @@ -60,7 +60,7 @@ class AvlTree { Node* node; - Iterator(Node* node_) + explicit iterator(Node* node_) : node(node_) { } diff --git a/code/Core/Misc/ImmutableCheck.h b/code/Core/Misc/ImmutableCheck.h index 386e12ab89..c2ad3010d7 100644 --- a/code/Core/Misc/ImmutableCheck.h +++ b/code/Core/Misc/ImmutableCheck.h @@ -1,6 +1,6 @@ /* * TRAKTOR - * Copyright (c) 2022 Anders Pistol. + * Copyright (c) 2022-2024 Anders Pistol. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -8,13 +8,15 @@ */ #pragma once -#if 0 -# include "Core/Serialization/DeepHash.h" -# include "Core/Serialization/ISerializable.h" +#include "Core/Serialization/DeepHash.h" +#include "Core/Serialization/ISerializable.h" namespace traktor { +/*! Helper to ensure object hasn't been modified. + * \ingroup Core + */ class ImmutableCheck { public: @@ -26,7 +28,7 @@ class ImmutableCheck ~ImmutableCheck() { - uint32_t hash = DeepHash(m_imm).get(); + const uint32_t hash = DeepHash(m_imm).get(); T_FATAL_ASSERT_M(hash == m_hash, L"Immutable object modified."); } @@ -37,6 +39,7 @@ class ImmutableCheck } +#if 0 # define T_IMMUTABLE_CHECK(imm) T_ANONYMOUS_VAR(ImmutableCheck)(imm); #else # define T_IMMUTABLE_CHECK(imm) diff --git a/code/Core/Misc/InvokeOnce.h b/code/Core/Misc/InvokeOnce.h index d641ffed7b..6155660678 100644 --- a/code/Core/Misc/InvokeOnce.h +++ b/code/Core/Misc/InvokeOnce.h @@ -1,6 +1,6 @@ /* * TRAKTOR - * Copyright (c) 2022 Anders Pistol. + * Copyright (c) 2022-2024 Anders Pistol. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -16,33 +16,12 @@ namespace traktor /*! Invoke method on pointer to object once then set pointer to null. * \ingroup Core */ -// \{ - -template < typename Type, typename P0 > -void invokeOnce(Type*& ref, void (Type::*M)(P0 p0), P0 p0) +template < typename Type, typename ... ArgumentTypes > +void invokeOnce(Type*& ref, void (Type::*M)(ArgumentTypes...), ArgumentTypes... args) { Type* ptr = Atomic::exchange< Type* >(ref, nullptr); if (ptr) - (ptr->*M)(p0); + (ptr->*M)(std::forward< ArgumentTypes >(args) ...); } -template < typename Type, typename P0, typename P1 > -void invokeOnce(Type*& ref, void (Type::*M)(P0 p0, P1 p1), P0 p0, P1 p1) -{ - Type* ptr = Atomic::exchange< Type* >(ref, nullptr); - if (ptr) - (ptr->*M)(p0, p1); } - -template < typename Type, typename P0, typename P1, typename P2 > -void invokeOnce(Type*& ref, void (Type::*M)(P0 p0, P1 p1, P2 p2), P0 p0, P1 p1, P2 p2) -{ - Type* ptr = Atomic::exchange< Type* >(ref, nullptr); - if (ptr) - (ptr->*M)(p0, p1, p2); -} - -// \} - -} - diff --git a/code/Core/Object.h b/code/Core/Object.h index d734ca1d54..ee3151d6cd 100644 --- a/code/Core/Object.h +++ b/code/Core/Object.h @@ -1,6 +1,6 @@ /* * TRAKTOR - * Copyright (c) 2022 Anders Pistol. + * Copyright (c) 2022-2024 Anders Pistol. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -57,7 +57,7 @@ class T_DLLCLASS Object : public RefCountImpl< ITypedObject > ; #endif - void* operator new (size_t size); + [[nodiscard]] void* operator new (size_t size); void* operator new (size_t size, void* memory); diff --git a/code/Core/Rtti/TypeInfo.cpp b/code/Core/Rtti/TypeInfo.cpp index 23acf93427..ff61efd6ce 100644 --- a/code/Core/Rtti/TypeInfo.cpp +++ b/code/Core/Rtti/TypeInfo.cpp @@ -76,7 +76,7 @@ void __registerTypeInfo(const TypeInfo* typeInfo) T_ASSERT(typeInfo2); const wchar_t* typeName2 = typeInfo2->getName(); - int32_t res = safeStringCompare(typeName2, typeName); + const int32_t res = safeStringCompare(typeName2, typeName); if (res > 0) break;