Commit 41c82090 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

fs: IDirectory: Make files() and dirs() methods const

parent 9c5c1f2c
......@@ -38,9 +38,9 @@ namespace fs
// Returns the absolute path to this directory
virtual const std::string& path() const = 0;
/// Returns a list of absolute files path
virtual const std::vector<std::string>& files() = 0;
virtual const std::vector<std::string>& files() const = 0;
/// Returns a list of absolute path to this folder subdirectories
virtual const std::vector<std::string>& dirs() = 0;
virtual const std::vector<std::string>& dirs() const = 0;
virtual std::shared_ptr<IDevice> device() const = 0;
};
}
......@@ -52,14 +52,14 @@ const std::string&Directory::path() const
return m_path;
}
const std::vector<std::string>& Directory::files()
const std::vector<std::string>& Directory::files() const
{
if ( m_dirs.size() == 0 && m_files.size() == 0 )
read();
return m_files;
}
const std::vector<std::string>& Directory::dirs()
const std::vector<std::string>& Directory::dirs() const
{
if ( m_dirs.size() == 0 && m_files.size() == 0 )
read();
......@@ -87,7 +87,7 @@ std::string Directory::toAbsolute( const std::string& path )
return std::string{ abs };
}
void Directory::read()
void Directory::read() const
{
std::unique_ptr<DIR, int(*)(DIR*)> dir( opendir( m_path.c_str() ), closedir );
if ( dir == nullptr )
......
......@@ -34,20 +34,20 @@ class Directory : public IDirectory
public:
explicit Directory( const std::string& path );
virtual const std::string& path() const override;
virtual const std::vector<std::string>& files() override;
virtual const std::vector<std::string>& dirs() override;
virtual const std::vector<std::string>& files() const override;
virtual const std::vector<std::string>& dirs() const override;
virtual std::shared_ptr<IDevice> device() const override;
private:
static std::string toAbsolute( const std::string& path );
private:
void read();
void read() const;
private:
std::string m_path;
std::vector<std::string> m_files;
std::vector<std::string> m_dirs;
mutable std::vector<std::string> m_files;
mutable std::vector<std::string> m_dirs;
mutable Cache<std::shared_ptr<IDevice>> m_device;
};
......
......@@ -110,7 +110,7 @@ public:
return m_path;
}
virtual const std::vector<std::string>& files() override
virtual const std::vector<std::string>& files() const override
{
if ( m_filePathes.size() == 0 )
{
......@@ -120,7 +120,7 @@ public:
return m_filePathes;
}
virtual const std::vector<std::string>& dirs() override
virtual const std::vector<std::string>& dirs() const override
{
if ( m_dirPathes.size() == 0 )
{
......@@ -265,8 +265,8 @@ private:
std::string m_path;
std::unordered_map<std::string, std::shared_ptr<File>> m_files;
std::unordered_map<std::string, std::shared_ptr<Directory>> m_dirs;
std::vector<std::string> m_filePathes;
std::vector<std::string> m_dirPathes;
mutable std::vector<std::string> m_filePathes;
mutable std::vector<std::string> m_dirPathes;
std::weak_ptr<Device> m_device;
};
......@@ -568,12 +568,12 @@ class NoopDirectory : public fs::IDirectory
abort();
}
virtual const std::vector<std::string>&files() override
virtual const std::vector<std::string>&files() const override
{
abort();
}
virtual const std::vector<std::string>&dirs() override
virtual const std::vector<std::string>&dirs() const override
{
abort();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment