open_file_map.hpp 847 B
Newer Older
Marc Vef's avatar
Marc Vef committed

#ifndef IFS_OPEN_FILE_MAP_HPP
#define IFS_OPEN_FILE_MAP_HPP

#include <preload/preload.hpp>
Marc Vef's avatar
Marc Vef committed

class OpenFile {
private:
Marc Vef's avatar
Marc Vef committed
    int fd_;
Marc Vef's avatar
Marc Vef committed

public:
    OpenFile(const std::string& path, const bool append_flag);
Marc Vef's avatar
Marc Vef committed

    // getter/setter
    std::string path() const;
Marc Vef's avatar
Marc Vef committed

    void path(const std::string& path_);
Marc Vef's avatar
Marc Vef committed

    int fd() const;

    void fd(int fd_);
    bool append_flag() const;

    void append_flag(bool append_flag);

Marc Vef's avatar
Marc Vef committed
};


class OpenFileMap {

private:
    std::map<int, std::shared_ptr<OpenFile>> files_;
Marc Vef's avatar
Marc Vef committed
    std::mutex files_mutex_;


public:
    OpenFileMap();

    OpenFile* get(int fd);
    bool exist(const int fd);
    int add(std::string path, const bool append);
Marc Vef's avatar
Marc Vef committed
    bool remove(const int fd);

};


#endif //IFS_OPEN_FILE_MAP_HPP