mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「🔨」 fix: cpp be like
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
|
/* 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();
|
struct pollfd getFileDescriptor();
|
||||||
|
|
||||||
virtual clientResType type(void);
|
virtual clientResType type(void);
|
||||||
|
int getId(void) const { return _res_id; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct pollfd _fd;
|
struct pollfd _fd;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/12 17:13:39 by adjoly #+# #+# */
|
/* 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 webserv {
|
||||||
namespace server {
|
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 {
|
class ResourceManager {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -37,7 +49,7 @@ class ResourceManager {
|
|||||||
* @throw std::out_of_range If the resource does not exist
|
* @throw std::out_of_range If the resource does not exist
|
||||||
*/
|
*/
|
||||||
static AClientResource *get(int id) {
|
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())
|
if (it != _res.end())
|
||||||
return (*it);
|
return (*it);
|
||||||
@ -59,10 +71,12 @@ class ResourceManager {
|
|||||||
* @param The id of the resource to remove
|
* @param The id of the resource to remove
|
||||||
*/
|
*/
|
||||||
static void remove(int id) {
|
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);
|
delete (*it);
|
||||||
|
_res.erase(it);
|
||||||
|
}
|
||||||
// TODO throw or not - to see
|
// TODO throw or not - to see
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
/* 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 <tomlpp.hpp>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <webserv.hpp>
|
#include <webserv.hpp>
|
||||||
|
#include <server/ResourceManager.hpp>
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
Logger *_log = not_nullptr;
|
Logger *_log = not_nullptr;
|
||||||
|
Reference in New Issue
Block a user