Brain.cpp
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   Brain.cpp                                          :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: gychoi <gychoi@student.42seoul.kr>         +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/08/16 19:34:16 by gychoi            #+#    #+#             */
 9  /*   Updated: 2023/08/17 21:09:50 by gychoi           ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include "Brain.hpp"
14  #include <iostream>
15  
16  /******************************
17   * Constructor and Destructor *
18   ******************************/
19  
20  Brain::Brain(void)
21  {
22  	std::cout << "[Brain] : Default constructor called" << std::endl;
23  }
24  
25  Brain::~Brain(void)
26  {
27  	std::cout << "[Brain] : Destructor called" << std::endl;
28  }
29  
30  Brain::Brain(Brain const& target)
31  {
32  	std::cout << "[Brain] : Copy constructor called" << std::endl;
33  	if (this != &target)
34  		*this = target;
35  }
36  
37  Brain&	Brain::operator=(Brain const& target)
38  {
39  	std::cout << "[Brain] : Copy assignment operatr called" << std::endl;
40  	if (this != &target)
41  		for (std::size_t i = 0; i < 100; i++)
42  			this->ideas[i] = target.ideas[i];
43  	return *this;
44  }
45  
46  /******************************
47   *      Getter  function      *
48   ******************************/
49  
50  std::string	Brain::getIdea(std::size_t idx)
51  {
52  	if (idx > 100) {
53  		std::cout << "[Brain] : Invalid ideas index" << std::endl;
54  		return std::string();
55  	}
56  	return this->ideas[idx];
57  }
58  
59  void	Brain::setIdea(std::size_t idx, std::string const& idea)
60  {
61  	if (idx > 100) {
62  		std::cout << "[Brain] : Invalid ideas index" << std::endl;
63  		return ;
64  	}
65  	this->ideas[idx] = idea;
66  }