removing useless C++ classes
This commit is contained in:
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Juliet
|
|
||||||
{
|
|
||||||
class NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NonCopyable() = default;
|
|
||||||
virtual ~NonCopyable() = default;
|
|
||||||
|
|
||||||
NonCopyable(const NonCopyable&) = delete;
|
|
||||||
const NonCopyable& operator=(const NonCopyable&) = delete;
|
|
||||||
};
|
|
||||||
} // namespace Juliet
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Juliet
|
|
||||||
{
|
|
||||||
class NonMovable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NonMovable() = default;
|
|
||||||
virtual ~NonMovable() = default;
|
|
||||||
|
|
||||||
NonMovable(const NonMovable&&) = delete;
|
|
||||||
const NonMovable& operator=(const NonMovable&&) = delete;
|
|
||||||
};
|
|
||||||
} // namespace Juliet
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Core/Common/NonCopyable.h>
|
|
||||||
#include <Core/Common/NonMovable.h>
|
|
||||||
#include <Core/Common/NonNullPtr.h>
|
|
||||||
|
|
||||||
namespace Juliet
|
|
||||||
{
|
|
||||||
// Two usages : Inherit from Singleton or use the static methods to register to it when you want.
|
|
||||||
// 1)
|
|
||||||
// class IThing {};
|
|
||||||
// class Thing : public Singleton::AutoRegister<IThing> {};
|
|
||||||
template <typename Type>
|
|
||||||
class Singleton final : public NonMovable, public NonCopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static void Register(NonNullPtr<Type> type);
|
|
||||||
static void Unregister(NonNullPtr<Type> type);
|
|
||||||
static Type* Get();
|
|
||||||
|
|
||||||
class AutoRegister : public Type
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AutoRegister();
|
|
||||||
virtual ~AutoRegister();
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Type* sInstance;
|
|
||||||
static bool sIsRegistered;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
bool Singleton<Type>::sIsRegistered = false;
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
Type* Singleton<Type>::sInstance = nullptr;
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
void Singleton<Type>::Register(NonNullPtr<Type> type)
|
|
||||||
{
|
|
||||||
Assert(!Get() && "Singleton is already registered. Make sure to only register it once");
|
|
||||||
sInstance = type.Get();
|
|
||||||
sIsRegistered = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
void Singleton<Type>::Unregister(NonNullPtr<Type> type)
|
|
||||||
{
|
|
||||||
Assert(sIsRegistered && "Trying to unregister a singleton that is not registered");
|
|
||||||
Assert(sInstance == type &&
|
|
||||||
"Trying to unregister an instance that is different from the one currently registered");
|
|
||||||
|
|
||||||
sInstance = nullptr;
|
|
||||||
sIsRegistered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
Type* Singleton<Type>::Get()
|
|
||||||
{
|
|
||||||
if (sIsRegistered)
|
|
||||||
{
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
Singleton<Type>::AutoRegister::AutoRegister()
|
|
||||||
{
|
|
||||||
Singleton<Type>::Register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Type>
|
|
||||||
Singleton<Type>::AutoRegister::~AutoRegister()
|
|
||||||
{
|
|
||||||
Singleton<Type>::Unregister(this);
|
|
||||||
}
|
|
||||||
} // namespace Juliet
|
|
||||||
@@ -1,19 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Core/Common/NonCopyable.h>
|
|
||||||
#include <Core/Networking/SocketHandle.h>
|
#include <Core/Networking/SocketHandle.h>
|
||||||
|
|
||||||
namespace Juliet
|
namespace Juliet
|
||||||
{
|
{
|
||||||
class Socket : NonCopyable
|
class Socket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~Socket() override;
|
virtual ~Socket();
|
||||||
|
|
||||||
Socket(Socket&& other) noexcept;
|
Socket(Socket&& other) noexcept;
|
||||||
Socket& operator=(Socket&& socket) noexcept;
|
Socket& operator=(Socket&& socket) noexcept;
|
||||||
|
|
||||||
Socket(const Socket&) = delete;
|
Socket(const Socket&) = delete;
|
||||||
Socket& operator=(const Socket&) = delete;
|
Socket& operator=(const Socket&) = delete;
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user