open_file_map.hpp 855 B
Newer Older
Marc Vef's avatar
Marc Vef committed
//
// Created by evie on 8/25/17.
//

#ifndef IFS_OPEN_FILE_MAP_HPP
#define IFS_OPEN_FILE_MAP_HPP

#include <map>
#include <mutex>

class OpenFile {
private:
    const char* path_;
Marc Vef's avatar
Marc Vef committed
    int fd_;
Marc Vef's avatar
Marc Vef committed

public:
    OpenFile(const char* path, const bool append_flag);
Marc Vef's avatar
Marc Vef committed

    // getter/setter
    const char* path() const;

    void path(const char* path_);

    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:
Marc Vef's avatar
Marc Vef committed
    std::map<int, 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(const char* path, const bool append);
Marc Vef's avatar
Marc Vef committed
    bool remove(const int fd);

};


#endif //IFS_OPEN_FILE_MAP_HPP