From 1c6c9be6ec6d712df4d663476328815bf671c78f Mon Sep 17 00:00:00 2001 From: aortigos Date: Fri, 8 May 2026 17:24:06 +0200 Subject: [PATCH] Channel class init --- Channel/Channel.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ Channel/Channel.hpp | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 Channel/Channel.cpp create mode 100644 Channel/Channel.hpp diff --git a/Channel/Channel.cpp b/Channel/Channel.cpp new file mode 100644 index 0000000..8a9912f --- /dev/null +++ b/Channel/Channel.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Channel.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); } diff --git a/Channel/Channel.hpp b/Channel/Channel.hpp new file mode 100644 index 0000000..2fd1618 --- /dev/null +++ b/Channel/Channel.hpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Channel.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +# include + +class Channel +{ + private: + std::string name_; + std::set members_; + std::set 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 -- 2.49.1