Compare commits

...

2 Commits

2 changed files with 102 additions and 0 deletions

55
Channel/Channel.cpp Normal file
View File

@@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Channel.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/08 16:41:40 by aortigos #+# #+# */
/* Updated: 2026/05/08 16:41:40 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Channel.hpp"
//////////////////
// Constructors //
//////////////////
Channel::Channel() { /* std::cout << "Channel default constructor called" << std::endl; */}
Channel::~Channel() { /* std::cout << "Channel destructor called" << std::endl; */}
Channel::Channel(const Channel &other)
{
*this = other;
// std::cout << "Channel copy constructor called" << std::endl;
}
Channel& Channel::operator=(const Channel &other)
{
if (this != &other)
{
name_ = other.name_;
members_ = other.members_;
operators_ = other.operators_;
}
// std::cout << "Channel copy assignment operator called" << std::endl;
return (*this);
}
// Constructor with name
Channel::Channel(std::string name) : name_(name) { /* std::cout << "Channel with name constructor called" << std::endl; */ }
// Members
void Channel::addMember(int fd) { this->members_.insert(fd); }
void Channel::removeMember(int fd) { this->members_.erase(fd); }
bool Channel::hasMember(int fd) const { return (this->members_.count(fd) > 0); }
// Operators
void Channel::addOperator(int fd) { this->operators_.insert(fd); }
void Channel::removeOperator(int fd) { this->operators_.erase(fd); }
bool Channel::hasOperator(int fd) const { return (this->operators_.count(fd) > 0); }

47
Channel/Channel.hpp Normal file
View File

@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Channel.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/08 16:41:40 by aortigos #+# #+# */
/* Updated: 2026/05/08 16:41:40 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CHANNEL_HPP
# define CHANNEL_HPP
# include <iostream>
# include <set>
class Channel
{
private:
std::string name_;
std::set<int> members_;
std::set<int> operators_;
public:
Channel();
Channel(std::string name);
Channel(const Channel &other);
Channel& operator=(const Channel &other);
~Channel();
// Users
void addMember(int fd);
void removeMember(int fd);
bool hasMember(int fd) const;
// Operators
void addOperator(int fd);
void removeOperator(int fd);
bool hasOperator(int fd) const;
};
#endif