summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-06-13 20:19:22 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-06-13 20:23:03 +0800
commit8ee8e55ff2b085762dad5ab41269448e7a91757f (patch)
treeec1ed6b4944ca1fc4f1adbf67a255912e23a516c /src/core
parent23492ea6f58762914a91516be6a9c180969178a2 (diff)
internal: shortened smart pointer types
Diffstat (limited to 'src/core')
-rw-r--r--src/core/chatManager.hpp6
-rw-r--r--src/core/chatServer.hpp4
-rw-r--r--src/core/server.cpp2
-rw-r--r--src/core/server.hpp8
-rw-r--r--src/core/session.cpp2
-rw-r--r--src/core/session.hpp10
-rw-r--r--src/core/sessionManager.hpp16
7 files changed, 24 insertions, 24 deletions
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 <memory>
+#include "../misc/memory.hpp"
#include <optional>
#include <string>
#include <vector>
@@ -14,7 +14,7 @@ class CChatManager {
struct SMessage {
std::string msg;
std::string username;
- std::optional<std::weak_ptr<CSession>> sender = std::nullopt;
+ std::optional<WP<CSession>> sender = std::nullopt;
bool admin = false;
};
void newMessage(const SMessage &msg);
@@ -22,4 +22,4 @@ class CChatManager {
std::vector<SMessage> getChat() const;
};
-inline std::unique_ptr<CChatManager> g_pChatManager;
+inline UP<CChatManager> 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 <memory>
+#include "../misc/memory.hpp"
#include <thread>
class CChatServer {
@@ -17,4 +17,4 @@ class CChatServer {
std::jthread m_sessionManagerThread;
};
-inline std::unique_ptr<CChatServer> g_pChatServer;
+inline UP<CChatServer> 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 <cstring>
-#include <memory>
+#include "../misc/memory.hpp"
#include <sys/socket.h>
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 <memory>
+#include "../misc/memory.hpp"
#include <netinet/in.h>
class CServer {
public:
CServer(uint16_t port);
~CServer();
- std::shared_ptr<CFileDescriptor> getSocket() const;
+ SP<CFileDescriptor> getSocket() const;
private:
- std::shared_ptr<CFileDescriptor> m_sockfd;
+ SP<CFileDescriptor> m_sockfd;
sockaddr_in m_addr;
mutable std::mutex m_mutex;
};
-inline std::unique_ptr<CServer> g_pServer;
+inline UP<CServer> 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 <arpa/inet.h>
#include <cerrno>
#include <cstring>
-#include <memory>
+#include "../misc/memory.hpp"
#include <optional>
#include <sys/socket.h>
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 <format>
-#include <memory>
+#include "../misc/memory.hpp"
#include <netinet/in.h>
#include <optional>
#include <string>
@@ -31,8 +31,8 @@ class CSession {
const std::string &getIp() const;
bool isAdmin() const;
- std::unique_ptr<SRecvData> read();
- std::unique_ptr<SRecvData> read(const std::string &msg, bool bypassDeaf = false);
+ UP<SRecvData> read();
+ UP<SRecvData> read(const std::string &msg, bool bypassDeaf = false);
bool write(const std::string &msg);
template <typename... Args>
bool write(std::format_string<Args...> fmt, Args &&...args);
@@ -57,8 +57,8 @@ class CSession {
WRITE
};
- std::weak_ptr<CSession> self;
- std::shared_ptr<CFileDescriptor> m_sockfd;
+ WP<CSession> self;
+ SP<CFileDescriptor> 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 <memory>
#include <thread>
#include <vector>
@@ -15,22 +15,22 @@ class CSessionManager {
void newSession();
void run();
- void broadcast(const std::string &msg, std::optional<std::weak_ptr<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender
- void kick(std::weak_ptr<CSession> session, const bool kill = false, const std::string &reason = "");
+ void broadcast(const std::string &msg, std::optional<WP<CSession>> self = std::nullopt) const; // second param only specified when we want to exclude the sender
+ void kick(WP<CSession> 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<CSession> getByName(const std::string &name) const;
- std::shared_ptr<CSession> getByIp(const std::string &ip) const;
- std::vector<std::shared_ptr<CSession>> getSessions() const;
+ SP<CSession> getByName(const std::string &name) const;
+ SP<CSession> getByIp(const std::string &ip) const;
+ std::vector<SP<CSession>> getSessions() const;
private:
void broadcast(const CChatManager::SMessage &msg) const;
- std::vector<std::pair<std::jthread, std::shared_ptr<CSession>>> m_vSessions;
+ std::vector<std::pair<std::jthread, SP<CSession>>> m_vSessions;
friend class CChatManager;
};
-inline std::shared_ptr<CSessionManager> g_pSessionManager;
+inline SP<CSessionManager> g_pSessionManager;