Verified Commit 5e96048b authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

use strongly typed enum.

parent 67f1dc0a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@ class OpenDir: public OpenFile {
        class DirEntry {
            public:
                std::string name;
                file_type type;
                FileType type;

                DirEntry(const std::string& name, const file_type type);
                DirEntry(const std::string& name, const FileType type);
        };

        std::vector<DirEntry> entries;
@@ -30,7 +30,7 @@ class OpenDir: public OpenFile {

    public:
        OpenDir(const std::string& path);
        void add(const std::string& name, const file_type& type);
        void add(const std::string& name, const FileType& type);
        struct dirent * readdir();
};

+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ enum class OpenFile_flags {
    flag_count // this is purely used as a size variable of this enum class
};

enum file_type {
enum class FileType {
    regular,
    directory
};
+3 −3
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
#include <cassert>


OpenDir::DirEntry::DirEntry(const std::string& name, const file_type type):
OpenDir::DirEntry::DirEntry(const std::string& name, const FileType type):
    name(name), type(type) {
}

@@ -15,7 +15,7 @@ OpenDir::OpenDir(const std::string& path): OpenFile(path, 0){
}


void OpenDir::add(const std::string& name, const file_type& type){
void OpenDir::add(const std::string& name, const FileType& type){
    entries.push_back(DirEntry(name, type));
}

@@ -24,7 +24,7 @@ void OpenDir::update_dirent(unsigned int pos){
    std::string entry_absolute_path = path_ + "/" + entry.name;
    dirent_.d_ino = std::hash<std::string>()(entry_absolute_path);
    dirent_.d_off = pos_;
    dirent_.d_type = ((entry.type == regular)? DT_REG : DT_DIR);
    dirent_.d_type = ((entry.type == FileType::regular)? DT_REG : DT_DIR);
    assert(sizeof(dirent_.d_name) >= strlen(entry.name.c_str()));
    strcpy(dirent_.d_name, entry.name.c_str());
    dirent_.d_reclen = sizeof(dirent_);
+1 −1
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ void rpc_send_get_dirents(OpenDir& open_dir){

        for(unsigned int i = 0; i < out.dirents_size; i++){

            file_type ftype = (*bool_ptr)? directory : regular;
            FileType ftype = (*bool_ptr)? FileType::directory : FileType::regular;
            bool_ptr++;

            //Check that we are not outside the recv_buff for this specific host