Skip to content

Commit 3e353f6

Browse files
committed
moving Unix folders to Core, implementing VFS base
1 parent e923346 commit 3e353f6

24 files changed

Lines changed: 400 additions & 16 deletions

Engine/Runtime/Includes/Core/ComponentStack.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace Squid
3333
template<typename T>
3434
inline T GetComponentAs(std::size_t index);
3535

36+
// snake_case names to be able to use range based loops
3637
inline iterator begin() { return m_components.begin(); }
3738
inline iterator end() { return m_components.end(); }
3839
inline reverse_iterator rbegin() { return m_components.rbegin(); }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef SQUID_CORE_FILE_HPP__
2+
#define SQUID_CORE_FILE_HPP__
3+
4+
#include <Core/PreCompiled.hpp>
5+
#include <Core/Enums.hpp>
6+
7+
namespace Squid
8+
{
9+
class SQUID_CORE_API File
10+
{
11+
public:
12+
File(const std::filesystem::path& filepaht);
13+
File(const std::filesystem::path& filepath, std::uint32_t flags);
14+
15+
bool Open(std::uint32_t flags);
16+
void Close();
17+
18+
template <typename T>
19+
inline void operator<<(T&& t) { m_stream << std::forward<T>(t); }
20+
21+
inline bool IsOpen() const { return m_stream.is_open(); }
22+
inline bool Exists() const { return std::filesystem::exists(m_filepath); }
23+
24+
inline std::size_t GetSize() const { return std::filesystem::file_size(m_filepath); }
25+
inline std::filesystem::path GetPath() const { return m_filepath; }
26+
inline std::filesystem::path GetDirectory() const { return m_filepath.parent_path(); }
27+
28+
~File() = default;
29+
30+
private:
31+
std::fstream m_stream;
32+
std::filesystem::path m_filepath;
33+
};
34+
}
35+
36+
#endif

Engine/Runtime/Includes/Platform/Unix/PreCompiled.hpp renamed to Engine/Runtime/Includes/Core/Unix/PreCompiled.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#define SQUID_DRIVERS_UNIX_PRE_COMPILED_HEADER_HPP__
33

44
#include <Core/CompilationProfile.hpp>
5-
#include <Platform/Unix/Unix.hpp>
5+
#include <Core/Unix/Unix.hpp>
66
#include <ctime>
7+
78
#ifdef SQUID_PLAT_UNIX
89
#include <unistd.h>
910
#include <signal.h>
File renamed without changes.

Engine/Runtime/Includes/Platform/Unix/UnixInstance.hpp renamed to Engine/Runtime/Includes/Core/Unix/UnixInstance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SQUID_DRIVERS_UNIX_INSTANCE_HPP__
22
#define SQUID_DRIVERS_UNIX_INSTANCE_HPP__
33

4-
#include <Platform/Unix/PreCompiled.hpp>
4+
#include <Core/Unix/PreCompiled.hpp>
55
#include <Core/OS/OSInstance.hpp>
66

77
namespace Squid

Engine/Runtime/Includes/Platform/Unix/UnixLibLoader.hpp renamed to Engine/Runtime/Includes/Core/Unix/UnixLibLoader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SQUID_UNIX_LIB_LOADER_HPP__
22
#define SQUID_UNIX_LIB_LOADER_HPP__
33

4-
#include <Platform/Unix/PreCompiled.hpp>
4+
#include <Core/Unix/PreCompiled.hpp>
55
#include <Core/OS/LibLoader.hpp>
66

77
namespace Squid
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef SQUID_CORE_VIRTUAL_DIRECTORY_HPP__
2+
#define SQUID_CORE_VIRTUAL_DIRECTORY_HPP__
3+
4+
#include <Core/PreCompiled.hpp>
5+
#include <Utils/NonCopyable.hpp>
6+
#include <Core/VirtualPath.hpp>
7+
#include <Core/File.hpp>
8+
9+
namespace Squid
10+
{
11+
struct FileEntry
12+
{
13+
SharedPtr<File> file;
14+
};
15+
16+
struct DirectoryEntry
17+
{
18+
SharedPtr<class VirtualDirectory> virtual_directory;
19+
};
20+
21+
struct Entry
22+
{
23+
std::string name;
24+
std::variant<FileEntry, DirectoryEntry> entry;
25+
26+
Entry(const std::string& n, std::variant<FileEntry, DirectoryEntry> e) : name(n), entry(e) {}
27+
};
28+
29+
class SQUID_CORE_API VirtualDirectory : public NonCopyable, EnableSharedFromThis<VirtualDirectory>
30+
{
31+
public:
32+
VirtualDirectory(const WeakPtr<VirtualDirectory>& parent, const std::string& name);
33+
34+
void MountRealDirectory(const std::filesystem::path& path);
35+
36+
template <typename F>
37+
inline void ForEachEntries(F&& f);
38+
39+
FileEntry GetFileEntry(std::string_view path);
40+
DirectoryEntry GetDirectoryEntry(std::string_view path);
41+
42+
~VirtualDirectory();
43+
44+
private:
45+
void ReleaseFromParent() noexcept;
46+
47+
private:
48+
std::string m_name;
49+
std::vector<std::filesystem::path> m_mounted_directories;
50+
std::vector<Entry> m_entries;
51+
WeakPtr<VirtualDirectory> m_parent;
52+
};
53+
}
54+
55+
#include <Core/VirtualDirectory.inl>
56+
57+
#endif
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include <Core/VirtualDirectory.hpp>
3+
4+
namespace Squid
5+
{
6+
template <typename F>
7+
void VirtualDirectory::ForEachEntries(F&& f)
8+
{
9+
static_assert(std::is_invocable_v<F(const Entry)>, "Squid::VirtualDirectory::ForEachEntries given callback is invalid");
10+
for(auto&& entry : m_entries)
11+
f(std::as_const(entry));
12+
}
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef SQUID_CORE_VIRTUAL_FILE_SYSTEM_HPP__
2+
#define SQUID_CORE_VIRTUAL_FILE_SYSTEM_HPP__
3+
4+
#include <Core/PreCompiled.hpp>
5+
#include <Core/File.hpp>
6+
#include <Core/VirtualPath.hpp>
7+
#include <Core/VirtualDirectory.hpp>
8+
9+
namespace Squid
10+
{
11+
class SQUID_CORE_API VirtualFileSystem
12+
{
13+
friend class CoreModule;
14+
15+
public:
16+
bool CreateVirtualDirectory(std::string_view path, std::string_view directory_name);
17+
bool MountVirtualDirectory(const std::filesystem::path& real_directory, const VirtualPath& virtual_directory);
18+
19+
private:
20+
VirtualFileSystem();
21+
~VirtualFileSystem() = default;
22+
23+
private:
24+
VirtualDirectory m_root;
25+
};
26+
}
27+
28+
#endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef SQUID_CORE_VIRTUAL_PATH_HPP__
2+
#define SQUID_CORE_VIRTUAL_PATH_HPP__
3+
4+
#include <Core/PreCompiled.hpp>
5+
6+
namespace Squid
7+
{
8+
class SQUID_CORE_API VirtualPath
9+
{
10+
public:
11+
VirtualPath() = default;
12+
VirtualPath(std::string_view path);
13+
14+
std::string GetExtension() const;
15+
std::string GetFilename() const;
16+
std::string GetStem() const;
17+
18+
VirtualPath GetParentPath() const;
19+
20+
VirtualPath operator/(const VirtualPath& path);
21+
22+
std::string ToString() const;
23+
24+
inline bool IsEmpty() const noexcept { return m_path_steps.empty(); }
25+
inline void Clear() { m_path_steps.clear(); m_is_absolute = false; }
26+
inline std::size_t GetLength() const { return m_path_steps.size(); }
27+
inline bool IsAbsolute() const noexcept { return m_is_absolute; }
28+
29+
friend std::ostream& operator<<(std::ostream& os, const VirtualPath& path);
30+
31+
~VirtualPath() = default;
32+
33+
private:
34+
std::vector<std::string> m_path_steps;
35+
bool m_is_absolute = false;
36+
};
37+
}
38+
39+
#endif

0 commit comments

Comments
 (0)