#include <iostream>
Brain::Brain()
+ : m_is_full(0)
+ , m_index(0)
{
std::cout << "Brain default cstr\n";
}
{
if (this == &other)
return (*this);
- for (size_t i(0); i < CAPACITY; ++i)
- ideas[i] = other.ideas[i];
+ m_is_full = other.m_is_full;
+ for (m_index = 0;
+ (m_is_full && m_index < CAPACITY) || (m_index < other.m_index);
+ ++m_index)
+ m_ideas[m_index] = other.m_ideas[m_index];
+ m_index = other.m_index;
return (*this);
}
+
+void Brain::addIdea(std::string idea)
+{
+ ++m_index;
+ if (m_index == CAPACITY)
+ m_is_full = 1;
+ m_index %= CAPACITY;
+ m_ideas[m_index] = idea;
+}
+
+void Brain::listIdeas() const
+{
+ size_t i;
+
+ if (m_is_full)
+ i = 0;
+ else
+ i = m_index + 1;
+ for (; i != m_index; i = (i + 1) % CAPACITY)
+ std::cout << m_ideas[i] << '\n';
+}
private:
static const size_t CAPACITY = 100;
- std::string ideas[CAPACITY];
+ bool m_is_full;
+ size_t m_index;
+ std::string m_ideas[CAPACITY];
public:
Brain();
~Brain();
Brain &operator=(const Brain &other);
+
+ void addIdea(std::string idea);
+ void listIdeas() const;
};
#endif // BRAIN_H