open_dir.hpp 747 B
Newer Older
Tommaso Tocci's avatar
Tommaso Tocci committed

#ifndef IFS_OPEN_DIR_HPP
#define IFS_OPEN_DIR_HPP

#include <string>
#include <vector>

#include <dirent.h>

#include <client/open_file_map.hpp>
Tommaso Tocci's avatar
Tommaso Tocci committed


class OpenDir: public OpenFile {
    private:

        class DirEntry {
            public:
                std::string name;
Tommaso Tocci's avatar
Tommaso Tocci committed
                FileType type;
Tommaso Tocci's avatar
Tommaso Tocci committed

Tommaso Tocci's avatar
Tommaso Tocci committed
                DirEntry(const std::string& name, const FileType type);
Tommaso Tocci's avatar
Tommaso Tocci committed
        };

        std::vector<DirEntry> entries;
        struct dirent dirent_;
        bool is_dirent_valid;

        void update_dirent(unsigned int pos);


    public:
        OpenDir(const std::string& path);
Tommaso Tocci's avatar
Tommaso Tocci committed
        void add(const std::string& name, const FileType& type);
Tommaso Tocci's avatar
Tommaso Tocci committed
        struct dirent * readdir();
Tommaso Tocci's avatar
Tommaso Tocci committed
        size_t size();
Tommaso Tocci's avatar
Tommaso Tocci committed
};


#endif //IFS_OPEN_DIR_HPP