Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2021
- ** cpp_d16
- ** File description:
- ** Created by Benoit HOFFMAN,
- */
- #include <algorithm>
- #include "DomesticKoala.hpp"
- DomesticKoala::DomesticKoala(const DomesticKoala &toCopy)
- : _koalaAction(toCopy._koalaAction)
- {
- _actions = new std::vector<methodPointer_t>;
- for (methodPointer_t ptr : *toCopy._actions)
- this->_actions->push_back(ptr);
- for (unsigned char index : toCopy._iterator)
- this->_iterator.push_back(index);
- }
- DomesticKoala &DomesticKoala::operator=(const DomesticKoala &toCopy)
- {
- _actions->clear();
- _iterator.clear();
- _koalaAction = toCopy._koalaAction;
- _actions = new std::vector<methodPointer_t>;
- for (methodPointer_t ptr : *toCopy._actions)
- this->_actions->push_back(ptr);
- for (unsigned char index : toCopy._iterator)
- this->_iterator.push_back(index);
- return *this;
- }
- DomesticKoala::~DomesticKoala()
- {
- }
- void DomesticKoala::learnAction(unsigned char command, methodPointer_t ptr)
- {
- _actions->push_back(ptr);
- _iterator.push_back(command);
- }
- void DomesticKoala::unlearnAction(unsigned char command)
- {
- unsigned int pos = static_cast<unsigned int>(
- std::find(_iterator.begin(), _iterator.end(), command)
- - _iterator.begin());
- if (pos < _iterator.size()) {
- _iterator.erase(_iterator.begin() + pos);
- _actions->erase(_actions->begin() + pos);
- }
- }
- void DomesticKoala::doAction(unsigned char command, const std::string ¶m)
- {
- int pos = std::find(_iterator.begin(), _iterator.end(), command)
- - _iterator.begin();
- try {
- (_koalaAction.*_actions->at(pos))(param);
- }
- catch (const std::out_of_range &except) {
- }
- }
- void DomesticKoala::setKoalaAction(KoalaAction &koalaAction)
- {
- _koalaAction = koalaAction;
- _actions->clear();
- _iterator.clear();
- }
- DomesticKoala::DomesticKoala(KoalaAction &k) : _koalaAction(k),
- _actions(new std::vector<methodPointer_t>)
- {
- }
- const std::vector<methodPointer_t> *DomesticKoala::getActions() const
- {
- return _actions;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement