הערה (קובץ קוד)
קובץ זה הוא קובץ קוד מסוג C.
#pragma once
#include "File.h"
#include <list>
#include <string>
#include <vector>
#include <memory>
/**
* @class Directory
* A subtype of File, it provides a way to organize files into containers.
*/
class Directory : public File {
public:
/**
* Creates a new empty folder.
* @param name the name of the folder.
* @param parent the folder that is the parent of this one. (if root then nullptr)
*/
Directory(const std::string& name, Directory* parent);
virtual ~Directory() = default;
using File::operator[];
/**
* This operator returns the file that is in the given relative path from this file.
* @param path The relative path to search at.
* @return A reference to the file in the relative path.
*/
virtual File& operator[](std::list<std::string> path) override;
/**
* This operator returns the file that is in the given relative path from this file.
* @param path The relative path to search at.
* @return A reference to the file in the relative path.
*/
virtual const File& operator[](std::list<std::string> path) const override;
/**
* Creates a CreateAction of a fitting type to the inputted user data.
* @param request The data to send to create the action.
* @return The action created.
*/
virtual std::unique_ptr<Action> CreateCreateAction(WriteRequest& request);
/**
* Creates a DeleteAction of a fitting type to the inputted user data.
* @param request The data to send to create the action.
* @return The action created.
*/
virtual std::unique_ptr<Action> CreateDeleteAction(WriteRequest& request);
/**
* Creates a ReadAction of a fitting type to the inputted user data.
* @param request The data to send to create the action.
* @return The action created.
*/
virtual std::unique_ptr<Action> CreateReadAction(ReadRequest& request) const override;
/**
* Creates a WriteAction of a fitting type to the inputted user data.
* @param request The data to send to create the action.
* @return The action created.
*/
virtual std::unique_ptr<Action> CreateWriteAction(WriteRequest& request) override;
/**
* Creates a SearchAction of a fitting type to the inputted user data.
* @param request The data to send to create the action.
* @return The action created.
*/
virtual std::unique_ptr<Action> CreateSearchAction(SearchRequest& request) const override;
/**
* Checks if the file can be deleted.
* @return if it's a folder and empty, then true, if it's a file than true always.
*/
virtual bool canBeDeleted() const override;
/**
* Adds a file to this folder.
* @param file a shared_ptr of the file to add.
*/
void addFile(std::shared_ptr<File> file);
/**
* Removes a file with a given name from the folder.
* @param name the file to remove.
*/
void removeFile(const std::string& name);
private:
std::list<std::shared_ptr<File>> files;
// returns the files as a vector instead of a list for matching the Utilities class provided.
std::vector<std::shared_ptr<File>> getFilesAsVector() const;
// finds out if a file is in the folder and returns a pointer to it.
std::shared_ptr<File> find(const std::string& name) const;
};