Skip to content

Commit

Permalink
Traktor: Some cleanup in Core classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 2, 2024
1 parent e49ead8 commit c64d2a9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 36 deletions.
6 changes: 3 additions & 3 deletions code/Core/Misc/AvlTree.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -60,7 +60,7 @@ class AvlTree
{
Node* node;

Iterator(Node* node_)
explicit iterator(Node* node_)
: node(node_)
{
}
Expand Down
13 changes: 8 additions & 5 deletions code/Core/Misc/ImmutableCheck.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/*
* 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
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#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:
Expand All @@ -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.");
}

Expand All @@ -37,6 +39,7 @@ class ImmutableCheck

}

#if 0
# define T_IMMUTABLE_CHECK(imm) T_ANONYMOUS_VAR(ImmutableCheck)(imm);
#else
# define T_IMMUTABLE_CHECK(imm)
Expand Down
29 changes: 4 additions & 25 deletions code/Core/Misc/InvokeOnce.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

// \}

}

4 changes: 2 additions & 2 deletions code/Core/Object.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion code/Core/Rtti/TypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c64d2a9

Please sign in to comment.