🔨」 fix: cpp be like

This commit is contained in:
2025-05-13 10:14:41 +02:00
parent b234a23101
commit 773e7855b0
3 changed files with 23 additions and 7 deletions

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;

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);
if (it != _res.end())
auto it = std::find_if(_res.begin(), _res.end(), CompareId(id));
if (it != _res.end()) {
delete (*it);
_res.erase(it);
}
// TODO throw or not - to see
}