StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
clonable.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <concepts>
23#include <memory>
24
29namespace StormByte {
35 template<typename SmartPointer, typename T>
37 std::same_as<SmartPointer, std::shared_ptr<T>> ||
38 std::same_as<SmartPointer, std::unique_ptr<T>>;
39
46 template<class T, typename SmartPointer = std::shared_ptr<T>>
48 public:
49 using PointerType = SmartPointer;
50
58 template<class Target, typename... Args>
59 static PointerType MakePointer(Args&&... args);
60
64 constexpr Clonable() = default;
65
69 constexpr Clonable(const Clonable&) = default;
70
74 constexpr Clonable(Clonable&&) noexcept = default;
75
79 constexpr Clonable& operator=(const Clonable&) = default;
80
84 constexpr Clonable& operator=(Clonable&&) noexcept = default;
85
89 virtual constexpr ~Clonable() noexcept = default;
90
95 virtual PointerType Clone() const = 0;
96
101 virtual PointerType Move() = 0;
102 };
103}
104
105#include <StormByte/clonable.txx>
Polymorphic clone/move into a smart pointer of type T.
Definition clonable.hxx:47
static PointerType MakePointer(Args &&... args)
Allocates Target and returns it as PointerType.
constexpr Clonable(const Clonable &)=default
Copy constructor.
virtual PointerType Clone() const =0
Deep copy into a new PointerType.
virtual PointerType Move()=0
Moves this object into a new PointerType.
constexpr Clonable()=default
Default constructor.
constexpr Clonable(Clonable &&) noexcept=default
Move constructor.
SmartPointer PointerType
SmartPointer alias.
Definition clonable.hxx:49
true when SmartPointer is shared_ptr<T> or unique_ptr<T>.
Definition clonable.hxx:36
Root namespace of the StormByte suite.