#include "Box.h" Box::Box(const std::string& name) : name(name), items(), subboxes() {} Box::Box(const std::string& name, const std::deque& items, const std::deque subboxes) : name(name), items(items), subboxes(subboxes) {} std::string& Box::get_name() { return name; } void Box::pushItem(std::string item) { items.push_back(item); } void Box::pushSubbox(Box* subbox) { subboxes.push_back(subbox); } void Box::removeUselessSubBoxes() { for (auto i = subboxes.begin(), end = subboxes.end(); i != end; ++i) { (*i)->removeUselessSubBoxes(); if ((*i)->items.empty() && (*i)->subboxes.size() < 2) { if ((*i)->subboxes.empty()) { subboxes.erase(i); // затова държа самия итератор continue; } *i = (*i)->subboxes[0]; } } } std::ostream& Box::printWithInd(std::ostream& ostr, std::string indent) { ostr << indent << name << std::endl; for (std::string& i : items) ostr << indent << " + " << i << std::endl; indent += " "; for (Box* sb : subboxes) sb->printWithInd(ostr, indent); return ostr; } std::ostream& Box::print(std::ostream& ostr) { return printWithInd(ostr, ""); }