From 5455e6ae997b6f363cf56e9e469e5e3123f05015 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 13 Sep 2024 14:29:08 +0100 Subject: [PATCH] refactor: move class EnableNonOwnerReferences into separate header file --- .../utility/enable_non_owner_references.h | 41 +++++++++++++++++++ .../bedrock/core/utility/non_owner_pointer.h | 22 +--------- 2 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 include/bedrock/core/utility/enable_non_owner_references.h diff --git a/include/bedrock/core/utility/enable_non_owner_references.h b/include/bedrock/core/utility/enable_non_owner_references.h new file mode 100644 index 000000000..13fefe53f --- /dev/null +++ b/include/bedrock/core/utility/enable_non_owner_references.h @@ -0,0 +1,41 @@ +// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +namespace Bedrock { + +class EnableNonOwnerReferences { +public: + struct ControlBlock { + EnableNonOwnerReferences *ptr; + }; + + EnableNonOwnerReferences() + { + control_block_ = std::make_shared(); + control_block_->ptr = this; + } + virtual ~EnableNonOwnerReferences() = default; + +private: + template + friend class NonOwnerPointer; + + std::shared_ptr control_block_; +}; +} // namespace Bedrock diff --git a/include/bedrock/core/utility/non_owner_pointer.h b/include/bedrock/core/utility/non_owner_pointer.h index 596148c59..95fc7462d 100644 --- a/include/bedrock/core/utility/non_owner_pointer.h +++ b/include/bedrock/core/utility/non_owner_pointer.h @@ -17,27 +17,9 @@ #include #include -namespace Bedrock { - -class EnableNonOwnerReferences { -public: - struct ControlBlock { - EnableNonOwnerReferences *ptr; - }; +#include "bedrock/core/utility/enable_non_owner_references.h" - EnableNonOwnerReferences() - { - control_block_ = std::make_shared(); - control_block_->ptr = this; - } - virtual ~EnableNonOwnerReferences() = default; - -private: - template - friend class NonOwnerPointer; - - std::shared_ptr control_block_; -}; +namespace Bedrock { template class NonOwnerPointer {