חזור לתיקייה: files

File

חיפוש בתיקיה
Ctrl K
לחץ כאן או הקש Ctrl K כדי לחפש בכל התיקיה

    File

    02340124

    מבוא לתכנות מערכות

    רשימות הרצאה לקריאה בשבת

    File

    הופק מתוך תקיית התואר של שקד

    uni-folder.vercel.app

    file.h

    הערה (קובץ קוד)

    קובץ זה הוא קובץ קוד מסוג C.

    #pragma once
    
    #include "Action.h"
    
    #include <list>
    #include <string>
    #include <memory>
    #include <vector>
    
    // The data to send to create*Action methods to create the correct actions.
    // ReadRequest for ReadAction
    struct ReadRequest {
        const std::string hostPath;
        const bool isCout;
    };
    
    // WriteRequest for WriteAction, DeleteAction, CreateAction
    struct WriteRequest {
        const std::string name;             // don't care in Write
        const std::string type;             // don't care in Delete and Write
        std::vector<std::string> linesVector;    // don't care in Delete
    };
    
    // SearchRequest for SearchAction
    struct SearchRequest {
        const std::string searchTerm;
        const bool comesFromCreateSearchAction;
        std::vector<std::string>& printingVector; // don't care in file search
        const std::string pathFromLocation;       // don't care in file search
    };
    
    class Directory;
    
    /**
     * @class File
     * A base class for various file types and managing files.
     * It can't be built on its own.
     */
    class File {
    public:
        virtual ~File() = default;
    
        /**
         * @return The name of the file in the system.
         */
        std::string getName() const;
    
        /**
         * @return The parent directory of the file in the system. (the folder the file is in)
         */
        Directory* getParent() const;
    
        /**
         * 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.
         */
        File& operator[](const std::vector<std::string>& path);
    
        /**
         * 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.
         */
        const File& operator[](const std::vector<std::string>& path) const;
    
        /**
         * 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) = 0;
    
        /**
         * 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 = 0;
    
        /**
         * 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 = 0;
    
        /**
         * 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) = 0;
    
        /**
         * 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 = 0;
    
        /**
         * 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;
    
    protected:
        /**
         * Creates a File - used only in children creations.
         * @param name The name of the file.
         * @param parent A reference to the file's parent - the folder that it's in.
         */
        File(const std::string& name, Directory* parent);
    
    private:
        const std::string name;
        Directory* const parent;
    };