#include "Folder.h" #include #include Folder::Folder(const std::string &filename) : File(filename, 0) { } unsigned long Folder::Size() const { unsigned long size = 0; for(const auto *file : files) size += file->Size(); return size; } void Folder::AddFile(const std::string &filename, unsigned long size) { // make sure the file doesn't already exist: if(std::find_if(files.begin(), files.end(), [&](const File *file) { return file->Filename() == filename; }) != files.end()) { std::cerr << "Folder \"" << this->Filename() << "\" already contains " << "the file \"" << filename << "\"." << std::endl; exit(-1); } // increment this folder's size total: this->size += size; // add the file: files.push_back(new File(filename, size)); } void Folder::AddFolder(const std::string &name) { if(std::find_if(files.begin(), files.end(), [&](const File *file) { return file->Filename() == name; }) != files.end()) { std::cout << "NOTE: Folder \"" << this->Filename() << "\" already contains " << "the subfolder \"" << name << "\"." << std::endl; // exit(-1); } files.push_back(new Folder(name)); } const std::vector& Folder::Files() const { return files; }