From 8ee8e55ff2b085762dad5ab41269448e7a91757f Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 13 Jun 2025 20:19:22 +0800 Subject: internal: shortened smart pointer types --- src/core/chatManager.hpp | 6 +++--- src/core/chatServer.hpp | 4 ++-- src/core/server.cpp | 2 +- src/core/server.hpp | 8 ++++---- src/core/session.cpp | 2 +- src/core/session.hpp | 10 +++++----- src/core/sessionManager.hpp | 16 ++++++++-------- 7 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src/core') diff --git a/src/core/chatManager.hpp b/src/core/chatManager.hpp index bd305de..d109424 100644 --- a/src/core/chatManager.hpp +++ b/src/core/chatManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "../misc/memory.hpp" #include #include #include @@ -14,7 +14,7 @@ class CChatManager { struct SMessage { std::string msg; std::string username; - std::optional> sender = std::nullopt; + std::optional> sender = std::nullopt; bool admin = false; }; void newMessage(const SMessage &msg); @@ -22,4 +22,4 @@ class CChatManager { std::vector getChat() const; }; -inline std::unique_ptr g_pChatManager; +inline UP g_pChatManager; diff --git a/src/core/chatServer.hpp b/src/core/chatServer.hpp index 00d2979..806030a 100644 --- a/src/core/chatServer.hpp +++ b/src/core/chatServer.hpp @@ -1,4 +1,4 @@ -#include +#include "../misc/memory.hpp" #include class CChatServer { @@ -17,4 +17,4 @@ class CChatServer { std::jthread m_sessionManagerThread; }; -inline std::unique_ptr g_pChatServer; +inline UP g_pChatServer; diff --git a/src/core/server.cpp b/src/core/server.cpp index a78c217..10eb4dd 100644 --- a/src/core/server.cpp +++ b/src/core/server.cpp @@ -1,7 +1,7 @@ #include "server.hpp" #include "../debug/log.hpp" #include -#include +#include "../misc/memory.hpp" #include CServer::CServer(uint16_t port) diff --git a/src/core/server.hpp b/src/core/server.hpp index c42192b..ea0e15b 100644 --- a/src/core/server.hpp +++ b/src/core/server.hpp @@ -1,19 +1,19 @@ #pragma once #include "../misc/FileDescriptor.hpp" -#include +#include "../misc/memory.hpp" #include class CServer { public: CServer(uint16_t port); ~CServer(); - std::shared_ptr getSocket() const; + SP getSocket() const; private: - std::shared_ptr m_sockfd; + SP m_sockfd; sockaddr_in m_addr; mutable std::mutex m_mutex; }; -inline std::unique_ptr g_pServer; +inline UP g_pServer; diff --git a/src/core/session.cpp b/src/core/session.cpp index 7b0b459..c8cceb0 100644 --- a/src/core/session.cpp +++ b/src/core/session.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include "../misc/memory.hpp" #include #include diff --git a/src/core/session.hpp b/src/core/session.hpp index ca951d1..9a953fc 100644 --- a/src/core/session.hpp +++ b/src/core/session.hpp @@ -4,7 +4,7 @@ #include "chatManager.hpp" #include "../debug/format.hpp" #include -#include +#include "../misc/memory.hpp" #include #include #include @@ -31,8 +31,8 @@ class CSession { const std::string &getIp() const; bool isAdmin() const; - std::unique_ptr read(); - std::unique_ptr read(const std::string &msg, bool bypassDeaf = false); + UP read(); + UP read(const std::string &msg, bool bypassDeaf = false); bool write(const std::string &msg); template bool write(std::format_string fmt, Args &&...args); @@ -57,8 +57,8 @@ class CSession { WRITE }; - std::weak_ptr self; - std::shared_ptr m_sockfd; + WP self; + SP m_sockfd; sockaddr_in m_addr; socklen_t m_addrLen = sizeof(m_addr); std::string m_name; diff --git a/src/core/sessionManager.hpp b/src/core/sessionManager.hpp index 71bcc5f..e84226c 100644 --- a/src/core/sessionManager.hpp +++ b/src/core/sessionManager.hpp @@ -1,9 +1,9 @@ #pragma once #include "../debug/format.hpp" +#include "../misc/memory.hpp" #include "chatManager.hpp" #include "session.hpp" -#include #include #include @@ -15,22 +15,22 @@ class CSessionManager { void newSession(); void run(); - void broadcast(const std::string &msg, std::optional> self = std::nullopt) const; // second param only specified when we want to exclude the sender - void kick(std::weak_ptr session, const bool kill = false, const std::string &reason = ""); + void broadcast(const std::string &msg, std::optional> self = std::nullopt) const; // second param only specified when we want to exclude the sender + void kick(WP session, const bool kill = false, const std::string &reason = ""); void addSession(const CSession &session); bool nameExists(const std::string &name); void shutdownSessions(); - std::shared_ptr getByName(const std::string &name) const; - std::shared_ptr getByIp(const std::string &ip) const; - std::vector> getSessions() const; + SP getByName(const std::string &name) const; + SP getByIp(const std::string &ip) const; + std::vector> getSessions() const; private: void broadcast(const CChatManager::SMessage &msg) const; - std::vector>> m_vSessions; + std::vector>> m_vSessions; friend class CChatManager; }; -inline std::shared_ptr g_pSessionManager; +inline SP g_pSessionManager; -- cgit v1.2.3