「🔨」 fix: cpp be like

This commit is contained in:
KeyZox committed 2025-05-13 10:14:41 +02:00
1 parent b234a23101
commit 773e7855b0
3 files changed
+22 -6

No files matched your search

+2 -1
View File
@@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
/* Updated: 2025/05/13 09:56:02 by adjoly ### ########.fr */
/* Updated: 2025/05/13 10:11:34 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,6 +37,7 @@ public:
struct pollfd getFileDescriptor();
virtual clientResType type(void);
int getId(void) const { return _res_id; }
protected:
struct pollfd _fd;
+18 -4
View File
@@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/12 17:13:39 by adjoly #+# #+# */
/* Updated: 2025/05/13 09:55:45 by adjoly ### ########.fr */
/* Updated: 2025/05/13 10:14:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,6 +25,18 @@
namespace webserv {
namespace server {
class CompareId {
public:
CompareId(int id) : _id(id) {}
bool operator()(const webserv::server::AClientResource *resource) const {
return resource->getId() == _id;
}
private:
int _id;
};
class ResourceManager {
public:
/**
@@ -37,7 +49,7 @@ class ResourceManager {
* @throw std::out_of_range If the resource does not exist
*/
static AClientResource *get(int id) {
auto it = std::find(_res.begin(), _res.end(), id);
auto it = std::find_if(_res.begin(), _res.end(), CompareId(id));
if (it != _res.end())
return (*it);
@@ -59,10 +71,12 @@ class ResourceManager {
* @param The id of the resource to remove
*/
static void remove(int id) {
auto it = std::find(_res.begin(), _res.end(), id);
auto it = std::find_if(_res.begin(), _res.end(), CompareId(id));
if (it != _res.end())
if (it != _res.end()) {
delete (*it);
_res.erase(it);
}
// TODO throw or not - to see
}
+2 -1
View File
@@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
/* Updated: 2025/05/08 12:00:41 by adjoly ### ########.fr */
/* Updated: 2025/05/13 10:07:53 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,6 +24,7 @@
#include <tomlpp.hpp>
#include <unistd.h>
#include <webserv.hpp>
#include <server/ResourceManager.hpp>
namespace webserv {
Logger *_log = not_nullptr;